├── .gitignore ├── LICENSE ├── README.md ├── download.sh ├── fix.sh └── run.sh /.gitignore: -------------------------------------------------------------------------------- 1 | data/ 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Matheus Pedroni 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Surround Linux 2 | This is a collection of simple scripts that automate the process of configuring 3 | virtual surround sound on linux distros using pulseaudio. 4 | 5 | ## What is virtual surround? 6 | Many modern audio sources provide 5.1 or even more audio channels. If you're 7 | using headphones, all this spatial information is lost when squeezing the audio 8 | into two channels. However, it is possible to emulate the spatial perception of 9 | sound position using some [fancy tricks](https://en.wikipedia.org/wiki/Virtual_surround). 10 | 11 | In this case, we're using head-related impulse responses (HRIR) derived from 12 | [head-related transfer functions (HRTF)](https://en.wikipedia.org/wiki/Head-related_transfer_function). 13 | 14 | HRIR files are publicly available thanks to [Salscheider](https://github.com/olesalscheider), 15 | who used two also publicly available databases ([here](https://sound.media.mit.edu/resources/KEMAR.html) 16 | and [here](http://recherche.ircam.fr/equipes/salles/listen/)) to generate those files. 17 | 18 | These scripts were inspired by a very good [how to](https://forum.endeavouros.com/t/howto-setting-up-virtual-surround-sound-for-headphones/6889) written by jonathon. 19 | 20 | ## Usage 21 | ### Downloading 22 | Please run download.sh to download necessary data: 23 | bash download.sh 24 | 25 | This will create a data folder in you current directory. **If you just want a very 26 | simple way**: please continue to read after *setting up*, I promise it's easy. 27 | 28 | Inside it, there are two folders. 29 | In data/hrir_listen/demos you will find many .ogg audio files containing demo audios 30 | of many different HRTF measured from different real people. 31 | 32 | If you want the **best possible** experience, listen patiently and choose which one 33 | yields the best spatial perception and note the **four-digit number** at the end 34 | of the file name. 35 | 36 | ### Setting up 37 | Now, run the run.sh script: 38 | bash run.sh 39 | 40 | Follow the instructions on the screen. If you choose the easy path, type 0 when 41 | asked for the audio number. You'll have to logout and login again before changes 42 | take effect. 43 | 44 | You may use pavucontrol or (if you're running a GNOME environment) the [Sound 45 | Input & Output Device Chooser](https://extensions.gnome.org/extension/906/sound-output-device-chooser/) 46 | GNOME extension to easily switch between output devices. 47 | 48 | **Use VirtualSurround as output when listening to surround content**, e.g., 49 | movies and video-games. Using VirtualSurround on stereo content may distort 50 | the audio a bit. 51 | 52 | ### Fix 53 | On some linux distros you won't see VirtualSurround as a sound output just yet. 54 | You'll have to run fix.sh as root: 55 | sudo bash fix.sh 56 | 57 | This will add your current user as part of the audio group, which should fix 58 | things up. 59 | 60 | Enjoy! 61 | -------------------------------------------------------------------------------- /download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir ./data 4 | 5 | cd data 6 | wget https://stuff.salscheider.org/hrir_kemar.tar.gz --no-check-certificate 7 | 8 | if [ $? -ne 0 ]; then 9 | echo "download failed, exiting" 10 | exit 1 11 | fi 12 | 13 | wget https://stuff.salscheider.org/hrir_listen.tar.gz --no-check-certificate 14 | 15 | if [ $? -ne 0 ]; then 16 | echo "download failed, exiting" 17 | exit 1 18 | fi 19 | 20 | for file in *.tar.gz 21 | do 22 | tar xzf "${file}" && rm "${file}" 23 | done 24 | 25 | echo "Download done." 26 | -------------------------------------------------------------------------------- /fix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # fix for some linux distros 4 | if [ "$EUID" -ne 0 ] 5 | then echo "Please run as root" 6 | exit 7 | fi 8 | 9 | addgroup $SUDO_USER audio 10 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sinks=$(pacmd list-sinks | grep -e 'name:') 4 | 5 | PS3="Choose a default sink: " 6 | select sink in $(echo $sinks | sed "s/name: /\n/g" | sed "s///g") 7 | do 8 | echo "Selected sink: $sink" 9 | break 10 | done 11 | 12 | file=9999 13 | while ! [ -f "./data/hrir_listen/hrirs/hrir-$file.wav" ] 14 | do 15 | read -p "Please choose a valid HRIR file number (check data/hrir_listen/hrirs, 0 for default): " file 16 | if [ $file -eq '0' ] 17 | then 18 | echo "Using default HRIR (hrir_kemar)" 19 | break 20 | fi 21 | done 22 | 23 | 24 | if [ $file -eq '0' ] 25 | then 26 | file_path="./data/hrir_kemar/hrir-kemar.wav" 27 | else 28 | file_path="./data/hrir_listen/hrirs/hrir-$file.wav" 29 | fi 30 | 31 | mkdir -p ~/.local/share/hrir 32 | echo "Copying HRIR file to ~/.local/share/hrir/hrir.wav" 33 | cp -a $file_path ~/.local/share/hrir/hrir.wav 34 | 35 | config_file="$HOME/.config/pulse/default.pa" 36 | 37 | if [ -f $config_file ] 38 | then 39 | echo "$config_file already exists, continuing will overwrite any previous module-virtual-surround-sink configuration" 40 | read -r -p "Are you sure? [y/n] " response 41 | response=${response,,} 42 | if ! [[ "$response" =~ ^(yes|y)$ ]] 43 | then 44 | echo "exiting" 45 | exit 0 46 | fi 47 | echo "modifying config file: $config_file" 48 | grep -v "module-virtual-surround" $config_file > tmp_config && mv tmp_config $config_file 49 | echo "" >> $config_file 50 | echo "load-module module-virtual-surround-sink sink_name=vsurround sink_properties=device.description=VirtualSurround hrir=$HOME/.local/share/hrir/hrir.wav master=$sink" >> $config_file 51 | else 52 | echo "creating config file: $config_file" 53 | touch $config_file 54 | echo "#!/usr/bin/pulseaudio -nF" >> $config_file 55 | echo "" >> $config_file 56 | echo ".include /etc/pulse/default.pa" >> $config_file 57 | echo "" >> $config_file 58 | echo "load-module module-virtual-surround-sink sink_name=vsurround sink_properties=device.description=VirtualSurround hrir=$HOME/.local/share/hrir/hrir.wav master=$sink" >> $config_file 59 | fi 60 | 61 | echo "Please logout ang login again" 62 | --------------------------------------------------------------------------------