Playing audio from Arduino Due with SD

Hi, I have Arduino Due , 4 ohms 3 watt speaker and SD card module with SD card. I am using HW 104 for amplifier. The audio in not playing properly I don't know why and I have tested in different frequency.

code same in Audio library

I've never used the Due but I know about digital audio...

What library, and is the library specifically for the Due?

Are your audio files in the "correct" format (whatever is supported by the library)?

What's happening?

Have you tested the amplifier with your computer or your phone?

Yes specifically for Due

now I am testing the audio is play but it is very fast and not clear

yes the amplifier is working good

I don't know the correct frequency. In arduino Uno is working on this frequency but not working correctly on Due

That usually means the playback sample rate is faster than the recording (or file) sample rate. It should be "clear" but also pitch-shifted.

With WAV files (or most standard audio formats) the sample rate is included in the file header and on a computer the playback software adjusts accordingly.

It could also happen if you have a mono file but the software thinks it's stereo or if you have an 8-bit and the software thinks it's 16-bits. (The 8 or 16-bit screw-up would also be badly distorted but probably "recognizable".)

If you created the file you should know the sample rate.

Hmmm... I would expect Due library to use the DAC so it wouldn't run on the Uno.

The code may have to be tweaked (or maybe there's a variable you can change) because the Due has a faster clock.

So... If you can figure-out the Due's timing and if you can read the audio data one sample at a time it shouldn't be too hard without using the audio library.

Here is a little introduction to how digital audio works.

You just have to write-out one sample at a time at the correct sample rate. For example - CD audio is 44,100 samples per second so you update the DAC 44,100 times per second. (I believe that works-out to about one sample every 22.7 microseconds, but you're probably using a lower sample rate.)

Normally there is an analog low-pass "smoothing filter" but if the sample-rate is high-enough you can get-by without it, and with a lower sample rate you won't get perfect quality anyway.

  • Since the Due has a 12-bit DAC you'll have to multiply or divide (or bit-shift) to accommodate 8, 16, or 24-bit data. If you are bit-shifting signed values, keep track of the +/- bit, which is the MSB.

  • The DAC can't go negative so you'll have to bias the output by adding 2048 to the signed value. Then add a series capacitor to "block" the DC bias. (8-bit WAV files are unsigned so they are already "'biased".)

If you are using WAV files, here is the WAV format. If you are using 16 or 24-bit the audio data is "little endian" which means the byte data is "reversed" with the least-significant byte first. And with stereo the channels alternate so with 16-bit stereo, the 1st two bytes are the left channel, and the next two are the right channel, then the left again, etc.

...If you are not using WAV files you'll have to know how the data is represented.

now the play back is fine but audio is not at all clear can i use 10uf 16v capacitor on DAC0 pin?

By reputation the DAC outputs on the Due are very delicate: the best thing you can do it route them into an opamp buffer circuit so they can't see low impedances or voltage spikes.

I believe they are rated for an absolute maximum of 3mA, and I'd stick to 1mA maximum to be on the safe side. This really means no direct (or capacitive) connection to the outside world.

ok sir. I have an doubt arduino due is heating overly can I use fan for that