ソースを参照

Add simple AudioAmplifier

dds
PaulStoffregen 6年前
コミット
bebf5dce98
4個のファイルの変更85行の追加5行の削除
  1. +38
    -0
      gui/index.html
  2. +1
    -0
      keywords.txt
  3. +26
    -1
      mixer.cpp
  4. +20
    -4
      mixer.h

+ 38
- 0
gui/index.html ファイルの表示

@@ -363,6 +363,7 @@ span.mainfunction {color: #993300; font-weight: bolder}
{"type":"AudioOutputTDM","data":{"defaults":{"name":{"value":"new"}},"shortName":"tdm","inputs":16,"outputs":0,"category":"output-function","color":"#E6E0F8","icon":"arrow-in.png"}},
{"type":"AudioOutputADAT","data":{"defaults":{"name":{"value":"new"}},"shortName":"adat","inputs":8,"outputs":0,"category":"output-function","color":"#E6E0F8","icon":"arrow-in.png"}},
{"type":"AudioOutputUSB","data":{"defaults":{"name":{"value":"new"}},"shortName":"usb","inputs":2,"outputs":0,"category":"output-function","color":"#E6E0F8","icon":"arrow-in.png"}},
{"type":"AudioAmplifier","data":{"defaults":{"name":{"value":"new"}},"shortName":"amp","inputs":1,"outputs":1,"category":"mixer-function","color":"#E6E0F8","icon":"arrow-in.png"}},
{"type":"AudioMixer4","data":{"defaults":{"name":{"value":"new"}},"shortName":"mixer","inputs":4,"outputs":1,"category":"mixer-function","color":"#E6E0F8","icon":"arrow-in.png"}},
{"type":"AudioPlayMemory","data":{"defaults":{"name":{"value":"new"}},"shortName":"playMem","inputs":0,"outputs":1,"category":"play-function","color":"#E6E0F8","icon":"arrow-in.png"}},
{"type":"AudioPlaySdWav","data":{"defaults":{"name":{"value":"new"}},"shortName":"playSdWav","inputs":0,"outputs":2,"category":"play-function","color":"#E6E0F8","icon":"arrow-in.png"}},
@@ -1401,6 +1402,43 @@ span.mainfunction {color: #993300; font-weight: bolder}
</div>
</script>

<script type="text/x-red" data-help-name="AudioAmplifier">
<h3>Summary</h3>
<div class=tooltipinfo>
<p>Amplify or attenuate a signal, or switch it on/off.
</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>In 0</td><td>Input signal</td></tr>
<tr class=odd><td align=center>Out 0</td><td>Amplified/Attn. Output</td></tr>
</table>
<h3>Functions</h3>
<p class=func><span class=keyword>gain</span>(level);</p>
<p class=desc>Adjust the amplification or attenuation.
"level" may be any floating point number from 0 to 32767.0.
1.0 passes the signal through directly. Level of 0 shuts the channel
off completely. Between 0 to 1.0 attenuates the signal, and above
1.0 amplifies it. Negative numbers may also be used, to invert the
signal.
</p>
<!--<h3>Examples</h3>
<p class=exam>File &gt; Examples &gt; Audio &gt; SamplePlayer
</p>-->
<h3>Notes</h3>
<p>Gain of 0 and 1.0 are handled efficiently as special cases. Zero
discards data without processing. 1.0 passes data directly, with
minimal overhead</p>
<p>Signal clipping can occur when any channel has gain greater than 1.0</p>
</script>
<script type="text/x-red" data-template-name="AudioAmplifier">
<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/x-red" data-help-name="AudioMixer4">
<h3>Summary</h3>
<div class=tooltipinfo>

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

@@ -51,6 +51,7 @@ AudioFilterStateVariable KEYWORD2
AudioInputAnalog KEYWORD2
AudioInputAnalogStereo KEYWORD2
AudioMixer4 KEYWORD2
AudioAmplifier KEYWORD2
AudioOutputAnalog KEYWORD2
AudioOutputAnalogStereo KEYWORD2
AudioPlayMemory KEYWORD2

+ 26
- 1
mixer.cpp ファイルの表示

@@ -131,4 +131,29 @@ void AudioMixer4::update(void)
}
}


void AudioAmplifier::update(void)
{
audio_block_t *block;
int32_t mult = multiplier;

if (mult == 0) {
// zero gain, discard any input and transmit nothing
block = receiveReadOnly(0);
if (block) release(block);
} else if (mult == MULTI_UNITYGAIN) {
// unity gain, pass input to output without any change
block = receiveReadOnly(0);
if (block) {
transmit(block);
release(block);
}
} else {
// apply gain to signal
block = receiveWritable(0);
if (block) {
applyGain(block->data, mult);
transmit(block);
release(block);
}
}
}

+ 20
- 4
mixer.h ファイルの表示

@@ -34,10 +34,10 @@ class AudioMixer4 : public AudioStream
{
#if defined(KINETISK)
public:
AudioMixer4(void) : AudioStream(4, inputQueueArray) {
AudioMixer4(void) : AudioStream(4, inputQueueArray) {
for (int i=0; i<4; i++) multiplier[i] = 65536;
}
virtual void update(void);
virtual void update(void);
void gain(unsigned int channel, float gain) {
if (channel >= 4) return;
if (gain > 32767.0f) gain = 32767.0f;
@@ -50,10 +50,10 @@ private:

#elif defined(KINETISL)
public:
AudioMixer4(void) : AudioStream(4, inputQueueArray) {
AudioMixer4(void) : AudioStream(4, inputQueueArray) {
for (int i=0; i<4; i++) multiplier[i] = 256;
}
virtual void update(void);
virtual void update(void);
void gain(unsigned int channel, float gain) {
if (channel >= 4) return;
if (gain > 127.0f) gain = 127.0f;
@@ -66,4 +66,20 @@ private:
#endif
};

class AudioAmplifier : public AudioStream
{
public:
AudioAmplifier(void) : AudioStream(1, inputQueueArray), multiplier(65536) {
}
virtual void update(void);
void gain(float n) {
if (n > 32767.0f) n = 32767.0f;
else if (n < -32767.0f) n = -32767.0f;
multiplier = n * 65536.0f;
}
private:
int32_t multiplier;
audio_block_t *inputQueueArray[1];
};

#endif

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