Go Down

Topic: How would I read a 16 bit PCM WAV file (Read 348 times) previous topic - next topic


Hi Guys,

I would like to read a 16 bit 3 channel wave file from an sd card, and output the data to a DAC. At the moment I am reading a CSV file of my data and I am outputting that to the DAC, everything seems to be working. However, this takes up alot of time, since I have to read in ascii represented HEX values, parse the data, convert the data unsigned integers then output them to the DAC.

I was thinking if I saved my data in 16 bit WAV format then I could read the data in, convert each value to unsigned ints then output it straight to the DAC. How would I begin to read a WAV file, I understand how they are formatted, but are they delimited? I know there are libraries out there like TMRpcm, but that wouldnt be suited to what I want to do. Any thoughts?

Thanks in Advance


[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


How would I begin to read a WAV file, I understand how they are formatted, but are they delimited?
You seem to be contradicting yourself here. If you understand how a WAV file is formatted why are you asking how they are delimited (what does that even mean?). And if you understand the format, what's the difficulty in reading it?

Don't send me technical questions via Private Message.



Just curious, which board are you using?  One with a DAC?  With 3 DACs?  Or maybe you're adding a multi-channel DAC chip, with some type of interface suitable for 3 channels of audio?

Regarding WAV data, after you parse the headers to find the section of the file which is the actual audio data, the samples are just packed as binary data, usually LSB first.  So the first 2 bytes of that section will be channel 1, the next 2 bytes will be channel 2, the 5th & 6th bytes will be channel 3.  Then the 7th & 8th bytes will be the second sample for channel 1, and so on...

Three channel WAV is somewhat unusual.  I'm curious what software is generating this file, and in general what you're doing (if you can say)?

FWIW, I wrote a WAV player in my audio lib some time ago, but it only supports mono and stereo, and only 44.1 kHz.  But I'm considering redoing it soon, probably not for more than 2 channels, but to support converting sample rates and maybe conversion to variable speeds.  Maybe...


Thank you for the reply guys,

I am using an Arduino Due with an external quad DAC, which is an AD5754, communicating with SPI. I havent actully created a wav file yet, to be honest I have never used a wav file before or created one. I am just trying to get my program to work faster, I believe the way I am doing it now is quite time consuming. Thank you for the advice I will certainly look in to it.

Go Up