1
+ /* *
2
+ * @file channel-converter-bin-diff.ino
3
+ * @author Urs Utzinger
4
+ * @brief On two channels reduce number of samples by binning, then compute difference between two channels
5
+ * @copyright GPLv3
6
+ **/
7
+
8
+ #include " AudioTools.h"
9
+
10
+ #define BINSIZE 4
11
+
12
+ AudioInfo info1 (44100 , 1 , 16 );
13
+ AudioInfo info2 (44100 , 2 , 16 );
14
+ AudioInfo info_out (44100 /BINSIZE, 1 , 16 );
15
+ SineWaveGenerator<int16_t > sineWave1 (16000 ); // subclass of SoundGenerator with max amplitude of 32000
16
+ SineWaveGenerator<int16_t > sineWave2 (16000 ); // subclass of SoundGenerator with max amplitude of 32000
17
+ GeneratedSoundStream<int16_t > sound1 (sineWave1); // stream generated from sine wave
18
+ GeneratedSoundStream<int16_t > sound2 (sineWave2); // stream generated from sine wave
19
+ InputMerge<int16_t > imerge;
20
+ ChannelBinDiff bindiffer; // Binning each channel by average length, setup see below
21
+ ConverterStream<int16_t > converted_stream (imerge, bindiffer); // pipe the merged sound to the converter
22
+ CsvOutput<int16_t > serial_out (Serial); // serial output
23
+ StreamCopy copier (serial_out, converted_stream); // stream the binner output to serial port
24
+
25
+ // Arduino Setup
26
+ void setup (void ) {
27
+ // Open Serial
28
+ Serial.begin (115200 );
29
+ while (!Serial);
30
+
31
+ AudioLogger::instance ().begin (Serial, AudioLogger::Debug); // Info, Warning, Error, Debug
32
+
33
+ // Setup sine wave
34
+ sineWave1.begin (info1, N_B4);
35
+ sineWave2.begin (info1, N_B5);
36
+
37
+ // Merge input to stereo
38
+ imerge.add (sound1);
39
+ imerge.add (sound2);
40
+ imerge.begin (info2);
41
+
42
+ // Setup binning
43
+ bindiffer.setChannels (2 );
44
+ bindiffer.setBits (16 );
45
+ bindiffer.setBinSize (BINSIZE);
46
+ bindiffer.setAverage (true );
47
+
48
+ // Define CSV Output
49
+ serial_out.begin (info_out);
50
+
51
+ }
52
+
53
+ // Arduino loop - copy sound to out with conversion
54
+ void loop () {
55
+ copier.copy ();
56
+ }
0 commit comments