pyo fails with "invalid number of channels" (but other portaudio code works fine)

2,938 views
Skip to first unread message

Lars Kellogg-Stedman

unread,
Jan 28, 2016, 9:24:35 AM1/28/16
to pyo-discuss
[Apologies if this is a dupe; I thought I posted it yesterday but it's not showing up in the group...]

I am trying to use pyo on a Fedora 23 system (which includes portaudio 19). Using pyo built from source yesterday, when I attempt to boot a pyo server:

>>> import pyo
pyo version 0.7.8 (uses single precision)
>>> s = pyo.Server().boot()

I get the following error:

Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1513
Expression 'ValidateParameters( outputParameters, hostApi, StreamDirection_Out )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2820
portaudio error in Pa_OpenStream: Invalid number of channels
Portaudio error: Invalid number of channels
Server not booted.

Other Python code that uses the portaudio API seems to work without a problem. For example, using sounddevice:

>>> import sounddevice
>>> d = sounddevice.rec(44100*10, samplerate=44100, channels=2)
>>> sounddevice.play(d, samplerate=44100)

Or using pyaudio:

>>> import pyaudio
>>> pa = pyaudio.PyAudio()
>>> i = pa.open(rate=44100, format=pyaudio.paFloat32, channels=2, input=True)
>>> d = i.read(41000 * 10)
>>> o = pa.open(rate=44100, format=pyaudio.paFloat32, channels=2, output=True)
>>> o.write(d)

Why is this error surfacing when using pyo and how do I correct it?  I've tried explicitly setting input and output devices before booting the server, and I've tried explicitly setting nchnls to "1" or "2", and in all cases I'm getting the same error.

Thanks!

Olivier Bélanger

unread,
Jan 28, 2016, 7:00:22 PM1/28/16
to pyo-discuss
Hi,

Can you paste back the output of pa_list_devices()?

>>> import pyo
>>> pyo.pa_list_devices()

Also, can you try to boot the server without the duplex mode:

s = Server(duplex=0).boot()

Olivier
> --
> You received this message because you are subscribed to the Google Groups
> "pyo-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pyo-discuss...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Lars Kellogg-Stedman

unread,
Jan 29, 2016, 11:04:50 AM1/29/16
to pyo-d...@googlegroups.com
On Thu, Jan 28, 2016 at 7:00 PM, Olivier Bélanger <bela...@gmail.com> wrote:
Can you paste back the output of pa_list_devices()?

Sure.
 
>>> import pyo
>>> pyo.pa_list_devices()

AUDIO devices:
0: IN, name: Scarlett 2i2 USB: Audio (hw:0,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
1: IN, name: HDA Intel PCH: ALC269VC Analog (hw:1,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
1: OUT, name: HDA Intel PCH: ALC269VC Analog (hw:1,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
2: OUT, name: HDA NVidia: HDMI 0 (hw:2,3), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
3: OUT, name: HDA NVidia: HDMI 0 (hw:2,7), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
4: OUT, name: HDA NVidia: HDMI 0 (hw:2,8), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
5: OUT, name: HDA NVidia: HDMI 0 (hw:2,9), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
6: IN, name: USB audio CODEC: Audio (hw:3,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
6: OUT, name: USB audio CODEC: Audio (hw:3,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
7: IN, name: USB Device 0x46d:0x81d: Audio (hw:4,0), host api index: 0, default sr: 48000 Hz, latency: 0.008000 s
8: IN, name: sysdefault, host api index: 0, default sr: 48000 Hz, latency: 0.021333 s
9: IN, name: pulse, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
9: OUT, name: pulse, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
10: IN, name: focusrite_monitor, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
10: OUT, name: focusrite_monitor, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
11: IN, name: default, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
11: OUT, name: default, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s

Note that this system is running Pulseaudio, and the ALSA 'default' device points to Pulseaudio.
 
Also, can you try to boot the server without the duplex mode:

s = Server(duplex=0).boot()

This results in the same error message:

>>> import pyo
>>> s = pyo.Server(duplex=0).boot()
[...]

Olivier Bélanger

unread,
Jan 29, 2016, 12:24:41 PM1/29/16
to pyo-discuss
Hi,

There is some input-only devices, what are the portaudio's defaults:

>>> pa_get_default_input()
>>> pa_get_default_output()

Olivier

Lars Kellogg-Stedman

unread,
Jan 29, 2016, 1:54:03 PM1/29/16
to pyo-d...@googlegroups.com

On Fri, Jan 29, 2016 at 12:24 PM, Olivier Bélanger <bela...@gmail.com> wrote:
There is some input-only devices, what are the portaudio's defaults:

>>> pa_get_default_input()
>>> pa_get_default_output()


So, this is odd.  The system configuration is the same (I haven't attached any new devices), but now:


AUDIO devices:
0: IN, name: Scarlett 2i2 USB: Audio (hw:0,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
0: OUT, name: Scarlett 2i2 USB: Audio (hw:0,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s

1: OUT, name: HDA Intel PCH: ALC269VC Analog (hw:1,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
2: OUT, name: HDA NVidia: HDMI 0 (hw:2,3), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
3: OUT, name: HDA NVidia: HDMI 0 (hw:2,7), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
4: OUT, name: HDA NVidia: HDMI 0 (hw:2,8), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
5: OUT, name: HDA NVidia: HDMI 0 (hw:2,9), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
6: IN, name: USB audio CODEC: Audio (hw:3,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
6: OUT, name: USB audio CODEC: Audio (hw:3,0), host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
7: IN, name: USB Device 0x46d:0x81d: Audio (hw:4,0), host api index: 0, default sr: 48000 Hz, latency: 0.008000 s
8: IN, name: sysdefault, host api index: 0, default sr: 48000 Hz, latency: 0.021333 s
8: OUT, name: sysdefault, host api index: 0, default sr: 48000 Hz, latency: 0.021333 s
9: OUT, name: front, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
10: OUT, name: surround40, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
11: IN, name: pulse, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
11: OUT, name: pulse, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
12: IN, name: focusrite_monitor, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
12: OUT, name: focusrite_monitor, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
13: OUT, name: dmix, host api index: 0, default sr: 48000 Hz, latency: 0.021333 s
14: IN, name: default, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
14: OUT, name: default, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s

The list now shows device 0 (the Scarlett 2i2) as both as input and output device, while in the previous list it only showed up as an input device.  Also, some of the virtual ALSA devices (dmix, front, surround40) are showing up in this list.  The only change I made between the two was changing the default Pulseaudio input and output device via the "Sound" control panel.

And now I can successfully boot a server and play a tone.

So...it's working now -- on this system -- for mysterious and unknown reasons.

But!

I tried the same thing on a Raspberry Pi with a USB sound card, and ran into the same "Invalid number of channels" message.  In this case, the selection of sound cards is much smaller, and it's straight ALSA (no jackd or pulseaudio or anything):

0: OUT, name: bcm2835 ALSA: - (hw:0,0), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
1: OUT, name: bcm2835 ALSA: IEC958/HDMI (hw:0,1), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
2: IN, name: USB Audio Device: - (hw:2,0), host api index: 0, default sr: 44100 Hz, latency: 0.008685 s
2: OUT, name: USB Audio Device: - (hw:2,0), host api index: 0, default sr: 44100 Hz, latency: 0.008685 s
3: OUT, name: sysdefault, host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
4: OUT, name: dmix, host api index: 0, default sr: 48000 Hz, latency: 0.021333 s
5: OUT, name: default, host api index: 0, default sr: 48000 Hz, latency: 0.021333 s

WIth the above:

>>> import pyo
>>> s = pyo.Server().boot()
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

portaudio error in Pa_OpenStream: Invalid number of channels
Portaudio error: Invalid number of channels
Server not booted.

But in this case, setting duplex=0 appears to work:

So I guess I'm all set?  Thanks for your help!

Olivier Bélanger

unread,
Jan 29, 2016, 2:02:55 PM1/29/16
to pyo-discuss
Hi,
Weird but great!
Here, you don't set the audio device so I guess it uses the internal
soundcard that effectively appears to be configured only for output.

To use the usb soundcard, you can try something like this:

s = Server()
s.setInOutDevice(2)
s.boot()

Olivier

>
> So I guess I'm all set? Thanks for your help!
>
Reply all
Reply to author
Forward
0 new messages