We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3442 - SDL_OpenAudioDevice always returns half the samples requested.
Summary: SDL_OpenAudioDevice always returns half the samples requested.
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: HG 2.0
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-02 17:34 UTC by Alain Dupuis
Modified: 2020-08-10 15:47 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alain Dupuis 2016-10-02 17:34:22 UTC
Whenever I compare the values requested with what obtained I always get half of the samples requested. I tried changing the number of channels, freq, and format to see if this happen with a particular combination, but it seems to happen with any combination.

Some of the values I've tried are;

           REQUESTED        OBTAINED

freq:      22050            22050
format:    AUDIO_S16SYS     AUDIO_S16SYS
channels:  2                2
samples:   256              128

freq:      44100            44100
format:    AUDIO_S16SYS     AUDIO_S16SYS
channels:  2                2
samples:   256              128

freq:      44100            44100
format:    AUDIO_F32        AUDIO_F32
channels:  2                2
samples:   256              128

freq:      44100            44100
format:    AUDIO_F32        AUDIO_F32
channels:  1                1
samples:   256              128

freq:      48000            48000
format:    AUDIO_S32SYS     AUDIO_S32SYS
channels:  4                4
samples:   512              256

This looks familiar to bug id 3073 but was closed as "Resolved Invalid".
Comment 1 Ryan C. Gordon 2016-10-04 18:21:47 UTC
Was this with PulseAudio? ALSA? Something else?

--ryan.
Comment 2 Alain Dupuis 2016-10-04 23:59:15 UTC
This is with PulseAudio.
Comment 3 Sam Lantinga 2016-10-08 01:41:29 UTC
This is because of the PA_STREAM_ADJUST_LATENCY code in SDL_pulseaudio.c
Comment 4 Alain Dupuis 2017-01-08 08:23:44 UTC
Since revision 10757:329d6d46fb90 I now get the same number of samples as requested. Not sure if it's the desired effect since it still has the PA_STREAM_ADJUST_LATENCY check in SDL_pulseaudio.c. Just thought I'd let you know. Otherwise, good work on that commit!
Comment 5 Ryan C. Gordon 2017-05-19 19:13:55 UTC
(In reply to Alain Dupuis from comment #4)
> Since revision 10757:329d6d46fb90 I now get the same number of samples as
> requested. Not sure if it's the desired effect since it still has the
> PA_STREAM_ADJUST_LATENCY check in SDL_pulseaudio.c. Just thought I'd let you
> know. Otherwise, good work on that commit!

Yeah, SDL now buffers between what the app wants to feed the device, and what the device wants to be fed, so it works out better for everyone.  :)

Marking this resolved!

--ryan.
Comment 6 Vincent Hamp 2020-07-12 07:54:23 UTC
I was just about to file a new bug when I found this entry. I'm getting the very same behavior explained in the entry post with 2.0.12 and pulseaudio 13.0.

freq            44100           44100
format          AUDIO_S16LSB    AUDIO_S16LSB
channels        4               4
silence         0               0
samples         256             128
padding         0               0
size            0               1024

freq            44100           44100
format          AUDIO_S16LSB    AUDIO_S16LSB
channels        2               2
silence         0               0
samples         256             128
padding         0               0
size            0               512

freq            44100           44100
format          AUDIO_S16LSB    AUDIO_S16LSB
channels        1               1
silence         0               0
samples         256             128
padding         0               0
size            0               256

freq            22050           22050
format          AUDIO_U8        AUDIO_U8
channels        2               2
silence         0               128
samples         256             128
padding         0               0
size            0               256

freq            22050           22050
format          AUDIO_U8        AUDIO_U8
channels        1               1
silence         0               128
samples         256             128
padding         0               0
size            0               128
Comment 7 Vincent Hamp 2020-07-22 10:24:19 UTC
I just found out that the bug only occurs when there are two structures passed to SDL_OpenAudio. Passing only the desired spec seems to work.