diff --git a/firmware/freq_table.h b/firmware/freq_table.h index e938d8a..24b19db 100644 --- a/firmware/freq_table.h +++ b/firmware/freq_table.h @@ -1,4 +1,6 @@ -const uint16_t freq_table[] = { +#include + +const uint16_t freq_table[] PROGMEM = { /*0x00*/ 39, /*0x01*/ 41, /*0x02*/ 43, diff --git a/firmware/synth.c b/firmware/synth.c index 0af06c5..1af8987 100644 --- a/firmware/synth.c +++ b/firmware/synth.c @@ -1,6 +1,8 @@ #include #include "synth.h" #include "freq_table.h" +#include + // sample rate is 8M / (3 * 64) enum { @@ -43,7 +45,7 @@ static const uint8_t wave_table[][2] = { }; -static const uint8_t patterns[][pattern_length][2] = { +static const uint8_t patterns[][pattern_length][2] PROGMEM = { {}, { { 33 - 12, 0 }, @@ -204,7 +206,7 @@ uint16_t synth_mix(void) // enter new row if(tick == 0) { uint8_t pattern_nr = pattern_table[seq][i]; - uint8_t note = patterns[pattern_nr][row][0]; + uint8_t note = pgm_read_byte(&patterns[pattern_nr][row][0]); if(note) { // new note, maybe? if(note == 0xff) { @@ -212,7 +214,7 @@ uint16_t synth_mix(void) } else { chan->level = 80; // TODO: less? chan->note = note; - chan->inst_nr = patterns[pattern_nr][row][1]; + chan->inst_nr = pgm_read_byte(&patterns[pattern_nr][row][1]); inst = &instruments[chan->inst_nr]; chan->pos = inst->wave_table_pos; if(inst->pulse_width) chan->pulse_width = inst->pulse_width; @@ -240,7 +242,7 @@ uint16_t synth_mix(void) synth_channel_t* chan = &channels[i]; const synth_instrument_t* inst = &instruments[chan->inst_nr]; - chan->phase += freq_table[(uint8_t)(chan->note + wave_table[chan->pos][0])]; + chan->phase += pgm_read_word(&freq_table[(uint8_t)(chan->note + wave_table[chan->pos][0])]); uint8_t amp; switch(wave_table[chan->pos][1]) {