| Summary: | [PATCH] SDL_netbsdaudio: Always use the device's preferred frequency | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Nia Alarie <nia> |
| Component: | audio | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | enhancement | ||
| Priority: | P2 | CC: | sezeroz |
| Version: | HG 2.0 | Keywords: | target-2.0.16 |
| Hardware: | x86 | ||
| OS: | NetBSD | ||
| Attachments: |
Patch to get and use the current hardware frequency with the AUDIO_GETFORMAT ioctl.
[v2] Patch to get and use the current hardware frequency with the AUDIO_GETFORMAT ioctl. [v3] Patch to get and use the current hardware frequency with the AUDIO_GETFORMAT ioctl |
||
Created attachment 4299 [details]
[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.
The last version of this patch I uploaded doesn't work with older NetBSD releases so shouldn't be applied. These changes sound useful. Is there a way to make this work with both old and new versions of NetBSD? Waiting for confirmation before resolving this bug. 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. SDL will automatically convert sample rate if the application requests it, so returning the native sample rate is completely reasonable here. 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. Created attachment 4643 [details]
[v3] Patch to get and use the current hardware frequency with the AUDIO_GETFORMAT ioctl
Attempt to work with older NetBSD releases.
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? Yup, looks good, thanks! https://hg.libsdl.org/SDL/rev/eec6a0d937e2 |
Created attachment 4298 [details] 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.