Skip to content

Commit d1ee081

Browse files
committed
streams-generator_sinfromtable-audiokit.ino
1 parent f166ee0 commit d1ee081

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @file streams-generator_sinfromtable-audiokit.ino
3+
* @brief Tesing SineFromTable with output on audiokit
4+
* @author Phil Schatzmann
5+
* @copyright GPLv3
6+
*/
7+
8+
#include "AudioTools.h"
9+
#include "AudioLibs/AudioKit.h"
10+
11+
uint16_t sample_rate=32000;
12+
uint8_t channels = 2; // The stream will have 2 channels
13+
SineFromTable<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
14+
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
15+
AudioKitStream out;
16+
//CsvStream<int16_t> out(Serial);
17+
int sound_len=1024;
18+
StreamCopy copier(out, sound, sound_len); // copies sound into i2s
19+
int freq = 122;
20+
21+
// Arduino Setup
22+
void setup(void) {
23+
// Open Serial
24+
Serial.begin(115200);
25+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
26+
27+
// start I2S
28+
Serial.println("starting I2S...");
29+
auto config = out.defaultConfig(); //TX_MODE
30+
config.sample_rate = sample_rate;
31+
config.channels = channels;
32+
config.bits_per_sample = 16;
33+
out.begin(config);
34+
35+
// Setup sine wave
36+
auto cfg = sineWave.defaultConfig();
37+
cfg.channels = channels;
38+
cfg.sample_rate = sample_rate;
39+
sineWave.begin(cfg, N_B4);
40+
Serial.println("started...");
41+
}
42+
43+
// Arduino loop - copy sound to out
44+
void loop() {
45+
copier.copy();
46+
// increase frequency
47+
freq += 10;
48+
if (freq>=10000){
49+
freq = 20;
50+
}
51+
sineWave.setFrequency(freq);
52+
}

0 commit comments

Comments
 (0)