0% found this document useful (0 votes)
43 views3 pages

ATtiny85 AudioPlayerlist

The document describes an audio sample player code written in C for an AVR microcontroller. It includes code to directly output audio samples stored in program memory without external components. The sample data provided is a recording of a duck quack sound encoded as unsigned 8-bit values at an 8kHz sample rate.

Uploaded by

leontti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

ATtiny85 AudioPlayerlist

The document describes an audio sample player code written in C for an AVR microcontroller. It includes code to directly output audio samples stored in program memory without external components. The sample data provided is a recording of a duck quack sound encoded as unsigned 8-bit values at an 8kHz sample rate.

Uploaded by

leontti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/* Audio Sample Player

David Johnson-Davies - www.technoblogy.com - 29th September 2014


CC BY 4.0
Licensed under a Creative Commons Attribution 4.0 International license:
http://creativecommons.org/licenses/by/4.0/
*/
/* Direct-coupled capacitorless output */
#include <avr/pgmspace.h>
#include <avr/sleep.h>
#define adc_disable() (ADCSRA &= ~(1<<ADEN))
// Audio encoded as unsigned 8-bit, 8kHz sampling
PROGMEM prog_uchar quack_wav[] = {
0x7d, 0x7c, 0x7e, 0x7e, 0x7d, 0x7b, 0x7b, 0x7c,
0x81, 0x83, 0x84, 0x86, 0x88, 0x8a, 0x8b, 0x8c,
0x6c, 0x6d, 0x71, 0x75, 0x78, 0x78, 0x75, 0x6b,
0x6f, 0x76, 0x7d, 0x82, 0x85, 0x82, 0x7f, 0x7b,
0x8e, 0x93, 0x94, 0x92, 0x8d, 0x86, 0x81, 0x80,
0xa3, 0xa9, 0xab, 0xa5, 0x91, 0x70, 0x59, 0x58,
0xa5, 0x98, 0x7a, 0x5c, 0x50, 0x55, 0x6a, 0x80,
0x77, 0x69, 0x62, 0x67, 0x73, 0x79, 0x7a, 0x74,
0x6d, 0x70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 0x5c, 0x59, 0x52, 0x5c, 0x7a,
0xd4, 0xec, 0xe4, 0xc2, 0x54, 0x23, 0x9d, 0xf6,
0xd0, 0x86, 0x44, 0x25, 0x37, 0x7d, 0x9a, 0x88,
0x84, 0x64, 0x78, 0x95, 0x9d, 0x90, 0x8d, 0x8d,
0x51, 0x55, 0x72, 0x76, 0x65, 0x5a, 0x5f, 0x6c,
0x97, 0xc2, 0xd7, 0xeb, 0xc2, 0x47, 0x3c, 0xbd,
0xcd, 0xad, 0x5d, 0x3e, 0x41, 0x74, 0x90, 0x6e,
0x82, 0x4a, 0x63, 0x92, 0xa0, 0x87, 0x70, 0x7b,
0x4b, 0x5e, 0x89, 0x77, 0x47, 0x46, 0x62, 0x7a,
0x99, 0xc6, 0xdd, 0xcb, 0x78, 0x19, 0x81, 0xf7,
0xe7, 0x7d, 0x3b, 0x4b, 0x56, 0x87, 0x88, 0x4c,
0x41, 0x37, 0x85, 0x9a, 0x80, 0x6e, 0x6a, 0x80,

rate
0x7c,
0x88,
0x64,
0x79,
0x83,
0x67,
0x8e,
0x6b,
0x78,
0xd6,
0x53,
0x8b,
0x3f,
0x87,
0x7d,
0x7c,
0x71,
0x4c,
0xa2,
0xd6,
0xa5,
0x8b,
0x51,
0xe9,
0x66,
0x94,
0x4e,
0x90,
0x70,
0x89,
0x99,
0x85,
0xd6,
0x5a,
0x83,
0x74,
0xf0,
0x4a,
0x8a,
0x74,
0xac,
0x3a,
0x8c,

0x7e,
0x7f,
0x62,
0x79,
0x89,
0x80,
0x96,
0x64,
0x84,
0xdd,
0x28,
0xa1,
0x31,
0x91,
0x25,
0x9f,
0x90,
0x45,
0xaa,
0xb6,
0xb6,
0x8b,
0x5b,
0xa0,
0x3f,
0x85,
0x49,
0xbb,
0xae,
0xa8,
0x97,
0x81,
0x6f,
0x4f,
0x91,
0x79,
0xab,
0x3f,
0x9d,
0x6b,
0x59,
0x68,
0x92,

0x7f,
0x76,
0x61,
0x7f,
0x91,
0x96,
0x94,
0x63,
0x8d,
0xc7,
0x24,
0xa2,
0x38,
0x93,
0x22,
0x93,
0xb1,
0x46,
0xb1,
0x7c,
0xa6,
0x7a,
0x5f,
0x24,
0x29,
0x82,
0x53,
0xdf,
0x9e,
0x94,
0x67,
0x82,
0x45,
0x92,
0x91,
0x78,
0x5a,
0x82,
0xa5,
0x75,
0x53,
0xac,
0x8a,

0x7f,
0x6f,
0x67,
0x88,
0x9a,
0xa3,
0x89,
0x68,
0x94,
0x84,
0x49,
0x91,
0x53,
0x8f,
0x67,
0x71,
0xb6,
0x4e,
0xba,
0x63,
0x84,
0x62,
0x6a,
0x35,
0x44,
0x8b,
0x5d,
0xf2,
0x7c,
0x70,
0x47,
0xa1,
0xa4,
0xb0,
0x71,
0x77,
0x77,
0xba,
0x76,
0x81,
0xae,
0x9a,
0x70,

0x65,
0xbc,
0x75,
0x68,
0x7b,
0xcb,
0x50,
0x8f,
0x58,
0x23,
0x8d,
0x6b,
0x82,
0xaa,
0x61,
0x87,
0x96,
0xa6,
0x5a,
0x73,
0xb3,
0x60,
0x93,
0x75,
0xb4,
0x6c,
0x88,
0x7f,
0x9a,
0x91,
0x89,
0xa3,
0x6b,
0x88,
0x85,
0xb2,
0x63,
0x82,
0x79,
0x7d,
0x8b,
0x7e,
0x8c,
0x6c,
0x85,
0x7c,
0xaf,
0x7d,
0x73,
0x69,
0x9a,
0x86,
0x75,
0x74,
0x99,
0x7a,
0x80,
0x7e,
0x80,
0x6d,

0x71,
0xd3,
0x3f,
0xa0,
0x67,
0x79,
0x6c,
0x5b,
0x6a,
0xaa,
0x5e,
0x8e,
0x8a,
0x5e,
0xa5,
0x78,
0xa3,
0xa2,
0x5a,
0x6f,
0xba,
0x72,
0x5c,
0x71,
0xd6,
0x68,
0x75,
0x91,
0xa3,
0x6d,
0x7a,
0xba,
0x7c,
0x79,
0x7b,
0xc8,
0x79,
0x74,
0x8f,
0x97,
0x7c,
0x80,
0xaa,
0x73,
0x82,
0x82,
0x73,
0x82,
0x71,
0x7e,
0x72,
0x79,
0x80,
0x65,
0x9d,
0x7c,
0x84,
0x7a,
0x71,
0x73,

0x78,
0xc6,
0x55,
0x89,
0x5d,
0x23,
0x93,
0x52,
0x7f,
0xdd,
0x44,
0xa2,
0x8a,
0x63,
0x9d,
0x72,
0xb2,
0x70,
0x82,
0x6f,
0x63,
0x79,
0x5e,
0x7c,
0x75,
0x7d,
0x7f,
0x92,
0x9b,
0x7a,
0x73,
0x84,
0x84,
0x6b,
0x70,
0x69,
0x8e,
0x78,
0x81,
0x8f,
0x76,
0x73,
0xa2,
0x7e,
0x71,
0x66,
0x43,
0x83,
0x87,
0x7d,
0x6a,
0x7c,
0x8b,
0x6c,
0x93,
0x8b,
0x7f,
0x74,
0x78,
0x96,

0x64,
0x5b,
0x73,
0x61,
0x74,
0x86,
0x75,
0x7d,
0x71,
0x7a,
0x7e,
0x8c,
0x8d,
0x93,
0x6a,
0x7d,
0xb4,
0x5a,
0x92,
0x71,
0x40,
0x86,
0x8a,
0x7f,
0x60,
0x99,
0x94,
0x9a,
0x7d,
0x86,
0x72,
0x2f,
0x7b,
0x7b,
0x79,
0x67,
0x8d,
0x84,
0x80,
0x99,
0x7d,
0x68,
0x53,
0x76,
0x74,
0x70,
0x93,
0x6c,
0x85,
0x61,
0xb6,
0x74,
0x81,
0x83,
0x7f,
0x7f,
0x77,
0x76,
0x8b,
0x90,

0x5a,
0x25,
0x9a,
0x6e,
0x76,
0xe5,
0x40,
0x9c,
0x68,
0x42,
0xa9,
0x7f,
0x8b,
0xc3,
0x54,
0x80,
0xb1,
0x6a,
0x66,
0x67,
0xc9,
0x63,
0x88,
0x7b,
0x94,
0x8a,
0x87,
0xa2,
0x68,
0x86,
0x81,
0x83,
0x6f,
0x86,
0x8b,
0x9e,
0x83,
0x7d,
0x93,
0x7b,
0x7f,
0x74,
0x51,
0x6a,
0x87,
0x81,
0xaf,
0x71,
0x7e,
0x7d,
0x95,
0x7b,
0x7c,
0x7e,
0x64,
0x77,
0x84,
0x73,
0x83,
0x83,

0x63,
0xaf,
0x82,
0x8b,
0x60,
0xa9,
0x5b,
0x8d,
0x75,
0x75,
0x9b,
0x7b,
0xa7,
0x91,
0x6f,
0x72,
0x78,
0x75,
0x56,
0x6d,
0xc0,
0x5a,
0x7a,
0x87,
0xa9,
0x69,
0x7a,
0xb0,
0x7f,
0x71,
0x7b,
0xd7,
0x74,
0x84,
0x9a,
0xa9,
0x6f,
0x7b,
0x99,
0x71,
0x81,
0x81,
0xb4,
0x66,
0x83,
0x74,
0x6c,
0x8e,
0x79,
0x8d,
0x56,
0x85,
0x85,
0x66,
0xa3,
0x6e,
0x88,
0x6c,
0x88,
0x7b,

0x6a,
0xec,
0x4d,
0x95,
0x67,
0x55,
0x95,
0x79,
0x88,
0xc1,
0x67,
0x7f,
0xb8,
0x48,
0x96,
0x73,
0x45,
0x81,
0x72,
0x72,
0x5e,
0x8b,
0x7e,
0x94,
0x9d,
0x6f,
0x6e,
0x7d,
0x83,
0x60,
0x6c,
0x87,
0x83,
0x80,
0x8b,
0x95,
0x7b,
0x7b,
0xa3,
0x80,
0x6b,
0x6d,
0x98,
0x7d,
0x7a,
0x75,
0x5b,
0x84,
0x83,
0x78,
0x8b,
0x81,
0x8b,
0x6c,
0xaf,
0x73,
0x85,
0x7b,
0x8c,
0x79,

0x75,
0x90,
0x56,
0x85,
0x7e,
0x69,
0xb7,
0x73,
0x9e,
0xb5,
0x4b,
0x7d,
0xbc,
0x5d,
0x7d,
0x70,
0xa5,
0x6c,
0x82,
0x75,
0x6e,
0xa3,
0x81,
0xa7,
0x7c,
0x82,
0x68,
0x39,
0x7a,
0x7b,
0x77,
0x60,
0x90,
0x84,
0x85,
0x75,
0x88,
0x6e,
0x6c,
0x77,
0x6b,
0x6c,
0x43,
0x83,
0x7d,
0x7b,
0x8c,
0x7f,
0x90,
0x7c,
0xac,
0x77,
0x81,
0x83,
0x6c,
0x89,
0x84,
0x7a,
0x99,
0x80,

0x76,
0x50,
0x96,
0x80,
0x8c,
0xc2,
0x76,
0x75,
0xaa,
0x5e,
0x82,
0x7b,
0xa0,
0x75,
0x59,
0x6f,
0xcd,
0x52,
0x7d,
0x88,
0x8c,
0x79,
0x81,
0xb2,
0x6c,
0x8a,
0x7e,
0x96,
0x6a,
0x85,
0x88,
0x91,
0x92,
0x87,
0xaa,
0x6c,
0x81,
0x6e,
0x51,
0x7a,
0x7f,
0x7a,
0x60,
0x85,
0x84,
0x87,
0xa8,
0x74,
0x7f,
0x80,
0x92,
0x7a,
0x7a,
0x85,
0x79,
0x7f,
0x88,
0x6f,
0x8b,
0x79,

0x82,
0x73,
0xaf,
0x78,
0x98,
0xce,
0x38,
0x7a,
0xac,
0x44,
0xa5,
0x79,
0x39,
0x8c,
0x66,
0x7f,
0x74,
0x72,
0x76,
0x8e,
0xa9,
0x5a,
0x82,
0xb4,
0x7a,
0x6a,
0x7d,
0xd2,
0x70,
0x7e,
0x92,
0xa1,
0x78,
0x7f,
0xbe,
0x7f,
0x6b,
0x7d,
0xaa,
0x70,
0x7c,
0x85,
0x97,
0x81,
0x84,
0x89,
0x93,
0x7a,
0x74,
0x89,
0x80,
0x82,
0x73,
0x7a,
0xa2,
0x7b,
0x85,
0x75,
0x66,
0x72,

0x94,
0xc0,
0x68,
0x74,
0xae,
0x7f,
0x68,
0x74,
0xb6,
0x66,
0x74,
0x66,
0x67,
0x82,
0x80,
0x85,
0x5f,
0xa2,
0x79,
0x9a,
0xa5,
0x6e,
0x71,
0x70,
0x7a,
0x62,
0x6f,
0x74,
0x83,
0x80,
0x8b,
0x9b,
0x79,
0x71,
0x60,
0x87,
0x6c,
0x76,
0xa0,
0x72,
0x77,
0x83,
0x91,
0x74,
0x7d,
0x80,
0x77,
0x88,
0x7e,
0x97,
0x76,
0x80,
0x7b,
0x75,
0x98,
0x80,
0x7d,
0x75,
0x9d,
0x6c,

0x9c,
0xcb,
0x3b,
0x7d,
0xc3,
0x47,
0xa0,
0x66,
0x5a,
0x7e,
0x5f,
0x68,
0xdd,
0x48,
0x8f,
0x88,
0x87,
0x90,
0x73,
0xaf,
0x67,
0x90,
0x6c,
0x43,
0x78,
0x87,
0x70,
0x60,
0x99,
0x8e,
0x8e,
0x86,
0x87,
0x73,
0x37,
0x7a,
0x82,
0x67,
0x5d,
0x87,
0x76,
0x77,
0x7c,
0x7f,
0x6f,
0x96,
0x6f,
0x84,
0x78,
0x95,
0x84,
0x7e,
0x84,
0x7b,
0x84,
0x81,
0x7e,
0x7a,
0xab,
0x75,

0x81,
0x81,
0x6d,
0x79,
0x8d,
0x81,
0x86,
0x7a,
0x81,
0x6b,
0x7f,
0x85,
0x78,
0x7d,
0x7b,
0x82,
0x74,
0x7c,
0x7f,
0x82,

0x7c,
0x8a,
0x7a,
0x7f,
0x85,
0x82,
0x82,
0x71,
0x7f,
0x7b,
0x7c,
0x85,
0x7f,
0x82,
0x7d,
0x72,
0x7a,
0x82,
0x80,
0x7f,

0x7a,
0x88,
0x7f,
0x8a,
0x79,
0x83,
0x83,
0x76,
0x84,
0x8f,
0x84,
0x82,
0x7e,
0x82,
0x7e,
0x90,
0x7b,
0x81,
0x7d,
0x80

0x7b,
0x7b,
0x6c,
0x8b,
0x79,
0x81,
0x84,
0x7f,
0x84,
0x85,
0x81,
0x7f,
0x77,
0x7b,
0x7d,
0x8e,
0x7c,
0x81,
0x7f,

0x84,
0x7c,
0x6c,
0x8e,
0x7b,
0x82,
0x81,
0x76,
0x83,
0x7a,
0x86,
0x7f,
0x7c,
0x7e,
0x7c,
0x72,
0x7b,
0x81,
0x80,

0x82,
0x83,
0x7b,
0x95,
0x7a,
0x7d,
0x7a,
0x75,
0x87,
0x7b,
0x82,
0x80,
0x81,
0x80,
0x7e,
0x7d,
0x78,
0x82,
0x7f,

0x7a,
0x7f,
0x79,
0x7e,
0x77,
0x7c,
0x7d,
0x77,
0x8e,
0x87,
0x7e,
0x80,
0x7d,
0x81,
0x81,
0x8c,
0x83,
0x82,
0x80,

0x7b,
0x71,
0x7a,
0x6b,
0x77,
0x86,
0x7d,
0x77,
0x94,
0x83,
0x81,
0x75,
0x7e,
0x7a,
0x80,
0x88,
0x81,
0x81,
0x7f,

0x7d,
0x72,
0x7a,
0x8f,
0x71,
0x84,
0x74,
0x7e,
0x76,
0x75,
0x80,
0x76,
0x7e,
0x7b,
0x82,
0x7c,
0x80,
0x82,
0x80,

0x82,
0x7c,
0x77,
0x8f,
0x7a,
0x80,
0x72,
0x7d,
0x6a,
0x7b,
0x81,
0x7e,
0x7f,
0x81,
0x88,
0x7d,
0x7e,
0x81,
0x81,

0x82,
0x7c,
0x81,
0x65,
0x81,
0x85,
0x7b,
0x7b,
0x91,
0x7c,
0x7f,
0x7b,
0x84,
0x7e,
0x8b,
0x86,
0x81,
0x81,
0x7d,

0x81,
0x73,
0x82,
0x70,
0x7c,
0x8a,
0x80,
0x7f,
0x8b,
0x82,
0x83,
0x77,
0x81,
0x7b,
0x8f,
0x81,
0x82,
0x7d,
0x80,

};
unsigned int quack_wav_len = 1467;
unsigned int p = 0;
void setup() {
// Enable 64 MHz PLL and use as source for Timer1
PLLCSR = 1<<PCKE | 1<<PLLE;
// Set up Timer/Counter1 for PWM output
TIMSK = 0;
TCCR1 = 1<<PWM1A | 2<<COM1A0 | 1<<CS10;
GTCCR = 1<<PWM1B | 2<<COM1B0;
OCR1A = 128; OCR1B = 128;

//
//
//
//

Timer interrupts OFF


PWM A, clear on match, 1:1 prescale
PWM B, clear on match
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 = 124;
// Divide by 1000
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
pinMode(4, OUTPUT);
pinMode(1, OUTPUT);
}
void loop() { }
// Sample interrupt
ISR(TIMER0_COMPA_vect) {
char sample = pgm_read_byte(&quack_wav[p++]);
OCR1A = sample; OCR1B = sample ^ 255;
// End of data? Go to sleep
if (p == quack_wav_len) {
adc_disable();
sleep_enable();
sleep_cpu(); // 1uA
}
}

You might also like