If you are using a DAC,
Just send the samples to DAC at the correct sample rate (per the WAV file header), and the DAC converts the WAV/PCM data to "sound" in real-time. (Actually to an analog
signal which needs to be amplified before the speaker converts it to sound). If the bit-depth of the WAV file doesn't match the DAC, scale it up or down (multiply or divide) as required.
...The audio doesn't need to be decoded. The header has to be "decoded" (or parsed) to get the bit depth, sample rate, and number of channels on order to get the bytes to the DAC with the correct speed/sequence/structure.
If you are "faking it" with Arduino PWM, scale-down the samples to 8-bits (if they are not 8-bits already) before writing the data to PWM at the correct sample rate. (i.e. Divide 16-bit samples by 256 or bit-shift right by 8-bits.) Note that 8-bit WAV files are unsigned, so that data can be sent directly to PWM. But, 16 bit or more WAV files are signed so you'll have to bias the 8-bit data for the PWM output which doesn't go negative.
Note that the 8-bits (and the low default PWM frequency) make for poor-quality sound. You need a DAC to get anything close to the quality from a soundcard or iPod, etc. (You can get an audio shield with a built-in DAC and a sample rate clock and that takes a big load off your Arduino and your software.)
Still I have 3Kb left in the memory.How can I program to decode the data of the wave file in the 3kb space.
What?
