BGM Music mpg123 with fade in/out
-
Hello I played around with my ORA XU4 and Raspberry devices and took also a look to the python method with playing background music (the script needs some improvements) but I like the nice fade in/out it offers if it detects some emulators running.
So this script actually works only for RetroPie on Raspberry and supports mpg123 (or any other music player)So I took one and a half hour to write a small script that offers the same for the mpg123 method that was introduced by @synack.
The How to install and setup mpg123 was wrapped by @MapleStory in the thread Quick and easy guide for adding music to Emulatonstation on RetroPie. Noob friendly!GetIt: So here is the script
You can download it also from my GITHUB account here
or use commandwget https://raw.githubusercontent.com/crcerror/RetroPie-Shares/master/BGM_vol_fade.sh
and make it executable.Install
We can now use
-stop
and-cont
parameter to force stoping and resuming music.- type
nano /opt/retropie/configs/all/runcommand-onstart.sh
- Write just scriptname with exact download location. Maybe
$HOME/scripts/BGM_vol_fade.sh -stop
- type
nano /opt/retropie/configs/all/runcommand-onend.sh
- Add line like
(sleep 2 && $HOME/scripts/BGM_vol_fade.sh -cont) &
4.1 This will load the voluming fading into background
4.2 This will avoid sound corruption caused by CPU overload and gives a better retro experience (Believe me!) - Please report and give some feedback!
Sidenote: The GitHUB version will likely be more updated than this script here!
OLD CODE
Please use GITHUB version instead!#!/bin/bash # A script to fade ALSA volume when starting or ending # a Emulator by using amixer and MASTER/PCM Control. # kill -19 pauses musicplayer, kill -18 continues musicplayer # Place the script in runcommand-onstart.sh to fade-out # Place the script in runcommand-onend.sh to fade-in # Status of musicplayer is determinated automatically # # by cyperghost # 2018/10/31 - Halloween # Reason I like the pyscript for BGM but it has it flaws and caveeats # so I recommend the mpg123 method brought by synack # Read here how to setup https://retropie.org.uk/forum/topic/9133 # Setup Musicplayer and Channel you want to change volume here readonly VOLUMECHANNEL="PCM" readonly MUSICPLAYER="mpg123" # Get ALSA volume value and calculate step VOLUMEALSA=$(amixer -M get $VOLUMECHANNEL | grep -o "...%]") VOLUMEALSA=${VOLUMEALSA//[^[:alnum:].]/} VOLUMESTEP=$(expr $VOLUMEALSA / 10) # ALSA-Commands VOLUMEZERO="amixer -q -M set $VOLUMECHANNEL 0%" VOLUMERESET="amixer -q -M set $VOLUMECHANNEL $VOLUMEALSA%" # Player-Status PLAYERPID="$(pidof $MUSICPLAYER)" PLAYERSTATUS=$(ps -ostate= -p $PLAYERPID) if [[ $PLAYERSTATUS == *S* ]]; then # Fading down and pausing in ten steps for a in {0..9}; do amixer -q -M set "$VOLUMECHANNEL" "${VOLUMESTEP}%-" sleep 0.2 done $VOLUMEZERO kill -19 $PLAYERPID sleep 0.5 $VOLUMERESET elif [[ $PLAYERSTATUS == *T* ]]; then # Playing and fading up in ten steps $VOLUMEZERO sleep 0.5 kill -18 $PLAYERPID for a in {0..9}; do amixer -q -M set "$VOLUMECHANNEL" "${VOLUMESTEP}%+" sleep 0.2 done $VOLUMERESET else echo "Musicplayer: $MUSICPLAYER is not running." fi
- type
-
will this work for retropie on the Pi3 or is it just for ORA/XU4?
-
@ExarKunIv It's just tested on a Raspberry.
I think for Odroid there should be a change in the channel-Volume and you need to install the volume mixer device..... I think XU4 uses pulseaudio so the mixer device is annother one. -
ok thanks
-
Did a nearly complete rewrite with some nice features. Please update from github!
-
question for the onend and onstart
do we put your command before or after what will be in there to start with just to get the mpg123 working?
UPDATE Never mind i got it to work now.
-
I've updated the script a bit
We can now use-stop
and-cont
parameter to force stoping and resuming music.Updated first topic to
-
hi,
i tried to use this fade in/out script with the GPi Image from supremeteam (basic-image with mpg123 backgroundmusic, no roms and bios), but it didn't work. Something must be incompatible. I think it cannot be a difficult thing, but i am a noob at all. Can somebody help me please? I tried to change the VOLUMECHANNEL-variable in the fade-script to pcm.monocard, but not getting a fade with that...
-
@strunx yes you have to identify the audio channel at first - what name is showen in EmulationStation if you enter its sound menu? It should be next to the sound volume..
-
@cyperghost thx for fast answering.
in emulationstation:
AudioCard: DEFAULT
Audio Device: PCM#!/bin/sh
home/pi/scripts/BGM_vol_fade.sh -stop#!/bin/sh
(sleep 2 && /home/pi/scripts/BGM_vol_fade.sh -cont) & -
@strunx Do you know how to execute commands?
Try
bash /path/to/your/script/BGM_vol_fade.sh
Or if the script is already in same directory you are working with then justbash BGM_vol_fade.sh
From your description it should work out of the box. Then write back what the error is.
How did you get the script? with wget command?
And is the script located to/home/pi/scripts
?PS: The Shebang thing (#!...) is not needed!
-
result of bash BGM_vol_fade.sh:
amixer: Unable to find simple control 'pcm',0ยด
typing: amixer -> result:
Simple mixer control 'PCM',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback -10239 - 400
Mono: Playback -2046 [77%] [-20.46dB] [on]script is located to /home/pi/scripts
-
@strunx Well usually it should work .... I've no Pi0 at hand and can't really help now. Maybe reinstalling alsa-utils will help. I think that nobody can support here hence you are using a premade ROM and nobody knows which build this is and what "special" patches were set.
I personally think it's not a big deal. Maybe you could try
MASTER
as volume input. -
@cyperghost i will try it out ... thx for helping so fast
-
-
-
-
-
-
-
-
@cyperghost I have a working scriptmodule that installs mpg123 and sets up the background music automatically. May I have your blessing to include a modified version of this volume fade script (with credit) in the distribution?
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.