{"action":"created","issue":{"url":"https://api.github.com/repos/samaaron/sonic-pi/issues/1109","repository_url":"https://api.github.com/repos/samaaron/sonic-pi","labels_url":"https://api.github.com/repos/samaaron/sonic-pi/issues/1109/labels{/name}","comments_url":"https://api.github.com/repos/samaaron/sonic-pi/issues/1109/comments","events_url":"https://api.github.com/repos/samaaron/sonic-pi/issues/1109/events","html_url":"https://github.com/samaaron/sonic-pi/issues/1109","id":144884842,"number":1109,"title":"Linux Audio and Sonic Pi","user":{"login":"soslug","id":4312889,"avatar_url":"https://avatars.githubusercontent.com/u/4312889?v=3","gravatar_id":"","url":"https://api.github.com/users/soslug","html_url":"https://github.com/soslug","followers_url":"https://api.github.com/users/soslug/followers","following_url":"https://api.github.com/users/soslug/following{/other_user}","gists_url":"https://api.github.com/users/soslug/gists{/gist_id}","starred_url":"https://api.github.com/users/soslug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soslug/subscriptions","organizations_url":"https://api.github.com/users/soslug/orgs","repos_url":"https://api.github.com/users/soslug/repos","events_url":"https://api.github.com/users/soslug/events{/privacy}","received_events_url":"https://api.github.com/users/soslug/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-31T12:27:36Z","updated_at":"2016-03-31T19:34:37Z","closed_at":null,"body":"I love Sonic Pi and it angers me when it doesn't play on my main Linux Desktop build, this being Linux Mint LTS which at the time of writing this issue is 17.3 and I am using 64Bit.\r\n\r\nNow that is out of the way I thought I would spend some time explaining why (as best as I can understand it) people are having trouble running Sonic-pi on main Linux builds such as Linux Mint, Fedora, Debian and so on. The reason appears to be this, it is - the Sound Server you are using no one distribution is necessarily the same.\r\n\r\nSonic-Pi seems to use the ALSA Sound Server or wants too, and Linux Mint uses or is using Pulseaudio so conflicts arise. Now as sound servers go, both are very good at what they do, and pulseaudo seems to be the direction distro are heading, the problem as I see it is that Sonic-Pi fails to use the default sound server insisting it uses Alsa instead, perhaps because this is what supercollider uses.\r\n\r\nFor most of us using the one sound server system you can effectively refer to the Sonic-Pi INSTALL-LINUX.md documentation and this should be enough to get this going. As two sound servers applications cannot run at the same time you need to kill or suspend the one you are using in favour of running the other. Most Linux operating systems favoured using the ALSA sound server and may still do, but of late, I know Linux Mint uses PulseAudio.\r\n\r\nNote - the above Installation as listed packages did not work on LinuxMint for me without me first installing the package build-essential, so if you get build dependency problems you should first try that. \r\n\r\nsudo apt-get install build-essential\r\n\r\nIf you are running Linux Mint 17.3 LTS you are using PulseAudio as your default Sound Server which is incompatible with Sonic-Pi, an acceptable means to get things running is one of the following methods. All methods will require the pre installation of jackd on Linux Mint, Ubuntu and Debian you can use (sudo apt-get install qjackctl) this will install most all the necessary packages:-\r\n\r\n**Method 1**\r\nDo not use \"sudo\" or superuser level or root user it is not needed to run these commands but will require a console terminal window open and ready for use.\r\n\r\npulseaudio -k\r\njackd -R -d alsa -d hw:0\r\n\r\nThis first command kills pulseaudio sound server and replaces it with jackd, the jackd command may look a little goofy but can be interpreted thus:\r\n\r\njackd - the Sound server using the devices specified by (-d alsa & -d hw:0) linux sees these as addressable devices.\r\n-R - this specifies Jack is to run in realtime mode for low audio latency.\r\n-d - specifies the devices we are using, either software or hardware, we are using two devices \"Alsa\" and the default \"hw\" output device as it is possible to address a different Hardware output device we specifically use \"hw:0\" to use the default hardware where only one audio sound card on the motherboard is available.\r\n\r\nThen launch Sonic-Pi gui or from the command line\r\n\r\nAfter ending you session in Sonic-Pi, to start Pulseaudio again you can use the following linux command as non superuser (ie do not run as sudo)\r\n\r\npulseaudio --start\r\n\r\n**Method 2**\r\npasuspender -- jackd -R -d alsa -d hw:0\r\n\r\nThis method has an advantage in that it suspends PulseAudio whilst Jackd is running, the rest is the same as the first method above.\r\n\r\n**Method 3**\r\nQJackCtl, this is a gui (graphical user interface) if this is installed it is located on Menu under Sound & Video on Linuxmint anyway. Running Qjackctl looks very scary but on systems with one single hardware sound device it is really very simple. Usually it just requires you to launch qjackctl-gui from the Sound & Video menu and press start, then run Sonic-Pi. If you have problems running this, and you will know if you do you will get a flurry of message errors to the screen. Then you may still need to kill PulseAudio, press the Stop button or kill the qjackctl gui then with.\r\n\r\npulseaudio -k\r\n\r\nThis needs to run on the command line console there is no equivalent gui that you can use, then activate qjackctl from the menu and press start button for Qjackctl.\r\n\r\nThis covers the 3 basic methods for using Sonic-Pi after you have followed all the compile instructions for your build. You can find more help on Jack Audio here:-\r\n\r\nhttp://linux.die.net/man/1/jackd\r\n\r\nYou might also want to build a startup bash script not only to setup jack but to start Sonic-Pi just copy this code below and save to a file in your own home directory.\r\n\r\n #!/bin/bash\r\n\r\npulseaudio -k\r\nkillall jackd\r\n/usr/bin/jackd -R -P40 -p128 -t5000 -dalsa -dhw:0 -r48000 -p2048 -n2 -S &\r\nDownloads/sonic-pi/bin/sonic-pi\r\nkillall jackd\r\n\r\nuse chmod +x _filename_\r\n\r\nThis allows you to run the script without using a shell like \"sh\" in front ./_filename_\r\nThis is essentially no different to our examples above and if it works for you I would say use it, the one problem I have yet to address is that the above code works well, but does not exit the script cleanly which for me I have to use \"control c\" to terminate the script file properly.\r\n \r\n========================\r\n\r\nSo what if your Linux Desktop has more than one sound card and you specifically want the audio coming out of the device you are using. How can your Desktop have more than one sound card? Well if your Desktop is installed with something like an Nvidia Graphics card and you are using HDMI or DVI to HDMI then it may surprise you to know you actually have three sound hardware devices recognised by Linux which you can use independently to one another.\r\n\r\nYou can actually test this out for yourself, but first you need to know how to address your additional devices. We can get a rough idea by using \"aplay\" on the command line terminal console window.\r\n\r\nOpen a new terminal window and type the following:\r\n\r\naplay -l (this i lower case L by the way you can use capital L instead which has the effect of giving a more comprehensive list)\r\nWith \"apaly -l\" you might get a response something like this:-\r\n\r\n**** List of PLAYBACK Hardware Devices ****\r\ncard 0: Intel [HDA Intel], device 0: STAC9200 Analog [STAC9200 Analog]\r\n  Subdevices: 1/1\r\n  Subdevice #0: subdevice #0\r\ncard 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]\r\n  Subdevices: 1/1\r\n  Subdevice #0: subdevice #0\r\ncard 1: NVidia [HDA NVidia], device 7: HDMI 0 [HDMI 0]\r\n  Subdevices: 1/1\r\n  Subdevice #0: subdevice #0\r\ncard 1: NVidia [HDA NVidia], device 8: HDMI 0 [HDMI 0]\r\n  Subdevices: 1/1\r\n  Subdevice #0: subdevice #0\r\ncard 1: NVidia [HDA NVidia], device 9: HDMI 0 [HDMI 0]\r\n  Subdevices: 1/1\r\n  Subdevice #0: subdevice #0\r\n\r\nAs you can see we have many more devices than we can actually use with 2 cards and 5 so called devices accessible. Lets first look at card 0 this refers  to my internal sound card on my computers  motherboard if i want to access this via jack I would use the following:-\r\n\r\njackd -R -d alsa -d hw:0\r\n\r\nHow can we test this well even if we use pulse audio we can still determine the hardware device to output from try this simple test.\r\n\r\nspeaker-test -c2 -twav (this uses the systems default sound card)\r\nThis is a repetitive test that will work over and over call a sample file to output to the selected audio device for front-left and front-right.\r\n\r\nspeaker-test - is the command\r\nc2 - how many channels are attached usually two but if you may have surround so may have 8 so c8\r\ntwav - is a set predefined wav files used, you can:-\r\n\r\nman speaker-test - for more info\r\n\r\nWe can also specify the exact sound hardware we want to use with \"-D\" on our command line string \r\n\r\nspeaker-test -c2 -Dhw:1,9 -twav\r\n\r\nBreaking this down again\r\n\r\nspeaker-test - is the command\r\nc2 - channels (if surround use c8)\r\nDhw:1,9 - card 1 device 9 which corresponds to a hdmi output channel I can use.\r\ntwav - predefinned wav files\r\n\r\nYou can now alter the same bash script above with this new hardware in mind\r\n\r\n #!/bin/bash\r\n\r\npulseaudio -k\r\nkillall jackd\r\n/usr/bin/jackd -R -P40 -p128 -t5000 -dalsa -dhw:1,9 -r48000 -p2048 -n2 -S &\r\nDownloads/sonic-pi/bin/sonic-pi\r\nkillall jackd\r\n\r\nuse chmod +x _filename_\r\n\r\nAnd everthing should work if it doesn't you might need to install \r\n\r\nsudo apt-get install pulseaudio-module-jack\r\n\r\nIt may work without it but should not cause harm if installed or not please do not alter the default.pa file located in /etc/pulse any helpful comments would be appreciated I will do my best to answer any questions as they arise, relating to the above topic as and when I can. Feel free to answer any question under this topic."},"comment":{"url":"https://api.github.com/repos/samaaron/sonic-pi/issues/comments/204092650","html_url":"https://github.com/samaaron/sonic-pi/issues/1109#issuecomment-204092650","issue_url":"https://api.github.com/repos/samaaron/sonic-pi/issues/1109","id":204092650,"user":{"login":"hzulla","id":1705654,"avatar_url":"https://avatars.githubusercontent.com/u/1705654?v=3","gravatar_id":"","url":"https://api.github.com/users/hzulla","html_url":"https://github.com/hzulla","followers_url":"https://api.github.com/users/hzulla/followers","following_url":"https://api.github.com/users/hzulla/following{/other_user}","gists_url":"https://api.github.com/users/hzulla/gists{/gist_id}","starred_url":"https://api.github.com/users/hzulla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzulla/subscriptions","organizations_url":"https://api.github.com/users/hzulla/orgs","repos_url":"https://api.github.com/users/hzulla/repos","events_url":"https://api.github.com/users/hzulla/events{/privacy}","received_events_url":"https://api.github.com/users/hzulla/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T19:34:37Z","updated_at":"2016-03-31T19:34:37Z","body":"I've been digging into the code of SuperCollider recently. It contains an alternative to the default JACK driver, using the PortAudio audio library. PortAudio can connect to ALSA and PulseAudio, but currently I get audio issues and buffer underruns using SuperCollider with PortAudio on Linux. There might be a fix for that, so we might get a working jackless version of Sonic Pi some time in the future."}}