Skip to content

Commit c6e9d6c

Browse files
ManuBlackslouken
authored andcommitted
AAudio: Implemented sample frames hint
1 parent aaa5d70 commit c6e9d6c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/audio/aaudio/SDL_aaudio.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ static bool BuildAAudioStream(SDL_AudioDevice *device)
308308
ctx.AAudioStreamBuilder_setFormat(builder, format);
309309
ctx.AAudioStreamBuilder_setSampleRate(builder, device->spec.freq);
310310
ctx.AAudioStreamBuilder_setChannelCount(builder, device->spec.channels);
311+
312+
// If no specific buffer size has been requested, the device will pick the optimal
313+
if(SDL_GetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES)) {
314+
ctx.AAudioStreamBuilder_setBufferCapacityInFrames(builder, 2 * device->sample_frames); // AAudio requires that the buffer capacity is at least
315+
ctx.AAudioStreamBuilder_setFramesPerDataCallback(builder, device->sample_frames); // twice the size of the data callback buffer size
316+
}
311317

312318
const aaudio_direction_t direction = (recording ? AAUDIO_DIRECTION_INPUT : AAUDIO_DIRECTION_OUTPUT);
313319
ctx.AAudioStreamBuilder_setDirection(builder, direction);

src/audio/aaudio/SDL_aaudiofuncs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSamplesPerFrame, (AAudioStreamBuild
3131
SDL_PROC(void, AAudioStreamBuilder_setFormat, (AAudioStreamBuilder * builder, aaudio_format_t format))
3232
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSharingMode, (AAudioStreamBuilder * builder, aaudio_sharing_mode_t sharingMode))
3333
SDL_PROC(void, AAudioStreamBuilder_setDirection, (AAudioStreamBuilder * builder, aaudio_direction_t direction))
34-
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setBufferCapacityInFrames, (AAudioStreamBuilder * builder, int32_t numFrames))
34+
SDL_PROC(void, AAudioStreamBuilder_setBufferCapacityInFrames, (AAudioStreamBuilder * builder, int32_t numFrames))
3535
SDL_PROC(void, AAudioStreamBuilder_setPerformanceMode, (AAudioStreamBuilder * builder, aaudio_performance_mode_t mode))
3636
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setUsage, (AAudioStreamBuilder * builder, aaudio_usage_t usage)) // API 28
3737
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setContentType, (AAudioStreamBuilder * builder, aaudio_content_type_t contentType)) // API 28

0 commit comments

Comments
 (0)