1+ /* *
2+ * @brief We use a predefied board (AudioKitEs8388V1) and output a sine
3+ * with the help of the AudioTools I2SCodecStream
4+ * @author phil schatzmann
5+ */
6+
7+ #include " AudioTools.h" // install https://github.com/pschatzmann/arduino-audio-tools
8+ #include " AudioLibs/I2SCodecStream.h"
9+
10+ AudioInfo info (44100 , 2 , 16 );
11+ SineWaveGenerator<int16_t > sineWave (32000 );
12+ GeneratedSoundStream<int16_t > sound (sineWave);
13+ I2SCodecStream out (AudioKitEs8388V1);
14+ StreamCopy copier (out, sound);
15+
16+ void setup () {
17+ // Setup logging
18+ Serial.begin (115200 );
19+ AudioLogger::instance ().begin (Serial, AudioLogger::Info);
20+ LOGLEVEL_AUDIODRIVER = AudioDriverInfo;
21+
22+ // setup pins
23+ // - add i2c codec pins: scl, sda, port, (I2C object)
24+ my_pins.addI2C (CODEC, 32 , 22 , 0x20 , 100000 , Wire);
25+ // - add i2s pins: mclk, bclk, ws, data_out, data_in
26+ my_pins.addI2S (CODEC, 0 , 14 , 15 , 22 );
27+
28+ // start I2S & codec with i2c and i2s configured above
29+ Serial.println (" starting I2S..." );
30+ auto config = out.defaultConfig ();
31+ config.copyFrom (info);
32+ out.begin (config);
33+
34+ // Setup sine wave
35+ sineWave.begin (info, N_B4);
36+ }
37+
38+ // Arduino loop - copy sound to out
39+ void loop () { copier.copy (); }
0 commit comments