From f13598b968e8b6ece1785aecb749253055576332 Mon Sep 17 00:00:00 2001 From: Chip Audette Date: Sun, 19 Feb 2017 16:06:03 -0500 Subject: [PATCH] Add Mixer8 to Mixer4 and rename files --- AudioMixer4_F32.cpp | 30 -------------- AudioMixer_F32.cpp | 60 +++++++++++++++++++++++++++ AudioMixer4_F32.h => AudioMixer_F32.h | 31 ++++++++++++-- OpenAudio_ArduinoLibrary.h | 2 +- 4 files changed, 89 insertions(+), 34 deletions(-) delete mode 100644 AudioMixer4_F32.cpp create mode 100644 AudioMixer_F32.cpp rename AudioMixer4_F32.h => AudioMixer_F32.h (55%) diff --git a/AudioMixer4_F32.cpp b/AudioMixer4_F32.cpp deleted file mode 100644 index acab10f..0000000 --- a/AudioMixer4_F32.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#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, out->length); - - 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, tmp->length); - arm_add_f32(out->data, tmp->data, out->data, tmp->length); - - release(tmp); - release(in); - } - - if (out) { - transmit(out); - release(out); - } -} diff --git a/AudioMixer_F32.cpp b/AudioMixer_F32.cpp new file mode 100644 index 0000000..59fe8b5 --- /dev/null +++ b/AudioMixer_F32.cpp @@ -0,0 +1,60 @@ +#include "AudioMixer_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, out->length); + + 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, tmp->length); + arm_add_f32(out->data, tmp->data, out->data, tmp->length); + + AudioStream_F32::release(tmp); + AudioStream_F32::release(in); + } + + if (out) { + AudioStream_F32::transmit(out); + AudioStream_F32::release(out); + } +} + +void AudioMixer8_F32::update(void) { + audio_block_f32_t *in, *out=NULL; + + out = receiveWritable_f32(0); //try to get the first input channel + if (!out) return; //if it's not there, return immediately + + arm_scale_f32(out->data, multiplier[0], out->data, out->length); //scale the first input channel + + //load and process the rest of the channels + 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, tmp->length); + arm_add_f32(out->data, tmp->data, out->data, tmp->length); + + AudioStream_F32::release(tmp); + AudioStream_F32::release(in); + } + + if (out) { + AudioStream_F32::transmit(out); + AudioStream_F32::release(out); + } +} diff --git a/AudioMixer4_F32.h b/AudioMixer_F32.h similarity index 55% rename from AudioMixer4_F32.h rename to AudioMixer_F32.h index ac153a5..21b1720 100644 --- a/AudioMixer4_F32.h +++ b/AudioMixer_F32.h @@ -1,23 +1,28 @@ /* - * AudioMixer4 + * AudioMixer * + * 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) + * + * Extended to AudioMixer8 + * By: Chip Audette, OpenAudio, Feb 2017 * * MIT License. use at your own risk. */ -#ifndef AUDIOMIXER4F32_H -#define AUDIOMIXER4F32_H +#ifndef AUDIOMIXER_F32_H +#define AUDIOMIXER_F32_H #include #include class AudioMixer4_F32 : public AudioStream_F32 { //GUI: inputs:4, outputs:1 //this line used for automatic generation of GUI node +//GUI: shortName:Mixer4 public: AudioMixer4_F32() : AudioStream_F32(4, inputQueueArray) { for (int i=0; i<4; i++) multiplier[i] = 1.0; @@ -35,4 +40,24 @@ public: float multiplier[4]; }; +class AudioMixer8_F32 : public AudioStream_F32 { +//GUI: inputs:8, outputs:1 //this line used for automatic generation of GUI node +//GUI: shortName:Mixer8 +public: + AudioMixer8_F32() : AudioStream_F32(8, inputQueueArray) { + for (int i=0; i<8; i++) multiplier[i] = 1.0; + } + + virtual void update(void); + + void gain(unsigned int channel, float gain) { + if (channel >= 8 || channel < 0) return; + multiplier[channel] = gain; + } + + private: + audio_block_f32_t *inputQueueArray[8]; + float multiplier[8]; +}; + #endif \ No newline at end of file diff --git a/OpenAudio_ArduinoLibrary.h b/OpenAudio_ArduinoLibrary.h index 9cba9aa..4868ab5 100644 --- a/OpenAudio_ArduinoLibrary.h +++ b/OpenAudio_ArduinoLibrary.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "input_i2s_f32.h" #include "play_queue_f32.h"