Now my audio "gurgles". What have I done???

The file below labeled “good” was recorded by my Uno at 38,500 samples per second. As you can hear, the music itself is clear, but has some random pops and skips.

Deciding the problem was likely that 38,500 samples were too fast for the SD Card to keep up with, I cut that in half, down to about 18,000 samples per second, and am still happy with the quality for voice.

However, now there is a new problem. The file below labeled “bad” has a motorboat sound that is making my voice “gurgle”. (Terrible). And I’ve tried everything I can think of, yet can’t solve it.

Listening to the wires to the SD Card, I find their signal is the “motorboat”. But the SD Card didn’t “motorboat” at all in the “good” sample, so why now?

Another change is that the “good” sample was made when I had more free memory, the buffers were buffA[256] and buffB[256]. Now as you can see, they are buffA[32] and buffB[32]. But I don’t see a way that could cause “motorboating” or make voice gurgle.

As a test, I have in the below sketch, dispensed with using the buffers (buffA & buffB) and send each byte of audio directly to the SD Card from within the interrupt function. I didn’t expect that to work, thinking I couldn’t call an interrupt from within an interrupt, but it actually sounds a little better than using the buffers! (Slightly less motorboating). It was with this sketch I made the “bad” file, also below.

The sketch probably doesn’t make much sense to you, being a part of a larger project that connects three Arduino Uno’s. But I’m hoping you’ve seen/heard the gurgling problem before, and can easily point out the error of my ways.

good.WAV

bad.WAV

DM_Waves.ino (8.02 KB)

Hi CosmicAu,

I don't know what your solution is, and I'd like to know if we can figure it out, but I want to share my similar problem, using an SD card to record audio using double buffer, interrupted or one byte at a time, polled it comes out choppy and or distorted. I am using a ADPCM codec to preshrink my data. I am going slower than you, 8khz sample, just for voice messages. I thought it might be during recording but I used a file generated by another of the same chip, copied and played it from the SD card and it comes out crappy, although it sounds perfect when read from ram. I am reading the data from the SD card one byte at a time every 125Us, slow. I used some code ideas from Arduino Mega Recording by David Patterson.

I be be part of this thread if I can help or learn in any way.

regards,

Stan K'

Hi, What are you using to amplify the audio before it gets to the arduino, have you monitored it at the input to the controller.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom.... :)

CosmickGold:
Deciding the problem was likely that 38,500 samples were too fast for the SD Card to keep up with, I cut that in half, down to about 18,000 samples per second, and am still happy with the quality for voice.

For “continous play of 8-bit sound samples” on a 8-bit Atmega controller you normally cannot use more than 8000 samples per second.

And doing so requires double buffering with 2 buffers of 512 bytes (= 1 sector on SD card) each.

Otherwise you cannot provide the correct sample data fast enough.

I don’t think that 18,000 samples per second might work on a 16 MHz Atmega, except you are using most of the RAM of a MEGA2560 for data buffering from SD card.

Each read action from an SD card may take (“worst case”) up to 50 milliseconds or even more, especially if the library needs to read a new FAT sector before reading a new data sector.

50 milliseconds with 8000 samples per second mean a minimum buffer size of 400 bytes, but with 18,000 samples per second you’d need 900 bytes to buffer 50 milliseconds without running out of data.

If you need better sound than 8-bit sound with 8000 samples per second, you’d have to use an external WAV-player board.

http://forum.arduino.cc/index.php?topic=180769.0

Check this thread from last summer (ooh, 2 summers! I need to get back to this), that demos sample & store to SD card at CD rate (44.1KHz) and playback from SD card at same rate. fat16ib is the best when it comes to SD card usage.

TomGeorge: You got the answer right, straight off the bat. Thank you. I was a bit dumb not to check the analog signal going into the processor. When I did, I found your hunch was right. (1) Too much noise from the SD card getting into the supply voltage, and from there into the analog audio signal. I need to use the "star" grounding pattern, and isolate analog ground from digital ground. (2) The analog input needed the DC bias externally set to 2.5 volts. It was way off, causing the noise from the SD Card to totally clip the audio signal when it went below 0 volts. (Thus the gurgling).

jurs: I'm really glad I was so dumb (as explained just above), because your comment is a virtual "reference manual", with so much needed info about what is possible, why, and how. All the stuff I REALLY need to know. I must use an ATmega328 DIP in this project, so understanding its abilities and limitations (as you explained them) is essential.

CrossRoads: I sent you a personal note of thanks. You're frequent help has become part of the solid ground I walk on.