From a2dca81d7cac47cb4596ecca677354d357d3a62e Mon Sep 17 00:00:00 2001 From: twobit Date: Mon, 6 Aug 2012 01:45:37 +0200 Subject: [PATCH] polyphonie --- firmware/main.c | 91 ++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 57 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index c01582c..4932eca 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -24,15 +24,10 @@ typedef struct { typedef struct { synth_channel_t channels[synth_channel_count]; - uint16_t output; } synth_t; static synth_t synth; -uint8_t counter = 0; -uint8_t pulsewidth = 0; -uint16_t maxcounter = 0xFF; -uint16_t pulsecounter = 0; static void synth_init(void) { @@ -44,49 +39,49 @@ static void synth_init(void) synth.channels[1].speed = 1728; } -static inline void synth_mix(void) +static inline uint16_t synth_mix(void) { - synth.output = 0; + uint16_t 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 >> 8) & 0xff; + output += ((chan->phase >> 8) & 0xff) / 2; } + + return output; } static void init_sampletimer(void) { // Timer 0 - // - //set timer0 to CTC & prescaler 64 == 125k + // set timer0 to CTC & prescaler 64 == 125k TCCR0A = (1 << WGM01); TCCR0B = (1 << CS00) | (1 << CS01); - //count up to 5 : + // count up to 5 : OCR0A = 3; - TCNT0=0; - //enable interrupt + TCNT0 = 0; + // enable interrupt TIMSK0 |= (1< maxcounter){ counter = 0; }; - pulsecounter++; - if (pulsecounter > 0x0200){ + if (pulsecounter > 0x300){ pulsecounter = 0; pulsewidth++; if (pulsewidth > maxcounter){ pulsewidth = 0; } } + OCR1B = ((counter > pulsewidth) ? 0xff : 0x00); + */ - - OCR1B = ((counter > pulsewidth) ? maxcounter : 0x00); - + OCR1B = synth_mix(); - //OCR1B = counter; - //OCR1B = OCR1B + 4; - if (OCR1B > 0x007F) { - // OCR1B = 0x00F; - } - PORTC ^= 0b01; - - //ICR1 = synth.output; - //sample_pending = 1; - }