From 4f9ca4e87b80446c943e504e6aa842654712f659 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Sun, 1 Jun 2025 01:29:12 +0800
Subject: [PATCH 3/6] CoreAudio: fix assignments

---
 .../AudioOutputStreamCoreAudio.cpp            | 24 ++++++++---------
 .../DeviceContextCoreAudio.cpp                | 27 +++++++------------
 2 files changed, 21 insertions(+), 30 deletions(-)

diff --git src/device/backend-coreaudio/AudioOutputStreamCoreAudio.cpp src/device/backend-coreaudio/AudioOutputStreamCoreAudio.cpp
index 74ec0f00..81b0c7b8 100644
--- src/device/backend-coreaudio/AudioOutputStreamCoreAudio.cpp
+++ src/device/backend-coreaudio/AudioOutputStreamCoreAudio.cpp
@@ -66,19 +66,17 @@ AudioOutputStreamCoreAudio::AudioOutputStreamCoreAudio(Session *session, Device
 	if (err)
 		session->e(format("CoreAudio: Error setting callback: %d", (int)err));
 
-	AudioStreamBasicDescription asbd = {
-		.mFormatID = kAudioFormatLinearPCM,
-		.mFormatFlags = 0
-			| kAudioFormatFlagIsFloat
-			| kAudioFormatFlagIsPacked,
-		//	| kAudioFormatFlagIsNonInterleaved,
-		.mSampleRate = (double)dev_sample_rate,
-		.mBitsPerChannel = 32,
-		.mChannelsPerFrame = 2,
-		.mFramesPerPacket = 1,
-		.mBytesPerFrame = 8,
-		.mBytesPerPacket = 8,
-	};
+		AudioStreamBasicDescription asbd;
+		asbd.mSampleRate       = static_cast<Float64>(dev_sample_rate);
+		asbd.mFormatID         = kAudioFormatLinearPCM;
+		asbd.mFormatFlags      = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
+		// asbd.mFormatFlags   |= kAudioFormatFlagIsNonInterleaved; // Uncomment if needed
+		asbd.mBytesPerPacket   = 8;    // For 32-bit float stereo: 4 bytes * 2 channels
+		asbd.mFramesPerPacket  = 1;
+		asbd.mBytesPerFrame    = 8;    // For 32-bit float stereo: 4 bytes * 2 channels
+		asbd.mChannelsPerFrame = 2;
+		asbd.mBitsPerChannel   = 32;
+		asbd.mReserved         = 0;
 
 	err = AudioUnitSetProperty(tone_unit, kAudioUnitProperty_StreamFormat,
 	kAudioUnitScope_Input, 0, &asbd, sizeof(asbd));
diff --git src/device/backend-coreaudio/DeviceContextCoreAudio.cpp src/device/backend-coreaudio/DeviceContextCoreAudio.cpp
index c23f5c71..84521513 100644
--- src/device/backend-coreaudio/DeviceContextCoreAudio.cpp
+++ src/device/backend-coreaudio/DeviceContextCoreAudio.cpp
@@ -142,14 +142,11 @@ void DeviceContextCoreAudio::update_device(DeviceManager* device_manager, bool s
 	AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress0, 0, nullptr, &propsize, &default_devid);
 
 
-
 	// all
-	theAddress0 = {
-			kAudioHardwarePropertyDevices,
-			//kAudioObjectPropertyScopeGlobal,
-			kAudioDevicePropertyScopeOutput,
-			kAudioObjectPropertyElementMain
-	};
+	theAddress0.mSelector = kAudioHardwarePropertyDevices;
+	// theAddress0.mScope = kAudioObjectPropertyScopeGlobal;
+	theAddress0.mScope = kAudioDevicePropertyScopeOutput;
+	theAddress0.mElement = kAudioObjectPropertyElementMain;
 
 	AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &theAddress0, 0, nullptr, &propsize);
 	devids.resize(propsize / sizeof(AudioDeviceID));
@@ -162,20 +159,16 @@ void DeviceContextCoreAudio::update_device(DeviceManager* device_manager, bool s
 
 // input
 	// default
-	theAddress0 = {
-		kAudioHardwarePropertyDefaultInputDevice,
-		kAudioDevicePropertyScopeInput,
-		kAudioObjectPropertyElementMain
-	};
+	theAddress0.mSelector = kAudioHardwarePropertyDefaultInputDevice;
+	theAddress0.mScope = kAudioDevicePropertyScopeInput;
+	theAddress0.mElement = kAudioObjectPropertyElementMain;
 	propsize = sizeof(AudioDeviceID);
 	AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress0, 0, nullptr, &propsize, &default_devid);
 
 	// all
-	theAddress0 = {
-		kAudioHardwarePropertyDevices,
-		kAudioDevicePropertyScopeInput,
-		kAudioObjectPropertyElementMain
-	};
+	theAddress0.mSelector = kAudioHardwarePropertyDevices;
+	theAddress0.mScope = kAudioDevicePropertyScopeInput;
+	theAddress0.mElement = kAudioObjectPropertyElementMain;
 	AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &theAddress0, 0, nullptr, &propsize);
 	devids.resize(propsize / sizeof(AudioDeviceID));
 	AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress0, 0, nullptr, &propsize, &devids[0]);
-- 
2.48.0

