Help with .WAV files / Audio Quality

Hello All,

I'm trying to output .WAV files to an 8 Ohm 1 Watt speaker using an Arduino Uno. However, every time I play the audio file, there is a loud pop at the beginning of the audio and the end. Below is the circuit diagram that I am copying, except that I am using a 104nF ceramic capacitor instead of the 100nF Capacitor, I'm also using a GPIO pin as the input to pin 3 and I'm using a 12V 1amp wall wart to power the lm386. Any help would be appreciated.

Here is my code:

#include <SD.h>                      // need to include the SD library
//#define SD_ChipSelectPin 53  //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 10  //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>           //  also need to include this library...
#include <SPI.h>

TMRpcm tmrpcm;   // create an object for use in this sketch


void setup(){

  tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
  tmrpcm.setVolume(5);

  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    Serial.println("SD fail");  
    return;   // don't do anything more if not
  }
}



void loop(){  
  delay(500);
  tmrpcm.play("Monster.wav");  
  while(1);

  if(Serial.available()){    
    if(Serial.read() == 'p'){ //send the letter p over the serial monitor to start playback
      tmrpcm.play("Monster.wav");
    }
  }

}

Please read the first topic telling how to get the best from this forum.
All basic information is missing. Your post looks like a mixture of panic and chaos.
No helper takes snippets serious.....
Do some reading, post again and helpers will be there.

I doubt this is a 104nF capacitor. A capacitor marked "104" is 0.1µF

I don't know how the TMRpcm functions but could it be the starting the file in Setup?

Try moving the play file command to the Loop function. Something like.

Loop{
    Wait 5 seconds
    Play audio
    While(1)  // stay here forever.
}

Hello JohnRob,

I took your advice and moved the play file command to the Loop function, I feel like I should have done that from the beginning. The audio is much louder and a bit more clear, but the pop at the beginning and end of the audio file is still there.

I assume the click is the DC bias... The Arduino can't go negative like a regular audio waveform so it's biased at 2.5V (that's an average of the PWM) and silence is 2.5V instead of 0V.

You can't hear DC bias but you'll get a click when the bias kicks-in and kicks-out. You might be able to fix it by "playing silence" when you're not playing sound. But, if there's a gap between playing silence and playing sound, you'll still get clicks.

Also, you should have a series capacitor between the Arduino & amplifier to block the bias from the amplifier. (That won't stop the click because the sudden-change when the bias kicks-in & out will temporarily get-through the capacitor, just like the audio gets-through.)

And, a low-pass filter to reduce the PWM into the amplifier wouldn't hurt.

I think @DVDdoug might be on the right track.
Can you measure the output of the LM386 at pin 6 when the unit is powered but not creating music? I think it will be at common (aka ground) potential.

Quick test, can you invert one of the audio pins? This would be so with no audio one output would be 0 the other 5V.

I think the issue is the input pin 3 should rest at 2.5 volts with no audio.
Before changing the circuit let's see if the above test gains us some knowledge.

The amplifier design in the OP is completely unworkable for the Arduino PCM outputs.

The inputs of the LM386 are ground referenced, with absolute maximum input voltages of +/- 0.4V.

You definitely need a capacitor to block the DC voltage and a voltage divider/low pass filter on the input.

Something like this from the data sheet, but I would add a 100 nF cap from pin 3 to GND and remove the 10uF cap between pins 1 and 8, to reduce the gain to 50.

The 100nF capacitor was supposed to be a shortcut way of making a low pass filter. Even if I have a resistor and capacitor the audio was the same, so I omitted the resistor from the circuit. When I'm not playing a sound, pin 3 sits at 2.26 Volts, which I'm assuming is the bias you are referring to.

I tried adding a capacitor in between the Arduino and amplifier and it reduced the popping noise, but completely distorts the audio to the point where you can't understand what is being played. I tried a 1uF, 100uF, and a 3.3uF capacitor. The smaller the value seems to help but is still awful.

I'm not too sure I understand why I would measure the output on pin 6, that is VCC and it equals 12V when there is no audio.

I'm also not sure what you mean by inverting one of the audio pins?

You are correct, pin 3 rests at about 2.26 volts when nothing is being played.

The common way is to use an Mp3 player module, like DFPlayer.
It has a built-in SD card slot and an efficient class-D amplifier (no LM386 dinosaur needed).
Leo..

Poor eyesight I meant the output pin 5 ( or maybe i pressed the wrong key).
My reason is to fine / verify pin 5 is at ground. This would mean the 250µF cap would have to charge to Vc/2 before audio started.

Now another question. It seems you are missing a filter stage. The Arduino PWM output is a signal that is either Vin of your Arduino or Ground. So the LM386 is not amplifying it is just being used as a ON/OFF driver and the filtering is done by the mechanics of the speaker.

You're fairly correct, there's no 'pop' at the start or end of a 'Play' - but they do make a 'pop' when they're powered on.

It is "awful", because you are applying a 5V waveform to an input designed for 100 mV.

I wasn't joking about the voltage divider. Or did you not read post #8?

I added a voltage divider to pin 3 and the audio is much much better. The popping before the audio file plays is much quieter, but the pop after the audio is still a bit annoying. Any more suggestions / troubleshooting tips?

The volume is also not as loud as I want it to be, but I will take what I can get at the moment :slight_smile:

Is that 10uF still in place (IC pin 1 to IC pin 8)?

There is not, I am using my original circuit but with a voltage divider in pin 3 and a couple of capacitors added here and their that I mentioned in my replies above.

It'll have more gain with that cap, but the pop will (probably?) be louder for it.
[One way to find out.]

Also, quick side-note, does anyone know what program was used to create the circuit that I am referring to in my original post?

It looks like a Kicad Schematic to me...
image

The yellow part color is optional.


Can you describe the source of the signal coming into the LM386? i.e. is it coming directly from an Arduino Digital output?

Thanks! I will definitely try that program out.

Yes, I have Digital Pin 9 from my Arduino going into a 10uF capacitor in series, then into a voltage divider of 10k ohm resistor, and a 330 ohm resistor, then going into Pin 3 of the LM386. KiCad is taking a bit longer than I expected to download, so I attempted to hand draw my circuit. I'm going to draw it out tomorrow once I get off of work.