sound errors pyo/ubuntu

559 views
Skip to first unread message

Thomas Bullock

unread,
Mar 23, 2016, 3:51:00 PM3/23/16
to psychopy-users
Dear Group

I'm having trouble getting PsychoPy to play any sounds.  I'm running PsychoPy 1.83.04 on Ubuntu 14.04 (loaded onto a Mac Mini), and I'm working exclusively with the coder interface.  All I'm trying to do is play a simple tone at a specified point during a trial (nothing fancy)!

I know that sound is working on my machine, and I'm able to play tones with MATLAB/PsychToolbox, so I *think* it's a python issue (but I may be wrong).

When I run the soundStimuli.py demo, I get these error messages:

#########################################################################
##### Running: /home/orso/Desktop/PsychoPy/demos/coder/stimuli/soundStimuli.py #####
pyo version 0.6.8 (uses single precision)
portaudio error in Pa_OpenStream: Invalid number of channels
Portaudio error: Invalid number of channels
Server not booted.
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
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
Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1514
Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection_In )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2818
The Server must be booted!
portaudio error in Pa_OpenStream: Invalid number of channels
Portaudio error: Invalid number of channels
Server not booted.
#####################################################################

I've googled this issue extensively and it seems to be a common problem - however none of the solutions I've tried have worked.  I've already tried:

Reinstalling the sound drivers
Installing Jack Server (it's installed but still doesn't want to start).
Switching from Pyo to PyGame audio (same errors)
Initializing the server using a different set of code that I found on a discussion thread here:

###########################
from pyo import Server, Sine
from psychopy import prefs

prefs.general['audioDriver'] = [u'jack']

s = Server(audio=u'jack').boot()
s.start()
a = Sine(mul=0.01).out()
s.stop()
#########################

Which throws up the following errors:

#########################################################
############# Running: /home/orso/Desktop/PsychoPy/Tom_Sound_3.py ##############
pyo version 0.6.8 (uses single precision)
jackdmp 1.9.10
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2013 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
JACK server starting in realtime mode with priority 10
audio_reservation_init
Acquire audio card Audio0
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot create thread 1 Operation not permitted
Cannot create thread 1 Operation not permitted
Cannot create thread 1 Operation not permitted
Cannot lock down 82274202 byte memory area (Cannot allocate memory)
ALSA: Cannot open PCM device alsa_pcm for playback. Falling back to capture-only mode
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
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
######################################################

If anyone has any suggestions for a solution to this problem I'd really like to hear them!

Thank you

Tom

piot

unread,
Mar 23, 2016, 4:51:40 PM3/23/16
to psychopy-users
Hi Tom,

I had the same issues on debian unstable. Did you try to configure jackd with QjackCtl? I couldn't do so, because my the X server was freezing, when I started Qjackctl..

The issue resolved after trying out different things from the following two websites:

https://wiki.archlinux.org/index.php/JACK_Audio_Connection_Kit

http://wiki.linuxaudio.org/wiki/system_configuration

The information on linuxaudio.org is very valuable for setting up sound, in my opinion..  the realTimeConfigQuickScan is quite handy...

this may be interesting as well
http://jackaudio.org/faq/pulseaudio_and_jack.html

It's some time ago and I don't remember all the steps taken, unfortunately...

good luck

best wishes
Piotr

Thomas Bullock

unread,
Mar 23, 2016, 6:13:40 PM3/23/16
to psychopy-users
Hi Piotr

Thank you for the advice.  Yes I've tried to configure jackd with QjackCtl - I can open the gui and get into the setup menu, but playing around with the settings doesn't seem to make any difference.  The JACK server just won't start.

I'll keep plugging away and post an update if I get anywhere with the solutions on those websites...

Cheers

Tom

Thomas Bullock

unread,
Mar 23, 2016, 10:30:41 PM3/23/16
to psychopy-users
So I wasn't able to figure out the JACK problem yet, but I did find a solution that I think will suit my needs (at least for now).  I downloaded pyaudio [sudo apt-get install python-pyaudio python3-pyaudio] and was able to create sounds using the example script pasted below.  Compared to the pyo commands this method seems a lot less elegant, but the timing consistency seems to be decent enough and it works! 

I'm still getting a bunch of JACK errors in the output window, but these don't seem to affect my experiment timing or the production of the sounds (perhaps there's a way to disable these warnings)?

I'll update this thread again if I figure out a solution to the Ubuntu JACK issue.

Thanks again for your help.

Tom

###################################################################
import math
import pyaudio

#sudo apt-get install python-pyaudio
PyAudio = pyaudio.PyAudio

#See http://en.wikipedia.org/wiki/Bit_rate#Audio
BITRATE = 16000 #number of frames per second/frameset.      

#See http://www.phy.mtu.edu/~suits/notefreqs.html
FREQUENCY = 261.63 #Hz, waves per second, 261.63=C4-note.
LENGTH = 1.2232 #seconds to play sound

NUMBEROFFRAMES = int(BITRATE * LENGTH)
RESTFRAMES = NUMBEROFFRAMES % BITRATE
WAVEDATA = ''    

for x in xrange(NUMBEROFFRAMES):
 WAVEDATA = WAVEDATA+chr(int(math.sin(x/((BITRATE/FREQUENCY)/math.pi))*127+128))    

#fill remainder of frameset with silence
for x in xrange(RESTFRAMES): 
 WAVEDATA = WAVEDATA+chr(128)

p = PyAudio()
stream = p.open(format = p.get_format_from_width(1), 
                channels = 1, 
                rate = BITRATE, 
                output = True)
stream.write(WAVEDATA)
stream.stop_stream()
stream.close()
p.terminate()
##################################################################
Reply all
Reply to author
Forward
0 new messages