Portaudio error when switching on microphone

Hi all,

I’ve got PsychoPy v1.85.3 working on Ubuntu 16.04 via the neurodebian repo, and I’m trying to use the microphone. Pyo is installed and imports successfully, but when running microphone.switchOn() I get stuck in the following loop of errors:

ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
portaudio error in Pa_OpenStream: Invalid number of channels
Portaudio error: Invalid number of channels
Server not booted.
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
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock
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.

The last few lines just repeat trying to boot the server and failing, which generates a loop I have to kill. This happens in my script, in the latencyFromTone.py demo, and just a simple two line script where I import microphone and try the microphone.switchOn().

Googling around has led me deep into sound libraries and dependencies that I have no clue about, so just wanted to check if anyone here are run into or solved similar issues.

Obviously, any help or pointers would be appreciated!

Thanks,
Colin

Hi all,

Just wanted to say I managed to fix this and also share the solution. It turns out I was able to string together bits from some helpful posts from the old psychopy google group.

This post had some useful bits of code for stripping down to pyo basics, and I reproduced their problem+solution (i.e., same configuration and the server would start with maxChnls=2 but fail with >2). HOWEVER, this wasn’t necessary to actually get my script running with pyo! All I had to do was import prefs and change prefs.general['audioDriver'] = [u'jack'] and it worked. Good, so no messing with lower level functions!

However, I then ran into a different error when trying mic_trial = microphone.AdvAudioCapture(name=‘mic_trial’, filename=micfilename, stereo=False):

sampleRate = sound.pyoSndServer.getSamplingRate()
AttributeError: ‘NoneType’ object has no attribute ‘getSamplingRate'

This error has been previously discussed here and here. As far as I know, the problem is in the way psychopy sets up the microphone server, so maybe still a bug as of v1.85.3 (haven’t tried the latest psychopy v1.90).

I solved this second issue using the work around suggested by Nicolas in the second post, which involved hard coding the two lines in psychopy/microphone.py using the sound.pyoSndServer.getSamplingRate() to instead just set the sampleRate = 44100. Note that I chose this value because it’s the default sampling rate listed in the pyo Server documentation, which goes against the original post’s suggestion that it’s mostly likely 48000. I don’t know how to confirm which is “correct”, but I can say my script now works.

Hope this helps someone else!

Cheers,
Colin