Title: Bad behaviour in .obuf*
Type: behavior Stage: test needed
Components: Extension Modules Versions: Python 2.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: gward Nosy List: gward, richaplin, rluse, samdennis
Priority: low Keywords:

Created on 2006-09-27 13:19 by samdennis, last changed 2017-10-11 10:36 by richaplin.

Messages (4)
msg30030 - (view) Author: Sam Dennis (samdennis) Date: 2006-09-27 13:19
The _ssize() function in ossaudiodev.c (2.4.3, but it's
the same in svn) calls SNDCTL_SET_CHANNELS with
channels=0 as part of an attempt to determine the total
number of samples per second for the current
configuration of the audio device, but as far as I can
tell this is not guaranteed to act as a query and at
least two implementations treat it as a request for a
monaural format (the ALSA pcm-oss module and the
alsa-oss library).

What this can safely be replaced with I don't know;
both Linux's OSS drivers and ALSA support
SOUND_PCM_READ_CHANNELS but this is not standard to the
best of my knowledge.  Storing the value returned when
the program calls .setfmt or .setparameters may be an
msg30031 - (view) Author: Bob Luse (rluse) Date: 2007-05-06 03:41
I just wanted to confirm that this is  problem for me as well when I run this.  I am writing an application where I need to get buffer information when I am running with 2 channels.  This is a quite normal situation these days.  I assume that the change is made to mono because in OSS mono is the default, so that it will work with what is now quite ancient hardware.  But, requesting the buffer size should not cause such a dramatic error.  I don't understand why this is such a problem.  Could there be a parameter for number of channels since you cannot request the buffer size unless you have already setup the hardware giving the number of channels?  So even if the System cannot figure out the number of channels, your application knows it and can tell it.  Granted, it is a kluge, but it is a kluge that can work whereas currently whenever you request buffer information the speed of your sound is cut in half making the obuf commands unusable.  Possibly another solution would be to remove these commands until they work.  I did notice that the program does reference SOUND_PCM_WRITE_CHANNELS.  Is SOUND_PCM_WRITE_CHANNELS standard and SOUND_PCM_READ_CHANNELS not standard?  I don't know that that is not true, but it does seem strange.  
msg114835 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-24 21:42
I think SNDCTL_SET_CHANNELS should have read SNDCTL_DSP_CHANNELS.  The code was changed in r42752 so is this still a problem?
msg304127 - (view) Author: Richard Aplin (richaplin) Date: 2017-10-11 10:36
Hi there yes this is very much an issue on Arm linux (e.g. Armbian). Calling any function that triggers a call to _ssize(..) - a function which is clearly intended to have no side-effects - instead resets the number of channels (and sample format?) by calling IOCTLs "SNDCTL_DSP_SETFMT" and "SNDCTL_DSP_CHANNELS" with arguments of zero as a way to query the current values. 

This doesn't work on many drivers; e.g. they take '0' as meaning 'mono' and switch to one channel. 

To repro:
        import ossaudiodev"/dev/dsp1","w")
        self.dsp.channels(2)  #<<Set to stereo

        #This will output audio in the wrong format (mono)! Remove the innocent looking "bufsize" test above and it will correctly output stereo

Frustrating bug! ;-)
Date User Action Args
2017-10-11 10:36:16richaplinsetnosy: + richaplin
messages: + msg304127
2014-02-03 19:46:25BreamoreBoysetnosy: - BreamoreBoy
2010-08-24 21:42:40BreamoreBoysetnosy: + BreamoreBoy
messages: + msg114835
2009-03-30 02:34:17ajaksu2setpriority: normal -> low
stage: test needed
type: behavior
versions: + Python 2.6, - Python 2.4
2006-09-27 13:19:49samdenniscreate