Hi there,
I can see there was quite a lot of discussion about the audio quality on DUE.
In my project I am using:
Arduino DUE,
4x4 Keypad,
SD Data shield,
a phone receiver detect (on/off)
an Amp (2 x 15W (6-18V) with TDA7297)
a Speaker (analog phone receiver)
The sound quality of my speaker is pretty bad. Cannot say it's completely unusable, but it gives a weird pulsating noise and the quality itself is not great.
I've tried: changing the power source, changing the speaker, giving better grounding, applying a capacitor across the input to a power supply of an amp. Nothing improved the quality by much.
Any suggestions would be highly appreciated
// Playing assigned filename
void playSound(const char* cName) {
File myFile = SD.open(cName);
const int S = 1024; // Number of samples to read in block
short buffer[S];
// until the file is not finished
Serial.println("playing ");
Serial.println(cName);
Audio.begin(44100, 200);
delay(200); //delay = no glitch at the beggining of an audio
while (myFile.available()) {
myFile.read(buffer, sizeof(buffer));
// Prepare samples
int volume = 512;
//max volume 1024
Audio.prepare(buffer, S, volume);
Audio.write(buffer, S);
if (state == STATE_IDLE) {
if (isKeyPressed()) {
if (isNumberKey(key)) {
break;
}
}
}
if (hookOffState == 0) {
break;
}
}
Audio.end();
myFile.close();
delay(50); //delay = no glitch at the beggining of an audio
I don't what you mean by an "analog phone speaker", but what sort of sound quality would you expect from it? That amplifier is capable of driving decent home stereo speaker boxes.
UPDATE.
Went to an electronics parts store. Tried multiple chargers (up to 6 amps). Almost no difference.
Went to the professional. They have inspected my project with an oscilloscope and more tools. The conclusion - these 3rd party data log shields suffer some major voltage fluctuations when reading the SD card.
I've tried to combat these fluctuations in prebuffering:
Changing the length of prebuffering affects the speed of a "noise". It somewhat helps.
I am trying to find an SD shied or some kind of module, which would not have this issue. I have already tried one different brand of this shield, sadly not that much of a difference.
Did you remove the carbon microphone cartridge and short the terminals together? Most phone handsets connect the mike and earphone together so the user can hear their own voice.
Paul
Did you remove the carbon microphone cartridge and short the terminals together? Most phone handsets connect the mike and earphone together so the user can hear their own voice.
Paul
No, mine didn't have this short. It was a 4 pin connector: 2 for the earphone and 2 for the mic.
I have also tried this whole setup with another, Arduino-friendly speaker, which gave the same results.
Yes and no - I've tried both. I was convinced that powering it from VIN makes these interferences, but when trying all different power sources I've powered Arduino and the Amp separately - it was little to no difference. Sometimes the sound quality improved, but these interferences (that goes every 200-400 msec) also could be heard much clearer...
I’m sorry, let me qualify this for anyone reading just in case, you do not power anything from Vin pin, EVER, it is the power input for the board, that leads to regulator.
The Due 3.3V supply is noisy, it has an on-board buck converter. For analog signal work I'd suggest using a separate module (the Due's inbuilt ADC and DAC are poor, note, not just because of the noisy supply). For audio work you really want separate analog supply from the microprocessor's digital supply, which is always noisy by its nature.
SDcards pull large currents (this is why they are hot after use) and will definitely put noise on their 3.3V supply - powering them from 5V using a module with a built-in 3.3V regulator can help isolate the noise they inject to the rest of the system. Good decoupling helps, at least 100µF (or more) electrolytic on top of any high speed decoupling is worth trying.
My Amp takes a minimum of 6V... So different power source it is.
Sadly, it does not solve a problem. I will try this setup with another, a new set of boards, but I doubt I've burned the old ones - so I expect no change in interference.
EDIT. Decoupling helps with a general audio quality, which is not the big issue (also my project should imitate an old phone, so it's even better). The biggest issue is that weird interference generated by SD card prebuffering. I'll try to record it today.
EDIT2. This is a recording of my interference. https://www.mboxdrive.com/noise.mp3
The sound should be a background hum when removing the phone receiver. Now we have these almost locomotive-sounding interferences every 400msec (or whatever I am putting as my prebuffer).
UPDATE.
I have tested the setup with different DUE boards, SD shields/modules, and different amplifiers and got the same/similar results - interference. But when testing with other, simpler boards (UNO and MEGA) it works without interference! A bit bizarre. Also, those boards don't have a proper DAC so the quality is not pristine, but it definitely has no repeating interference.