From f9a0e09cf9e44821d15a9ba5263f12de522d9041 Mon Sep 17 00:00:00 2001
From: patrick-radius
Date: Sat, 31 Dec 2016 12:53:45 +0100
Subject: [PATCH 1/2] Added mixer
---
AudioMixer4_F32.cpp | 30 ++++++++++++++++++++++++++++++
AudioMixer4_F32.h | 28 ++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
create mode 100644 AudioMixer4_F32.cpp
create mode 100644 AudioMixer4_F32.h
diff --git a/AudioMixer4_F32.cpp b/AudioMixer4_F32.cpp
new file mode 100644
index 0000000..40e9757
--- /dev/null
+++ b/AudioMixer4_F32.cpp
@@ -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);
+ }
+}
diff --git a/AudioMixer4_F32.h b/AudioMixer4_F32.h
new file mode 100644
index 0000000..524087a
--- /dev/null
+++ b/AudioMixer4_F32.h
@@ -0,0 +1,28 @@
+#ifndef AUDIOMIXER4F32_H
+#define AUDIOMIXER4F32_H
+
+#include
+#include
+
+
+class AudioMixer4_F32 : public AudioStream_F32 {
+public:
+ AudioMixer4_F32() : AudioStream_F32(4, inputQueueArray) {
+ for (int i=0; i<4; i++) multiplier[i] = 0.5;
+ }
+
+ virtual void update(void);
+
+ void gain(unsigned int channel, float gain) {
+ if (channel >= 4) return;
+ if (gain > 127.0f) gain = 127.0f;
+ else if (gain < 0.0f) gain = 0.0f;
+ multiplier[channel] = gain;
+ }
+
+ private:
+ audio_block_f32_t *inputQueueArray[4];
+ float multiplier[4];
+};
+
+#endif
\ No newline at end of file
From dac6bf4ad4763cd7f4031aea5b9ed6777522004b Mon Sep 17 00:00:00 2001
From: patrick-radius
Date: Mon, 2 Jan 2017 10:32:05 +0100
Subject: [PATCH 2/2] Added license block and remove arbitrary limits. Added
array lowerbound check
---
AudioMixer4_F32.h | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/AudioMixer4_F32.h b/AudioMixer4_F32.h
index 524087a..0b7af83 100644
--- a/AudioMixer4_F32.h
+++ b/AudioMixer4_F32.h
@@ -1,22 +1,31 @@
+/*
+ * 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
#include
-
class AudioMixer4_F32 : public AudioStream_F32 {
public:
AudioMixer4_F32() : AudioStream_F32(4, inputQueueArray) {
- for (int i=0; i<4; i++) multiplier[i] = 0.5;
+ 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) return;
- if (gain > 127.0f) gain = 127.0f;
- else if (gain < 0.0f) gain = 0.0f;
+ if (channel >= 4 || channel < 0) return;
multiplier[channel] = gain;
}