commit
5e0cc472fd
@ -0,0 +1,30 @@ |
||||
#include "AudioMixer4_F32.h" |
||||
|
||||
void AudioMixer4_F32::update(void) { |
||||
audio_block_f32_t *in, *out=NULL; |
||||
|
||||
out = receiveWritable_f32(0); |
||||
if (!out) return; |
||||
|
||||
arm_scale_f32(out->data, multiplier[0], out->data, AUDIO_BLOCK_SAMPLES); |
||||
|
||||
for (int channel=1; channel < 4; channel++) { |
||||
in = receiveReadOnly_f32(channel); |
||||
if (!in) { |
||||
continue; |
||||
} |
||||
|
||||
audio_block_f32_t *tmp = allocate_f32(); |
||||
|
||||
arm_scale_f32(in->data, multiplier[channel], tmp->data, AUDIO_BLOCK_SAMPLES); |
||||
arm_add_f32(out->data, tmp->data, out->data, AUDIO_BLOCK_SAMPLES); |
||||
|
||||
release(tmp); |
||||
release(in); |
||||
} |
||||
|
||||
if (out) { |
||||
transmit(out); |
||||
release(out); |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
/*
|
||||
* AudioMixer4 |
||||
*
|
||||
* Created: Patrick Radius, December 2016 |
||||
* Purpose: Mix up to 4 audio channels with individual gain controls. |
||||
* Assumes floating-point data. |
||||
*
|
||||
* This processes a single stream fo audio data (ie, it is mono)
|
||||
*
|
||||
* MIT License. use at your own risk. |
||||
*/ |
||||
|
||||
#ifndef AUDIOMIXER4F32_H |
||||
#define AUDIOMIXER4F32_H |
||||
|
||||
#include <arm_math.h> |
||||
#include <AudioStream_F32.h> |
||||
|
||||
class AudioMixer4_F32 : public AudioStream_F32 { |
||||
public: |
||||
AudioMixer4_F32() : AudioStream_F32(4, inputQueueArray) { |
||||
for (int i=0; i<4; i++) multiplier[i] = 1.0; |
||||
} |
||||
|
||||
virtual void update(void); |
||||
|
||||
void gain(unsigned int channel, float gain) { |
||||
if (channel >= 4 || channel < 0) return; |
||||
multiplier[channel] = gain; |
||||
} |
||||
|
||||
private: |
||||
audio_block_f32_t *inputQueueArray[4]; |
||||
float multiplier[4]; |
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue