Add Mixer8 to Mixer4 and rename files

feature_setBlockSize
Chip Audette 8 years ago
parent 324d2bbef0
commit f13598b968
  1. 30
      AudioMixer4_F32.cpp
  2. 60
      AudioMixer_F32.cpp
  3. 31
      AudioMixer_F32.h
  4. 2
      OpenAudio_ArduinoLibrary.h

@ -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);
}
}

@ -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);
}
}

@ -1,23 +1,28 @@
/* /*
* AudioMixer4 * AudioMixer
* *
* AudioMixer4
* Created: Patrick Radius, December 2016 * Created: Patrick Radius, December 2016
* Purpose: Mix up to 4 audio channels with individual gain controls. * Purpose: Mix up to 4 audio channels with individual gain controls.
* Assumes floating-point data. * Assumes floating-point data.
* *
* This processes a single stream fo audio data (ie, it is mono) * 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. * MIT License. use at your own risk.
*/ */
#ifndef AUDIOMIXER4F32_H #ifndef AUDIOMIXER_F32_H
#define AUDIOMIXER4F32_H #define AUDIOMIXER_F32_H
#include <arm_math.h> #include <arm_math.h>
#include <AudioStream_F32.h> #include <AudioStream_F32.h>
class AudioMixer4_F32 : public AudioStream_F32 { class AudioMixer4_F32 : public AudioStream_F32 {
//GUI: inputs:4, outputs:1 //this line used for automatic generation of GUI node //GUI: inputs:4, outputs:1 //this line used for automatic generation of GUI node
//GUI: shortName:Mixer4
public: public:
AudioMixer4_F32() : AudioStream_F32(4, inputQueueArray) { AudioMixer4_F32() : AudioStream_F32(4, inputQueueArray) {
for (int i=0; i<4; i++) multiplier[i] = 1.0; for (int i=0; i<4; i++) multiplier[i] = 1.0;
@ -35,4 +40,24 @@ public:
float multiplier[4]; 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 #endif

@ -7,7 +7,7 @@
#include <AudioEffectCompressor_F32.h> #include <AudioEffectCompressor_F32.h>
#include <AudioFilterFIR_F32.h> #include <AudioFilterFIR_F32.h>
#include <AudioFilterIIR_F32.h> #include <AudioFilterIIR_F32.h>
#include <AudioMixer4_F32.h> #include <AudioMixer_F32.h>
#include <AudioMultiply_F32.h> #include <AudioMultiply_F32.h>
#include "input_i2s_f32.h" #include "input_i2s_f32.h"
#include "play_queue_f32.h" #include "play_queue_f32.h"

Loading…
Cancel
Save