-
Notifications
You must be signed in to change notification settings - Fork 32
/
AudioMixer_F32.cpp
76 lines (65 loc) · 1.99 KB
/
AudioMixer_F32.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Fix 1 to n problem Bob Larkin June 2020
* Adapted to Chip Audette's Tympan routine. Allows random channels.
* Class name does not have "_OA" to be backward compatible.
*
* MIT License. use at your own risk.
*/
#include "AudioMixer_F32.h"
void AudioMixer4_F32::update(void) {
audio_block_f32_t *in, *out=NULL;
int channel = 0;
//get the first available channel
while (channel < 4) {
out = receiveWritable_f32(channel);
if (out) break;
channel++;
}
if (!out) return; //there was no data output array available, so exit.
arm_scale_f32(out->data, multiplier[channel], out->data, out->length);
//add in the remaining channels, as available
channel++;
while (channel < 4) {
in = receiveReadOnly_f32(channel);
if (in) {
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);
} else {
//do nothing, this vector is empty
}
channel++;
}
AudioStream_F32::transmit(out);
AudioStream_F32::release(out);
}
void AudioMixer8_F32::update(void) {
audio_block_f32_t *in, *out=NULL;
//get the first available channel
int channel = 0;
while (channel < 8) {
out = receiveWritable_f32(channel);
if (out) break;
channel++;
}
if (!out) return; //there was no data output array. so exit.
arm_scale_f32(out->data, multiplier[channel], out->data, out->length);
//add in the remaining channels, as available
channel++;
while (channel < 8) {
in = receiveReadOnly_f32(channel);
if (in) {
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);
} else {
//do nothing, this vector is empty
}
channel++;
}
AudioStream_F32::transmit(out);
AudioStream_F32::release(out);
}