mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 15:47:31 +08:00
Use 20 ms as the default audio buffer size on Android
It turns out that Android will not pick a low latency buffer size by default.
This commit is contained in:
@@ -321,11 +321,15 @@ static bool BuildAAudioStream(SDL_AudioDevice *device)
|
|||||||
ctx.AAudioStreamBuilder_setSampleRate(builder, device->spec.freq);
|
ctx.AAudioStreamBuilder_setSampleRate(builder, device->spec.freq);
|
||||||
ctx.AAudioStreamBuilder_setChannelCount(builder, device->spec.channels);
|
ctx.AAudioStreamBuilder_setChannelCount(builder, device->spec.channels);
|
||||||
|
|
||||||
// If no specific buffer size has been requested, the device will pick the optimal
|
int32_t sample_frames;
|
||||||
if(SDL_GetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES)) {
|
if (SDL_GetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES)) {
|
||||||
ctx.AAudioStreamBuilder_setBufferCapacityInFrames(builder, 2 * device->sample_frames); // AAudio requires that the buffer capacity is at least
|
sample_frames = device->sample_frames;
|
||||||
ctx.AAudioStreamBuilder_setFramesPerDataCallback(builder, device->sample_frames); // twice the size of the data callback buffer size
|
} else {
|
||||||
|
// Use 20 ms for the default audio buffer size
|
||||||
|
sample_frames = (device->spec.freq / 50);
|
||||||
}
|
}
|
||||||
|
ctx.AAudioStreamBuilder_setBufferCapacityInFrames(builder, 2 * sample_frames); // AAudio requires that the buffer capacity is at least
|
||||||
|
ctx.AAudioStreamBuilder_setFramesPerDataCallback(builder, sample_frames); // twice the size of the data callback buffer size
|
||||||
|
|
||||||
const aaudio_direction_t direction = (recording ? AAUDIO_DIRECTION_INPUT : AAUDIO_DIRECTION_OUTPUT);
|
const aaudio_direction_t direction = (recording ? AAUDIO_DIRECTION_INPUT : AAUDIO_DIRECTION_OUTPUT);
|
||||||
ctx.AAudioStreamBuilder_setDirection(builder, direction);
|
ctx.AAudioStreamBuilder_setDirection(builder, direction);
|
||||||
|
|||||||
Reference in New Issue
Block a user