Skip to content

Commit

Permalink
Enforce a quantum size measured in milliseconds, overriding the OS bu…
Browse files Browse the repository at this point in the history
…ffer size.

The spec states that the default update interval is 10ms, with 1024_QUANTUM
being a somewhat poorly-named flag to use a 21.33ms interval instead. So, the
graph needs to be consistent in size no matter what the OS wants, we'll need to
depend on SDL doing the right thing with the internal SDL_AudioStream.
  • Loading branch information
flibitijibibo committed Mar 19, 2020
1 parent a44f228 commit a0f859c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/FAudio_platform_sdl2.c
Expand Up @@ -84,9 +84,21 @@ void FAudio_PlatformInit(
want.format = AUDIO_F32;
want.channels = mixFormat->Format.nChannels;
want.silence = 0;
want.samples = 1024;
want.callback = FAudio_INTERNAL_MixCallback;
want.userdata = audio;
if (flags & FAUDIO_1024_QUANTUM)
{
/* Get the sample count for a 21.33ms frame.
* For 48KHz this should be 1024.
*/
want.samples = (int) (
want.freq / (1000.0 / (64.0 / 3.0))
);
}
else
{
want.samples = want.freq / 100;
}

/* Open the device (or at least try to) */
iosretry:
Expand All @@ -95,16 +107,7 @@ void FAudio_PlatformInit(
0,
&want,
&have,
#if SDL_VERSION_ATLEAST(2, 0, 9)
(flags & FAUDIO_1024_QUANTUM) ? 0 : SDL_AUDIO_ALLOW_SAMPLES_CHANGE
#else
#ifdef _WIN32
#error Windows absolutely positively needs SDL 2.0.9!
#else
#pragma message("Please update to SDL 2.0.9 ASAP!")
#endif
0
#endif
);
if (device == 0)
{
Expand Down

0 comments on commit a0f859c

Please sign in to comment.