Go Down

Topic: TMRpcm library - popping on volume change (Read 2200 times) previous topic - next topic

rkeahey

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

robtillaart

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);
}

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

rkeahey

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

Grumpy_Mike

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.

T7k7

#4
May 17, 2015, 02:50 am Last Edit: May 17, 2015, 04:46 am by T7k7
How can I change volume with pot? Possible?

Grumpy_Mike

#5
May 17, 2015, 07:34 am Last Edit: May 17, 2015, 07:35 am by Grumpy_Mike
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.

T7k7

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

T7k7

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

Grumpy_Mike

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?

Quote
no amps in the game
Then game over.

T7k7

#9
May 17, 2015, 03:17 pm Last Edit: May 17, 2015, 03:20 pm by T7k7
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.

T7k7

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

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
tmrpcm.setVolume(val);

Grumpy_Mike

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

T7k7


rkeahey

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

Grumpy_Mike


Go Up