Skip to content

Commit 2c30d64

Browse files
committed
Output Mixer Test
1 parent 86e48bb commit 2c30d64

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

examples/examples-audiokit/streams-generator_outputmixer-audiokit/streams-generator_outputmixer-audiokit.ino

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,51 @@
44
* @author Phil Schatzmann
55
* @copyright GPLv3
66
*/
7-
7+
88
#include "AudioTools.h"
99
#include "AudioTools/AudioLibs/AudioBoardStream.h"
1010

11-
AudioInfo info(32000, 2, 16);
12-
SineWaveGenerator<int16_t> sineWave1(32000); // subclass of SoundGenerator with max amplitude of 32000
13-
SineWaveGenerator<int16_t> sineWave2(32000); // subclass of SoundGenerator with max amplitude of 32000
14-
GeneratedSoundStream<int16_t> sound1(sineWave1); // Stream generated from sine wave
15-
GeneratedSoundStream<int16_t> sound2(sineWave2); // Stream generated from sine wave
11+
AudioInfo info(44100, 2, 16);
12+
const int N = 5;
13+
SineWaveGenerator<int16_t> sineWave[N](32000);
14+
GeneratedSoundStream<int16_t> sound[N];
1615
AudioBoardStream out(AudioKitEs8388V1);
17-
OutputMixer<int16_t> mixer(out, 2); // output mixer with 2 outputs mixing to AudioBoardStream
18-
StreamCopy copier1(mixer, sound1); // copies sound into mixer
19-
StreamCopy copier2(mixer, sound2); // copies sound into mixer
16+
OutputMixer<int16_t> mixer(out, N, DefaultAllocatorRAM);
17+
StreamCopy copier[N](DefaultAllocatorRAM);
2018

2119
// Arduino Setup
22-
void setup(void) {
23-
// Open Serial
20+
void setup(void) {
21+
// Open Serial
2422
Serial.begin(115200);
2523
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
2624

25+
for (int j = 0; j < N; j++) {
26+
sineWave[j].begin(info, 440 * (j + 1));
27+
sound[j].setInput(sineWave[j]);
28+
sound[j].begin(info);
29+
copier[j].begin(mixer, sound[j]);
30+
}
31+
2732
// start I2S
2833
Serial.println("starting I2S...");
2934
auto config = out.defaultConfig(TX_MODE);
30-
config.copyFrom(info);
35+
config.copyFrom(info);
3136
out.begin(config);
3237

33-
// Setup sine wave
34-
sineWave1.begin(info, N_B4);
35-
sineWave2.begin(info, N_E4);
36-
3738
// setup Output mixer with default buffer size
3839
mixer.begin();
3940

4041
Serial.println("started...");
4142
}
4243

43-
// Arduino loop - copy sound to out
44+
// Arduino loop - copy sound to out
4445
void loop() {
45-
// write idx 0 to the mixer
46-
copier1.copy();
47-
// write idx 1 to the mixer and flush (because stream count = 2)
48-
copier2.copy();
49-
50-
// We could flush to force the output but this is not necessary because we were already writing all streams
51-
//mixer.flushMixer();
52-
46+
// write each output
47+
for (int j = 0; j < N; j++) {
48+
copier[j].copy();
49+
}
50+
51+
// We could flush to force the output but this is not necessary because we
52+
// were already writing all streams
53+
// mixer.flushMixer();
5354
}

0 commit comments

Comments
 (0)