Here all all the steps to resolve the distorted audio files when using the Audio library for the Arduino Due.
Open the file /Arduino/libraries/Audio/src/Audio.cpp
Add the 5 lines (as provided by mastrogippo):
Directly under
// Start DAC
dac->begin(VARIANT_MCK / sampleRate);
dac->setOnTransmitEnd_CB(onTransmitEnd, this);
}
void AudioClass::rst(void){
// Buffering starts from the beginning
running = buffer;
next = buffer;
}
Save this as a non formatted text file.
Open the file /Arduino/libraries/Audio/src/Audio.h
Add the 1 line void rst(); (as provided by Steamboat:)
Directly under
class AudioClass : public Print {
public:
AudioClass(DACClass &_dac) : dac(&_dac) { };
void prepare(int16_t *buffer, int S, int volume);
void begin(uint32_t sampleRate, uint32_t msPreBuffer);
void end();
void rst();
Save this as a non formatted text file.
In your code, Assuming you are starting with the Arduino SimpleAudioPlayer example, add Audio.rst(); directly after your myFile.close(); statement.
myFile.close();
Audio.rst();
Upon compilation of your code, the additions to the Audio.cpp and Audio.h files will be incorporated into your final code for uploading to the Due. Utilizing this method will produce the first and all subsequent audio files being played clearly without distortion.