ソースを参照

Add AudioSynthNoiseWhite

dds
PaulStoffregen 10年前
コミット
7163cbba4a
6個のファイルの変更174行の追加0行の削除
  1. +1
    -0
      Audio.h
  2. +43
    -0
      gui/list.html
  3. バイナリ
      gui/whitenoise.png
  4. +1
    -0
      keywords.txt
  5. +82
    -0
      synth_whitenoise.cpp
  6. +47
    -0
      synth_whitenoise.h

+ 1
- 0
Audio.h ファイルの表示

@@ -74,6 +74,7 @@
#include "synth_sine.h"
#include "synth_waveform.h"
#include "synth_dc.h"
#include "synth_whitenoise.h"
#include "multiplier.h"

// TODO: more audio processing objects....

+ 43
- 0
gui/list.html ファイルの表示

@@ -859,6 +859,49 @@
</script>


<script type="text/javascript">
RED.nodes.registerType('AudioSynthNoiseWhite',{
shortName: "noise",
inputs:0,
outputs:1,
category: 'synth-function',
color:"#E6E0F8",
icon: "arrow-in.png"
});
</script>
<script type="text/x-red" data-help-name="AudioSynthNoiseWhite">
<h3>Summary</h3>
<div>
<p>Create white noise.
</p>
<p align=center><img src="whitenoise.png"></p>
</div>
<h3>Audio Connections</h3>
<table class=doc align=center cellpadding=3>
<tr class=top><th>Port</th><th>Purpose</th></tr>
<tr class=odd><td align=center>Out 0</td><td>White Noise</td></tr>
</table>
<h3>Functions</h3>
<p class=func><span class=keyword>amplitude</span>(level);</p>
<p class=desc>Set the output peak level, from 0 (off) to 1.0.
The default is off. Noise is generated only after setting
to a non-zero level.
</p>
<h3>Notes</h3>
<p>Setting the amplitude to zero causes this object to stop using
CPU time to generate random numbers.
</p>
</script>
<script type="text/x-red" data-template-name="AudioSynthNoiseWhite">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>





<script type="text/javascript">
RED.nodes.registerType('AudioEffectFade',{

バイナリ
gui/whitenoise.png ファイルの表示

変更前 変更後
幅: 240  |  高さ: 86  |  サイズ: 20KB

+ 1
- 0
keywords.txt ファイルの表示

@@ -30,6 +30,7 @@ AudioSynthWaveform KEYWORD2
AudioSynthWaveformSine KEYWORD2
AudioSynthWaveformSineModulated KEYWORD2
AudioSynthWaveformDc KEYWORD2
AudioSynthNoiseWhite KEYWORD2
isPlaying KEYWORD2
positionMillis KEYWORD2
lengthMillis KEYWORD2

+ 82
- 0
synth_whitenoise.cpp ファイルの表示

@@ -0,0 +1,82 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "synth_whitenoise.h"

// Park-Miller-Carta Pseudo-Random Number Generator
// http://www.firstpr.com.au/dsp/rand31/

void AudioSynthNoiseWhite::update(void)
{
audio_block_t *block;
uint32_t *p, *end;
int32_t n1, n2, gain;
uint32_t lo, hi, val1, val2;

gain = level;
if (gain == 0) return;
block = allocate();
if (!block) return;
p = (uint32_t *)(block->data);
end = p + AUDIO_BLOCK_SAMPLES/2;
lo = seed;
do {
hi = multiply_16bx16t(16807, lo); // 16807 * (lo >> 16)
lo = 16807 * (lo & 0xFFFF);
lo += (hi & 0x7FFF) << 16;
lo += hi >> 15;
lo = (lo & 0x7FFFFFFF) + (lo >> 31);
n1 = signed_multiply_32x16b(gain, lo);
hi = multiply_16bx16t(16807, lo); // 16807 * (lo >> 16)
lo = 16807 * (lo & 0xFFFF);
lo += (hi & 0x7FFF) << 16;
lo += hi >> 15;
lo = (lo & 0x7FFFFFFF) + (lo >> 31);
n2 = signed_multiply_32x16b(gain, lo);
val1 = pack_16b_16b(n2, n1);
hi = multiply_16bx16t(16807, lo); // 16807 * (lo >> 16)
lo = 16807 * (lo & 0xFFFF);
lo += (hi & 0x7FFF) << 16;
lo += hi >> 15;
lo = (lo & 0x7FFFFFFF) + (lo >> 31);
n1 = signed_multiply_32x16b(gain, lo);
hi = multiply_16bx16t(16807, lo); // 16807 * (lo >> 16)
lo = 16807 * (lo & 0xFFFF);
lo += (hi & 0x7FFF) << 16;
lo += hi >> 15;
lo = (lo & 0x7FFFFFFF) + (lo >> 31);
n2 = signed_multiply_32x16b(gain, lo);
val2 = pack_16b_16b(n2, n1);
*p++ = val1;
*p++ = val2;
} while (p < end);
seed = lo;
transmit(block);
release(block);
}




+ 47
- 0
synth_whitenoise.h ファイルの表示

@@ -0,0 +1,47 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef synth_whitenoise_h_
#define synth_whitenoise_h_
#include "AudioStream.h"
#include "utility/dspinst.h"

class AudioSynthNoiseWhite : public AudioStream
{
public:
AudioSynthNoiseWhite() : AudioStream(0, NULL), level(0), seed(1) {}
void amplitude(float n) {
if (n < 0.0) n = 0.0;
else if (n > 1.0) n = 1.0;
level = (int32_t)(n * 65536.0);
}
virtual void update(void);
private:
int32_t level; // 0=off, 65536=max
uint32_t seed; // must start at 1
};

#endif

読み込み中…
キャンセル
保存