sonic-pi-net / sonic-pi

Code. Music. Live.
https://sonic-pi.net
Other
10.8k stars 922 forks source link

sonic pi not working with HiFiberry DAC #367

Closed Zaaphod closed 8 years ago

Zaaphod commented 9 years ago

I'm using the NOOBs rasbian installation. sonic pi was preinstalled and worked through the HDMI interface. I installed my HiFiberry DAC card and now sonic pi only displays the title screen and stays there.. if I click on it, it just disappears, but the program itself never comes up. If I try a second time, it says it can't start because it's already running, even though there is no evidence of it running anywhere that I can see. Is there some place to configure sonic pi for the hifiberry DAC card? everything else works great, I can play music and videos with VLC media player and the sound comes from the HiFiberry card. I'm a bit of a noob with linux and even more of a noob with raspberry pi, so I have no idea where to look to try to fix this... I suspect sonic pi is looking for specific hardware and not looking for my DAC card.
my asound.conf has been changed as part of the HiFiberry install to read:

pcm.!default { type hw card 0 } ctl.!default { type hw card 0 }

I somehow need to get sonic pi to use this card instead of whatever the default is.

Any ideas on how to configure or fix this?

samaaron commented 9 years ago

Sorry, I can't help at this stage. I'm still learning how to properly tame audio on Linux. One place to start tweaking is here: https://github.com/samaaron/sonic-pi/blob/master/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb#L224 where we configure scsynth and jack. Another is here: https://github.com/samaaron/sonic-pi/blob/master/app/gui/qt/mainwindow.cpp#L939 where we configure amixer.

If you can get things to work, please do consider sending a pull request allowing other HiFiberry users to use Sonc Pi.

samaaron commented 9 years ago

The nice people at HiFiBerry have offered to send me out a board to work out these kinks with Sonic Pi. This means that we'll hopefully support these DAC hats out of the box in a future version.

Zaaphod commented 9 years ago

I'll have a look and see if I can figure anything out. That's great that HiFiberry sent you a board to develop with! I must say I am incredibly impressed with HiFiBerry.. I have a huge rediculous computer with an very expensive gaming sound card installed, and my Raspberry Pi with HiFiberry sounds WAY better than that!

I did learn a little more about this issue. I found out that by launching sonic-pi from a terminal window instead of the menu, I can see a little more of what's happening... this is what I get:

QGtkStyle was unable to detect the current GTK+ theme starting OSC server Listening on port 4558 ruby /opt/sonic-pi/app/gui/qt/../../../app/server/bin/sonic-pi-server.rb Waiting for server... Waiting for server... Waiting for server... Waiting for server... ... ... endlessly.... it never stops waiting for server

So to try to lean more, I terminated the terminal window and opened a new one and tried to start the server myself by typing in ruby /opt/sonic-pi/app/gui/qt/../../../app/server/bin/sonic-pi-server.rb

I got this: Using protocol: UDP jackd: no process found scsynth: no process found jackdmp 1.9.9 Copyright 2001-2005 Paul Davis and others. Copyright 2004-2012 Grame. jackdmp comes with ABSOLUTELY NO WARRANTY this is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started JACK server starting in realtime mode with priority 10 Cannot lock down 14130080 byte memory area (Cannot allocate memory) Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started control device hw:0 control device hw:0 audio_reservation_init Acquire audio card Audio0 creating alsa driver ... hw:0|hw:0|2048|3|44100|0|0|nomon|swmeter|-|32bit control device hw:0 ALSA: Cannot open PCM device alsa_pcm for capture. Falling back to playback-only mode configuring for 44100Hz, period 2048 frames (46.4ms), buffer = 3 periods ALSA: mmap-based access is not possible for the playback stream of this audio interface ALSA: Cannot configure playback channel JackTemporaryException : now quits ... Cannot initialize driver JackServer::Open failed with -1 Failed to open server cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started ... ... ... the last 3 lines repeat over and over endlessly.

I do not have a clue what any of that means... but maybe someone familiar with this will see something in it.

samaaron commented 9 years ago

Looks like jack is struggling to work with the HiFiBerry hat with the supplied settings. Hopefully I can figure it out over the next couple of days once I get the dev board.

rbnpi commented 9 years ago

Zaphod. A temporary solution can get Sonic Pi working for you, but I'm afraid NOT through your HiFiBerry card. I have the IQaudio card which suffers from exactly the same problem. Both cards use the i2s bus to connect to their DAC and I don't think this works with jack currently. The IQaudio card is set up as the default alsa device and I guess the HiFi Berry one is too. You will probably find that the original BCM2835 is still active. In my case it is in card slot 1. you can see this by typing aplay -l in a terminal window, which should show your HiFiBerry card in slot 0 and (hopefully) the old BCM2835 in slot 1

You can then alter the scsynthexternal.rb file in sonic pi to reflect this new location.

sudo nano /opt/sonic-pi/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb

scroll down to find the line (it is quite a long way down!)

sys("jackd -R -T -p 32 -d alsa -n 3 -p 2048 -r 44100& "

alter it to read

sys("jackd -R -T -p 32 -d alsa -d hw:1,0 -n 3 -p 2048 -r 44100& "

then press ctrl+X followed by Y return to exit saving the change.

If your BCM2835 is shown in a different slot by the aplay -l command (say slot n) then alter the hw:1,0 addition to hw:n,0 where n is the number you get.

Finally if your BCM2835 does NOT appear and has been completely disabled by the HiFiBerry install, check whether there is an uncommented line snd-bcm2835 in the file /etc/modules and if not add it using sudo nano /etc/modules

Hope this is of some temporary help for you.

If you are worried about changing the sonic pi file, you can make a backup of it first using sudo cp /opt/sonic-pi/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb /opt/sonic-pi/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb.bak before you edit it. If things go wrong you can then replace the original file from the backup.

Note that if you upgrade sonic pi with a later install it will overwrite this mod and it will need to be done again pending another solution.

Zaaphod commented 9 years ago

Any luck getting Sonic Pi to work through the HiFi Berry Card?

samaaron commented 9 years ago

@Zaaphod Unfortunately @rbnpi is right. Until the HiFi Berry Card works with Jackd, it's not going to work with Sonic Pi. Sorry.

hzulla commented 8 years ago

@samaaron @Zaaphod There have been recent changes for getting Sonic Pi to work with alternative sound cards on the Rpi. Did these changes resolve this issue?

samaaron commented 8 years ago

This was resolved in release v2.9

rbnpi commented 8 years ago

This was solved but now a problem again for this and IQAudio with the stuttering that occurs with the latest Raspbian. Problems down to jack and not SPI think.

On 31 May 2016, at 11:55, Sam Aaron notifications@github.com wrote:

Closed #367 https://github.com/samaaron/sonic-pi/issues/367.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samaaron/sonic-pi/issues/367#event-676836347, or mute the thread https://github.com/notifications/unsubscribe/AFVDiSyxuF3nOld-l0msoZ5RzA_XX1juks5qHBOugaJpZM4DjV9K.

samaaron commented 8 years ago

@rbnpi the stuttering problem is a totally separate issue :-)

From Sonic Pi's perspective, we now support external audio cards :-)