Skip to content

Commit

Permalink
amy.c: Direct calls to amy_add_event will pick up any nonempty bp str…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
dpwe committed Mar 17, 2024
1 parent 54232e6 commit 966806b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/amy-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ int main(int argc, char ** argv) {


amy_reset_oscs();
example_voice_chord(0, 128);
//example_voice_chord(0, 128);
//example_drums(0, 4);
example_fm(0);

// Now just spin for 10s
while(amy_sysclock() - start < 5000) {
Expand All @@ -82,7 +83,7 @@ int main(int argc, char ** argv) {
}
usleep(THREAD_USLEEP);
}
show_debug(3);
show_debug(9);

if (output_filename) {
ma_encoder_uninit(&encoder);
Expand Down
5 changes: 3 additions & 2 deletions src/amy.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ void amy_add_event_internal(struct event e, uint16_t base_osc) {

char * bps[MAX_BREAKPOINT_SETS] = {e.bp0, e.bp1};
for(uint8_t i=0;i<MAX_BREAKPOINT_SETS;i++) {
//if(bps[i][0] != 0) {
if(AMY_IS_SET(e.bp_is_set[i])) {
// amy_parse_message sets bp_is_set for anything including an empty string,
// but direct calls to amy_add_event can just put a nonempty string into bp0/1.
if(AMY_IS_SET(e.bp_is_set[i]) || bps[i][0] != 0) {
struct synthinfo t;
parse_breakpoint(&t, bps[i], i);
for(uint8_t j=0;j<MAX_BREAKPOINTS;j++) {
Expand Down
56 changes: 47 additions & 9 deletions src/examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ void example_drums(uint32_t start, int loops) {

e = amy_default_event();
e.time = start;
int last_bass_was_on = 0;
int actually_send_the_bass;
while (loops--) {
for (unsigned int i = 0; i < sizeof(pattern) / sizeof(int); ++i) {
e.time += 250;
Expand Down Expand Up @@ -272,20 +270,60 @@ void example_drums(uint32_t start, int loops) {
if(bassline[i]>0) {
e.velocity = 0.5 * volume;
e.midi_note = bassline[i] - 12;
//last_bass_was_on = 1;
//actually_send_the_bass = 1;
} else {
//actually_send_the_bass = last_bass_was_on;
e.velocity = 0;
//last_bass_was_on = 0;
}
//if (actually_send_the_bass) {
amy_add_event(e);
//}
amy_add_event(e);
}
}
}

void example_fm(uint32_t start) {
// Direct construction of an FM tone, as in the documentation.
struct event e;

// Output oscillator (op 1)
e = amy_default_event();
e.time = start;
e.osc = 0;
e.wave = SINE;
e.ratio = 0.2f;
e.amp_coefs[COEF_CONST] = 0.1f;
e.amp_coefs[COEF_VEL] = 0;
e.amp_coefs[COEF_EG0] = 1.0f;
strcpy(e.bp0, "0,1,1000,0,0,0");
amy_add_event(e);

// Modulating oscillator (op 2)
e = amy_default_event();
e.time = start;
e.osc = 1;
e.wave = SINE;
e.ratio = 1.0f;
e.amp_coefs[COEF_CONST] = 1.0f;
e.amp_coefs[COEF_VEL] = 0;
e.amp_coefs[COEF_EG0] = 0;
amy_add_event(e);

// ALGO control oscillator
e = amy_default_event();
e.time = start;
e.osc = 2;
e.wave = ALGO;
e.algorithm = 1; // algo 1 has op 2 driving op 1 driving output (plus a second chain for ops 6,5,4,3).
strcpy(e.algo_source, "-1,-1,-1,-1,1,0");
amy_add_event(e);

// Add a note on event.
e = amy_default_event();
e.time = start + 100;
e.osc = 2;
e.midi_note = 60;
e.velocity = 1.0f;
amy_add_event(e);
}


// Minimal custom oscillator

#if AMY_HAS_CUSTOM == 1
Expand Down
10 changes: 5 additions & 5 deletions src/examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include "amy.h"


void example_reverb() ;
void example_chorus() ;
void example_ks(uint32_t start) ;
void bleep(uint32_t start) ;
void example_fm(uint32_t start) ;
void example_reverb();
void example_chorus();
void example_ks(uint32_t start);
void bleep(uint32_t start);
void example_fm(uint32_t start);
void example_multimbral_fm();
void example_drums(uint32_t start, int loops);
void example_sine(uint32_t start);
Expand Down

0 comments on commit 966806b

Please sign in to comment.