Volume Fade In/Out on Play/Stop

Hi everyone, I am running a Pi Musicbox with a HiFiBerry DAC+. I would like to implement a Fade in/out everytime i enter mpc play/pause/stop. How would I do such a thing?

Thank you very much

Not sure how effective it would be but you could probably wrap the mpc commands in a script to simulate what Mopidy-Alarmclock does: https://github.com/DavisNT/mopidy-alarmclock/blob/f20da16c7f879b2b52c7a05aceaccb811d84fa7f/mopidy_alarmclock/alarm_manager.py#L120-L133

It seems that I could work something out with this. Where would I modify the original mopidy classes? Thank you!

Sorry I should have been more clear: assuming you are calling mpc from the command line the idea would be to wrap this in a shell script.

The code reference above is just to serve as an example of the logic involved, and you should be able to accomplish something similar using mpc volume [+-]<num> in a for loop with a short delay between each call.

I tried a very basic function in my python script,

I first tried with delays between each calls :

def fadeOut():
os.system(“mpc volume -10”)
time.sleep(.05)
os.system(“mpc volume -10”)
time.sleep(.05)
os.system(“mpc volume -10”)
time.sleep(.05)
os.system(“mpc volume -10”)
time.sleep(.05)
os.system(“mpc volume -10”)
time.sleep(.05)
os.system(“mpc volume -10”)
time.sleep(.05)
os.system(“mpc volume -10”)
time.sleep(.05)
os.system(“mpc volume 0”)

But it was very slow. so I remove them, but it still takes around 5 secondes to do all the mpc volume steps. Is it because of my python script, it there a way to make a smooth and fast fade in/out ? I would like it to take around 1.5 to 2 seconds

If you’re using a DAC+ then you probably also have the software mixer configured? Please check if mopidy.conf contains the following:

[audio]
mixer = software

I’ve always experienced a short delay before the volume starts changing with the software mixer, and the fact that you are triggering multiple changes probably make this even more noticeable.

I’m not aware of a workaround for this, sorry.

The DAC+ should support hardware volume control i.e. using mixer = alsamixer and setting up the alsamixer section correctly in settings.ini.

I think it’s only the hifiberry DAC that doesn’t support hardware mixing.

I recall experiencing some distortion on my DAC+ when changing the volume, which is why I switched to the software mixer.

But it might just be specific to my set-up.

I will try changing the mixer to hardware. Hopefully, this solves my problem. Thank you very much guys, I will keep you updated

I feel like this is something that should be in an official build, considering people like me who use loudspeakers and cringe at the pop and slap that occurs when switching tracks in the middle of a track or pausing/playing tracks. Of course it is loud and irritating, but it can also potentially damage the speaker. All it takes is an imperceptible, less than half a second drop in volume to fix this, it would barely be noticeable to the user.

By this, do you mean it should be in Mopidy, rather than musicbox? I don’t think there’s any way to consistently achieve this functionality outside of Mopidy itself.

I don’t think I’ve really noticed these pops on my setup. Is this just with the dac+ and software mixer?