Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad behaviour in <ossaudio audio device>.obuf* #44040

Closed
samdennis mannequin opened this issue Sep 27, 2006 · 6 comments
Closed

Bad behaviour in <ossaudio audio device>.obuf* #44040

samdennis mannequin opened this issue Sep 27, 2006 · 6 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@samdennis
Copy link
Mannequin

samdennis mannequin commented Sep 27, 2006

BPO 1566331
Nosy @tiran, @raplin

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2006-09-27.13:19:49.000>
labels = ['extension-modules', 'type-bug', '3.9', '3.10', '3.11']
title = 'Bad behaviour in <ossaudio audio device>.obuf*'
updated_at = <Date 2021-10-20.12:39:09.354>
user = 'https://bugs.python.org/samdennis'

bugs.python.org fields:

activity = <Date 2021-10-20.12:39:09.354>
actor = 'christian.heimes'
assignee = 'gward'
closed = False
closed_date = None
closer = None
components = ['Extension Modules']
creation = <Date 2006-09-27.13:19:49.000>
creator = 'samdennis'
dependencies = []
files = []
hgrepos = []
issue_num = 1566331
keywords = []
message_count = 5.0
messages = ['30030', '30031', '114835', '304127', '404440']
nosy_count = 5.0
nosy_names = ['gward', 'samdennis', 'rluse', 'christian.heimes', 'richaplin']
pr_nums = []
priority = 'low'
resolution = None
stage = 'test needed'
status = 'pending'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1566331'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

@samdennis
Copy link
Mannequin Author

samdennis mannequin commented Sep 27, 2006

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
option.

@samdennis samdennis mannequin assigned gward Sep 27, 2006
@samdennis samdennis mannequin added the extension-modules C modules in the Modules dir label Sep 27, 2006
@samdennis samdennis mannequin assigned gward Sep 27, 2006
@samdennis samdennis mannequin added the extension-modules C modules in the Modules dir label Sep 27, 2006
@rluse
Copy link
Mannequin

rluse mannequin commented May 6, 2007

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.

@devdanzin devdanzin mannequin added type-bug An unexpected behavior, bug, or error labels Mar 30, 2009
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Aug 24, 2010

I think SNDCTL_SET_CHANNELS should have read SNDCTL_DSP_CHANNELS. The code was changed in r42752 so is this still a problem?

@raplin
Copy link
Mannequin

raplin mannequin commented Oct 11, 2017

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
self.dsp=ossaudiodev.open("/dev/dsp1","w")
self.dsp.setfmt(ossaudiodev.AFMT_S16_LE)
self.dsp.channels(2) #<<Set to stereo
self.dsp.speed(96000)
...
self.bufSize=self.dsp.bufsize()
...

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

Frustrating bug! ;-)

@tiran
Copy link
Member

tiran commented Oct 20, 2021

Does the issue still affect supported Python and Linux versions? Majority of distros are using pipewire or pulseaudio these days.

@tiran tiran added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Oct 20, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@AA-Turner
Copy link
Member

The ossaudiodev module has now been deprecated and will be removed (see PEP-594 & #91217 for details), closing.

A

@AA-Turner AA-Turner closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants