TMRPCM WAV file player noisy sound before and after playing a wav file


I am new to using Arduino. Using the TMRPCM library module found at to play a series of wav files. This works quite well and appears to be an amazing piece of programming.

The issue is that there is a loud crackle or pop sound immediately before and after playing each wav file and I can't figure out how to get rid of this sound. It seems that you would need to change the TMRPCM software or somehow mute the sound at the start and end of each wav played. But I don't have enough programming experience to understand how this player works or how to implement this.

Has anyone else seen this issue and how are you getting around it?

Thank you regards Simon

What hardware are you using, how is it wired up? This may not be a software problem! Is the noise problem just before you start playing wav file or do you have noise when you are not playing a file. Try a delay(5000) in your code just before you start to play the file. Is there noise during the delay?

Post your whole code!


Hi Mark,

Thanks for your quick reply, much appreciated. I’m using a UNO with 328 ATMega. There is no noise when the .WAV file is not playing and there is virtually no noise when it is playing. The issue is that right before each file starts to play and right after it finishes playing there is a lot pop/crack/clunk sound when the TMRpcm play command is issued and then again right after it is finished playing the file. (Which makes me suspect the TMRpcm file)

I have tried your suggestion of putting a delay in but it makes no difference.

The project accesses a series of .WAV files on an SD Card and plays them one after another when pin 2 of the UNO is pulled high. Project first plays two door bell chimes just to conform that it is up and running and able to access the SD card and play a .WAV.

It all works except for the annoying noise right before and after each file is played. I have attached my program plus the tmrpcm library file used. As I did not write this library file and it appears to be written by an expert user I’m not knowledgable enough see how it or the program would be modified to eliminate this issue. If you have any suggestions I’d be glad to try them.

Thank you Mark and have a good evening.

TMRpcm.h (471 Bytes)

TMRpcm.cpp (5.54 KB)

SD_Card_WAV_Reader_Experiment.ino (2.2 KB)

This is just a stab in the dark but I can’t figure out what this initialization accomplishes (in the play method of TMRpcm.cpp):

    for(int i=0; i<buffSize; i++){ buffer[0][i] = i,buffSize; }
    for(int i=0; i<buffSize; i++){ buffer[1][i] = i+buffSize;  }

In particular, the “i,buffSize;” in the first for loop is strange. I’d suggest that you try changing it to this:

    for(int i=0; i<buffSize; i++){ buffer[0][i] = 0; }
    for(int i=0; i<buffSize; i++){ buffer[1][i] = 0;  }

If it doesn’t mangle the audio altogether, I’d be interested to know if it gets rid of the noise at the beginning.


Hi Pete,

Thanks for your response. I tried the code modification, the files still play and the audio sounds mostly good while playing, but the main problem persists. Still loud pop/crackle/clunk type sounds at the beginning and end of each file played. Any more ideas? do you know of another reliable .WAV player code module for Arduino that I could try instead of this one?

Thanks, regards Simon

Sorry, I don't know of any other players.


This is now fixed in the latest update:
It took me a while to figure it out, but found it was due to the difference between the last sample and the first sample in the new audio, so created a ramp to handle the transition.

The code posted above was supposed to create a ramp from 0 to 150, but only helped a bit for playback.


for(int i=0; i<buffSize; i++){ buffer[0][i] = i; }
for(int i=0; i<buffSize; i++){ buffer[1][i] = i+buffSize;  }

Now it uses the last timer value compared against the first new value and creates a transition.

There is still a pop on the first initialization, but after that, it should be gone.

Hi again TMRH20,

thanks for the S/W update. Unfortunately not too much improvement in the sound so far as I can tell. Still have annoying pops and cracks, mostly at the end and beginning of each file. Also now the volume control does not seem to work. Before I could use these commands in the program to turn the volume up and down:

tmrpcm.volume(0); volume up tmrpcm.volume(1); volume down

Volume up still seems to work but volume down results in a loud buzzing sound when I play the second .WAV file for some reason. Any other things that you can think of that might improve it. Thanks for your excellent work so far!

Regards, Simon

sncarter: Still have annoying pops and cracks, mostly at the end and beginning of each file.

Well there is one main caveat, being that if you play a wav file of one sample rate, followed by a file of another sample rate, there will still be a small pop heard on the transition. This could be fixed, but for the effort and extra lines of code required, I am not sure if worthwhile.

If you are getting pops and cracks during playback, then that is something altogether different. Try using the quality(0); command or a lower sample rate to see if that makes a difference. That usually indicates buffer underruns are occurring.

If the above does not help, does it do it when starting/stopping the same file? And does it still pop when you pause/unpause?

sncarter: Volume up still seems to work but volume down results in a loud buzzing sound when I play the second .WAV file for some reason.

I would guess that this would be related to sample rate also. Is the second file encoded at a sample rate higher than 16khz? I remember having this same issue, but it was with a fairly high sample rate and a different version of the library. Are you sure you copied over the old files when you updated the library? Otherwise, please email the wav file to tmrh20 at gmail and I will try to recreate the issue.

Hi TMRH20,

Once again thanks for your assistance!

Just to be sure I re-sampled a bunch of files at 8 KHz tonight and you are right it does improve the sound quality, much less crackle and pop at the start of each file and better sound during playing. Still quite distinct crackle and pop at the end of each file though as I think you expected. Some slight crackles during play could be due to over driving and the one transistor audio amp I'm using, I will try something else such as an op amp when I get a chance. Using the same file each time does not change anything. I tried the Quality(0), Quality(4) and Quality(9) but could not discern any difference.

I don`t know how to use the pause command. I tried tmrpcm.pause(1) stop? and tmrpcm.pause(0) go? or is it vice - versa? but that does not seem to work and give compile error:

SD_Card_WAV_Reader_Experiment.ino: In function 'void setup()': SD_Card_WAV_Reader_Experiment:31: error: no matching function for call to 'TMRpcm::pause(int)' C:\Users\SimonDell\Documents\Arduino\libraries\TMRpcm/TMRpcm.h:15: note: candidates are: void TMRpcm::pause()

Probably because I`m not using it properly. How do you use it?

Thanks for your help again. Should I send you some sample .WAV files?

Regards, Simon

Yeah no prob.

It still sounds like you have an old version of the library. Please make sure there is only one copy of TMRpcm.cpp and TMRpcm.h anywhere in your library folder and that you have the latest version from Github. If there are multiple copies, the IDE will always use the first one it finds.

The pause command is just tmrpcm.pause(); , and the quality command is a 0 (low) 1(high), so tmrpcm.quality(0); or tmrpcm.quality(1); you should notice a definite difference using 8khz files, and the command has to be run when the music is stopped.

I would like to see if I can recreate the issue with lowering the volume, so if you still have that issue, please send that file.

I just started working with this library and I am having the same problem but I think I know what is going on and I found a work-around that I hope will be helpful to someone.

The problem is that the speaker pin has a 16kHz signal on it after playing a file. This causes a noise in the speaker that is quite annoying but it is not noticeable unless you run the signal through an amplifier. The easy fix is to write a low signal to the speaker pin when the audio is not playing.

You will notice this fix at the start of the loop function.

#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(1);  // values 0 to 7

  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
  }"martha.wav"); //the sound file "music" will play each time the arduino powers up, or is reset

void loop(){ 
  if(!tmrpcm.isPlaying()) {
    digitalWrite(tmrpcm.speakerPin, LOW);
    //pinMode(tmrpcm.speakerPin, OUTPUT);
    switch(sData) {
      case 'e':
        Serial.println("Playing: exterminate.wav");"extermin.wav");
      case 'm':
        Serial.println("Playing: marthasaves.wav");"martha.wav");
      case 't':
        Serial.println("Playing: tardis.wav");"tardis.wav");


Attached are two audio files. Sample1.wma is before the fix and Sample2.wma is after the fix. My microphone did not do a great job picking up the noise but if you listen carefully to both you can hear the difference after the Arduino plays the audio.

Sample1.wma (92.6 KB)

Sample2.wma (75 KB)

Thanks for the info! I just committed a whole pile of updates to the code including some that provide an automated workaround to the popping noises. I was able to completely prevent popping sounds on an Arduino Mega on timer start, between tracks, and on disabling. I found that it worked differently on my Duemilanove board, so the library now auto selects the ramping methods, but I have mostly tested it on a Mega. It also has an option to bypass metadata for files with song, artist, and album information which is another potential source of popping type sounds. The disable() command can be used to provide a ramp between tracks of differing sample rates as well.

The latest version should always be available at if anybody is interested in providing feedback.

The two options for managing popping sounds are found in pcmConfig.h (Info available on the github wiki)

define rampMega


I had the same problem than sncarter (crackling sound at the end). I uncommented the #define HANDLE_TAGS line in the pcmConfig.h file and it's working fine now Thanks for this fix !

Hi, I’m having the issue as well. I have the latest version of the library, however if I uncomment the HANDLE_TAGS no sound will be played at all. any help?

EDIT: I just found a solution without need to modify the HANDLE_TAGS. Just remove the metadata from the sounds! In Audition when you click on “export” there’s a tick box which says “include metadata”. Untick that one and the pops are gone :slight_smile:

i guess I'm trying to wake up this topic,

I'm using tmrpcm with music example code exactly as is and using example wav supplied. every thing works great on ide 1.05, but when using ide 1.8 with every thing the same the sound is bad and crackly. any ideas.