Skip to content

Fix/macos - #5

Merged
maximilien-noal merged 5 commits into
mainfrom
fix/macos
Aug 24, 2026
Merged

Fix/macos#5
maximilien-noal merged 5 commits into
mainfrom
fix/macos

Conversation

@maximilien-noal

Copy link
Copy Markdown
Member

No description provided.

…and add unit tests

- Introduced CoreAudioBufferPolicy to manage audio buffer count based on sample rate and buffer frames.
- Updated SdlCoreAudioDriver to utilize CoreAudioBufferPolicy for calculating buffer count.
- Enhanced SdlWasapiDriver to maintain consistent coding style and error handling.
- Refactored SdlAudioDevice to support callback thread management.
- Added AssemblyInfo.cs to expose internal members for testing.
- Implemented unit tests for CoreAudioBufferPolicy to validate buffer count calculations.
@maximilien-noal maximilien-noal self-assigned this Aug 24, 2026
@maximilien-noal
maximilien-noal merged commit 4674bd2 into main Aug 24, 2026
4 checks passed
@maximilien-noal
maximilien-noal deleted the fix/macos branch August 24, 2026 19:17
/// Reference: SDL_coreaudio.m AssignDeviceToAudioQueue -> kAudioQueueProperty_CurrentDevice.
/// </summary>
[DllImport(AudioToolboxLib, EntryPoint = "AudioQueueSetProperty")]
internal static extern int AudioQueueSetProperty(
/// Used for default device identifiers and boolean-style device flags.
/// </summary>
[DllImport(CoreAudioLib, EntryPoint = "AudioObjectGetPropertyData")]
internal static extern int AudioObjectGetPropertyData(
/// Used for hog-mode process identifiers.
/// </summary>
[DllImport(CoreAudioLib, EntryPoint = "AudioObjectGetPropertyData")]
internal static extern int AudioObjectGetPropertyData(
/// Used for CFStringRef device UID values.
/// </summary>
[DllImport(CoreAudioLib, EntryPoint = "AudioObjectGetPropertyData")]
internal static extern int AudioObjectGetPropertyData(
/// Releases a CoreFoundation object retained by a property query.
/// </summary>
[DllImport(CoreFoundationLib, EntryPoint = "CFRelease")]
internal static extern void CFRelease(IntPtr cf);
}

_currentBuffer = IntPtr.Zero;
CoreAudioNativeMethods.AudioQueueEnqueueBuffer(_audioQueue, currentBuffer, 0, IntPtr.Zero);
Comment on lines +414 to +417
CoreAudioNativeMethods.CFRunLoopRunInMode(
_defaultRunLoopMode,
seconds,
(byte)(returnAfterSourceHandled ? 1 : 0));
// Set channel layout
if (!AssignDeviceToAudioQueue())
{
CoreAudioNativeMethods.AudioQueueDispose(_audioQueue, 1);
if (result != CoreAudioConstants.NoErr)
{
_threadError = $"CoreAudio: AudioQueueSetProperty (kAudioQueueProperty_ChannelLayout) failed with error {result}";
CoreAudioNativeMethods.AudioQueueDispose(_audioQueue, 1);
SilenceValue);
}

CoreAudioNativeMethods.AudioQueueEnqueueBuffer(inAudioQueue, currentBuffer, 0, IntPtr.Zero);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants