Skip to content

Commit fe98751

Browse files
committed
reduce latency
1 parent f23644d commit fe98751

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

audio/drivers_microphone/coreaudio_mic_macos.m

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -652,21 +652,41 @@ static void coreaudio_macos_microphone_device_list_free(const void *data, struct
652652
}
653653

654654
RARCH_LOG("[CoreAudio macOS Mic]: Initializing AudioUnit %p\n", mic->audio_unit);
655-
status = AudioUnitInitialize(mic->audio_unit);
656-
if (status != noErr)
657-
{
658-
RARCH_ERR("[CoreAudio macOS Mic]: Failed to initialize AudioUnit: %d\n", (int)status);
659-
AudioComponentInstanceDispose(mic->audio_unit);
660-
if (mic->device_name) free(mic->device_name);
661-
662-
free(mic);
663-
return NULL;
664-
}
655+
656+
/* Set a smaller buffer frame size for lower latency */
657+
UInt32 buffer_frame_size = 256; /* Small buffer for lower latency */
658+
status = AudioUnitSetProperty(mic->audio_unit,
659+
kAudioDevicePropertyBufferFrameSize,
660+
kAudioUnitScope_Global,
661+
0,
662+
&buffer_frame_size,
663+
sizeof(buffer_frame_size));
664+
if (status != noErr)
665+
{
666+
RARCH_WARN("[CoreAudio macOS Mic]: Failed to set buffer frame size to %u: %d\n",
667+
(unsigned)buffer_frame_size, (int)status);
668+
/* Non-fatal, continue with default buffer size */
669+
}
670+
else
671+
{
672+
RARCH_LOG("[CoreAudio macOS Mic]: Set buffer frame size to %u frames for lower latency\n",
673+
(unsigned)buffer_frame_size);
674+
}
675+
676+
status = AudioUnitInitialize(mic->audio_unit);
677+
if (status != noErr)
678+
{
679+
RARCH_ERR("[CoreAudio macOS Mic]: Failed to initialize AudioUnit: %d\n", (int)status);
680+
AudioComponentInstanceDispose(mic->audio_unit);
681+
if (mic->device_name) free(mic->device_name);
682+
free(mic);
683+
return NULL;
684+
}
665685
atomic_store(&mic->is_initialized, true);
666686
RARCH_LOG("[CoreAudio macOS Mic]: AudioUnit successfully initialized.\n");
667687

668-
/* Initialize FIFO buffer - 150ms buffer size like iOS version */
669-
size_t fifo_size = mic->format.mSampleRate * mic->format.mBytesPerFrame * 0.15f;
688+
/* Initialize FIFO buffer - 50ms buffer size */
689+
size_t fifo_size = mic->format.mSampleRate * mic->format.mBytesPerFrame * 0.05f;
670690
RARCH_LOG("[CoreAudio macOS Mic]: Creating FIFO buffer of size %u bytes (%.1f ms at %.0f Hz)\n",
671691
(unsigned)fifo_size,
672692
(float)fifo_size * 1000.0f / (mic->format.mSampleRate * mic->format.mBytesPerFrame),

0 commit comments

Comments
 (0)