Last active
August 8, 2024 17:32
-
-
Save Visuelle-Musik/f2b1cab6df605b6f627f4db3a4f89619 to your computer and use it in GitHub Desktop.
AMY_Test_ESP32_add_event_glitch.ino
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> | |
#include <ESP_I2S.h> | |
AMY amy; | |
I2SClass I2S; | |
struct event e = amy.default_event(); | |
long my_clock = amy.sysclock(); | |
void setup() | |
{ | |
// This is if you're using an Alles board, you have to poke 5V_EN to turn on the speaker | |
// You can ignore this if you're not using an Alles | |
// pinMode(21, OUTPUT); // ### MB 20240807 | |
// digitalWrite(21, 1); // ### MB 20240807 | |
// Set your I2S pins. Data/SD/DIN/DOUT, SCK/BLCK, FS/WS/LRCLK. | |
// int8_t bclk, int8_t ws, int8_t dout, | |
I2S.setPins(4, 6, 5, -1, -1); // Original settings! | |
// 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_MONO); // I2S.begin(I2S_PHILIPS_MODE, AMY_SAMPLE_RATE, BYTES_PER_SAMPLE8); | |
// Start up AMY | |
amy.begin(/* cores= */ 1, /* reverb= */ 0, /* chorus= */ 0); | |
// Send AMY messages in two ways: first, using the wire protocol: | |
// This sends a sine wave at 220Hz on osc 0 with velocity 1 | |
amy.send_message("v0f220l1"); | |
// The second way is to use the structure directly | |
// We fill in an event struct with what we want and "schedule" it for 2.5 seconds from now | |
e.osc = 0; | |
e.wave = SINE; | |
e.freq_coefs[COEF_CONST] = 440; | |
e.velocity = 1; | |
e.time = my_clock+2500; | |
amy.add_event(e); | |
/* ### MB 20240807 ============================= | |
// reset everything at 5000ms | |
amy.reset(my_clock+5000); | |
// Constructed FM example, plays a bell-like tone | |
amy.fm(my_clock+5001); | |
// Reset everything at 7500ms | |
amy.reset(my_clock+7500); | |
// Run an example drum loop to start 7500ms from now, play twice, stop | |
amy.drums(my_clock+7501, 8); | |
### MB 20240807 ================================= */ | |
} | |
void loop() | |
{ | |
static long next_action_time = amy.sysclock()+100; // ### MB 20240808 | |
static float frequency = 440.f; | |
// In your loop you have to get the buffer of samples and then play it out your device | |
short * samples = amy.render_to_buffer(); | |
I2S.write((uint8_t*)samples, AMY_BLOCK_SIZE*AMY_NCHANS*BYTES_PER_SAMPLE); | |
my_clock = amy.sysclock(); | |
if(my_clock > next_action_time) | |
{ | |
frequency += 0.5f; | |
if(frequency > 4400.f) | |
frequency = 440.f; | |
e.freq_coefs[COEF_CONST] = frequency; | |
amy.add_event(e); | |
next_action_time = amy.sysclock()+100; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment