Go Down

Topic: Creating 4Khz sample rate DAC possible arduino (Read 100 times) previous topic - next topic

Weru7

Hi I have code that output 8bit 8Khz sound ample from Digispark ATtiny 85   
 I succeed played 8Khz sample rate example but due to ATtiny 85 limited flash memory I was limited to play ~0.7 second sample ,and I'm trying to transfer the audio on lowest bit rate possible (I'l use RF to transfer it lather )  .
I use Audacity to reduce sample rate to 4000Hz and export it to 8bit PCM Raw file , and get hex dump of the raw file xxd -i -s +44 'watch_4k.raw' , but I only got whistle like sound repeated too fast .

I use this sketch to test my samples https://paste.ubuntu.com/p/t72yPBwjz3/ ^(It's bit long I cant't paste it here ) credits . DigiSpark Attiny 85 clock speed are 16.5 MHz higher than the original Attiny 85 internal clock speed which is MHz So I modify OCR0A from 128 to 250

here is complete code that doing Audio sampling on

Code: [Select]
       unsigned int quack_wav_len = 5102;  // 2038 3k , 2732 4k
    unsigned int p = 0;
    void setup() {
      // put your setup code here, to run once:
      // Enable 64 MHz PLL and use as source for Timer1
      PLLCSR = 1<<PCKE | 1<<PLLE;     
      // Set up Timer/Counter1 for PWM output
      TIMSK = 0;                              // Timer interrupts OFF
      TCCR1 = 1<<PWM1A | 2<<COM1A0 | 1<<CS10; // PWM A, clear on match, 1:1 prescale
      GTCCR = 1<<PWM1B | 2<<COM1B0;           // PWM B, clear on match
      OCR1A = 128 ;  OCR1B = 128;             // 50% duty at start
       //   Set up Timer/Counter0   for 8kHz interrupt to output samples.
      TCCR0A = 3<<WGM00;                      // Fast PWM
      TCCR0B = 1<<WGM02 | 2<<CS00;            // 1/8 prescale
      TIMSK = 1<<OCIE0A;                      // Enable compare match
      OCR0A = 250;                            // Divide by 1000 "1000 รท 8 " >> 
      set_sleep_mode( SLEEP_MODE_PWR_DOWN );
      pinMode( 4 , OUTPUT ) ;    pinMode(  1 , OUTPUT ) ;
    }

    void loop() {
                 }

    // repeat loop
    ISR( TIMER0_COMPA_vect ) {
      char sample = pgm_read_byte(&quack_wav[p++]);
      OCR1A = sample;
      OCR1B = sample ^ 255;
      if ( p == quack_wav_len ) p=0;
      }


Go Up