Skip to content

Instantly share code, notes, and snippets.

@mmstick
Created January 19, 2014 13:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmstick/8505289 to your computer and use it in GitHub Desktop.
Save mmstick/8505289 to your computer and use it in GitHub Desktop.
Append -gui as an argument to use the GUI. This allows users to modify their local PulseAudio configuration simply and efficiently.
#!/bin/bash
# This script requires YAD to be installed
# Input New Values
if [ "$1" == "-gui" ]; then
## YAD Input Form
YADInput=$(yad --form \
--title="PulseAudio Configurator" \
--separator="," \
--field="Sample Rate:CB" "22050\!44100\!48000\!96000" \
--field="Sample Format:CB" "s16ne\!s24ne\!s32ne\!float32ne" \
--field="Resample Method:CB" "src-sinc-fastest\!src-sinc-medium-quality\!src-sinc-best-quality" \
--field="Fragments:NUM" \
--field="Fragment Size:NUM")
## Parsed Input
newSampleRate=$(echo $YADInput | cut -d \, -f 1)
newSampleFormat=$(echo $YADInput | cut -d \, -f 2)
newResampleMethod=$(echo $YADInput | cut -d \, -f 3)
newFragments=$(echo $YADInput | cut -d \, -f 4 | cut -d \. -f 1)
newFragmentSize=$(echo $YADInput | cut -d \, -f 5 | cut -d \. -f 1)
else
## Grab the Current Settings for Comparison
if [ -e ~/.config/pulse/daemon.conf ]; then
sampleRate=$(grep "default-sample-rate" ~/.config/pulse/daemon.conf | cut -d \ -f 3)
sampleFormat=$(grep "default-sample-format" ~/.config/pulse/daemon.conf | cut -d \ -f 3)
resampleMethod=$(grep "resample-method" ~/.config/pulse/daemon.conf | cut -d \ -f 3)
fragments=$(grep "default-fragments" ~/.config/pulse/daemon.conf | cut -d \ -f 3)
fragmentSize=$(grep "default-fragment-size-msec" ~/.config/pulse/daemon.conf | cut -d \ -f 3)
else
sampleRate=$(grep "default-sample-rate" /etc/pulse/daemon.conf | cut -d \ -f 3)
sampleFormat=$(grep "default-sample-format" /etc/pulse/daemon.conf | cut -d \ -f 3)
resampleMethod=$(grep "resample-method" /etc/pulse/daemon.conf | cut -d \ -f 3)
fragments=$(grep "default-fragments" /etc/pulse/daemon.conf | cut -d \ -f 3)
fragmentSize=$(grep "default-fragment-size-msec" /etc/pulse/daemon.conf | cut -d \ -f 3)
fi
## Present Sample Format in a Human Readable Format
if [ -n $(echo $sampleFormat | grep float32) ]; then
humanReadableSampleFormat="32-bit Floating Point"
elif [ -n $(echo $sampleFormat | grep s32) ]; then
humanReadableSampleFormat="32-bit Signed Integer"
elif [ -n $(echo $sampleFormat | grep s24) ]; then
humanReadableSampleFormat="24-bit Signed Integer"
elif [ -n $(echo $sampleFormat | grep s16) ]; then
humanReadableSampleFormat="16-bit Signed Integer"
fi
## Echo Current Settings
echo "Sample Rate: $sampleRate Hz"
echo "Sample Format: $humanReadableSampleFormat"
echo "Resample Method: $resampleMethod"
echo "Fragments: $fragments"
echo "Fragment Size: $fragmentSize ms"
## Input New
echo "Input new Sample Rate:"
read newSampleRate
echo "Input new Sample Format:"
read newSampleFormat
echo "Input new Resample Method:"
read newResampleMethod
echo "Input number of fragments:"
read newFragments
echo "Input size of each fragment:"
read newFragmentSize
fi
# Input Settings
if [ -e ~/.config/pulse/daemon.conf ]; then
rm ~/.config/pulse/daemon.conf
fi
touch ~/.config/pulse/daemon.conf
echo "default-sample-rate = $newSampleRate" >> ~/.config/pulse/daemon.conf
echo "default-sample-format = $newSampleFormat" >> ~/.config/pulse/daemon.conf
echo "resample-method = $newResampleMethod" >> ~/.config/pulse/daemon.conf
echo "default-fragments = $newFragments" >> ~/.config/pulse/daemon.conf
echo "default-fragment-size-msec = $newFragmentSize" >> ~/.config/pulse/daemon.conf
# Restart PulseAudio
pulseaudio -k
sleep 2
pulseaudio --dump-conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment