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

check_input_settings does not raise exception for some unsupported sample rates on macOS #505

Open
HaroldMills opened this issue Nov 22, 2023 · 4 comments

Comments

@HaroldMills
Copy link

On my 2019 MacBook Pro running macOS 13.6.1, the following script:

import sounddevice as sd

settings = {'device': 1, 'channels': 1, 'samplerate': 44100, 'dtype': 'int16'}
sd.check_input_settings(**settings)
sd.rec(frames=settings['samplerate'], blocking=True, **settings)

(you might need to modify the device index for a different computer) first checks if the specified input settings are supported and then, if they are (i.e. if the call to check_input_settings does not raise an exception), attempts to record for one second with those settings. For my Mac's built-in microphone this works as expected for a sample rate of 44100 Hz. For various other sample rates, however, including 48000, 24000, and 22050 Hz, it does not. For those sample rates the call to check_input_settings does not raise an exception, but the script terminates inside the call to rec with the console message:

libc++abi: terminating

It seems that this may be a bug in check_input_settings, which should raise an exception for unsupported sample rates.

@HaroldMills HaroldMills changed the title check_input_settings does not raise exception for some unsupported settings on macOS check_input_settings does not raise exception for some unsupported sample rates on macOS Nov 22, 2023
@HaroldMills
Copy link
Author

Is there another way to determine whether or not a given sample rate is supported on macOS? I tried using a stream to record, like this:

stream = sd.InputStream(**settings)
stream.start()
stream.read(settings['samplerate'])

hoping that the initializer might raise an exception for an unsupported sample rate, but it does not. The read fails with the same console message that rec produces, as in my original comment.

@HaroldMills
Copy link
Author

check_input_settings does reject some sample rates on macOS, namely ones outside of the range [1000, 384000].

@mgeier
Copy link
Member

mgeier commented Nov 23, 2023

check_input_setting() only calls Pa_IsFormatSupported() from the underlying PortAudio library:

parameters, dtype, samplesize, samplerate = _get_stream_parameters(
'input', device=device, channels=channels, dtype=dtype, latency=None,
extra_settings=extra_settings, samplerate=samplerate)
_check(_lib.Pa_IsFormatSupported(parameters, _ffi.NULL, samplerate))

Can you please ask your question at https://github.com/PortAudio/portaudio/issues or at the PortAudio mailing list?

@HaroldMills
Copy link
Author

Thanks for the suggestion. I'll look into this as a PortAudio issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants