mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

CoreAudio: Updated a deprecated symbol. #519

Closed cubeleo closed 2 years ago

cubeleo commented 2 years ago

kAudioObjectPropertyElementMaster was deprecated in macOS 12.0 and iOS 15.0 and replaced with kAudioObjectPropertyElementMain.

mackron commented 2 years ago

Thanks for this! I think this would fix this issue from a while ago which I've been exceptionally slack on getting to: https://github.com/mackron/miniaudio/issues/462.

In that bug report, a user mentioned the use of the __is_identifier(), but I can't think of a reason why your change with MAC_OS_VERSION_12_0 and __IPHONE_15_0 wouldn't work. I'll merge this soon.

cubeleo commented 2 years ago

Great! Very glad to contribute. Caveats: I looked around for a while to find guidance from Apple on how treat deprecations like this where we want the code to be able to compile on older and newer systems, but I only found older versions of an Availability.h header in their open source stuff that defines these macros. Also, I only tested on macOS, not iOS, and only the latest macOS.

mackron commented 2 years ago

Yeah, that's no worries. I'm not an Apple user so I'm unsure on how to approach backwards compatibility myself to be honest. When I get to merging this, I'll test the build on my Macbook and then just let the community report any compatibility issues as they come up.

Just something I thought of while writing this - kAudioObjectPropertyElementMain and kAudioObjectPropertyElementMaster have the same value, right? As in, they're just an alias?

cubeleo commented 2 years ago

Actually, with a bit more testing and reading how JUCE did this, I think the check can be made better. We need to check for the allowed OS version. I pushed what I believe is the better check:

if (defined(MAC_OS_VERSION_12_0) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_12_0) || \

(defined(__IPHONE_15_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_15_0)
cubeleo commented 2 years ago

Just something I thought of while writing this - kAudioObjectPropertyElementMain and kAudioObjectPropertyElementMaster have the same value, right? As in, they're just an alias?

Yeah, they are given the same value, in the way Apple tends to deprecate things. They use a macro to suggest the replacement for the deprecated symbol and the OS versions that apply. Here is the actual entry for kAudioObjectPropertyElementMaster in the enum, showing the deprecation and replacement. Notice at the end of this line they've assigned the value kAudioObjectPropertyElementMain to kAudioObjectPropertyElementMaster: kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain

mackron commented 2 years ago

OK, that's good. I'll go ahead and merge this soon.

mackron commented 2 years ago

I was finally able to dig out my MacBook and give this a try. It seems to work no problems on my machine which I believe uses the old naming for this token. This has been merged into the dev branch and will be released soon.

cubeleo commented 2 years ago

Great news! Thanks for the merge.