Created
September 16, 2024 18:00
-
-
Save Visuelle-Musik/b7fbfd9c8b656c84876ce82aa16fdd07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AMY-Arduino.h" | |
AMY amy; | |
// --- I2S Driver --- | |
#include <ESP_I2S.h> | |
I2SClass I2S; | |
// --- Initialize everything --- | |
void setup() | |
{ | |
// --- Start up AMY --- | |
amy.begin(1, 0, 1, 0); // Cores==2, Reverb==0, Chorus==1, Echo==0 | |
// --- Serial stuff (Serial Monitor output and IMDI in) --- | |
Serial.begin(115200); | |
// --- Set and start I2S --- | |
I2S.setPins(13, 11, 12, -1, -1); // MB 20240807 | |
I2S.begin(I2S_MODE_STD, AMY_SAMPLE_RATE, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); // I2S.begin(I2S_PHILIPS_MODE, AMY_SAMPLE_RATE, BYTES_PER_SAMPLE8); | |
} | |
// --- Main loop function --- | |
void loop() | |
{ | |
int num_partials = 16; | |
float base_freq = 261.63; | |
int base_osc = 0; | |
struct event e = amy.default_event(); | |
e.time=0; | |
e.osc=base_osc; | |
e.wave=PARTIALS; | |
sprintf(e.algo_source,"%d",num_partials); | |
amy.add_event(e); | |
for(int i=1; i< num_partials+1; i++) | |
{ | |
// Set up each partial as the corresponding harmonic of the base_freq, with an amplitude of 1/N, 50ms attack, and a decay of 1 sec / N | |
e = amy.default_event(); | |
e.osc=base_osc+i; | |
e.wave=PARTIAL; | |
e.freq_coefs[COEF_CONST]=base_freq*i; | |
sprintf(e.bp0,"50,%.2f,%d,0,0,0", 1.f/i, 1000/i); | |
amy.add_event(e); | |
} | |
e = amy.default_event(); | |
e.time=100; | |
e.osc=0; | |
e.midi_note=60; | |
e.velocity=0.5; | |
amy.add_event(e); | |
e = amy.default_event(); | |
e.time=200; | |
e.osc=0; | |
e.midi_note=72; | |
e.velocity=1; | |
amy.add_event(e); | |
// --- Render the amy-events from above to audio --- | |
while(true) | |
{ | |
short* samples = amy.render_to_buffer(); | |
I2S.write((uint8_t*)samples, AMY_BLOCK_SIZE*AMY_NCHANS*BYTES_PER_SAMPLE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment