Hi guys. Now my SD is working again (pull up on MISO was the key to success) I am listening to an 8 bit version of The Who's My Generation and its awesome.
However....
I am using Timer1 as my headphone jack is attached to OCR1A and OCR1B. I am using a 1824p at 16Mhz.
It "sounds" like it might be playing slowly. I have made the main adjustments I can think of, so I was wondering whether it could be because Timer 1 is a 16 bit timer, and therefore I am only filling to bottom 8 bits or something like that?
These are my methods to initialize the timer:
void start_playback(void) { //audio on OCR1A and OCR1B TCCR1A |= (1 << COM1A1) | (1 << COM1B1)| (1 << WGM12) | (1 << WGM10); //Clear OC0A on Compare Match, set OC0A at BOTTOM, fast PWM // TCCR0A |= (1 << COM0A1) | (1 << COM0B1)| (1 << WGM01) | (1 << WGM00); TCCR1B |= (1 << CS10); // no prescale OCR1A = 0; OCR1B = 0; play_index = 0; active = 1; TIMSK1 |= (1 << TOIE1); DDRD |= 0b00110000; }
and to stop the timer:
void stop_playback(void) { PORTD &= ~0b00110000; TCCR1B &= ~(1 << CS10); // no prescale }
And my interrupt:
ISR(TIMER1_OVF_vect) { divider++; if (divider == 1) { //'4' for 8 bit raw if (active == 1) { OCR1A = buff1[play_index++]; OCR1B = buff1[play_index++]; } // if active == 1 else { OCR1A = buff2[play_index++]; OCR1B = buff1[play_index++]; } //else if (play_index >= 512) { if (active == 1) { active = 2; } // if active == 1 else { active = 1; } //else play_index = 0; } //play_index >= 512 divider = 0; } // div_er == 2 if (play_index == 100) { // trigger read of the other buffer when one part used read_next = 1; }// if play_index == 100 } //function
Changing what divider has to be changes the "speed" that the OCR's are updated at. When it is 1 its like daffy duck (fast) but 2 sounds like the devil just walked in...
Any ideas as to what I havent done to make it play at the correct speed, and...
secondly, as I have the option of stereo sound, and I am using a 16 bit Timer, is all I have to do to get better quality audio, record for 16Khz stereo, and then do I set OCR1B as one byte ahead of OCR1A or something (i.e they get every other byte each?)
Oh No! Just remembered, the ADC is only 8 bit anyway so having 16 bit timer is useless isnt it? Can still do stereo though right?