From d86b12449c80f651274b64a490f90ce12509679f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Tue, 30 Jan 2024 13:52:57 +0100 Subject: [PATCH 1/9] Custom oscillator (wave) plays --- Makefile | 4 ++-- src/amy-example.c | 6 ++++- src/amy.c | 23 +++++++++++++++---- src/amy.h | 25 +++++++++++++++++---- src/amy_config.h | 1 + src/custom.c | 42 +++++++++++++++++++++++++++++++++++ src/envelope.c | 3 +++ src/examples.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ src/examples.h | 2 ++ src/oscillators.c | 2 +- src/pcm.c | 4 ++-- 11 files changed, 154 insertions(+), 14 deletions(-) create mode 100644 src/custom.c diff --git a/Makefile b/Makefile index 4f7297c..5817f68 100644 --- a/Makefile +++ b/Makefile @@ -31,11 +31,11 @@ default: $(TARGET) all: default SOURCES = src/algorithms.c src/amy.c src/envelope.c src/examples.c \ - src/filters.c src/oscillators.c src/pcm.c src/partials.c \ + src/filters.c src/oscillators.c src/pcm.c src/partials.c src/custom.c \ src/delay.c src/log2_exp2.c OBJECTS = $(patsubst %.c, %.o, src/algorithms.c src/amy.c src/envelope.c \ - src/delay.c src/partials.c \ + src/delay.c src/partials.c src/custom.c \ src/examples.c src/filters.c src/oscillators.c src/pcm.c src/log2_exp2.c \ src/libminiaudio-audio.c) diff --git a/src/amy-example.c b/src/amy-example.c index 85813b2..d880e08 100644 --- a/src/amy-example.c +++ b/src/amy-example.c @@ -46,6 +46,8 @@ int main(int argc, char ** argv) { } uint32_t start = amy_sysclock(); + example_init_custom(); + amy_start(/* cores= */ 1, /* reverb= */ 1, /* chorus= */ 1); ma_encoder_config config = ma_encoder_config_init(ma_encoding_format_wav, ma_format_s16, AMY_NCHANS, AMY_SAMPLE_RATE); @@ -68,6 +70,8 @@ int main(int argc, char ** argv) { //example_sine(start); bleep(start); + example_custom_beep(); + example_drums(start+500, 4); example_multimbral_fm(start + 2500, /* start_osc= */ 6); @@ -76,7 +80,7 @@ int main(int argc, char ** argv) { if (output_filename) { int16_t * frames = amy_simple_fill_buffer(); int num_frames = AMY_BLOCK_SIZE; - result = ma_encoder_write_pcm_frames(&encoder, frames, num_frames, NULL); + ma_encoder_write_pcm_frames(&encoder, frames, num_frames, NULL); } usleep(THREAD_USLEEP); } diff --git a/src/amy.c b/src/amy.c index 0e84eee..6903983 100644 --- a/src/amy.c +++ b/src/amy.c @@ -179,7 +179,7 @@ void config_chorus(float level, int max_delay) { alloc_chorus_delay_lines(); } // if we're turning on for the first time, start the oscillator. - if (synth[CHORUS_MOD_SOURCE].status == OFF) { //chorus.level == 0) { + if (synth[CHORUS_MOD_SOURCE].status == STATUS_OFF) { //chorus.level == 0) { #ifdef CHORUS_ARATE // Setup chorus oscillator. synth[CHORUS_MOD_SOURCE].logfreq_coefs[COEF_CONST] = logfreq_of_freq(CHORUS_DEFAULT_LFO_FREQ); @@ -554,7 +554,7 @@ void reset_osc(uint16_t i ) { synth[i].sample = F2S(0); synth[i].mod_value = F2S(0); synth[i].substep = 0; - synth[i].status = OFF; + synth[i].status = STATUS_OFF; AMY_UNSET(synth[i].chained_osc); AMY_UNSET(synth[i].mod_source); synth[i].mod_target = 0; @@ -608,6 +608,9 @@ int8_t oscs_init() { if(pcm_samples) { pcm_init(); } + if(AMY_HAS_CUSTOM == 1) { + custom_init(); + } events = (struct delta*)malloc_caps(sizeof(struct delta) * AMY_EVENT_FIFO_LEN, EVENTS_RAM_CAPS); synth = (struct synthinfo*) malloc_caps(sizeof(struct synthinfo) * AMY_OSCS, SYNTH_RAM_CAPS); msynth = (struct mod_synthinfo*) malloc_caps(sizeof(struct mod_synthinfo) * AMY_OSCS, SYNTH_RAM_CAPS); @@ -745,6 +748,9 @@ void osc_note_on(uint16_t osc, float initial_freq) { if(synth[osc].wave==PARTIAL) partial_note_on(osc); if(synth[osc].wave==PARTIALS) partials_note_on(osc); } + if(AMY_HAS_CUSTOM == 1) { + if(synth[osc].wave==CUSTOM) custom_note_on(osc, initial_freq); + } } void apply_target_to_coefs(uint16_t osc, int target_val, int which_coef) { @@ -912,6 +918,7 @@ void play_event(struct delta d) { if(synth[synth[d.osc].mod_source].wave==TRIANGLE) triangle_mod_trigger(synth[d.osc].mod_source); if(synth[synth[d.osc].mod_source].wave==PULSE) pulse_mod_trigger(synth[d.osc].mod_source); if(synth[synth[d.osc].mod_source].wave==PCM) pcm_mod_trigger(synth[d.osc].mod_source); + if(synth[synth[d.osc].mod_source].wave==CUSTOM) custom_mod_trigger(synth[d.osc].mod_source); } } @@ -935,6 +942,11 @@ void play_event(struct delta d) { #endif } else if(synth[d.osc].wave==PCM) { pcm_note_off(d.osc); } + else if(synth[d.osc].wave==CUSTOM) { + #if AMY_HAS_CUSTOM == 1 + custom_note_off(d.osc); + #endif + } else { // osc note off, start release AMY_UNSET(synth[d.osc].note_on_clock); @@ -1008,7 +1020,7 @@ void hold_and_modify(uint16_t osc) { } else { if ( (total_samples - synth[osc].zero_amp_clock) >= MIN_ZERO_AMP_TIME_SAMPS) { //printf("h&m: time %f osc %d OFF\n", total_samples/(float)AMY_SAMPLE_RATE, osc); - synth[osc].status = OFF; + synth[osc].status = STATUS_OFF; AMY_UNSET(synth[osc].note_off_clock); AMY_UNSET(synth[osc].zero_amp_clock); } @@ -1080,6 +1092,9 @@ SAMPLE render_osc_wave(uint16_t osc, uint8_t core, SAMPLE* buf) { if(synth[osc].wave == PARTIAL) max_val = render_partial(buf, osc); if(synth[osc].wave == PARTIALS) max_val = render_partials(buf, osc); } + if(AMY_HAS_CUSTOM == 1) { + if(synth[osc].wave == CUSTOM) max_val = render_custom(buf, osc); + } AMY_PROFILE_STOP(RENDER_OSC_WAVE) return max_val; } @@ -1091,7 +1106,7 @@ void amy_render(uint16_t start, uint16_t end, uint8_t core) { if(synth[osc].status==AUDIBLE) { // skip oscs that are silent or mod sources from playback SAMPLE max_val = render_osc_wave(osc, core, per_osc_fb[core]); // check it's not off, just in case. todo, why do i care? - if(synth[osc].wave != OFF) { + if(synth[osc].wave != WAVE_OFF) { // apply filter to osc if set if(synth[osc].filter_type != FILTER_NONE) filter_process(per_osc_fb[core], osc, max_val); mix_with_pan(fbl[core], per_osc_fb[core], msynth[osc].last_pan, msynth[osc].pan); diff --git a/src/amy.h b/src/amy.h index 26abb47..f17cabc 100644 --- a/src/amy.h +++ b/src/amy.h @@ -90,6 +90,8 @@ enum coefs{ #define ALGO 8 #define PARTIAL 9 #define PARTIALS 10 +#define CUSTOM 11 +#define WAVE_OFF 12 // synth[].status values #define EMPTY 0 #define SCHEDULED 1 @@ -97,8 +99,7 @@ enum coefs{ #define AUDIBLE 3 #define IS_MOD_SOURCE 4 #define IS_ALGO_SOURCE 5 -// Is this for .wave or .status? -#define OFF 11 +#define STATUS_OFF 6 #define true 1 #define false 0 @@ -402,6 +403,16 @@ struct state { int16_t latency_ms; }; +// custom oscillator +struct custom_oscillator { + void (*init)(void); + void (*note_on)(struct synthinfo* osc, float freq); + void (*note_off)(struct synthinfo* osc); + void (*mod_trigger)(struct synthinfo* osc); + SAMPLE (*render)(SAMPLE* buf, struct synthinfo* osc); + SAMPLE (*compute_mod)(struct synthinfo* osc); +}; + // Shared structures extern uint32_t total_samples; extern struct synthinfo *synth; @@ -431,8 +442,8 @@ void amy_stop(); void amy_live_start(); void amy_live_stop(); void amy_reset_oscs(); -void amy_print_devices(); - +void amy_print_devices(); +void amy_set_custom(struct custom_oscillator* custom); extern float render_am_lut(float * buf, float step, float skip, float incoming_amp, float ending_amp, const float* lut, int16_t lut_size, float *mod, float bandwidth); extern void ks_init(); @@ -440,6 +451,7 @@ extern void ks_deinit(); extern void algo_init(); extern void algo_deinit(); extern void pcm_init(); +extern void custom_init(); extern SAMPLE render_ks(SAMPLE * buf, uint16_t osc); extern SAMPLE render_sine(SAMPLE * buf, uint16_t osc); extern SAMPLE render_fm_sine(SAMPLE *buf, uint16_t osc, SAMPLE *mod, SAMPLE feedback_level, uint16_t algo_osc, SAMPLE mod_amp); @@ -454,6 +466,7 @@ extern SAMPLE render_partial(SAMPLE *buf, uint16_t osc) ; extern void partials_note_on(uint16_t osc); extern void partials_note_off(uint16_t osc); extern SAMPLE render_partials(SAMPLE *buf, uint16_t osc); +extern SAMPLE render_custom(SAMPLE *buf, uint16_t osc) ; extern SAMPLE compute_mod_pulse(uint16_t osc); extern SAMPLE compute_mod_noise(uint16_t osc); @@ -462,6 +475,7 @@ extern SAMPLE compute_mod_saw_up(uint16_t osc); extern SAMPLE compute_mod_saw_down(uint16_t osc); extern SAMPLE compute_mod_triangle(uint16_t osc); extern SAMPLE compute_mod_pcm(uint16_t osc); +extern SAMPLE compute_mod_custom(uint16_t osc); extern void sine_note_on(uint16_t osc, float initial_freq); extern void fm_sine_note_on(uint16_t osc, uint16_t algo_osc); @@ -471,6 +485,8 @@ extern void triangle_note_on(uint16_t osc, float initial_freq); extern void pulse_note_on(uint16_t osc, float initial_freq); extern void pcm_note_on(uint16_t osc); extern void pcm_note_off(uint16_t osc); +extern void custom_note_on(uint16_t osc, float freq); +extern void custom_note_off(uint16_t osc); extern void partial_note_on(uint16_t osc); extern void partial_note_off(uint16_t osc); extern void algo_note_on(uint16_t osc); @@ -483,6 +499,7 @@ extern void saw_up_mod_trigger(uint16_t osc); extern void triangle_mod_trigger(uint16_t osc); extern void pulse_mod_trigger(uint16_t osc); extern void pcm_mod_trigger(uint16_t osc); +extern void custom_mod_trigger(uint16_t osc); extern SAMPLE amy_get_random(); extern void algo_custom_setup_patch(uint16_t osc, uint16_t * target_oscs); diff --git a/src/amy_config.h b/src/amy_config.h index 24c72cb..d37cefe 100644 --- a/src/amy_config.h +++ b/src/amy_config.h @@ -22,6 +22,7 @@ extern const uint16_t pcm_samples; #define AMY_MAX_DRIFT_MS 20000 // ms of time you can schedule ahead before synth recomputes time base #define AMY_KS_OSCS 1 // How many karplus-strong oscillators to keep track of (0 disables KS) #define AMY_HAS_PARTIALS 1 // 1 = Make partials available +#define AMY_HAS_CUSTOM 1 // 1 = Make custom oscillators available #define PCM_AMY_SAMPLE_RATE 22050 #define AMY_EVENT_FIFO_LEN 2000 diff --git a/src/custom.c b/src/custom.c new file mode 100644 index 0000000..35ab475 --- /dev/null +++ b/src/custom.c @@ -0,0 +1,42 @@ +// custom.c + +#include "amy.h" +#include + +struct custom_oscillator* custom_osc; + +void amy_set_custom(struct custom_oscillator* custom) { + assert(custom_osc == NULL); + custom_osc = custom; +} + +void custom_init() { + if (custom_osc != NULL) { + custom_osc->init(); + } +} + +void custom_note_on(uint16_t osc, float freq) { + assert(custom_osc != NULL); + custom_osc->note_on(&synth[osc], freq); +} + +void custom_note_off(uint16_t osc) { + assert(custom_osc != NULL); + custom_osc->note_off(&synth[osc]); +} + +void custom_mod_trigger(uint16_t osc) { + assert(custom_osc != NULL); + custom_osc->mod_trigger(&synth[osc]); +} + +SAMPLE render_custom(SAMPLE* buf, uint16_t osc) { + assert(custom_osc != NULL); + return custom_osc->render(buf, &synth[osc]); +} + +SAMPLE compute_mod_custom(uint16_t osc) { + assert(custom_osc != NULL); + return custom_osc->compute_mod(&synth[osc]); +} diff --git a/src/envelope.c b/src/envelope.c index 1711fc1..78afb2a 100644 --- a/src/envelope.c +++ b/src/envelope.c @@ -25,6 +25,9 @@ SAMPLE compute_mod_value(uint16_t mod_osc) { if(synth[mod_osc].wave == SINE) value = compute_mod_sine(mod_osc); if(pcm_samples) if(synth[mod_osc].wave == PCM) value = compute_mod_pcm(mod_osc); + if(AMY_HAS_CUSTOM == 1) { + if(synth[mod_osc].wave == CUSTOM) value = compute_mod_custom(mod_osc); + } synth[mod_osc].mod_value = value; return value; } diff --git a/src/examples.c b/src/examples.c index 708edf2..4a4e873 100644 --- a/src/examples.c +++ b/src/examples.c @@ -200,3 +200,59 @@ void example_drums(uint32_t start, int loops) { } } } + + +void beeper_init(void) { + printf("Beeper init\n"); +} + +void beeper_note_on(struct synthinfo* osc, float freq) { + printf("Beeper note on\n"); + saw_down_note_on(osc->osc, freq); +} + +void beeper_note_off(struct synthinfo* osc) { + printf("Beeper note off\n"); + osc->note_off_clock = total_samples; +} + +void beeper_mod_trigger(struct synthinfo* osc) { + saw_down_mod_trigger(osc->osc); +} + +SAMPLE beeper_render(SAMPLE* buf, struct synthinfo* osc) { + return render_saw_down(buf, osc->osc); +} + +SAMPLE beeper_compute_mod(struct synthinfo* osc) { + return compute_mod_saw_down(osc->osc); +} + +struct custom_oscillator beeper = { + beeper_init, + beeper_note_on, + beeper_note_off, + beeper_mod_trigger, + beeper_render, + beeper_compute_mod +}; + +void example_init_custom() { + if(AMY_HAS_CUSTOM == 1) { + amy_set_custom(&beeper); + } +} + +void example_custom_beep() { + struct event e = amy_default_event(); + e.osc = 50; + e.time = amy_sysclock(); + e.freq_coefs[0] = 880; + e.wave = CUSTOM; + e.velocity = 1; + amy_add_event(e); + + e.velocity = 0; + e.time += 500; + amy_add_event(e); +} diff --git a/src/examples.h b/src/examples.h index 64a1f99..402c845 100644 --- a/src/examples.h +++ b/src/examples.h @@ -13,3 +13,5 @@ void example_fm(uint32_t start) ; void example_multimbral_fm(uint32_t start, int start_osc) ; void example_drums(uint32_t start, int loops); void example_sine(uint32_t start); +void example_init_custom(); +void example_custom_beep(); diff --git a/src/oscillators.c b/src/oscillators.c index d38f817..0f460ce 100644 --- a/src/oscillators.c +++ b/src/oscillators.c @@ -536,7 +536,7 @@ void partial_note_off(uint16_t osc) { AMY_UNSET(synth[osc].note_on_clock); synth[osc].note_off_clock = total_samples; synth[osc].last_amp = 0; - synth[osc].status = OFF; + synth[osc].status = STATUS_OFF; } diff --git a/src/pcm.c b/src/pcm.c index 6b8fbc4..c84dd9f 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -64,7 +64,7 @@ SAMPLE render_pcm(SAMPLE* buf, uint16_t osc) { synth[osc].phase = P_WRAPPED_SUM(synth[osc].phase, step); base_index = INT_OF_P(synth[osc].phase, PCM_INDEX_BITS); if(base_index >= patch->length) { // end - synth[osc].status = OFF;// is this right? + synth[osc].status = STATUS_OFF;// is this right? sample = 0; } else { if(msynth[osc].feedback > 0) { // loop @@ -94,7 +94,7 @@ SAMPLE compute_mod_pcm(uint16_t osc) { uint32_t base_index = INT_OF_P(synth[osc].phase, PCM_INDEX_BITS); SAMPLE sample; if(base_index >= patch->length) { // end - synth[osc].status = OFF;// is this right? + synth[osc].status = STATUS_OFF;// is this right? sample = 0; } else { sample = L2S(table[base_index]); From 9be5d7b61ff7815b10c5198e43568c1fa45824e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Wed, 31 Jan 2024 10:23:08 +0100 Subject: [PATCH 2/9] Custom state for custom oscillator --- src/amy.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/amy.h b/src/amy.h index f17cabc..c886c76 100644 --- a/src/amy.h +++ b/src/amy.h @@ -338,6 +338,8 @@ struct synthinfo { SAMPLE filter_delay[2 * FILT_NUM_DELAYS]; // The block-floating-point shift of the filter delay values. int last_filt_norm_bits; + // Optional custom oscillator state. Everyone loves a void pointer. + void* custom_state; }; // synthinfo, but only the things that mods/env can change. one per osc From bb76555fa68e679493da759992e773f2de7d5497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Wed, 31 Jan 2024 10:38:43 +0100 Subject: [PATCH 3/9] Move fixpoint config to config --- src/amy_config.h | 1 + src/amy_fixedpoint.h | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/amy_config.h b/src/amy_config.h index d37cefe..be5b967 100644 --- a/src/amy_config.h +++ b/src/amy_config.h @@ -9,6 +9,7 @@ #define AMY_OSCS 120 #define AMY_SAMPLE_RATE 44100 #define AMY_NCHANS 2 +#define AMY_USE_FIXEDPOINT // These are overriden for you if you include pcm_X.h {tiny, small, large} diff --git a/src/amy_fixedpoint.h b/src/amy_fixedpoint.h index 9bcfcd8..19d984d 100644 --- a/src/amy_fixedpoint.h +++ b/src/amy_fixedpoint.h @@ -51,9 +51,6 @@ // #define MUL_KK mul4_k12k11(a, b) // #define MUL_KKS mul4_k16k7(a, b) // the second arg is "sensitive". -#define AMY_USE_FIXEDPOINT - - #ifndef AMY_USE_FIXEDPOINT #warning "floating point calc" From ee9273962bdce667b65c103da7fa680cb2b49a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Wed, 31 Jan 2024 10:39:07 +0100 Subject: [PATCH 4/9] Make amy_config.h location configurable --- src/amy.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/amy.h b/src/amy.h index c886c76..6def7d4 100644 --- a/src/amy.h +++ b/src/amy.h @@ -20,7 +20,11 @@ typedef struct { } pcm_map_t; +#ifdef AMY_CONFIG_H +#include AMY_CONFIG_H +#else #include "amy_config.h" +#endif // Rest of amy setup #define SAMPLE_MAX 32767 From 2bedf1cd62b1d4fa505a94565ed42d8f6f78587a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Thu, 1 Feb 2024 21:49:33 +0100 Subject: [PATCH 5/9] No need for custom void pointer --- src/amy.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/amy.h b/src/amy.h index 6def7d4..40d96ce 100644 --- a/src/amy.h +++ b/src/amy.h @@ -342,8 +342,6 @@ struct synthinfo { SAMPLE filter_delay[2 * FILT_NUM_DELAYS]; // The block-floating-point shift of the filter delay values. int last_filt_norm_bits; - // Optional custom oscillator state. Everyone loves a void pointer. - void* custom_state; }; // synthinfo, but only the things that mods/env can change. one per osc From 1570155cd73f066bd6ff5ec53c6c176118e16cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Sat, 3 Feb 2024 12:38:37 +0100 Subject: [PATCH 6/9] Stop warning in float mode --- src/amy_fixedpoint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amy_fixedpoint.h b/src/amy_fixedpoint.h index 19d984d..dde7276 100644 --- a/src/amy_fixedpoint.h +++ b/src/amy_fixedpoint.h @@ -53,7 +53,7 @@ #ifndef AMY_USE_FIXEDPOINT -#warning "floating point calc" +//#warning "floating point calc" #define ARITH "float" From 8e1a431d10da22f3b8a717db1ed1b7d3e01046c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Sat, 3 Feb 2024 12:57:18 +0100 Subject: [PATCH 7/9] Cleanup before PR --- src/amy-example.c | 6 ++++-- src/amy_config.h | 2 +- src/examples.c | 11 ++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/amy-example.c b/src/amy-example.c index d880e08..a717e3d 100644 --- a/src/amy-example.c +++ b/src/amy-example.c @@ -46,7 +46,9 @@ int main(int argc, char ** argv) { } uint32_t start = amy_sysclock(); + #if AMY_HAS_CUSTOM == 1 example_init_custom(); + #endif amy_start(/* cores= */ 1, /* reverb= */ 1, /* chorus= */ 1); @@ -68,9 +70,9 @@ int main(int argc, char ** argv) { //example_reverb(); //example_chorus(); //example_sine(start); - bleep(start); + //example_custom_beep(); - example_custom_beep(); + bleep(start); example_drums(start+500, 4); example_multimbral_fm(start + 2500, /* start_osc= */ 6); diff --git a/src/amy_config.h b/src/amy_config.h index be5b967..147e724 100644 --- a/src/amy_config.h +++ b/src/amy_config.h @@ -23,7 +23,7 @@ extern const uint16_t pcm_samples; #define AMY_MAX_DRIFT_MS 20000 // ms of time you can schedule ahead before synth recomputes time base #define AMY_KS_OSCS 1 // How many karplus-strong oscillators to keep track of (0 disables KS) #define AMY_HAS_PARTIALS 1 // 1 = Make partials available -#define AMY_HAS_CUSTOM 1 // 1 = Make custom oscillators available +#define AMY_HAS_CUSTOM 0 // 1 = Make custom oscillators available #define PCM_AMY_SAMPLE_RATE 22050 #define AMY_EVENT_FIFO_LEN 2000 diff --git a/src/examples.c b/src/examples.c index 4a4e873..0cb5eaa 100644 --- a/src/examples.c +++ b/src/examples.c @@ -201,18 +201,19 @@ void example_drums(uint32_t start, int loops) { } } +// Minimal custom oscillator + +#if AMY_HAS_CUSTOM == 1 void beeper_init(void) { printf("Beeper init\n"); } void beeper_note_on(struct synthinfo* osc, float freq) { - printf("Beeper note on\n"); saw_down_note_on(osc->osc, freq); } void beeper_note_off(struct synthinfo* osc) { - printf("Beeper note off\n"); osc->note_off_clock = total_samples; } @@ -238,9 +239,7 @@ struct custom_oscillator beeper = { }; void example_init_custom() { - if(AMY_HAS_CUSTOM == 1) { - amy_set_custom(&beeper); - } + amy_set_custom(&beeper); } void example_custom_beep() { @@ -256,3 +255,5 @@ void example_custom_beep() { e.time += 500; amy_add_event(e); } + +#endif From 528b5738d64a783c39c87b739d9bbdd3b8790854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Thu, 8 Feb 2024 11:58:19 +0100 Subject: [PATCH 8/9] Better handling of dynamic include --- src/amy.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/amy.h b/src/amy.h index 40d96ce..8ab24a8 100644 --- a/src/amy.h +++ b/src/amy.h @@ -19,13 +19,15 @@ typedef struct { uint8_t midinote; } pcm_map_t; - -#ifdef AMY_CONFIG_H -#include AMY_CONFIG_H -#else -#include "amy_config.h" +#ifndef AMY_CONFIG_H +#define AMY_CONFIG_H amy_config.h #endif +#define QUOTED(x) #x +#define INCLUDE(x) QUOTED(x) + +#include INCLUDE(AMY_CONFIG_H) + // Rest of amy setup #define SAMPLE_MAX 32767 #define MAX_ALGO_OPS 6 From 181eddfce104873392d60092a7ad0814cfedfe30 Mon Sep 17 00:00:00 2001 From: Brian Whitman Date: Wed, 14 Feb 2024 16:36:00 -0800 Subject: [PATCH 9/9] Update setup.py --- src/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup.py b/src/setup.py index b5276d7..a221fe9 100644 --- a/src/setup.py +++ b/src/setup.py @@ -2,7 +2,7 @@ import glob import os # the c++ extension module -sources = ['algorithms.c', 'amy.c', 'delay.c', 'envelope.c', 'filters.c', 'patches.c', 'libminiaudio-audio.c', 'oscillators.c', 'partials.c', 'pcm.c', 'pyamy.c', 'log2_exp2.c'] +sources = ['algorithms.c', 'amy.c', 'delay.c', 'envelope.c', 'filters.c', 'custom.c', 'patches.c', 'libminiaudio-audio.c', 'oscillators.c', 'partials.c', 'pcm.c', 'pyamy.c', 'log2_exp2.c'] os.environ["CC"] = "gcc" os.environ["CXX"] = "g++"