Lookuptables for WAV player

Go To Last Post
55 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey so I finally managed to generate a sine wave using a atmega8 saw it on a scope and heard a single tone on the 8ohm speaker.

Now i want to use this to play actual small wav files through the setup.

1) How do i generate a lookup table for the WAV file?
2) If i sample at about 4khz, do i need to run a timer that loads OCR1B at 4khz.

Im using a 12Mhz clock so that means for TCNTn value==30000(12Mhz/4khz) i load OCR1B value with reference to code below?


#include 
#include 
#include 
const uint8_t  sinewave[] PROGMEM= //256 values
{
0x80,0x83,0x86,0x89,0x8c,0x8f,0x92,0x95,0x98,0x9c,0x9f,0xa2,0xa5,0xa8,0xab,0xae,
0xb0,0xb3,0xb6,0xb9,0xbc,0xbf,0xc1,0xc4,0xc7,0xc9,0xcc,0xce,0xd1,0xd3,0xd5,0xd8,
0xda,0xdc,0xde,0xe0,0xe2,0xe4,0xe6,0xe8,0xea,0xec,0xed,0xef,0xf0,0xf2,0xf3,0xf5,
0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfc,0xfd,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfd,0xfc,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,
0xf6,0xf5,0xf3,0xf2,0xf0,0xef,0xed,0xec,0xea,0xe8,0xe6,0xe4,0xe2,0xe0,0xde,0xdc,
0xda,0xd8,0xd5,0xd3,0xd1,0xce,0xcc,0xc9,0xc7,0xc4,0xc1,0xbf,0xbc,0xb9,0xb6,0xb3,
0xb0,0xae,0xab,0xa8,0xa5,0xa2,0x9f,0x9c,0x98,0x95,0x92,0x8f,0x8c,0x89,0x86,0x83,
0x80,0x7c,0x79,0x76,0x73,0x70,0x6d,0x6a,0x67,0x63,0x60,0x5d,0x5a,0x57,0x54,0x51,
0x4f,0x4c,0x49,0x46,0x43,0x40,0x3e,0x3b,0x38,0x36,0x33,0x31,0x2e,0x2c,0x2a,0x27,
0x25,0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17,0x15,0x13,0x12,0x10,0x0f,0x0d,0x0c,0x0a,
0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x05,0x06,0x07,0x08,
0x09,0x0a,0x0c,0x0d,0x0f,0x10,0x12,0x13,0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21,0x23,
0x25,0x27,0x2a,0x2c,0x2e,0x31,0x33,0x36,0x38,0x3b,0x3e,0x40,0x43,0x46,0x49,0x4c,
0x4f,0x51,0x54,0x57,0x5a,0x5d,0x60,0x63,0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c
};
uint8_t i=0;
ISR(TIMER1_OVF_vect){
	OCR1B=pgm_read_byte(&sinewave[i]);
   i++;
	}
int main(void) {

DDRB=(1<<2);
// initial OCR1B value
OCR1B=0x80;
//Output compare OC1A 8 bit non inverted PWM
TCCR1A=0x31;
//start timer without prescaler
TCCR1B |=_BV(CS10);
//enable output compare interrupt for OCR1B
TIMSK=(1<<TOIE1);
//enable global interrups
sei();
    while (1) {
   //loop for ever. Interrupts will do the job.
    }
}



  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:

1) How do i generate a lookup table for the WAV file?

Take a look at Sox. I have been using it for something similar.
http://sox.sourceforge.net/

You can convert and re-sample all kinds of audio files with this software. For example, you could convert a 16-bit wav file to raw signed/unsigned 8-bit values for use with your code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also have a look at the Roman Black algorithm discussed here:
https://www.avrfreaks.net/index.p...
http://www.romanblack.com/picsou...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You use your lookup table to *generate* a waveform, you don't need it to play a wave file. Here your lookup table is your waveform, in this case a sine.
Your wave file is .. the waveform itself.

so just save your wave file as a raw unsigned 8bit binary file at your desired sampling rate, and put this data into your progmem array the same way you did your sine. (use Hxd or something to convert the binary file to a .c file) And then run timer1 at that sampling rate.

Also don't forget the range checking on i, since like this it will make a lot of noise after it finished the array, since it will be playing opcodes.

And unless your happy with a few seconds of sound at terrible sampling rates, indeed take a look at Roman Black's 1bit differential sound encoding.

Have fun!

Ok, who is wrong here :
4000/256 = ~15Hz tone
Or i'm wrong in calculating this, or you must of heard something else ..

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try using Sound Recorder in Windows to record 8-bit 8KHz PCM to a WAV file then use a utility such as xxd to convert it to C data initialisers then simply replace:

const uint8_t  sinewave[] PROGMEM=

with that data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Ok, who is wrong here :
4000/256 = ~15Hz tone
Or i'm wrong in calculating this, or you must of heard something else ..

For the sine wave frequency was about 100Hz,(PWM freq/256) and clock was 12Mhz so PWM was (12/(2*255*1)).

For the .wav assuming i have the lookuptable at a sampling rate of 3khz .so i choose a prescaler of 8 right to give PWM frequency of 3khz same as sampling rate.
i.e.- 12/(2*255*8)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry smiley means 8

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Try using Sound Recorder in Windows to record 8-bit 8KHz PCM to a WAV file then use a utility such as xxd to convert it to C data initialisers then simply replace:

const uint8_t  sinewave[] PROGMEM=

with that data.

i tried downloading xxd but couldn't find a working link.i found an app online for the purpose but how do i check if its producing the right array

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:

but how do i check if its producing the right array

Sox (mentioned above) comes with a play command that can play just about any audio format including raw (headerless).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
Quote:

Ok, who is wrong here :
4000/256 = ~15Hz tone
Or i'm wrong in calculating this, or you must of heard something else ..

For the sine wave frequency was about 100Hz,(PWM freq/256) and clock was 12Mhz so PWM was (12/(2*255*1)).

For the .wav assuming i have the lookuptable at a sampling rate of 3khz .so i choose a prescaler of 8 right to give PWM frequency of 3khz same as sampling rate.
i.e.- 12/(2*255*8)

I'm assuming your Array contains one full cycle of a sine wave, which is 256 entries long.
If you were to loop through this Array at 4kHz, this would produce a tone of 4000/256 = 15.625Hz

Your lookup table does not have a samplerate, it has a resolution. Your resolution is 256, eg you use 256 steps for one full wave.

If it takes 256 cycles to produce one full wave, the produced frequency will be the sampling frequency divided by that number of cycles. Where in this case the sampling frequency is the playback rate, at which you call Timer 1 overflow.

When you record sound digitally, you store one sample (analog value) per a time interval, beeing the samplerate or sample frequency. When the recorded samples are played back at the same sample rate, it reproduces the same sound. If it is played at a different rate, not only will the playback length be different, the sound will also be pitched.

The speed at which you traverse your lookup table of one full wave determines the frequency of the note produced.

At a samplerate of 4kHz, each sample lasts 1/4000=250usec
It takes 256 cycles to produce a full wave.
So it takes 256*250usec=64msec for one full wave,
which makes the frequency 1/64msec = 15.625Hz

A closer look at your lookup table shows that it is indeed one full wave. It goes from 0x80 to 0xff, back to 0x80, to 0x00, and back to 0x80. Each quarter eating up 4 lines of text.

I don't mean to come over all lecturing and all, i noticed you were confusing some things, and felt a more complete explanation was in order to clarify things.

As for saving binary files to data initializer strings for a few languages, check out HxD, it's a very good hex editor. I always keep it in my toolbox.
It can also export as intel hex or Motorola S Record.
http://mh-nexus.de/en/hxd/
wait, did i mention it's free..

edit: spelling

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

i tried downloading xxd but couldn't find a working link.i found an app online for the purpose but how do i check if its producing the right array

xxd is part of vim - a Windows version is available on this page:

http://www.vim.org/download.php

Download vim72w32.zip - it's in there - you don't need anything else from the .zip, xxd.exe is a stand-alone utility:

D:\>xxd -?
Usage:
       xxd [options] [infile [outfile]]
    or
       xxd -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]
Options:
    -a          toggle autoskip: A single '*' replaces nul-lines. Default off.
    -b          binary digit dump (incompatible with -p,-i,-r). Default hex.
    -c cols     format  octets per line. Default 16 (-i: 12, -ps: 30).
    -E          show characters in EBCDIC. Default ASCII.
    -g          number of octets per group in normal output. Default 2.
    -h          print this summary.
    -i          output in C include file style.
    -l len      stop after  octets.
    -ps         output in postscript plain hexdump style.
    -r          reverse operation: convert (or patch) hexdump into binary.
    -r -s off   revert with  added to file positions found in hexdump.
    -s [+][-]seek  start at  bytes abs. (or +: rel.) infile offset.
    -u          use upper case hex letters.
    -v          show version: "xxd V1.10 27oct98 by Juergen Weigert (Win32)".

(so you want to use the -i option)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

(so you want to use the -i option)

Nice! Thanks for that tip. I've been using hexdump for this type of function, but xxd -i option doesn't require any hand editing. Been using vi for 15+ years now and I hadn't run across xxd before ;) Learn something new every day.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just one thing to note about "xxd -i", the name given to the array of data comes directly from the filename of the original binary file - so it sometimes makes sense to give it a short, meaningful name.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
sorry smiley means 8

Just click at your original post instead and then click the "Disable Smilies in this post" and then click "Submit".

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey so i tried playing my WAV file unfortunately i couldnt reproduce the audio.

It was sampled at 8khz and i loaded ocr1b at that frequency with the help of another timer.

Could it be tht Im using the wrong PWM mode I currently have phase correct 8 bit PWM mode using timer1? if yes then what should i use?

Also can anyone post a lookuptable of a small 8khz wav file mine contains a lot of 128's toward the end,when ideally it should be very low,because with 128 my duty cycle will still be 50%(top=255).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
hey so i tried playing my WAV file unfortunately i couldnt reproduce the audio.

It was sampled at 8khz and i loaded ocr1b at that frequency with the help of another timer.

Could it be tht Im using the wrong PWM mode I currently have phase correct 8 bit PWM mode using timer1? if yes then what should i use?

Also can anyone post a lookuptable of a small 8khz wav file mine contains a lot of 128's toward the end,when ideally it should be very low,because with 128 my duty cycle will still be 50%(top=255).

You still don't seem to completely understand.

Again, your lookup table does not have a samplerate, it's just a lookup table of a full sine wave, it has a resolution. If it was a recorded signal, then it would have a samplerate.

Admittedly, it's a question of terminology because the two are the same (time based resolution = samplerate). It is to avoid confusion. One does not speak of samplerate for a full wave lookup table.

And the value 128 is the center of your wave, it has a DC offset since you cannot create negative voltages. Actually 0x80 is zero for a signed char.
It's perfectly fine.

A lookup table of a sine is created as follows.

Divide the number of radians in a circle by the number of steps you require (resolution). This is your angle increment.

Then for each step get the Sin() value of the step number multiplied by the angle increment. And multiply this value with your amplitude, in this case being 127, since your samples are 8 bit.

double AngleInc = 2 * PI / steps;
for (int x=0; x < steps; x++)
  bytevalues[x] = (byte)( 127. * Sin(x * AngleInc) )

But your current lookup table is good.
To make it easier, try the following :

Setup timer 1 for compare matches (or overflows) on 4kHz (samplerate).
Setup timer 0 for fast pwm mode, 8bit, with a minimum pwm frequency of the samplerate used (4kHz).
So that you can load a new output value in every pwm cycle.
Now, on your timer 1 compare match (or overflow), load the timer 0 OCR register with the next value in the table.

If you do everything correct, you will see a sine wave of 15.625Hz on your scope.
If you used a High Pass filter, you will not see the DC offset, as it has been filtered out.

Once that is working, go on using a recorded wave file, resample it to 4kHz, 8bit, 1channel, and save it as a raw binary file (eg. no headers).
Convert it to a C data initializer string, either using xxd or HxD or other suggestions made above, and put it into your code.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

Last Edited: Thu. Jun 25, 2009 - 03:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is the cast to byte c89 c99 or gcc specific? I dont think I've ever seen that.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Is the cast to byte c89 c99 or gcc specific? I dont think I've ever seen that.

It's just some pseudo code to demonstrate how to generate the table. As far as I understand it's just an explicit type conversion. I am not aware of any differences in implementation amongst different C ISO standards.

Likely you are talking about the signedness ?
Perhaps I should of written (uint8_t), but i found byte to be less confusing in this example.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok so i implemented the code ive shown below. I get a vibrating sound not resembling my audio at all.

Here are my specifications-

1. Clock frequency-12Mhz
2. WAV file sampled at 6khz
3. TIMER 1 for Fast 8bit PWM Non-Inverting Mode (No Prescaler)
4. Timer 2 for loading OCR1B value (prescaler 8). OCR2=250 =12Mhz/(8khz*8).
5.Atmega8

#include 
#include 
#include 
const uint8_t  sinewave[] PROGMEM= //256 values
{ 
82,
73,
70,
70,
218,
15,
0,
0,
87,
65,
86,
69,
102,
109,
116,
32,
18,
0,
0,
0,
1,
0,
1,
0,
112,
23,
0,
0,
112,
23,
0,
0,
1,
0,
8,
0,
0,
0,
100,
97,
116,
97,
180,
15,
0,
0,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
128,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
128,
128,
128,
129,
128,
127,
128,
129,
128,
128,
128,
127,
128,
129,
128,
127,
128,
127,
128,
129,
128,
127,
128,
129,
128,
128,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
128,
128,
127,
128,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
129,
129,
127,
128,
129,
128,
128,
129,
128,
126,
128,
129,
128,
128,
128,
128,
128,
128,
128,
129,
127,
127,
130,
129,
127,
127,
128,
127,
128,
129,
127,
128,
129,
128,
128,
129,
128,
128,
128,
128,
128,
130,
128,
126,
128,
129,
128,
128,
128,
126,
126,
128,
130,
129,
128,
127,
128,
128,
129,
129,
126,
127,
129,
130,
130,
127,
126,
130,
129,
127,
129,
128,
126,
130,
130,
125,
127,
130,
126,
127,
129,
128,
127,
128,
129,
128,
126,
129,
131,
127,
124,
130,
131,
126,
129,
129,
124,
126,
132,
130,
126,
126,
130,
129,
125,
128,
129,
124,
128,
133,
129,
127,
128,
127,
128,
129,
129,
127,
127,
130,
128,
127,
130,
127,
124,
131,
132,
127,
126,
127,
129,
129,
126,
127,
130,
124,
128,
135,
125,
123,
132,
129,
124,
129,
129,
126,
130,
127,
126,
130,
129,
127,
131,
129,
123,
130,
131,
123,
126,
130,
127,
127,
130,
129,
126,
126,
129,
130,
127,
127,
130,
131,
127,
127,
131,
129,
126,
127,
128,
130,
129,
127,
127,
127,
123,
127,
134,
126,
122,
133,
133,
122,
127,
132,
124,
128,
135,
128,
124,
128,
128,
128,
131,
127,
126,
131,
128,
126,
131,
126,
123,
132,
132,
127,
128,
127,
123,
128,
132,
127,
127,
131,
128,
125,
129,
129,
126,
130,
132,
128,
125,
125,
127,
129,
128,
127,
129,
129,
128,
129,
129,
127,
126,
130,
131,
130,
127,
125,
128,
130,
127,
128,
131,
128,
124,
124,
129,
129,
124,
128,
132,
125,
126,
132,
128,
124,
130,
131,
128,
132,
132,
126,
126,
130,
130,
129,
128,
127,
126,
124,
126,
128,
126,
126,
127,
125,
127,
130,
129,
128,
129,
130,
135,
135,
127,
126,
131,
131,
130,
132,
128,
119,
119,
126,
125,
122,
125,
125,
124,
127,
131,
130,
126,
131,
136,
136,
136,
132,
132,
136,
136,
131,
122,
117,
123,
127,
121,
117,
117,
115,
121,
133,
133,
123,
124,
132,
136,
138,
141,
140,
137,
138,
142,
136,
118,
116,
129,
127,
117,
115,
110,
102,
113,
131,
133,
127,
128,
132,
135,
140,
143,
143,
143,
144,
144,
138,
120,
113,
127,
125,
110,
110,
111,
103,
110,
130,
134,
126,
127,
134,
136,
140,
148,
149,
145,
145,
144,
135,
118,
115,
126,
122,
108,
103,
99,
102,
122,
141,
137,
123,
122,
130,
136,
146,
155,
151,
145,
145,
144,
135,
117,
110,
121,
120,
105,
100,
99,
107,
130,
143,
133,
122,
123,
130,
139,
151,
156,
149,
144,
145,
142,
134,
117,
106,
116,
117,
103,
92,
101,
124,
138,
136,
131,
124,
119,
129,
146,
154,
153,
150,
148,
142,
137,
132,
115,
105,
114,
114,
97,
91,
112,
135,
139,
133,
129,
121,
117,
133,
151,
152,
149,
154,
151,
139,
133,
131,
113,
102,
111,
113,
94,
91,
121,
145,
139,
129,
128,
121,
118,
133,
152,
154,
151,
154,
150,
135,
128,
127,
114,
105,
109,
107,
92,
97,
128,
147,
139,
129,
127,
121,
120,
134,
151,
154,
153,
155,
149,
133,
126,
123,
110,
104,
108,
104,
94,
107,
135,
145,
136,
129,
127,
121,
122,
135,
148,
152,
154,
155,
146,
132,
126,
119,
107,
104,
108,
101,
96,
115,
139,
143,
135,
131,
130,
124,
123,
134,
145,
151,
156,
156,
145,
131,
124,
115,
105,
105,
104,
96,
101,
125,
143,
142,
135,
133,
129,
123,
124,
135,
145,
152,
158,
156,
142,
130,
122,
110,
101,
102,
99,
95,
109,
135,
146,
141,
135,
133,
127,
121,
127,
138,
146,
154,
159,
152,
138,
127,
117,
106,
102,
101,
95,
97,
119,
140,
144,
139,
137,
133,
126,
123,
130,
139,
146,
155,
158,
148,
135,
125,
112,
102,
99,
97,
94,
106,
130,
144,
143,
139,
136,
130,
124,
126,
134,
141,
149,
157,
154,
142,
131,
121,
109,
102,
100,
94,
95,
114,
136,
144,
141,
139,
137,
130,
125,
129,
136,
142,
150,
156,
150,
138,
128,
117,
106,
102,
98,
91,
100,
122,
139,
142,
140,
141,
138,
130,
127,
131,
136,
143,
151,
153,
145,
135,
126,
114,
105,
100,
93,
94,
110,
129,
139,
140,
142,
141,
135,
130,
130,
134,
138,
145,
151,
148,
140,
132,
121,
111,
105,
98,
92,
99,
117,
132,
137,
140,
143,
141,
135,
131,
132,
135,
139,
146,
149,
144,
137,
128,
118,
110,
104,
96,
94,
106,
123,
133,
137,
140,
143,
140,
135,
133,
134,
136,
141,
146,
145,
140,
134,
125,
115,
109,
103,
96,
99,
113,
126,
132,
135,
140,
142,
139,
135,
135,
136,
138,
142,
144,
141,
136,
131,
123,
115,
110,
102,
97,
103,
116,
126,
131,
135,
141,
142,
138,
136,
136,
137,
139,
143,
143,
139,
134,
128,
120,
114,
109,
101,
99,
108,
119,
126,
130,
136,
140,
140,
138,
138,
138,
138,
140,
142,
140,
136,
131,
125,
118,
113,
106,
100,
103,
114,
123,
127,
132,
138,
140,
139,
137,
138,
138,
140,
142,
142,
138,
134,
128,
121,
116,
111,
102,
100,
109,
121,
126,
129,
134,
138,
139,
137,
137,
138,
138,
141,
143,
142,
136,
130,
122,
115,
110,
103,
97,
106,
122,
131,
132,
133,
138,
138,
132,
134,
139,
141,
144,
150,
148,
140,
132,
122,
106,
99,
96,
87,
99,
133,
152,
146,
137,
131,
121,
115,
126,
145,
154,
157,
161,
152,
132,
120,
111,
97,
94,
96,
94,
114,
148,
157,
140,
125,
119,
111,
116,
140,
159,
160,
158,
156,
142,
123,
118,
107,
93,
98,
101,
100,
125,
155,
152,
130,
120,
116,
112,
125,
153,
164,
156,
153,
150,
133,
120,
118,
103,
93,
102,
101,
104,
136,
159,
145,
123,
118,
114,
114,
136,
162,
163,
152,
151,
145,
126,
120,
114,
97,
97,
103,
98,
114,
151,
158,
133,
119,
117,
111,
120,
151,
167,
156,
149,
150,
137,
122,
122,
109,
92,
100,
103,
99,
129,
161,
151,
124,
117,
114,
111,
132,
163,
166,
150,
149,
146,
128,
121,
119,
99,
93,
103,
97,
109,
149,
162,
137,
119,
116,
110,
117,
150,
169,
157,
148,
150,
137,
122,
124,
110,
89,
99,
105,
98,
126,
163,
153,
121,
115,
115,
110,
131,
166,
167,
147,
148,
148,
128,
120,
119,
97,
91,
105,
99,
110,
152,
163,
133,
115,
115,
110,
120,
155,
172,
154,
146,
150,
135,
121,
124,
106,
88,
102,
102,
98,
136,
168,
146,
117,
116,
112,
110,
141,
172,
162,
145,
150,
143,
123,
123,
115,
91,
96,
105,
97,
121,
162,
156,
124,
114,
113,
107,
129,
167,
169,
148,
146,
148,
130,
122,
121,
97,
89,
105,
101,
108,
151,
165,
134,
114,
115,
108,
118,
157,
174,
154,
144,
149,
136,
122,
124,
105,
86,
101,
104,
102,
139,
167,
144,
116,
114,
110,
112,
147,
175,
160,
144,
149,
140,
123,
125,
111,
86,
96,
105,
100,
133,
169,
150,
116,
113,
111,
108,
140,
175,
165,
143,
148,
143,
124,
124,
115,
87,
94,
107,
99,
126,
167,
155,
118,
112,
113,
107,
134,
173,
168,
144,
146,
145,
127,
123,
118,
89,
90,
106,
101,
123,
164,
158,
122,
111,
111,
107,
132,
171,
169,
146,
145,
145,
128,
124,
121,
91,
88,
107,
101,
118,
163,
161,
123,
111,
113,
107,
128,
169,
171,
145,
143,
147,
130,
123,
123,
95,
86,
106,
102,
113,
158,
165,
128,
110,
113,
107,
122,
164,
175,
148,
140,
148,
134,
123,
124,
100,
84,
102,
102,
110,
155,
169,
133,
110,
112,
107,
119,
161,
177,
151,
139,
147,
136,
122,
126,
106,
84,
98,
103,
106,
148,
172,
140,
111,
110,
107,
115,
154,
178,
156,
138,
146,
139,
123,
126,
112,
84,
96,
105,
102,
137,
172,
149,
113,
110,
109,
110,
145,
178,
162,
138,
143,
143,
125,
125,
119,
89,
91,
106,
99,
124,
168,
160,
121,
109,
110,
107,
133,
174,
171,
141,
139,
146,
130,
124,
125,
97,
85,
104,
101,
112,
158,
170,
132,
108,
110,
107,
120,
163,
178,
149,
136,
145,
137,
123,
128,
112,
85,
98,
105,
99,
137,
174,
151,
113,
109,
109,
110,
144,
179,
163,
135,
141,
145,
128,
125,
126,
94,
85,
106,
100,
111,
160,
171,
131,
107,
110,
108,
122,
164,
177,
148,
135,
146,
138,
123,
129,
115,
85,
96,
107,
96,
128,
173,
158,
116,
108,
112,
108,
134,
176,
170,
137,
137,
147,
132,
123,
129,
106,
84,
102,
105,
100,
139,
174,
149,
111,
108,
110,
112,
146,
178,
162,
133,
139,
146,
129,
123,
128,
102,
87,
106,
101,
100,
148,
176,
142,
109,
109,
109,
114,
151,
179,
157,
133,
142,
144,
126,
125,
127,
99,
88,
107,
100,
102,
151,
175,
139,
108,
110,
109,
114,
153,
180,
155,
131,
141,
143,
126,
126,
130,
101,
88,
108,
100,
96,
145,
177,
145,
110,
110,
109,
112,
148,
179,
159,
132,
139,
145,
129,
125,
131,
108,
88,
106,
103,
91,
133,
176,
154,
115,
109,
110,
109,
139,
176,
165,
135,
137,
146,
132,
124,
133,
117,
90,
99,
106,
89,
117,
171,
168,
124,
106,
110,
107,
126,
168,
175,
143,
132,
144,
138,
124,
130,
129,
98,
91,
110,
98,
95,
146,
177,
143,
109,
110,
111,
113,
147,
177,
159,
132,
138,
144,
130,
126,
135,
119,
92,
99,
106,
87,
110,
167,
172,
129,
107,
111,
108,
121,
161,
177,
149,
132,
142,
139,
124,
129,
137,
113,
92,
104,
100,
85,
121,
175,
167,
122,
108,
111,
107,
125,
166,
175,
145,
133,
142,
137,
123,
129,
135,
111,
93,
106,
101,
85,
121,
173,
165,
122,
108,
113,
110,
126,
164,
173,
145,
133,
142,
137,
124,
129,
137,
116,
94,
104,
102,
82,
112,
171,
172,
127,
108,
112,
108,
118,
159,
177,
151,
132,
139,
138,
125,
129,
140,
127,
99,
99,
106,
84,
90,
150,
183,
148,
111,
110,
110,
108,
139,
175,
167,
136,
133,
140,
130,
124,
137,
140,
115,
97,
106,
101,
76,
102,
166,
178,
136,
111,
113,
107,
111,
149,
177,
158,
133,
136,
139,
127,
127,
140,
138,
116,
101,
105,
98,
75,
98,
162,
182,
143,
113,
112,
107,
108,
142,
174,
163,
137,
135,
138,
127,
125,
139,
143,
126,
108,
103,
100,
79,
79,
135,
184,
167,
125,
110,
107,
103,
122,
160,
172,
152,
136,
136,
131,
124,
132,
143,
139,
124,
110,
102,
94,
77,
86,
143,
184,
163,
124,
110,
106,
102,
122,
161,
175,
154,
135,
132,
127,
123,
134,
147,
142,
127,
114,
103,
94,
83,
80,
119,
173,
177,
139,
111,
105,
102,
112,
147,
174,
165,
140,
130,
127,
123,
129,
144,
147,
137,
126,
113,
99,
90,
83,
86,
125,
173,
174,
137,
110,
104,
103,
115,
147,
171,
163,
141,
129,
125,
124,
132,
144,
145,
137,
130,
121,
105,
93,
88,
84,
102,
149,
178,
158,
122,
106,
103,
108,
128,
157,
169,
155,
136,
126,
124,
127,
137,
146,
144,
136,
131,
123,
104,
90,
89,
89,
100,
139,
174,
165,
128,
105,
103,
108,
123,
150,
168,
161,
140,
126,
122,
124,
134,
145,
148,
141,
134,
128,
114,
97,
91,
94,
93,
106,
146,
173,
155,
120,
105,
107,
112,
127,
152,
167,
158,
138,
124,
121,
125,
136,
147,
148,
139,
132,
130,
120,
103,
93,
95,
96,
95,
121,
161,
169,
139,
111,
106,
111,
119,
137,
159,
165,
150,
130,
121,
122,
129,
140,
147,
145,
138,
132,
130,
121,
104,
94,
98,
102,
96,
106,
145,
170,
152,
119,
107,
113,
119,
128,
147,
161,
157,
139,
124,
120,
124,
134,
144,
147,
142,
135,
132,
129,
118,
103,
97,
103,
106,
99,
104,
136,
164,
155,
126,
111,
115,
120,
124,
138,
155,
158,
145,
127,
119,
122,
131,
141,
147,
145,
138,
132,
129,
124,
114,
104,
102,
107,
108,
98,
103,
136,
163,
155,
127,
113,
117,
121,
123,
133,
150,
157,
147,
129,
119,
121,
129,
139,
147,
148,
142,
134,
128,
125,
122,
114,
108,
108,
111,
107,
96,
100,
132,
161,
157,
133,
117,
117,
119,
120,
127,
144,
157,
151,
134,
121,
120,
127,
135,
142,
147,
145,
137,
130,
126,
125,
122,
114,
109,
110,
112,
107,
95,
101,
133,
160,
157,
133,
118,
117,
120,
119,
125,
140,
154,
153,
138,
123,
119,
125,
133,
140,
146,
147,
141,
131,
125,
125,
125,
122,
116,
112,
112,
110,
102,
94,
107,
139,
161,
154,
132,
117,
117,
119,
119,
125,
139,
153,
152,
138,
124,
120,
126,
133,
138,
143,
146,
143,
133,
126,
125,
127,
126,
120,
115,
113,
112,
109,
100,
97,
114,
144,
159,
149,
129,
118,
118,
119,
119,
125,
139,
151,
151,
138,
125,
122,
127,
132,
135,
140,
146,
145,
136,
126,
124,
127,
127,
124,
119,
116,
114,
110,
104,
98,
102,
125,
150,
157,
144,
126,
117,
117,
119,
120,
127,
141,
151,
148,
135,
124,
123,
128,
132,
134,
139,
144,
144,
136,
127,
125,
128,
129,
126,
122,
120,
117,
112,
106,
101,
100,
113,
135,
153,
153,
139,
124,
117,
117,
118,
121,
129,
142,
150,
146,
133,
124,
124,
129,
133,
134,
138,
143,
143,
136,
128,
126,
128,
129,
127,
122,
118,
116,
113,
109,
103,
102,
114,
135,
151,
151,
137,
123,
118,
119,
120,
121,
127,
140,
149,
146,
133,
124,
123,
129,
133,
133,
135,
140,
142,
138,
130,
126,
128,
131,
129,
125,
121,
118,
116,
112,
107,
104,
106,
120,
139,
150,
147,
134,
123,
119,
120,
121,
122,
128,
139,
147,
143,
133,
124,
124,
130,
133,
133,
133,
137,
140,
138,
132,
127,
128,
131,
131,
127,
121,
119,
118,
115,
110,
105,
104,
114,
131,
145,
148,
139,
128,
122,
121,
121,
121,
123,
132,
142,
145,
139,
129,
125,
128,
132,
132,
131,
133,
137,
140,
137,
131,
129,
130,
132,
130,
125,
121,
119,
119,
116,
111,
106,
106,
115,
129,
142,
145,
139,
131,
125,
122,
122,
121,
123,
129,
138,
143,
140,
132,
127,
128,
131,
132,
131,
131,
134,
138,
138,
134,
130,
129,
131,
131,
127,
122,
119,
119,
118,
114,
109,
107,
111,
122,
136,
143,
142,
135,
128,
124,
123,
123,
122,
125,
132,
139,
141,
136,
130,
128,
130,
132,
132,
130,
130,
134,
137,
137,
134,
131,
130,
131,
130,
127,
122,
120,
119,
118,
116,
112,
108,
110,
120,
133,
141,
142,
135,
129,
126,
125,
125,
123,
124,
129,
136,
140,
137,
132,
129,
130,
132,
132,
130,
129,
132,
135,
136,
135,
132,
130,
130,
130,
127,
123,
120,
119,
119,
117,
114,
110,
110,
117,
128,
138,
141,
137,
131,
127,
126,
126,
125,
124,
126,
132,
137,
137,
134,
131,
130,
132,
132,
131,
129,
130,
132,
135,
136,
134,
132,
130,
130,
129,
125,
122,
119,
119,
118,
117,
114,
111,
114,
121,
131,
138,
138,
134,
130,
128,
128,
127,
126,
125,
128,
132,
135,
136,
134,
132,
131,
131,
131,
130,
129,
130,
132,
134,
134,
133,
131,
130,
129,
128,
125,
122,
120,
119,
118,
117,
115,
113,
115,
122,
131,
136,
137,
133,
130,
128,
129,
129,
127,
126,
127,
131,
134,
136,
135,
132,
130,
130,
131,
131,
131,
130,
131,
132,
134,
133,
131,
129,
128,
127,
125,
122,
119,
118,
118,
117,
116,
116,
118,
124,
130,
135,
135,
132,
129,
128,
129,
130,
129,
128,
129,
131,
134,
135,
134,
132,
130,
130,
132,
132,
131,
130,
131,
132,
133,
132,
130,
128,
126,
125,
123,
122,
120,
118,
117,
117,
118,
119,
122,
126,
130,
133,
133,
131,
129,
129,
130,
130,
130,
130,
130,
132,
133,
134,
133,
132,
131,
131,
132,
132,
131,
131,
131,
131,
131,
130,
129,
127,
125,
123,
122,
121,
119,
118,
118,
119,
120,
122,
124,
127,
129,
131,
131,
130,
129,
129,
130,
131,
132,
132,
132,
132,
133,
133,
133,
133,
132,
132,
132,
131,
131,
130,
130,
130,
130,
128,
127,
125,
123,
122,
120,
120,
119,
119,
120,
121,
122,
123,
125,
127,
129,
130,
130,
130,
131,
132,
133,
133,
132,
132,
133,
134,
134,
133,
132,
131,
132,
132,
131,
130,
129,
129,
129,
128,
127,
125,
123,
122,
122,
121,
121,
121,
121,
122,
122,
123,
124,
124,
125,
127,
128,
130,
131,
133,
133,
133,
133,
134,
134,
134,
133,
133,
132,
132,
132,
131,
131,
130,
129,
128,
128,
127,
127,
126,
125,
125,
124,
123,
122,
121,
121,
122,
123,
124,
124,
124,
125,
126,
127,
127,
128,
129,
131,
132,
132,
132,
132,
133,
133,
133,
132,
132,
132,
132,
132,
131,
130,
130,
130,
129,
129,
128,
127,
126,
126,
126,
124,
123,
123,
124,
124,
124,
123,
123,
124,
125,
126,
127,
126,
127,
127,
129,
130,
130,
129,
130,
130,
131,
131,
131,
131,
131,
132,
131,
130,
130,
130,
131,
130,
129,
129,
128,
129,
129,
127,
126,
126,
126,
126,
125,
124,
125,
126,
127,
126,
126,
125,
126,
127,
128,
128,
128,
127,
128,
128,
129,
129,
129,
129,
128,
129,
130,
130,
130,
129,
129,
129,
130,
130,
129,
129,
128,
129,
129,
129,
128,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
129,
129,
128,
128,
129,
129,
129,
128,
128,
128,
128,
129,
129,
128,
128,
128,
128,
129,
128,
128,
127,
127,
128,
128,
128,
128,
127,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
129,
128,
128,
128,
128,
129,
129,
128,
128,
128,
129,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128
};
uint8_t i=0;
ISR(TIMER2_COMP_vect){
	OCR1B=pgm_read_byte(&sinewave[i]);
   i++;
	}
int main(void) {

DDRB=(1<<2);
OCR2=250;
TCCR2=(1<<WGM21);
TCCR1A=(1<<COM1B1)|(1<<WGM10);
TCCR1B=(1<<WGM12);
TCCR1B |= _BV(CS10);
TCCR2|=(1<<CS21);
TIMSK=(1<<OCIE2);
sei();
    while (1) {
   //loop for ever. Interrupts will do the job.
    }
}


#include 
#include 
#include 
const uint8_t  sinewave[] PROGMEM= //256 values
{ 
82,
73,
70,
70,
218,
15,
0,
0,
87,
65,
86,
69,
102,
109,
116,
32,
18,
0,
0,
0,
1,
0,
1,
0,
112,
23,
0,
0,
112,
23,
0,
0,
1,
0,
8,
0,
0,
0,
100,
97,
116,
97,
180,
15,
0,
0,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
128,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
128,
128,
128,
129,
128,
127,
128,
129,
128,
128,
128,
127,
128,
129,
128,
127,
128,
127,
128,
129,
128,
127,
128,
129,
128,
128,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
128,
128,
127,
128,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
127,
129,
129,
127,
128,
129,
128,
128,
129,
128,
126,
128,
129,
128,
128,
128,
128,
128,
128,
128,
129,
127,
127,
130,
129,
127,
127,
128,
127,
128,
129,
127,
128,
129,
128,
128,
129,
128,
128,
128,
128,
128,
130,
128,
126,
128,
129,
128,
128,
128,
126,
126,
128,
130,
129,
128,
127,
128,
128,
129,
129,
126,
127,
129,
130,
130,
127,
126,
130,
129,
127,
129,
128,
126,
130,
130,
125,
127,
130,
126,
127,
129,
128,
127,
128,
129,
128,
126,
129,
131,
127,
124,
130,
131,
126,
129,
129,
124,
126,
132,
130,
126,
126,
130,
129,
125,
128,
129,
124,
128,
133,
129,
127,
128,
127,
128,
129,
129,
127,
127,
130,
128,
127,
130,
127,
124,
131,
132,
127,
126,
127,
129,
129,
126,
127,
130,
124,
128,
135,
125,
123,
132,
129,
124,
129,
129,
126,
130,
127,
126,
130,
129,
127,
131,
129,
123,
130,
131,
123,
126,
130,
127,
127,
130,
129,
126,
126,
129,
130,
127,
127,
130,
131,
127,
127,
131,
129,
126,
127,
128,
130,
129,
127,
127,
127,
123,
127,
134,
126,
122,
133,
133,
122,
127,
132,
124,
128,
135,
128,
124,
128,
128,
128,
131,
127,
126,
131,
128,
126,
131,
126,
123,
132,
132,
127,
128,
127,
123,
128,
132,
127,
127,
131,
128,
125,
129,
129,
126,
130,
132,
128,
125,
125,
127,
129,
128,
127,
129,
129,
128,
129,
129,
127,
126,
130,
131,
130,
127,
125,
128,
130,
127,
128,
131,
128,
124,
124,
129,
129,
124,
128,
132,
125,
126,
132,
128,
124,
130,
131,
128,
132,
132,
126,
126,
130,
130,
129,
128,
127,
126,
124,
126,
128,
126,
126,
127,
125,
127,
130,
129,
128,
129,
130,
135,
135,
127,
126,
131,
131,
130,
132,
128,
119,
119,
126,
125,
122,
125,
125,
124,
127,
131,
130,
126,
131,
136,
136,
136,
132,
132,
136,
136,
131,
122,
117,
123,
127,
121,
117,
117,
115,
121,
133,
133,
123,
124,
132,
136,
138,
141,
140,
137,
138,
142,
136,
118,
116,
129,
127,
117,
115,
110,
102,
113,
131,
133,
127,
128,
132,
135,
140,
143,
143,
143,
144,
144,
138,
120,
113,
127,
125,
110,
110,
111,
103,
110,
130,
134,
126,
127,
134,
136,
140,
148,
149,
145,
145,
144,
135,
118,
115,
126,
122,
108,
103,
99,
102,
122,
141,
137,
123,
122,
130,
136,
146,
155,
151,
145,
145,
144,
135,
117,
110,
121,
120,
105,
100,
99,
107,
130,
143,
133,
122,
123,
130,
139,
151,
156,
149,
144,
145,
142,
134,
117,
106,
116,
117,
103,
92,
101,
124,
138,
136,
131,
124,
119,
129,
146,
154,
153,
150,
148,
142,
137,
132,
115,
105,
114,
114,
97,
91,
112,
135,
139,
133,
129,
121,
117,
133,
151,
152,
149,
154,
151,
139,
133,
131,
113,
102,
111,
113,
94,
91,
121,
145,
139,
129,
128,
121,
118,
133,
152,
154,
151,
154,
150,
135,
128,
127,
114,
105,
109,
107,
92,
97,
128,
147,
139,
129,
127,
121,
120,
134,
151,
154,
153,
155,
149,
133,
126,
123,
110,
104,
108,
104,
94,
107,
135,
145,
136,
129,
127,
121,
122,
135,
148,
152,
154,
155,
146,
132,
126,
119,
107,
104,
108,
101,
96,
115,
139,
143,
135,
131,
130,
124,
123,
134,
145,
151,
156,
156,
145,
131,
124,
115,
105,
105,
104,
96,
101,
125,
143,
142,
135,
133,
129,
123,
124,
135,
145,
152,
158,
156,
142,
130,
122,
110,
101,
102,
99,
95,
109,
135,
146,
141,
135,
133,
127,
121,
127,
138,
146,
154,
159,
152,
138,
127,
117,
106,
102,
101,
95,
97,
119,
140,
144,
139,
137,
133,
126,
123,
130,
139,
146,
155,
158,
148,
135,
125,
112,
102,
99,
97,
94,
106,
130,
144,
143,
139,
136,
130,
124,
126,
134,
141,
149,
157,
154,
142,
131,
121,
109,
102,
100,
94,
95,
114,
136,
144,
141,
139,
137,
130,
125,
129,
136,
142,
150,
156,
150,
138,
128,
117,
106,
102,
98,
91,
100,
122,
139,
142,
140,
141,
138,
130,
127,
131,
136,
143,
151,
153,
145,
135,
126,
114,
105,
100,
93,
94,
110,
129,
139,
140,
142,
141,
135,
130,
130,
134,
138,
145,
151,
148,
140,
132,
121,
111,
105,
98,
92,
99,
117,
132,
137,
140,
143,
141,
135,
131,
132,
135,
139,
146,
149,
144,
137,
128,
118,
110,
104,
96,
94,
106,
123,
133,
137,
140,
143,
140,
135,
133,
134,
136,
141,
146,
145,
140,
134,
125,
115,
109,
103,
96,
99,
113,
126,
132,
135,
140,
142,
139,
135,
135,
136,
138,
142,
144,
141,
136,
131,
123,
115,
110,
102,
97,
103,
116,
126,
131,
135,
141,
142,
138,
136,
136,
137,
139,
143,
143,
139,
134,
128,
120,
114,
109,
101,
99,
108,
119,
126,
130,
136,
140,
140,
138,
138,
138,
138,
140,
142,
140,
136,
131,
125,
118,
113,
106,
100,
103,
114,
123,
127,
132,
138,
140,
139,
137,
138,
138,
140,
142,
142,
138,
134,
128,
121,
116,
111,
102,
100,
109,
121,
126,
129,
134,
138,
139,
137,
137,
138,
138,
141,
143,
142,
136,
130,
122,
115,
110,
103,
97,
106,
122,
131,
132,
133,
138,
138,
132,
134,
139,
141,
144,
150,
148,
140,
132,
122,
106,
99,
96,
87,
99,
133,
152,
146,
137,
131,
121,
115,
126,
145,
154,
157,
161,
152,
132,
120,
111,
97,
94,
96,
94,
114,
148,
157,
140,
125,
119,
111,
116,
140,
159,
160,
158,
156,
142,
123,
118,
107,
93,
98,
101,
100,
125,
155,
152,
130,
120,
116,
112,
125,
153,
164,
156,
153,
150,
133,
120,
118,
103,
93,
102,
101,
104,
136,
159,
145,
123,
118,
114,
114,
136,
162,
163,
152,
151,
145,
126,
120,
114,
97,
97,
103,
98,
114,
151,
158,
133,
119,
117,
111,
120,
151,
167,
156,
149,
150,
137,
122,
122,
109,
92,
100,
103,
99,
129,
161,
151,
124,
117,
114,
111,
132,
163,
166,
150,
149,
146,
128,
121,
119,
99,
93,
103,
97,
109,
149,
162,
137,
119,
116,
110,
117,
150,
169,
157,
148,
150,
137,
122,
124,
110,
89,
99,
105,
98,
126,
163,
153,
121,
115,
115,
110,
131,
166,
167,
147,
148,
148,
128,
120,
119,
97,
91,
105,
99,
110,
152,
163,
133,
115,
115,
110,
120,
155,
172,
154,
146,
150,
135,
121,
124,
106,
88,
102,
102,
98,
136,
168,
146,
117,
116,
112,
110,
141,
172,
162,
145,
150,
143,
123,
123,
115,
91,
96,
105,
97,
121,
162,
156,
124,
114,
113,
107,
129,
167,
169,
148,
146,
148,
130,
122,
121,
97,
89,
105,
101,
108,
151,
165,
134,
114,
115,
108,
118,
157,
174,
154,
144,
149,
136,
122,
124,
105,
86,
101,
104,
102,
139,
167,
144,
116,
114,
110,
112,
147,
175,
160,
144,
149,
140,
123,
125,
111,
86,
96,
105,
100,
133,
169,
150,
116,
113,
111,
108,
140,
175,
165,
143,
148,
143,
124,
124,
115,
87,
94,
107,
99,
126,
167,
155,
118,
112,
113,
107,
134,
173,
168,
144,
146,
145,
127,
123,
118,
89,
90,
106,
101,
123,
164,
158,
122,
111,
111,
107,
132,
171,
169,
146,
145,
145,
128,
124,
121,
91,
88,
107,
101,
118,
163,
161,
123,
111,
113,
107,
128,
169,
171,
145,
143,
147,
130,
123,
123,
95,
86,
106,
102,
113,
158,
165,
128,
110,
113,
107,
122,
164,
175,
148,
140,
148,
134,
123,
124,
100,
84,
102,
102,
110,
155,
169,
133,
110,
112,
107,
119,
161,
177,
151,
139,
147,
136,
122,
126,
106,
84,
98,
103,
106,
148,
172,
140,
111,
110,
107,
115,
154,
178,
156,
138,
146,
139,
123,
126,
112,
84,
96,
105,
102,
137,
172,
149,
113,
110,
109,
110,
145,
178,
162,
138,
143,
143,
125,
125,
119,
89,
91,
106,
99,
124,
168,
160,
121,
109,
110,
107,
133,
174,
171,
141,
139,
146,
130,
124,
125,
97,
85,
104,
101,
112,
158,
170,
132,
108,
110,
107,
120,
163,
178,
149,
136,
145,
137,
123,
128,
112,
85,
98,
105,
99,
137,
174,
151,
113,
109,
109,
110,
144,
179,
163,
135,
141,
145,
128,
125,
126,
94,
85,
106,
100,
111,
160,
171,
131,
107,
110,
108,
122,
164,
177,
148,
135,
146,
138,
123,
129,
115,
85,
96,
107,
96,
128,
173,
158,
116,
108,
112,
108,
134,
176,
170,
137,
137,
147,
132,
123,
129,
106,
84,
102,
105,
100,
139,
174,
149,
111,
108,
110,
112,
146,
178,
162,
133,
139,
146,
129,
123,
128,
102,
87,
106,
101,
100,
148,
176,
142,
109,
109,
109,
114,
151,
179,
157,
133,
142,
144,
126,
125,
127,
99,
88,
107,
100,
102,
151,
175,
139,
108,
110,
109,
114,
153,
180,
155,
131,
141,
143,
126,
126,
130,
101,
88,
108,
100,
96,
145,
177,
145,
110,
110,
109,
112,
148,
179,
159,
132,
139,
145,
129,
125,
131,
108,
88,
106,
103,
91,
133,
176,
154,
115,
109,
110,
109,
139,
176,
165,
135,
137,
146,
132,
124,
133,
117,
90,
99,
106,
89,
117,
171,
168,
124,
106,
110,
107,
126,
168,
175,
143,
132,
144,
138,
124,
130,
129,
98,
91,
110,
98,
95,
146,
177,
143,
109,
110,
111,
113,
147,
177,
159,
132,
138,
144,
130,
126,
135,
119,
92,
99,
106,
87,
110,
167,
172,
129,
107,
111,
108,
121,
161,
177,
149,
132,
142,
139,
124,
129,
137,
113,
92,
104,
100,
85,
121,
175,
167,
122,
108,
111,
107,
125,
166,
175,
145,
133,
142,
137,
123,
129,
135,
111,
93,
106,
101,
85,
121,
173,
165,
122,
108,
113,
110,
126,
164,
173,
145,
133,
142,
137,
124,
129,
137,
116,
94,
104,
102,
82,
112,
171,
172,
127,
108,
112,
108,
118,
159,
177,
151,
132,
139,
138,
125,
129,
140,
127,
99,
99,
106,
84,
90,
150,
183,
148,
111,
110,
110,
108,
139,
175,
167,
136,
133,
140,
130,
124,
137,
140,
115,
97,
106,
101,
76,
102,
166,
178,
136,
111,
113,
107,
111,
149,
177,
158,
133,
136,
139,
127,
127,
140,
138,
116,
101,
105,
98,
75,
98,
162,
182,
143,
113,
112,
107,
108,
142,
174,
163,
137,
135,
138,
127,
125,
139,
143,
126,
108,
103,
100,
79,
79,
135,
184,
167,
125,
110,
107,
103,
122,
160,
172,
152,
136,
136,
131,
124,
132,
143,
139,
124,
110,
102,
94,
77,
86,
143,
184,
163,
124,
110,
106,
102,
122,
161,
175,
154,
135,
132,
127,
123,
134,
147,
142,
127,
114,
103,
94,
83,
80,
119,
173,
177,
139,
111,
105,
102,
112,
147,
174,
165,
140,
130,
127,
123,
129,
144,
147,
137,
126,
113,
99,
90,
83,
86,
125,
173,
174,
137,
110,
104,
103,
115,
147,
171,
163,
141,
129,
125,
124,
132,
144,
145,
137,
130,
121,
105,
93,
88,
84,
102,
149,
178,
158,
122,
106,
103,
108,
128,
157,
169,
155,
136,
126,
124,
127,
137,
146,
144,
136,
131,
123,
104,
90,
89,
89,
100,
139,
174,
165,
128,
105,
103,
108,
123,
150,
168,
161,
140,
126,
122,
124,
134,
145,
148,
141,
134,
128,
114,
97,
91,
94,
93,
106,
146,
173,
155,
120,
105,
107,
112,
127,
152,
167,
158,
138,
124,
121,
125,
136,
147,
148,
139,
132,
130,
120,
103,
93,
95,
96,
95,
121,
161,
169,
139,
111,
106,
111,
119,
137,
159,
165,
150,
130,
121,
122,
129,
140,
147,
145,
138,
132,
130,
121,
104,
94,
98,
102,
96,
106,
145,
170,
152,
119,
107,
113,
119,
128,
147,
161,
157,
139,
124,
120,
124,
134,
144,
147,
142,
135,
132,
129,
118,
103,
97,
103,
106,
99,
104,
136,
164,
155,
126,
111,
115,
120,
124,
138,
155,
158,
145,
127,
119,
122,
131,
141,
147,
145,
138,
132,
129,
124,
114,
104,
102,
107,
108,
98,
103,
136,
163,
155,
127,
113,
117,
121,
123,
133,
150,
157,
147,
129,
119,
121,
129,
139,
147,
148,
142,
134,
128,
125,
122,
114,
108,
108,
111,
107,
96,
100,
132,
161,
157,
133,
117,
117,
119,
120,
127,
144,
157,
151,
134,
121,
120,
127,
135,
142,
147,
145,
137,
130,
126,
125,
122,
114,
109,
110,
112,
107,
95,
101,
133,
160,
157,
133,
118,
117,
120,
119,
125,
140,
154,
153,
138,
123,
119,
125,
133,
140,
146,
147,
141,
131,
125,
125,
125,
122,
116,
112,
112,
110,
102,
94,
107,
139,
161,
154,
132,
117,
117,
119,
119,
125,
139,
153,
152,
138,
124,
120,
126,
133,
138,
143,
146,
143,
133,
126,
125,
127,
126,
120,
115,
113,
112,
109,
100,
97,
114,
144,
159,
149,
129,
118,
118,
119,
119,
125,
139,
151,
151,
138,
125,
122,
127,
132,
135,
140,
146,
145,
136,
126,
124,
127,
127,
124,
119,
116,
114,
110,
104,
98,
102,
125,
150,
157,
144,
126,
117,
117,
119,
120,
127,
141,
151,
148,
135,
124,
123,
128,
132,
134,
139,
144,
144,
136,
127,
125,
128,
129,
126,
122,
120,
117,
112,
106,
101,
100,
113,
135,
153,
153,
139,
124,
117,
117,
118,
121,
129,
142,
150,
146,
133,
124,
124,
129,
133,
134,
138,
143,
143,
136,
128,
126,
128,
129,
127,
122,
118,
116,
113,
109,
103,
102,
114,
135,
151,
151,
137,
123,
118,
119,
120,
121,
127,
140,
149,
146,
133,
124,
123,
129,
133,
133,
135,
140,
142,
138,
130,
126,
128,
131,
129,
125,
121,
118,
116,
112,
107,
104,
106,
120,
139,
150,
147,
134,
123,
119,
120,
121,
122,
128,
139,
147,
143,
133,
124,
124,
130,
133,
133,
133,
137,
140,
138,
132,
127,
128,
131,
131,
127,
121,
119,
118,
115,
110,
105,
104,
114,
131,
145,
148,
139,
128,
122,
121,
121,
121,
123,
132,
142,
145,
139,
129,
125,
128,
132,
132,
131,
133,
137,
140,
137,
131,
129,
130,
132,
130,
125,
121,
119,
119,
116,
111,
106,
106,
115,
129,
142,
145,
139,
131,
125,
122,
122,
121,
123,
129,
138,
143,
140,
132,
127,
128,
131,
132,
131,
131,
134,
138,
138,
134,
130,
129,
131,
131,
127,
122,
119,
119,
118,
114,
109,
107,
111,
122,
136,
143,
142,
135,
128,
124,
123,
123,
122,
125,
132,
139,
141,
136,
130,
128,
130,
132,
132,
130,
130,
134,
137,
137,
134,
131,
130,
131,
130,
127,
122,
120,
119,
118,
116,
112,
108,
110,
120,
133,
141,
142,
135,
129,
126,
125,
125,
123,
124,
129,
136,
140,
137,
132,
129,
130,
132,
132,
130,
129,
132,
135,
136,
135,
132,
130,
130,
130,
127,
123,
120,
119,
119,
117,
114,
110,
110,
117,
128,
138,
141,
137,
131,
127,
126,
126,
125,
124,
126,
132,
137,
137,
134,
131,
130,
132,
132,
131,
129,
130,
132,
135,
136,
134,
132,
130,
130,
129,
125,
122,
119,
119,
118,
117,
114,
111,
114,
121,
131,
138,
138,
134,
130,
128,
128,
127,
126,
125,
128,
132,
135,
136,
134,
132,
131,
131,
131,
130,
129,
130,
132,
134,
134,
133,
131,
130,
129,
128,
125,
122,
120,
119,
118,
117,
115,
113,
115,
122,
131,
136,
137,
133,
130,
128,
129,
129,
127,
126,
127,
131,
134,
136,
135,
132,
130,
130,
131,
131,
131,
130,
131,
132,
134,
133,
131,
129,
128,
127,
125,
122,
119,
118,
118,
117,
116,
116,
118,
124,
130,
135,
135,
132,
129,
128,
129,
130,
129,
128,
129,
131,
134,
135,
134,
132,
130,
130,
132,
132,
131,
130,
131,
132,
133,
132,
130,
128,
126,
125,
123,
122,
120,
118,
117,
117,
118,
119,
122,
126,
130,
133,
133,
131,
129,
129,
130,
130,
130,
130,
130,
132,
133,
134,
133,
132,
131,
131,
132,
132,
131,
131,
131,
131,
131,
130,
129,
127,
125,
123,
122,
121,
119,
118,
118,
119,
120,
122,
124,
127,
129,
131,
131,
130,
129,
129,
130,
131,
132,
132,
132,
132,
133,
133,
133,
133,
132,
132,
132,
131,
131,
130,
130,
130,
130,
128,
127,
125,
123,
122,
120,
120,
119,
119,
120,
121,
122,
123,
125,
127,
129,
130,
130,
130,
131,
132,
133,
133,
132,
132,
133,
134,
134,
133,
132,
131,
132,
132,
131,
130,
129,
129,
129,
128,
127,
125,
123,
122,
122,
121,
121,
121,
121,
122,
122,
123,
124,
124,
125,
127,
128,
130,
131,
133,
133,
133,
133,
134,
134,
134,
133,
133,
132,
132,
132,
131,
131,
130,
129,
128,
128,
127,
127,
126,
125,
125,
124,
123,
122,
121,
121,
122,
123,
124,
124,
124,
125,
126,
127,
127,
128,
129,
131,
132,
132,
132,
132,
133,
133,
133,
132,
132,
132,
132,
132,
131,
130,
130,
130,
129,
129,
128,
127,
126,
126,
126,
124,
123,
123,
124,
124,
124,
123,
123,
124,
125,
126,
127,
126,
127,
127,
129,
130,
130,
129,
130,
130,
131,
131,
131,
131,
131,
132,
131,
130,
130,
130,
131,
130,
129,
129,
128,
129,
129,
127,
126,
126,
126,
126,
125,
124,
125,
126,
127,
126,
126,
125,
126,
127,
128,
128,
128,
127,
128,
128,
129,
129,
129,
129,
128,
129,
130,
130,
130,
129,
129,
129,
130,
130,
129,
129,
128,
129,
129,
129,
128,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
127,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
129,
129,
128,
128,
129,
129,
129,
128,
128,
128,
128,
129,
129,
128,
128,
128,
128,
129,
128,
128,
127,
127,
128,
128,
128,
128,
127,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
129,
128,
128,
128,
128,
129,
129,
128,
128,
128,
129,
129,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128,
128
};
uint8_t i=0;
ISR(TIMER2_COMP_vect){
	OCR1B=pgm_read_byte(&sinewave[i]);
   i++;
	}
int main(void) {

DDRB=(1<<2);
OCR2=250;
TCCR2=(1<<WGM21);
TCCR1A=(1<<COM1B1)|(1<<WGM10);
TCCR1B=(1<<WGM12);
TCCR1B |= _BV(CS10);
TCCR2|=(1<<CS21);
TIMSK=(1<<OCIE2);
sei();
    while (1) {
   //loop for ever. Interrupts will do the job.
    }
}



  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should be a little more critical about your wave data.
That sure doesn't look anything near a sinewave.
Generate one with a piece of C code instead.

And you're still not wrapping the index variable.

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

that is actually an wav file sampled. have already got the sine wave.what exactly do u mean by wrapping the index variable?...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
that is actually an wav file sampled. have already got the sine wave.what exactly do u mean by wrapping the index variable?...

if (++i == len(sinewave)) i = 0;

So you were able to confirm the sine wave was correct ?
eg. Verified that all your frequencies are correct.
So you know the timers are actually running at their expected speeds.

Download HxD (link in my previous post) open your raw wav file and choose Export as C string, and it will generate a nice looking table like in your original post.

edit:

Taking a quick look at that data, the amplitude of the signal is overall very low, except from some noise here and there.
Start with a sound that you can clearly recognize, like a constant tone. So you will still hear it when it's pitched. And make sure the signal strength is just below clipping level.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i generated a sine wave using audacity and heard a tone on my speaker however noise accompanying it was pretty significant.

I then tried playing a wav file with sufficient amplitude sampled at 6khz but the speaker produced unrecognizable sound,possibly because of noise superimposition.

I think having heard the tone it's safe to say the code is working,and my problem lies with the filter design.

Presently i have a 2nd order low pass butterworth filter with 1k and a 0.022uF capacitor(i didn't have a choice with the capacitors these are the only ones i had as i couldn't go to the lab for sometime),this gives a cutoff of about 8khz,maybe if i get the cutoff to 4khz,then noise will be filtered out?

Any suggestions on the filter front, as well as on any problem/insight on the code will be appreciated

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you attenuate the pwm frequency, there should not be any noise.

You could try injecting an audio signal before the filter to deduce if the noise is caused by it..
Use the ouput from your PC speakers for example..

What does it look like on the scope ?
That's why it's easier to use a simple looping constant sine wave to first fix all your problems ..

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i reverted to a first order butterworth filter with 4khz cutoff but still problem persists.

r=1k and c=0.042uf to give cut-off at about 4khz, and PWM frequency is 47khz (12mhz/255),so attenuation should be sufficient .(A=Amax/sqrt(1+(f/fh)^2)).

I am posting my audio file as well as the exported C array from hxd,maybe there's some problem there.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
i reverted to a first order butterworth filter with 4khz cutoff but still problem persists.

r=1k and c=0.042uf to give cut-off at about 4khz, and PWM frequency is 47khz (12mhz/255),so attenuation should be sufficient .(A=Amax/sqrt(1+(f/fh)^2)).

I am posting my audio file as well as the exported C array from hxd,maybe there's some problem there.

looking at the first 4 characters of your lookup table in robot.c, i think your problem is very clear. And it's not your filter :
0x52, 0x49, 0x46, 0x46 = "RIFF"

Sure you must of seen this in HxD when you exported it !?

You need to have a RAW DATA FILE !
Your .wav file contains a header, describing the waveformat used to store the sound (eg. samplerate, bitsPerSample, Channels,..)
You don't want this in your export. So you first need to get a RAW data file.
With one byte per sample at the desired samplerate.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

Last Edited: Fri. Jun 26, 2009 - 06:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually it usually doesn't matter if you play the 62 bytes at the start of a WAV file (including "RIFF") because it's over so quick (62/8000s ~= 8ms) that the worst that happens is an almost imperceptible "crackle" at the start of the real audio.

OTOH I usually use an editor to strip the first 62 but, if you have plenty of storage, leave them there and just start your data pointer at offset 62

Cliff

PS Now if you were using ADPCM where the data is RELATIVE to the previous data it could take a while to get over a "glitch" like this.

PPS Sorry, I'm wrong I think 62 is the size of an RGB .BMP header, the WAV header is just 44 bytes in fact - so 5..6ms

Last Edited: Fri. Jun 26, 2009 - 06:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Actually it usually doesn't matter if you play the 62 bytes at the start of a WAV file (including "RIFF") because it's over so quick 62/8000s ~= 8ms that the worst that happens is an almost imperceptible "crackle" at the start of the real audio.

OTOH I usually use an editor to strip the first 62 but, if you have plenty of storage, leave them there and just start your data pointer at offset 62

Cliff

Yes agreed, but I wouldn't be surprised if the waveformat is incorrect. eg. 2 channels or wrong samplesize. Or indeed that the encoding is incorrect.

To The OP :

Ok, I just copied your data back into a .wav file.
It plays "BOING!".
And this is the format :

Pcm 6000Hz 1 channels 8 bits per sample
Extra Size: 0 Block Align: 1 Average Bytes Per Second: 6000
WaveFormat: 8 bit PCM: 6kHz 1 channels
Length: 3506 bytes: 00:00:00.5840000 

This is correct, so lose the header and try again.

And you still haven't said if you implemented wrapping of i. So did you ?

Cliff:
A Wave file doesn't always have a fixed size header.

edit:
I cannot believe Audacity doesn't support saving to raw pcm files.. Guess I'll take a look at the plugin architecture..

Meanwhile, I suggest you take a look at SoX, as already suggested by telliott :
http://sox.sourceforge.net/

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

im wrapping up the index variable. also i didnt remove the RIFF header for the precise reason that clawson mentioned i.e it is for a very small duration. Ill try and remove the header and see what happens

and sound is "warning"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Cliff:
A Wave file doesn't always have a fixed size header.

I'll give you that but once you have found your "standard" recording method, tools, procedure you can be pretty sure that every file you churn out will have a fixed size header. If you use Cooledit 2000 (I do) or Windows Sound Recorder and record 8bit 9KHz mono PCM then I think I can guarantee that in both cases you will get those 44 bytes.

Of course another feature of Cooledit is that it will also save ".raw" as well but I tend to leave the WAV header on as a record of what the sample rate is and whether it's 8 or 16 bit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Electricity is out right now,otherwise I would have tried it instantly. considering the fact that wave was PCM not ADPCM would removal of a header make much difference.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
im wrapping up the index variable. also i didnt remove the RIFF header for the precise reason that clawson mentioned i.e it is for a very small duration. Ill try and remove the header and see what happens

and sound is "warning"

The sound you posted in robot.c is a voice saying "BOING!" !

Your samplerate timer (Timer 1) is setup correctly to 6kHz(*), but why do you set your PWM Timer to CTC mode ?

* if your system clock is indeed 12MHz

TCCR1B=(1<<WGM12); 

Cliff:
Yes, indeed. I just wanted to point out that it doesn't have to be a fixed size..
The format chunk doesn't necessarily have to be in front of the data chunk.
source: http://www.sonicspot.com/guide/w...
Good thing that most software does this consistently.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

datasheet says wgm12 and wgm10 enabled for fast pwm 8 bit

im attaching my code

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
datasheet says wgm12 and wgm10 enabled for fast pwm 8 bit

im attaching my code

Yes, you are right, i missed the fact that WGM10 was a flag in the TCCR1A register.
So it is indeed configured correctly.

Your PWM frequency would also be ~47kHz (12MHz/256).

Are you certain your system clock is 12MHz ?

If it is an active filter, what opamp are you using, and how are you supplying power to it ?

What does the output look like on the scope before and after the filter ?
This is why I keep saying to use a simple constant sine wave, so you can actually see whats going on using a scope.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes im quite certain. unfortunately i wont get to use the lab till monday till then i have setup without the scope on my study table. as for op amp im using LM324 supplying it 5v through an 8051 training board which takes input from an 12v ac adapter and has pins for 5v regulated supply (basically same as a 7805). Ill see the sine wave on scope b4 and after filter and report back till then ill try tomorrow and day after on the all elusive WARNING or BOING! :-).

I am really working hard on this hope I am not making a stupid mistake. guess as a noob learning curve is steep.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abhishekbhardwaj007 wrote:
yes im quite certain. unfortunately i wont get to use the lab till monday till then i have setup without the scope on my study table. as for op amp im using LM324 supplying it 5v through an 8051 training board which takes input from an 12v ac adapter and has pins for 5v regulated supply (basically same as a 7805). Ill see the sine wave on scope b4 and after filter and report back till then ill try tomorrow and day after on the all elusive WARNING or BOING! :-).

I am really working hard on this hope I am not making a stupid mistake. guess as a noob learning curve is steep.

The important thing is to never give up. Keep at it, and i'm sure you will solve it.

Post the exact schematic of your filter, and we'll take a look.

You could inject an audio signal from your pc or iPod or whatever into your filter, to hear if the filter is actually working.

Or you could capture the output of your filter with the Mic or Line Input on your PC, and use an audio oscilloscope application to analyze the waveform.
This one seems nice :
http://www.zeitnitz.de/Christian...

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about just printing the data out the serial port? Subtract 128 to make it bipolar, divide by 4, add 32 and print out that many spaces then a *.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

actually what i am developing requires messages to be stored on the atnega8 itself. the voice quality might not be good but the above requirement is imperative.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so i tested it out on the scope today and the filter output was giving a sine wave but with a lot of noise. but when i put the probes on the output of the buffer op amp i saw saturation was taking place. I was just getting a DC level. I then increased the Vcc to the op amp from 5v to 10V but saturation still remained. I then did 0CR1b=0.1*sinewave[i] and I got the required sine wave at the output of the op amp,but there was a lot of noise.

So question is how do i lose noise?

I m using R=1k C=0.04uf LM324 op amp in voltage follower configuration with 10V single supply. Someone suggested I can use a transistor to drive the 8 ohm speaker? Will that reduce noise? Also what transistor and biasing should one use? Configuration should be CC for a buffer I suppose?

BASICALLY HOW TO REDUCE NOISE

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My experience has been that the 5V PWM wave from the AVR right into a 4K RC low pass filter (470 ohms and .1uf) works fine into the pc line in. Dont need an active filter.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if put an 8 ohm speaker parallel to the capacitor it causes loading and i get a flat line on the scope.

How do i feed the output to my PC/Laptop for analysis

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Run your AVR system clock through a 74HC4046 VCO IC. Ignore the phase-lock-loop section of the IC. By changing the voltage on the VCO input, your AVR system clock changes and this changes the frequency of the generated sine-wave. Make another table that has every third of the 256 wave values removed. Run this table through another PWM channel on a different timer. This wave will be harmonically related to the original sine wave.
Use a second AVR with a USART to capture MIDI commands. These commands are serial 8/N/1 with 31,250 baudrate (which divides evenly with an 8MHz internal AVR system clock). MIDI also is electronically a '5-mA current-loop', so you need an opto-isolator to capture the input signal. Many schematics on the web from MIDI input.
Parse the MIDI Note-On commands to adjust the voltage for the VCO by using a PWM channel on the MIDI AVR. A MIDI Note-ON message for middle C (at moderate volume) would be 0x90 0x3c 0x50. Make a musical scale 12-note table of several octaves that matches the PWM DAC output voltage to the 74HC4046 VCO that products the correct frequency for that note on the Audio AVR.

As you can see, making Waves on an AVR is a complex process. So don't make waves. Get an inexpensive MIDI synthesizer such as the Yamaha FB01 from eBay for $25-$30 and use the AVR instead to be a MIDI controller. Use a standard PS2 keyboard as the Note input. I have several projects that do this in the Project Archives here. The code is in assembler, but it is modular and well-commented. So it should not be too difficult to convert it to C. If you do this, please re-load the code back here into the Project section.

Thank You, Good Luck.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i feel the above is a slightly tedious and pocket heavy method.thanks though

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok so i am getting a perfect sine wave at the output of the LM324 (used in an active filter with unity gain), but the as soon as I put the speaker at the output the waveform starts to clip at the top. I put a resistor in series and I get the waveform back but with reduced sound of course. My guess is that the op-amp can't provide enough current after a particular point so it starts to clip. Any design changes that may help me overcome this?

Also now I want to play an arbitary wav file. I have a sample file sampled at 6khz but how do I know what the highest frequency in the wav file is ,I will have to change my filter accordingly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just posted example code and an explanation regarding sample frequency for outputting sound. It is completely applicable to any sound. Check it out.

https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=80060

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No need to change filters. It would be good to choose a consistent sampling rate for all of your files. 8kHz is a good compromise between size and fidelity.

You might want to store the waves in external memory, depending on what you want to play, but I found the ATMega168 could hold a few LUTs of 256 entry waveforms. (saw, square, tri).

Alternatively, on the internet somewhere is a granular synth for arduino. I ported it to accept a 1v/oct input like a modular synth. Extra knobs can be used for psuedo-filtering.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

im not able to reproduce the wav file with the current filter setting. although i achieved a sine wave with it.

i produced a sine wave of 500hz sampled at 6khz using audacity , i reproduced it using my code and i had the cutoff for my filter at 500Hz.

Now I want to play the wav file sampled at 6 khz ,but the same filter config is not working. I just want to make things clear about the relation of the filter cut-off to sample rate(also the rate at which I load my samples from LUT), is it = to sample rate? or 1/2 the sample rate??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also: Do you have access to an oscilloscope? It makes "debugging" easier compared to listening through a speaker. If you are careful, guitar amplifiers can usually take a high-impedance input.

In short, if you are playing files at 6kHz sampling rate, update your PWM module at 6kHz. You will be able to faithfully reproduce signals up to 3kHz, and your filter cutoff may be in the neighborhood of 4kHz.

These are all estimations. I recommend a higher sampling rate but of course, it depends on the application. 6khz is fine for a 500hz sine wave

ISR(TIMER2_COMP_vect){ 
   OCR1B=pgm_read_byte(&sinewave[i]); 
   i++; 
   } 

Basically you want TIMER2_COMP_vect to be called at whatever rate you sample your signals at to avoid pitch-inaccuracies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Im attaching the code again. I am doing exactly the same thing, loading values at 6khz (my clock is 12Mhz,so corresponds to a value of 250,with a prescalar of 8 .

There might be something wrong with my op-amp (LM324) it might be saturating. Is there anyway I can play the output of my filter via my PC.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The quad OpAmp LM324 is not a good choice to drive a speaker, Consider the LM386 "Low Voltage Audio Power Amplifier."
Be aware that there are 3 sub-types of the LM386 available, characterized for different supply voltages:
The -1 and -3 for 4V to 12V supply and the -4 for 5V to 18V supply.

Stan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes but the speaker at the moment is not sounding anything like the audio, all i get is clicks that don't make up a legible sound and i put the probe on the filter output as well as the op-amp output and see that both of them are same corresponding to voltage follower configuration.

If any one can post a schematic using an RC filter that actually works for them? Sampling rate is 6khz.

I also tried Roman Black sound is barely legible,which is why Im keen on PWM

Pages