Last active
March 21, 2018 21:21
-
-
Save mwgamera/5895059 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# fadeout.sh length [pid]... | |
# Slowly lower the volume along the half sine slope then kill | |
# some processes and restore original volume at the end. | |
# Requires sleepenh and amixer. | |
# klg, Jun 2013 | |
CTL=PCM | |
LEN=${1:-0} | |
shift | |
A=$(amixer -- get "$CTL" | | |
sed -n 's/^.*: Playback \([0-9][0-9]*\) (*\[.*)*$/\1/p' | sed 1q) | |
T=$({ | |
echo "a=${A:-0}; t=$LEN" | |
echo ' /* arcsine */ | |
define r(x){ | |
if (x<0) return (a(sqrt(1-x*x)/x)+4*a(1)); | |
if (x>0) return (a(sqrt(1-x*x)/x)); | |
return (2*a(1)); | |
}' | |
echo 'scale=10' | |
echo 'for (x=a-1; x>=0; x--) { t*r(2*x/a-1)/a(1)/4 }' | |
} | bc -l) | |
trap 'amixer -- set "$CTL" playback $A > /dev/null; exit' 0 INT QUIT | |
AX=$A | |
T0=$(sleepenh 0) | |
for X in $T; do | |
sleepenh "$T0" "$X" | |
amixer -- set "$CTL" playback $((AX-=1)) | |
done > /dev/null | |
amixer -- set "$CTL" playback 0 > /dev/null | |
test 0 -lt "$#" && kill "$@" | |
sleep 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment