|
4 | 4 | * @author Phil Schatzmann
|
5 | 5 | * @copyright GPLv3
|
6 | 6 | */
|
7 |
| - |
| 7 | + |
8 | 8 | #include "AudioTools.h"
|
9 | 9 | #include "AudioTools/AudioLibs/AudioBoardStream.h"
|
10 | 10 |
|
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]; |
16 | 15 | 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); |
20 | 18 |
|
21 | 19 | // Arduino Setup
|
22 |
| -void setup(void) { |
23 |
| - // Open Serial |
| 20 | +void setup(void) { |
| 21 | + // Open Serial |
24 | 22 | Serial.begin(115200);
|
25 | 23 | AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
26 | 24 |
|
| 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 | + |
27 | 32 | // start I2S
|
28 | 33 | Serial.println("starting I2S...");
|
29 | 34 | auto config = out.defaultConfig(TX_MODE);
|
30 |
| - config.copyFrom(info); |
| 35 | + config.copyFrom(info); |
31 | 36 | out.begin(config);
|
32 | 37 |
|
33 |
| - // Setup sine wave |
34 |
| - sineWave1.begin(info, N_B4); |
35 |
| - sineWave2.begin(info, N_E4); |
36 |
| - |
37 | 38 | // setup Output mixer with default buffer size
|
38 | 39 | mixer.begin();
|
39 | 40 |
|
40 | 41 | Serial.println("started...");
|
41 | 42 | }
|
42 | 43 |
|
43 |
| -// Arduino loop - copy sound to out |
| 44 | +// Arduino loop - copy sound to out |
44 | 45 | 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(); |
53 | 54 | }
|
0 commit comments