-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathstreams-synthbasic1-audiokit.ino
61 lines (51 loc) · 1.81 KB
/
streams-synthbasic1-audiokit.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file streams-synthbasic-audiokit.ino
* @author Phil Schatzmann
* @brief see https://www.pschatzmann.ch/home/2021/12/17/ai-thinker-audio-kit-building-a-simple-synthesizer-with-the-audiotools-library/)
* @copyright GPLv3
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
AudioBoardStream kit(AudioKitEs8388V1);
SineWaveGenerator<int16_t> sine;
GeneratedSoundStream<int16_t> in(sine);
StreamCopy copier(kit, in);
void actionKeyOn(bool active, int pin, void* ptr){
int freq = *((float*)ptr);
sine.setFrequency(freq);
in.begin();
}
void actionKeyOff(bool active, int pin, void* ptr){
in.end();
}
// We want to play some notes on the AudioKit keys
void setupActions(){
// assign buttons to notes
auto act_low = AudioActions::ActiveLow;
static float note[] = {N_C3, N_D3, N_E3, N_F3, N_G3, N_A3}; // frequencies
kit.audioActions().add(kit.getKey(1), actionKeyOn, actionKeyOff, act_low, &(note[0])); // C3
kit.audioActions().add(kit.getKey(2), actionKeyOn, actionKeyOff, act_low, &(note[1])); // D3
kit.audioActions().add(kit.getKey(3), actionKeyOn, actionKeyOff, act_low, &(note[2])); // E3
kit.audioActions().add(kit.getKey(4), actionKeyOn, actionKeyOff, act_low, &(note[3])); // F3
kit.audioActions().add(kit.getKey(5), actionKeyOn, actionKeyOff, act_low, &(note[4])); // G3
kit.audioActions().add(kit.getKey(6), actionKeyOn, actionKeyOff, act_low, &(note[5])); // A3
}
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial,AudioLogger::Info);
// Setup output
auto cfg = kit.defaultConfig(TX_MODE);
cfg.sd_active = false;
kit.begin(cfg);
kit.setVolume(80);
// Setup sound generation based on AudioKit settins
in.begin(cfg);
// activate keys
setupActions();
}
// copy the data
void loop() {
copier.copy();
kit.processActions();
}