TMRpcm library - popping on volume change

I'm using the TMRpcm library (https://github.com/TMRh20/TMRpcm) for a project and have noticed a distinct popping when the audio.setVolume() command is issued while a WAV file is playing. Occurs on both volume increase and decrease. Here is an example code snippet:

int vol_lev = 3;

tmrpcm.play(buf); // buf contains the file name for the WAV file

while (tmrpcm.isPlaying()) {

audio.setVolume(vol_lev);

}

Has anybody experienced this problem, and if so, any suggestions on how to eliminate?

Thanks

don't know the library, but does it also pops when you do increase the volume in small steps?

int delta = +1; while (tmrpcm.isPlaying()) { if (vol_lev == 255) delta = -1; if (vol_lev == 0) delta = +1; vol_lev += delta; audio.setVolume(vol_lev); }

Hi Rob,

Thanks for the reply. The volume can only be specified in levels from 0 to 7, so there's not much granularity that you can specify. The pops occur at both volume increase and decrease.

Robert

The pop is a DC shift in the signal. Try coupling it to your output device through a capacitor. Although that might not fix it.

How can I change volume with pot? Possible?

What do you mean? The way you do this is put the audio output across the pot and take the input I too the amplifier at the wiper. But that is so trivial I assume you are asking something else.

We have volume values from 0 to 7, I meant about the way to pot that (no amps in the game).

There is also volume up/down, maybe that's the key... again not documented how to code it with pot.

T7k7: We have volume values from 0 to 7, I meant about the way to pot that (no amps in the game).

Can we have that again using words that make some sort of sense.

Are you talking about a digital pot?

no amps in the game

Then game over.

Grumpy_Mike, well, if you read TMRpcm docs, there is volume level from 0 to 7, and game isn't over ofcourse, there is the way to drive those values using the pot for sure, it is not documented how, but there is the way and I will find out, will figure out the volume (0) and (1) - for up and down and I am sure I will manage to drive the volume of TMRpcm using the potentiometer. You may think that 38,856 posts gives you authority to dismiss this as "game over" but it isn't the case, you can only have your opinion as I have mine. :-) Cheers.

OKAY! Figured out how to change TMRpcm volume using the pot, solely and without an amp:

TMRpcm tmrpcm;   // create an audio object
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

Then in the loop simply add:

val = analogRead(potpin);            // reads the pot value (and this is between 0 and 1023)
val = map(val, 0, 1023, 0, 7);     // this does the trick: scale it to use it for our need (values 0 to 7, instead 0 to 1023)

And finally use it in your audio:

tmrpcm.setVolume(val);

So that is what you wanted to do, why did you not say. Must be you lack of language skills I suppose.

Oh comeon, Tesla :slight_smile:

Grumpy_Mike,

Thanks for your reply. I’ve attached a diagram of the speaker configuration that I’m using. Could you suggest how to modify it based on your suggestion to use a capacitor to possibly eliminate the popping.

Thanks!

Robert

Try this one:-

Thanks G_M! Will give it a try.

R