[alsa-devel] [Portaudio] Recording devices opened mono still sending stereo causing corrupt audio

Ross Bencina rossb-lists at audiomulch.com
Sat Oct 12 03:05:04 CEST 2013

On 11/10/2013 11:33 PM, Clemens Ladisch wrote:
> Sean M. Pappalardo - D.J. Pegasus wrote:
>> the problem occurs when PA is asked to open just one channel of
>> a sound input device yet the device seems to stream two anyway.
> Many devices do not support mono streams.
>> I'm suspecting there's a miscommunication between PA and ALSA
> The communication between ALSA and PA works just fine; ALSA reports the
> minimum number of channels, and PA saves this value.
> What does not work is the communication between PA and the application;
> PA has no mechanism to report the minimum number of channels.

Since PortAudio is designed to provide useful features to the client, it 
does not make sense to restrict the client from opening a stereo device 
as mono.

This is by design.

However obviously there is an implementation issue in PA/ALSA if it does 
not respect ALSA's interface requiring support for a minimum number of 
channels > 1.

In this case PortAudio should either select the first (left) channel  or 
downmix to mono before passing to the client. I'd suggest the former. 
(or in general min(userRequestedChannelCount,availableChannelCount)

> Even worse, if some application tries to use a channel count that is too
> low, PA cleverly replaces it with the minimum support channel count:
>    self->numHostChannels = PA_MAX( params->channelCount, StreamDirection_In == streamDir ? devInfo->minInputChannels
>            : devInfo->minOutputChannels );
> and then does not bother to tell anybody about this.

The implementation should be dropping the second channel. So it should 
be telling the PA buffer processor to do so.

> This bug is especially egregious because PA does later check whether the
> number of channels is actually supported by the device; the code above
> ensures that this checks uses the wrong channel number.

Thanks for your input,


> Regards,
> Clemens

More information about the Alsa-devel mailing list