diff --git a/firmware/main.c b/firmware/main.c index 4932eca..5a759e9 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -5,52 +5,8 @@ #include #include "main.h" +#include "synth.h" -volatile uint8_t sample_pending; - - -// 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]; -} 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 = 1728; -} - -static inline uint16_t synth_mix(void) -{ - uint16_t output = 0; - - for (int i = 0; i < synth_channel_count; i++) { - synth_channel_t *chan = &synth.channels[i]; - chan->phase += chan->speed; - output += ((chan->phase >> 8) & 0xff) / 2; - } - - return output; -} static void init_sampletimer(void) { @@ -104,7 +60,6 @@ static void init_motor(void) - int main(void) { @@ -155,5 +110,3 @@ ISR(TIMER0_COMPA_vect) } - - diff --git a/firmware/synth.c b/firmware/synth.c new file mode 100644 index 0000000..de0970d --- /dev/null +++ b/firmware/synth.c @@ -0,0 +1,45 @@ +#include + +// sample rate is 8M / (3 * 64) + + +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]; +} synth_t; + +static synth_t synth; + + +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 = 1728; +} + +uint16_t synth_mix(void) +{ + uint16_t output = 0; + + for (int i = 0; i < synth_channel_count; i++) { + synth_channel_t *chan = &synth.channels[i]; + chan->phase += chan->speed; + output += ((chan->phase >> 8) & 0xff) / 2; + } + + return output; +} + diff --git a/firmware/synth.h b/firmware/synth.h new file mode 100644 index 0000000..6b90c0f --- /dev/null +++ b/firmware/synth.h @@ -0,0 +1,4 @@ + +void synth_init(void); +uint16_t synth_mix(void); +