Use mplayer as pa/pw backend

dobeshow

Member
Joined
Jun 1, 2022
Messages
92
Reaction score
43
Credits
598
No idea where else to put this...
It creates various pulseaudio sinks with mplayer as the backend. It takes stereo sources and uses the dirty mplayer tricks to blow it up to 2.1-5.1 without stupidly copying the front channels to the back/center/lfe. It's by far perfect since it introduces some latency and cpu load even if no audio is playing. But at least it sounds better than the pa upmix. Also works with pipewire. Mainly used for sptify.

careful. might blow up your ears!
Bash:
#!/bin/sh
#
AUDIGY=$(pactl list sinks | command grep -e 'analog-surround-51' | command grep -e 'Name: alsa_output.pci' | cut -f2 -d' ' )
# alsa_output.pci-0000_06_00.0.analog-surround-51

init(){
    pactl set-sink-volume ${AUDIGY} 10%
    killall -9 parec
    killall -9 mplayer
    pactl unload-module module-null-sink
#    systemctl --user restart pipewire
    pactl set-sink-volume ${AUDIGY} 10%
}

twopointone() {
pactl load-module module-null-sink\
      sink_name=mplayer_2-1\
      channels=2\
      rate=44100\
      format=s32le\
      sink_properties=device.description=mplayer-backend_2.1
   
parec -d mplayer_2-1.monitor\
      --no-remix\
      --rate=44100\
      --channels=2\
      --latency-msec=1\
      --volume 65534 | mplayer\
               -rawaudio samplesize=2:channels=2:rate=44100:bitrate=44100\
               -af channels=6,sub=80:5\
               -volume 0\
               -nocache\
               -demuxer rawaudio\
               -really-quiet - 2<&0 &
pactl set-sink-volume mplayer_2-1 140%
}

threepointone(){
pactl load-module module-null-sink\
      sink_name=mplayer_3-1\
      channels=2\
      rate=44100\
      format=s32le\
      sink_properties=device.description=mplayer-backend_3.1

parec -d mplayer_3-1.monitor\
      --no-remix\
      --rate=44100\
      --channels=2\
      --latency-msec=10\
      --volume 65534 | mplayer\
               -rawaudio samplesize=2:channels=2:rate=44100:bitrate=44100\
               -af channels=6,sub=80:5,center=4\
               -volume 50\
               -nocache\
               -demuxer rawaudio\
               -really-quiet - 2<&0 &
pactl set-sink-volume mplayer_3-1 100%
}

fivepointone(){
    pactl load-module module-null-sink\
      sink_name=mplayer_5-1\
      channels=2\
      format=s32le\
      rate=44100\
      sink_properties=device.description=mplayer-backend_5.1

    parec -d mplayer_5-1.monitor\
      --no-remix\
      --rate=44100\
      --channels=2\
      --latency-msec=10\
      --volume 65534 | mplayer\
                   -rawaudio samplesize=2:channels=2:rate=44100:bitrate=44100\
                   -af surround=15,channels=6,sub=80:5,center=4\
                   -volume 50\
                   -nocache\
                   -demuxer rawaudio\
                   -really-quiet - 2<&0 &
        pactl set-sink-volume mplayer_5-1 100%
}

fourpointone(){
    pactl load-module module-null-sink\
      sink_name=mplayer_4-1\
      channels=2\
      format=s32le\
      rate=44100\
      sink_properties=device.description=mplayer-backend_4.1
    parec -d mplayer_4-1.monitor\
      --no-remix\
      --rate=44100\
      --channels=2\
      --latency-msec=10\
      --volume 65534 | mplayer\
                   -rawaudio samplesize=2:channels=2:rate=44100:bitrate=44100\
                   -af surround=15,channels=6,sub=80:5\
                   -volume 50\
                   -nocache\
                   -demuxer rawaudio\
                   -really-quiet - 2<&0 &
    pactl set-sink-volume mplayer_4-1 100%
}


init
twopointone
#threepointone
#fourpointone
fivepointone

pactl set-sink-volume alsa_output.pci-0000_06_00.0.analog-surround-51 20%
pactl set-sink-volume mplayer_2-1 100%
#pactl set-sink-volume mplayer_3-1 130%
#pactl set-sink-volume mplayer_4-1 130%
pactl set-sink-volume mplayer_5-1 100%
 
Last edited:


G'day @dobeshow and thanks for sharing - where you have placed this Thread is fine :)

Might just be worth mentioning (eg editing your Post) to say that if the User is using the Bourne Again SHell (bash) that they may need to change the first line to

Code:
#!/bin/bash

If they read this far, they will work that out.

Cheers

Chris Turner
wizardfromoz
 
G'day @dobeshow and thanks for sharing - where you have placed this Thread is fine :)

Might just be worth mentioning (eg editing your Post) to say that if the User is using the Bourne Again SHell (bash) that they may need to change the first line to

Code:
#!/bin/bash

If they read this far, they will work that out.

Cheers

Chris Turner
wizardfromoz
i changed it. it should work with any shell. i think :p
 
You can run any script in any shell.

My working shell (what my command terminal open with) is ksh. I can run shell scripts written in sh, bash, ksh or csh as long as the shebang in the script I'm executing points to the interpreter the script was written in. That said, changing the shebang may break the script if the syntax doesn't match the interprater.

There's some pretty good examples here: https://linuxize.com/post/bash-shebang/
 

Staff online

Members online


Top