Arduino Due Audio.h and DAC output bad pop at start and end

Hi all,

I'd like to create program which sounds a tone on command, or at pre-specified times of day. Using the Arduino Due and the onboard DAC, it is putting out very nice 44100 16-bit audio track to my amp's line in.

The file it plays is stored on an ethernet shield with SD card. Ethernet is not being used. Just the SD.

I'm using SimpleAudioPlayer.

I have struck a problem. It sounds, for all the world, like the needle is being dropped on the record when Audio.begin() is executed, Audio.prepare(buffer, S, 1024) is executed, and Audio.end() is executed.

Basically, unusable.

Is this the expected behaviour of the DAC? Would the issue be the dac.h or audio.h?

I have tried:

Multiple Dues

Multiple WAV files (different bit rate, mono/stereo, etc)

Multiple ethernet shields

Code workarounds like "analogWrite(0,0);" before Audio.begin();

Any help to silently initialise and prepare the DAC would be most appreciated.

Regards,

Mark

If you only want to output a (single ?) predefined tone thru one of the 2 DACs, why would you use an SD card ?

A similar problem happened in the very early days of the Teensy Audio Library. I solved it by adding code in the constructor to slowly rise the DAC from 0 to 2048 over about a quarter second.

Here's the code:

Maybe you could do something similar in setup(), before sending actual audio to the DAC.

Perhaps you could initialize the DAC to midrail at startup?

A general purpose DAC have 0..2^n-1 corresponding to 0V to Vcc (on on the Due Vcc/6 to 5Vcc/6)

Many audio DACs takes signed values and output bipolar signals (they have an internal negative rail).