Skip to content

Commit

Permalink
fixing drums example on arduino. updating esp32 example with latest i…
Browse files Browse the repository at this point in the history
…2s info
  • Loading branch information
bwhitman committed Aug 7, 2024
1 parent 0900d41 commit 74c86df
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 20 deletions.
21 changes: 11 additions & 10 deletions examples/AMY_Test_ESP32/AMY_Test_ESP32.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <AMY-Arduino.h>
#include <I2S.h>
#include <ESP_I2S.h>

AMY amy;

I2SClass I2S;

void setup() {
// This is if you're using an Alles board, you have to poke 5V_EN to turn on the speaker
Expand All @@ -11,10 +11,9 @@ void setup() {
digitalWrite(21, 1);

// Set your I2S pins. Data/SD/DIN/DOUT, SCK/BLCK, FS/WS/LRCLK.
I2S.setDataPin(27); // 27
I2S.setSckPin(26); // 26
I2S.setFsPin(25); // 25
I2S.begin(I2S_PHILIPS_MODE, AMY_SAMPLE_RATE, BYTES_PER_SAMPLE*8);
// int8_t bclk, int8_t ws, int8_t dout,
I2S.setPins(4, 6, 5, -1, -1);
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);
Expand All @@ -35,16 +34,18 @@ void setup() {
e.velocity = 1;
e.time = clock+2500;
amy.add_event(e);

// Run an example script to start 5s from now
amy.drums(clock+5000, 2);

// Run an example at 5s from now
amy.voice_chord(clock+5000, 0);
// Run an example drum loop to start 10s from now, play twice, stop
amy.drums(clock+7500, 2);

}


void loop() {
// 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_blocking(samples, AMY_BLOCK_SIZE*AMY_NCHANS*BYTES_PER_SAMPLE);
I2S.write((uint8_t*)samples, AMY_BLOCK_SIZE*AMY_NCHANS*BYTES_PER_SAMPLE);
}

5 changes: 5 additions & 0 deletions src/AMY-Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void AMY::reset() {
}


void AMY::reset(uint32_t start) {
example_reset(start);
}

void AMY::restart() {
amy_restart();
}
Expand Down Expand Up @@ -73,6 +77,7 @@ void AMY::drums(uint32_t start, uint16_t loops) {
example_drums(start, loops);
}


void AMY::voice_chord(uint32_t start, uint16_t patch) {
example_voice_chord(start, patch);
}
Expand Down
1 change: 1 addition & 0 deletions src/AMY-Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AMY
void voice_chord(uint32_t start, uint16_t patch);
void fm(uint32_t start);
void reset();
void reset(uint32_t start);
struct event default_event();
void add_event(struct event e);
void send_message(char * message);
Expand Down
7 changes: 5 additions & 2 deletions src/amy-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ int main(int argc, char ** argv) {
example_fm(5000);


// Now just spin for 6s

example_drums(10000,2);

// Now just spin for 15s
uint32_t start = amy_sysclock();
while(amy_sysclock() - start < 6000) {
while(amy_sysclock() - start < 15000) {
if (output_filename) {
int16_t * frames = amy_simple_fill_buffer();
int num_frames = AMY_BLOCK_SIZE;
Expand Down
2 changes: 2 additions & 0 deletions src/amy.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ void amy_profiles_print() { for(uint8_t i=0;i<NO_TAG;i++) { AMY_PROFILE_PRINT(i)
// This defaults PCM size to small. If you want to be different, include "pcm_large.h" or "pcm_tiny.h"
#ifdef ALLES
#include "pcm_large.h"
#elif defined ARDUINO
#include "pcm_tiny.h"
#else
#include "pcm_small.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/amy_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define AMY_SAMPLE_RATE 44100
#ifdef ALLES
#define AMY_NCHANS 1
#elif defined ARDUINO
#define AMY_NCHANS 1
#else
#define AMY_NCHANS 2
#endif
Expand Down
34 changes: 26 additions & 8 deletions src/examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
// set by the arch
extern void delay_ms(uint32_t ms);

void example_reset(uint32_t start) {
struct event e = amy_default_event();
e.osc = 0;
e.reset_osc = 1000;
e.time = start;
amy_add_event(e);
}

void example_voice_alloc() {
// alloc 2 juno voices, then try to alloc a dx7 voice on voice 0
struct event e = amy_default_event();
Expand Down Expand Up @@ -185,32 +193,42 @@ void example_multimbral_fm() {

// Emulate the Tulip "drums()" example via event calls.
void example_drums(uint32_t start, int loops) {
struct event e = amy_default_event();
e.time = start;

float volume = 0.5;

// bd, snare, hat, cow, hicow
int oscs[] = {0, 1, 2, 3, 4};
int patches[] = {1, 5, 0, 10, 10};


// Reset all used oscs first, just in case
for (unsigned int i = 0; i < sizeof(oscs) / sizeof(int); ++i) {
struct event e_reset = amy_default_event();
e_reset.time = start;
e_reset.osc = oscs[i];
e_reset.reset_osc = oscs[i];
amy_add_event(e_reset);
}

struct event e = amy_default_event();
e.time = start + 1;
float volume = 0.5;
e.wave = PCM;
//e.freq = 0;
e.velocity = 0;

for (unsigned int i = 0; i < sizeof(oscs) / sizeof(int); ++i) {
e.osc = oscs[i];
e.patch = patches[i];
amy_add_event(e);
}
// Update high cowbell.
e = amy_default_event();
e.time = start;
e.time = start+1;
e.osc = 4;
e.midi_note = 70;
amy_add_event(e);

// osc 5 : bass
e = amy_default_event();
e.time = start;
e.time = start+1;
e.osc = 5;
e.wave = SAW_DOWN;
e.filter_freq_coefs[COEF_CONST] = 650.0; // LOWEST filter center frequency.
Expand All @@ -231,7 +249,7 @@ void example_drums(uint32_t start, int loops) {
int bassline[] = {50, 0, 0, 0, 50, 52, 51, 0};

e = amy_default_event();
e.time = start;
e.time = start+1;
while (loops--) {
for (unsigned int i = 0; i < sizeof(pattern) / sizeof(int); ++i) {
e.time += 250;
Expand Down
1 change: 1 addition & 0 deletions src/examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ void example_custom_beep();
void example_patches();
void example_voice_chord(uint32_t start, uint16_t patch);
void example_voice_alloc();
void example_reset(uint32_t start);

0 comments on commit 74c86df

Please sign in to comment.