1

I've got a MacOS/X program that uses CoreAudio to do sound output. It works fine, but whenever I compile it, the compiler emits the "XXX is deprecated" warnings shown below.

My question is, how should I update/replace these function calls so that I get the same functionality but done in a non-deprecated way? I can't seem to find any documentation on what Apple wants me to do in this case.

[  0%] Building CXX object CMakeFiles/myprogram.dir/MyProgram.cpp.o
/MyProgram.cpp:295:25: warning: 'AudioDeviceSetProperty' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
   const OSStatus err = AudioDeviceSetProperty(cadi()->GetAudioDeviceID(), 0, 0, FALSE, kAudioDevicePropertyHogMode, sizeof(myPID), &myPID);
                        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareDeprecated.h:855:1: note: 'AudioDeviceSetProperty' has been explicitly marked deprecated here
AudioDeviceSetProperty( AudioDeviceID                       inDevice,
^
/MyProgram.cpp:352:31: warning: 'AudioDeviceAddPropertyListener' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
         const OSStatus err = AudioDeviceAddPropertyListener(deviceID, 0, false, kAudioDeviceProcessorOverload, PlaybackDevicePropertyChanged, NULL);
                              ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareDeprecated.h:884:1: note: 'AudioDeviceAddPropertyListener' has been explicitly marked deprecated here
AudioDeviceAddPropertyListener( AudioDeviceID                   inDevice,
^
/MyProgram.cpp:358:31: warning: 'AudioDeviceRemovePropertyListener' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
         const OSStatus err = AudioDeviceRemovePropertyListener(deviceID, 0, false, kAudioDeviceProcessorOverload, PlaybackDevicePropertyChanged);
                              ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareDeprecated.h:911:1: note: 'AudioDeviceRemovePropertyListener' has been explicitly marked deprecated here
AudioDeviceRemovePropertyListener(  AudioDeviceID                   inDevice,
^
/MyProgram.cpp:437:24: warning: 'AudioHardwareGetPropertyInfo' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
      OSStatus osErr = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyPlugInForBundleID, &outSize, &outWritable);
                       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareDeprecated.h:321:1: note: 'AudioHardwareGetPropertyInfo' has been explicitly marked deprecated here
AudioHardwareGetPropertyInfo(   AudioHardwarePropertyID inPropertyID,
^
/MyProgram.cpp:450:18: warning: 'AudioHardwareGetProperty' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
         osErr = AudioHardwareGetProperty(kAudioHardwarePropertyPlugInForBundleID, &outSize, &pluginAVT);
                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareDeprecated.h:342:1: note: 'AudioHardwareGetProperty' has been explicitly marked deprecated here
AudioHardwareGetProperty(   AudioHardwarePropertyID inPropertyID,
^
/MyProgram.cpp:582:12: warning: 'AudioHardwareGetPropertyInfo' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
   osErr = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyPlugInForBundleID, &outSize, &outWritable);
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareDeprecated.h:321:1: note: 'AudioHardwareGetPropertyInfo' has been explicitly marked deprecated here
AudioHardwareGetPropertyInfo(   AudioHardwarePropertyID inPropertyID,
^
/MyProgram.cpp:595:12: warning: 'AudioHardwareGetProperty' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
   osErr = AudioHardwareGetProperty(kAudioHardwarePropertyPlugInForBundleID, &outSize, &pluginAVT);
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareDeprecated.h:342:1: note: 'AudioHardwareGetProperty' has been explicitly marked deprecated here
AudioHardwareGetProperty(   AudioHardwarePropertyID inPropertyID,
^
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
  • I guess you will have to research about each of these functions case by vase. Such as in https://stackoverflow.com/questions/25070819/setting-mac-os-x-volume-programmatically-after-10-6-snow-leopard – Eugene Sh. Apr 20 '23 at 14:43
  • @EugeneSh. the replacement function recommended in the answer to that question (`AudioHardwareServiceSetPropertyData()`) is also deprecated :/ – Jeremy Friesner Apr 20 '23 at 14:52
  • 1
    You can use `AudioObjectSetPropertyData` for the `AudioDeviceSetProperty` calls. Start with those then see what you have left. – Rhythmic Fistman Apr 20 '23 at 15:27

1 Answers1

2

If you go to the definitions of the functions in AudioHardwareDeprecated.h you will find alternatives mentioned in the documentation.

Take AudioDeviceSetProperty() For example:

Also note that the same functionality is provided by the function AudioObjectSetPropertyData().

This result in the following replacements:

AudioDeviceSetProperty()
Replace with AudioObjectSetPropertyData()

AudioDeviceAddPropertyListener()
Replace with AudioObjectAddPropertyListener() in conjunction with AudioObjectPropertyListenerProc

AudioDeviceRemovePropertyListener()
Replace with AudioObjectRemovePropertyListener() in conjunction with AudioObjectPropertyListenerProc()

AudioHardwareGetPropertyInfo()
Replace with AudioObjectHasProperty(), AudioObjectIsPropertySettable() and AudioObjectGetPropertyDataSize()

AudioHardwareGetProperty()
Replace with AudioObjectGetPropertyData()

Ruurd Adema
  • 920
  • 7
  • 17