Skip to content

Commit 3b882f8

Browse files
committed
some more examples
1 parent 9e0cf30 commit 3b882f8

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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(); }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @brief We just set up the codec for a predefined board (AudioDriverES8388)
3+
* @author phil schatzmann
4+
*/
5+
6+
#include "AudioBoard.h"
7+
8+
void setup() {
9+
// configure codec
10+
CodecConfig cfg;
11+
cfg.adc_input = ADC_INPUT_LINE1;
12+
cfg.dac_output = DAC_OUTPUT_ALL;
13+
cfg.i2s.bits = BIT_LENGTH_16BITS;
14+
cfg.i2s.rate = RATE_44K;
15+
// cfg.i2s.fmt = I2S_NORMAL;
16+
// cfg.i2s.mode = MODE_SLAVE;
17+
AudioDriverES8388.begin(cfg);
18+
}
19+
20+
void loop() {}

0 commit comments

Comments
 (0)