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

[PATCH] SDL_netbsdaudio: Always use the device's preferred frequency #3630

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed
Labels
enhancement New feature or request

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: NetBSD, x86

Comments on the original bug report:

On 2020-04-08 14:19:52 +0000, Nia Alarie wrote:

Created attachment 4298
Patch to get and use the current hardware frequency with the AUDIO_GETFORMAT ioctl.

The NetBSD kernel's audio resampling code is much simpler and lower quality than libsamplerate.

Presumably, if SDL always performs I/O on the audio device in its native frequency, we can avoid resampling audio in the kernel and let SDL do it with libsamplerate instead.

On 2020-04-08 14:30:46 +0000, Nia Alarie wrote:

Created attachment 4299
[v2] Patch to get and use the current hardware frequency with the AUDIO_GETFORMAT ioctl.

Actually, we shouldn't set the device "blocksize" at all (the kernel will ignore it and calculate its own), but especially don't set it to the value of spec->size before spec->size is calculated.

On 2020-12-27 09:24:22 +0000, Nia Alarie wrote:

The last version of this patch I uploaded doesn't work with older NetBSD releases so shouldn't be applied.

On 2020-12-27 21:11:58 +0000, Sam Lantinga wrote:

These changes sound useful. Is there a way to make this work with both old and new versions of NetBSD?

On 2020-12-27 21:12:25 +0000, Sam Lantinga wrote:

Waiting for confirmation before resolving this bug.

On 2021-01-06 13:46:09 +0000, Nia Alarie wrote:

Yes, we can easily make this work on older versions of NetBSD by #ifdefing around the AUDIO_GETFORMAT ioctl usage.

I wonder if this is actually how SDL is supposed to work, though. I just assumed that SDL now does the conversions automatically, so to revisit this patch I'd need reassurance about the internal behaviour.

On 2021-01-06 17:29:29 +0000, Sam Lantinga wrote:

SDL will automatically convert sample rate if the application requests it, so returning the native sample rate is completely reasonable here.

On 2021-01-06 17:30:33 +0000, Sam Lantinga wrote:

Basically the audio driver should change to the requested frequency if the audio hardware can run at that frequency, and return the actual frequency if not.

On 2021-01-08 12:46:29 +0000, Nia Alarie wrote:

Created attachment 4643
[v3] Patch to get and use the current hardware frequency with the AUDIO_GETFORMAT ioctl

Attempt to work with older NetBSD releases.

On 2021-01-08 12:50:42 +0000, Nia Alarie wrote:

OK, new patch uploaded.

Background: The audio device supports any arbitrary sample rate from 1-192kHz. The user can configure a native frequency for the device, which is nearly always 48kHz by default. Audio at a different frequency will play without issue, but will be resampled in the kernel, and we definitely want libsamplerate to be used instead.

v3 of the patch should always set this->spec.freq to the native rate (usually 48kHz) on NetBSD 9.x and newer, but will leave it unchanged on older releases and rely on the in-kernel resampler. Does that sound right?

On 2021-01-08 18:10:30 +0000, Sam Lantinga wrote:

Yup, looks good, thanks!
https://hg.libsdl.org/SDL/rev/eec6a0d937e2

@SDLBugzilla SDLBugzilla added the enhancement New feature or request label Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant