forked from chipaudette/OpenAudio_ArduinoLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioEffectGain_F32.h
58 lines (48 loc) · 1.83 KB
/
AudioEffectGain_F32.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* AudioEffectGain_F32
*
* Created: Chip Audette, November 2016
* Purpose; Apply digital gain to the audio data. Assumes floating-point data.
*
* This processes a single stream fo audio data (ie, it is mono)
*
* MIT License. use at your own risk.
*/
#ifndef _AudioEffectGain_F32_h
#define _AudioEffectGain_F32_h
#include <arm_math.h> //ARM DSP extensions. for speed!
#include <AudioStream_F32.h>
class AudioEffectGain_F32 : public AudioStream_F32
{
//GUI: inputs:1, outputs:1 //this line used for automatic generation of GUI node
public:
//constructor
AudioEffectGain_F32(void) : AudioStream_F32(1, inputQueueArray_f32) {};
AudioEffectGain_F32(const AudioSettings_F32 &settings) : AudioStream_F32(1, inputQueueArray_f32) {};
//here's the method that does all the work
void update(void) {
//Serial.println("AudioEffectGain_F32: updating."); //for debugging.
audio_block_f32_t *block;
block = AudioStream_F32::receiveWritable_f32();
if (!block) return;
//apply the gain
//for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) block->data[i] = gain * (block->data[i]); //non DSP way to do it
arm_scale_f32(block->data, gain, block->data, block->length); //use ARM DSP for speed!
//transmit the block and be done
AudioStream_F32::transmit(block);
AudioStream_F32::release(block);
}
//methods to set parameters of this module
void setGain(float g) { gain = g; }
void setGain_dB(float gain_dB) {
float gain = pow(10.0, gain_dB / 20.0);
setGain(gain);
}
//methods to return information about this module
float getGain(void) { return gain; }
float getGain_dB(void) { return 20.0*log10(gain); }
private:
audio_block_f32_t *inputQueueArray_f32[1]; //memory pointer for the input to this module
float gain = 1.0; //default value
};
#endif