This commit is contained in:
2026-02-12 21:00:02 -08:00
parent 77f8236347
commit 8bdbf227ca
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
# Implementing a Synthesizer using the STK Framwork
We can use the STK framework to implement a Synthesizer which receives Midi Messages and translates them
into sound. Here we use a Clarinet...
We demo how to use the Stream output classes provided by STK.
For [further info see my blog](https://www.pschatzmann.ch/home/2021/12/21/ai-thinker-audiokit-a-simply-synthesizer-with-stk/)
### Dependencies
- https://github.com/pschatzmann/arduino-audio-tools
- https://github.com/pschatzmann/arduino-audio-driver
- https://github.com/pschatzmann/arduino-midi
- https://github.com/pschatzmann/Arduino-STK

View File

@@ -0,0 +1,65 @@
/**
* @file streams-synthstk-audiokit.ino
* @brief see https://www.pschatzmann.ch/home/2021/12/17/ai-thinker-audiokit-a-simple-synthesizer-with-stk/
* @author Phil Schatzmann
* @copyright Copyright (c) 2021
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver
#include "StkAll.h" // install https://github.com/pschatzmann/Arduino-STK
AudioBoardStream kit(AudioKitEs8388V1);
Clarinet clarinet(440);
Voicer voicer;
ArdStreamOut output(&kit);
float noteAmplitude = 128;
int group = 0;
void actionKeyOn(bool active, int pin, void* ptr){
float note = *((float*)ptr);
voicer.noteOn(note, noteAmplitude, group);
}
void actionKeyOff(bool active, int pin, void* ptr){
float note = *((float*)ptr);
voicer.noteOff(note, noteAmplitude, group);
}
// We want to play some notes on the AudioKit keys
void setupActions(){
// assign buttons to notes
auto act_low = AudioActions::ActiveLow;
static int note[] = {48,50,52,53,55,57}; // midi keys
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::Warning);
voicer.addInstrument(&clarinet, group);
// define data format
auto cfg = kit.defaultConfig(TX_MODE);
cfg.channels = 1;
cfg.bits_per_sample = 16;
cfg.sample_rate = Stk::sampleRate();
cfg.sd_active = false;
kit.begin(cfg);
// play notes with keys
setupActions();
}
void loop() {
for (int j=0;j<1024;j++) {
output.tick( voicer.tick() );
}
kit.processActions();
}