From 6e241296484f6c31c93c038dbc3d19ca1a1908dd Mon Sep 17 00:00:00 2001 From: john stone Date: Tue, 14 Aug 2012 22:53:25 +0200 Subject: [PATCH] sorry 2bt... need to play the 8bit way --- firmware/freq_table.h | 2 ++ firmware/main.c | 12 +++++------- firmware/synth.c | 42 ++++++++++++++++++------------------------ 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/firmware/freq_table.h b/firmware/freq_table.h index 24b19db..9791d55 100644 --- a/firmware/freq_table.h +++ b/firmware/freq_table.h @@ -1,5 +1,7 @@ #include + + const uint16_t freq_table[] PROGMEM = { /*0x00*/ 39, /*0x01*/ 41, diff --git a/firmware/main.c b/firmware/main.c index 4ea679f..74d57b2 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -70,8 +70,6 @@ static void init_leds(void) /*enable interrupt*/ TIMSK2 |= (1<inst_nr]; @@ -215,12 +215,12 @@ uint8_t synth_mix(void) chan->pulse_width += inst->pulse_sweep; - chan->pos++; if(wave_table[chan->pos][1] == 0xff) chan->pos += wave_table[chan->pos][0]; - // enter new row + // enter new rol + // w if(tick == 0) { uint8_t pattern_nr = pattern_table[seq][i]; uint8_t note = pgm_read_byte(&patterns[pattern_nr][row][0]); @@ -240,8 +240,7 @@ uint8_t synth_mix(void) } } } - if(++sample == tick_length) { - sample = 0; + if(++sample == 0){ if(++tick == row_length) { tick = 0; if(++row == pattern_length) { @@ -257,7 +256,7 @@ uint8_t synth_mix(void) uint8_t output = 0; for(int i = 0; i < channel_count; i++) { synth_channel_t* chan = &channels[i]; - const synth_instrument_t* inst = &instruments[chan->inst_nr]; + // const synth_instrument_t* inst = &instruments[chan->inst_nr]; chan->phase += pgm_read_word(&freq_table[(uint8_t)(chan->note + wave_table[chan->pos][0])]); @@ -281,7 +280,7 @@ uint8_t synth_mix(void) break; } - output += ((amp & 0xff) * chan->level) >> 8; + output += (((amp & 0xff) * chan->level) >> 8); } return output; @@ -291,7 +290,8 @@ uint8_t synth_mix(void) /* fill all the timeslots */ inline void synth_poll(void) { /* refill timeslots queue */ - while (timeslots_fill < (SYNTH_BUFSIZE-1)) +// while (timeslots_fill < (SYNTH_BUFSIZE-1)) + if (timeslots_fill < (SYNTH_BUFSIZE-1)) enqueue_timeslot(synth_mix()); } @@ -307,16 +307,10 @@ static inline uint8_t dequeue_timeslot() { if(timeslots_fill){ /* buffer not underrun... move forward in readbuffer */ -#if 1 /*debug */ - PORTC = 0; -#endif timeslots_fill --; timeslots_read ++; - } else { /*buffer underrun. not moving forward*/ -#if 1 - PORTC = 0b00000001 ; -#endif - } + } + return t; }