sorry 2bt... need to play the 8bit way
This commit is contained in:
parent
96d7a0ed9d
commit
6e24129648
|
@ -1,5 +1,7 @@
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const uint16_t freq_table[] PROGMEM = {
|
const uint16_t freq_table[] PROGMEM = {
|
||||||
/*0x00*/ 39,
|
/*0x00*/ 39,
|
||||||
/*0x01*/ 41,
|
/*0x01*/ 41,
|
||||||
|
|
|
@ -70,8 +70,6 @@ static void init_leds(void)
|
||||||
/*enable interrupt*/
|
/*enable interrupt*/
|
||||||
TIMSK2 |= (1<<OCIE2A);
|
TIMSK2 |= (1<<OCIE2A);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,12 +86,13 @@ static void init_motor(void)
|
||||||
/* vibration motor on B1, initially off: */
|
/* vibration motor on B1, initially off: */
|
||||||
DDRB |= (1 << PORTB1);
|
DDRB |= (1 << PORTB1);
|
||||||
PORTB &= ~( 1<<PORTB1);
|
PORTB &= ~( 1<<PORTB1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
void __attribute__((noreturn))
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
/* hardware initialisation: */
|
/* hardware initialisation: */
|
||||||
//init_leds();
|
//init_leds();
|
||||||
|
@ -120,12 +119,11 @@ int main(void)
|
||||||
USART0_crlf();
|
USART0_crlf();
|
||||||
//last_darkval=darkval;
|
//last_darkval=darkval;
|
||||||
};
|
};
|
||||||
synth_poll();
|
|
||||||
//USART0_put_uint16(0xA09F);
|
//USART0_put_uint16(0xA09F);
|
||||||
//USART0_crlf();
|
//USART0_crlf();
|
||||||
};
|
}
|
||||||
|
|
||||||
/* never */ return 0;
|
/* never return 0; */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
channel_count = 3,
|
channel_count = 3,
|
||||||
tick_length = 400,
|
//tick_length = 400,
|
||||||
|
// tick_length = 256,
|
||||||
row_length = 4,
|
row_length = 4,
|
||||||
pattern_length = 16
|
pattern_length = 16
|
||||||
};
|
};
|
||||||
|
@ -172,7 +173,7 @@ enum {
|
||||||
|
|
||||||
|
|
||||||
static synth_channel_t channels[channel_count];
|
static synth_channel_t channels[channel_count];
|
||||||
static int16_t sample;
|
static int8_t sample;
|
||||||
static int8_t tick;
|
static int8_t tick;
|
||||||
static int8_t row;
|
static int8_t row;
|
||||||
static int8_t seq;
|
static int8_t seq;
|
||||||
|
@ -181,10 +182,12 @@ static int8_t seq;
|
||||||
/* PROTOTYPES */
|
/* PROTOTYPES */
|
||||||
uint8_t synth_mix(void);
|
uint8_t synth_mix(void);
|
||||||
|
|
||||||
static uint16_t timeslots[SYNTH_BUFSIZE];
|
static uint8_t timeslots[SYNTH_BUFSIZE];
|
||||||
static uint8_t timeslots_write; // current write head
|
static uint8_t timeslots_write; // current write head
|
||||||
static uint8_t timeslots_read; // current read head
|
static uint8_t timeslots_read; // current read head
|
||||||
uint8_t timeslots_fill;
|
|
||||||
|
/*register for atomic ++ and -- */
|
||||||
|
register uint8_t timeslots_fill asm("r2");
|
||||||
|
|
||||||
|
|
||||||
static void enqueue_timeslot(uint8_t synthval);
|
static void enqueue_timeslot(uint8_t synthval);
|
||||||
|
@ -197,15 +200,12 @@ void synth_init(void)
|
||||||
row = 0;
|
row = 0;
|
||||||
seq = 0;
|
seq = 0;
|
||||||
timeslots_fill = 0;
|
timeslots_fill = 0;
|
||||||
//prefill timeslot buffer
|
|
||||||
enqueue_timeslot(synth_mix());
|
|
||||||
enqueue_timeslot(synth_mix());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t synth_mix(void)
|
inline uint8_t synth_mix(void)
|
||||||
{
|
{
|
||||||
if(sample == 0) { // new tick
|
if(sample == 0) { // new tick
|
||||||
for(int i = 0; i < channel_count; i++) {
|
for(int i = 1; i < channel_count; i++) {
|
||||||
synth_channel_t* chan = &channels[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];
|
||||||
|
@ -215,12 +215,12 @@ uint8_t synth_mix(void)
|
||||||
|
|
||||||
chan->pulse_width += inst->pulse_sweep;
|
chan->pulse_width += inst->pulse_sweep;
|
||||||
|
|
||||||
|
|
||||||
chan->pos++;
|
chan->pos++;
|
||||||
if(wave_table[chan->pos][1] == 0xff) chan->pos += wave_table[chan->pos][0];
|
if(wave_table[chan->pos][1] == 0xff) chan->pos += wave_table[chan->pos][0];
|
||||||
|
|
||||||
|
|
||||||
// enter new row
|
// enter new rol
|
||||||
|
// w
|
||||||
if(tick == 0) {
|
if(tick == 0) {
|
||||||
uint8_t pattern_nr = pattern_table[seq][i];
|
uint8_t pattern_nr = pattern_table[seq][i];
|
||||||
uint8_t note = pgm_read_byte(&patterns[pattern_nr][row][0]);
|
uint8_t note = pgm_read_byte(&patterns[pattern_nr][row][0]);
|
||||||
|
@ -240,8 +240,7 @@ uint8_t synth_mix(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(++sample == tick_length) {
|
if(++sample == 0){
|
||||||
sample = 0;
|
|
||||||
if(++tick == row_length) {
|
if(++tick == row_length) {
|
||||||
tick = 0;
|
tick = 0;
|
||||||
if(++row == pattern_length) {
|
if(++row == pattern_length) {
|
||||||
|
@ -257,7 +256,7 @@ uint8_t synth_mix(void)
|
||||||
uint8_t output = 0;
|
uint8_t output = 0;
|
||||||
for(int i = 0; i < channel_count; i++) {
|
for(int i = 0; i < channel_count; i++) {
|
||||||
synth_channel_t* chan = &channels[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])]);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
output += ((amp & 0xff) * chan->level) >> 8;
|
output += (((amp & 0xff) * chan->level) >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
@ -291,7 +290,8 @@ uint8_t synth_mix(void)
|
||||||
/* fill all the timeslots */
|
/* fill all the timeslots */
|
||||||
inline void synth_poll(void) {
|
inline void synth_poll(void) {
|
||||||
/* refill timeslots queue */
|
/* 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());
|
enqueue_timeslot(synth_mix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,16 +307,10 @@ static inline uint8_t dequeue_timeslot() {
|
||||||
if(timeslots_fill){
|
if(timeslots_fill){
|
||||||
/* buffer not underrun... move forward in readbuffer */
|
/* buffer not underrun... move forward in readbuffer */
|
||||||
|
|
||||||
#if 1 /*debug */
|
|
||||||
PORTC = 0;
|
|
||||||
#endif
|
|
||||||
timeslots_fill --;
|
timeslots_fill --;
|
||||||
timeslots_read ++;
|
timeslots_read ++;
|
||||||
} else { /*buffer underrun. not moving forward*/
|
|
||||||
#if 1
|
|
||||||
PORTC = 0b00000001 ;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user