diff --git a/firmware/Makefile b/firmware/Makefile index 8d77fe0..b415906 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -60,7 +60,7 @@ EXTRAINCDIRS = # -Wall...: warning level # -Wa,...: tell GCC to pass this to the assembler. # -ahlms: create assembler listing -CFLAGS = -O$(OPT) +CFLAGS = -O$(OPT) -g CFLAGS += -funsigned-char CFLAGS += -funsigned-bitfields CFLAGS += -fpack-struct diff --git a/firmware/main.c b/firmware/main.c index 8bc5d64..58f4174 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -6,11 +6,54 @@ #include "main.h" +volatile uint8_t sample_pending; //25kHz -ISR (TIMER0_OVF_vect) +ISR(TIMER0_OVF_vect) { + ICR1 = synth.output; + sample_pending = 1; +} +// sample rate is 8M / (5 * 64) = 25000 + +enum { + synth_channel_count = 2 +}; + +typedef struct { + uint16_t phase; + uint16_t speed; + +} synth_channel_t; + +typedef struct { + synth_channel_t channels[synth_channel_count]; + uint16_t output; +} synth_t; + +static synth_t synth; + +static void synth_init(void) +{ + // some test values + synth.channels[0].phase = 0; + synth.channels[0].speed = 1153; + + synth.channels[1].phase = 0; + synth.channels[1].speed = 23456; +} + +static inline void synth_mix(void) +{ + synth.output = 0; + + for (int i = 0; i < synth_channel_count; i++) { + synth_channel_t *chan = &synth.channels[i]; + chan->phase += chan->speed; + + synth.output += (chan->phase >> 16) & 0xff; + } } static void init_sampletimer(void) @@ -18,27 +61,26 @@ static void init_sampletimer(void) // Timer 0 // //set timer0 to CTC & prescaler 64 == 125k - TCCR0A = (1<