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

Deprecation warnings when building on macOS #462

Closed emoon closed 2 years ago

emoon commented 2 years ago

Hi,

First thanks for a great lib! When building for macOS I get the following warnings: I have Xcode 13.3 installed and my OS version is 12.3.1

./external/miniaudio.h:18038:19: warning: variable 'totalClientFramesProcessed' set but not used [-Wunused-but-set-variable]
        ma_uint64 totalClientFramesProcessed = 0;
                  ^
./external/miniaudio.h:30725:36: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddressDevices.mElement  = kAudioObjectPropertyElementMaster;
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                   kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:30759:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:30801:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:30830:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:30885:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:30923:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:31013:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:31135:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:31173:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement  = kAudioObjectPropertyElementMaster;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:31202:41: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddressDefaultDevice.mElement = kAudioObjectPropertyElementMaster;
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                        kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:32275:37: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
            propAddress.mElement  = kAudioObjectPropertyElementMaster;
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:32305:37: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
            propAddress.mElement  = kAudioObjectPropertyElementMaster;
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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
    ^
./external/miniaudio.h:32756:37: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
            propAddress.mElement  = kAudioObjectPropertyElementMaster;
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    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

Thanks for the report. Do you know what I should use to check for this at compile time so it works on both older and newer versions of the compiler?

emoon commented 2 years ago

Hey,

So I'm not really sure but I found this post https://developer.apple.com/forums/thread/109760?answerId=696147022#696147022 which states

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 120000
  // ... compiles only when using the macOS12.0 SDK (or later) that comes with Xcode 13.1
#endif

So maybe that can be used to detect which version of the SDK that is being compiled against.

Edit: I asked around and got a reply about this

The downside with such code, generally, is you have to write both compile time and runtime check nested I think; 
thus nonzero runtime overhead (since building against 11 SDK implies deployment target <= 11, so you cannot assume 12+)

So tbh, I'm not sure what the best way to solve this is (unless requiring users to use an older SDK, but I would assume more people would run into this later on)

meshula commented 2 years ago

This workaround with __is_identifier, as qemu has done, looks safe to me.

https://lists.gnu.org/archive/html/qemu-devel/2022-01/msg02375.html

fwiw, here's where the damage was done: https://www.mail-archive.com/qemu-devel@nongnu.org/msg860665.html

The pattern I'd suggest is test for the Main identifier, if not found test for the Master identifier, if not compile time assert.

and docs on __is_identifier: https://github.com/intel/llvm/blob/sycl/clang/docs/LanguageExtensions.rst#__is_identifier

This avoids needing to check OS versions. Don't know if this code has to compile under gcc, and if there's a similar affordance in gcc.

mackron commented 2 years ago

This should be fixed thanks to this PR: https://github.com/mackron/miniaudio/pull/519