thestk / rtaudio

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.
Other
1.49k stars 318 forks source link

kAudioObjectPropertyElementMain not defined for MacOS < 12.0 #351

Closed nukelash closed 2 years ago

nukelash commented 2 years ago

This commit (https://github.com/thestk/rtaudio/commit/e9b1d0262a5e75e09c510eb9c5825daf86884d29) changed instances of kAudioObjectPropertyElementMaster to kAudioObjectPropertyElementMain in RtAudio.cpp, I'm assuming because Master was deprecated in MacOS 12.0

However macOS < 12.0 still requires the Master naming convention, so RtAudio.cpp doesn't build in earlier (still maintained) macOS versions now. Was this intentional and if not could this be changed? Thanks

https://developer.apple.com/documentation/coreaudio/kaudioobjectpropertyelementmaster https://developer.apple.com/documentation/coreaudio/kaudioobjectpropertyelementmain

garyscavone commented 2 years ago

I couldn't test on an os-x version < 10.12 but I think I fixed this problem for both >= and < 10.12.

ndonald2 commented 2 years ago

Seconding that this is an issue on macOS 10.15. I think the problem is that the new symbol kAudioObjectPropertyElementMain is only defined in 12.0+

aking all in .
  CXX      librtaudio_la-RtAudio.lo
RtAudio.cpp:596:43: error: use of undeclared identifier 'kAudioObjectPropertyElementMain'; did you mean
      'kAudioObjectPropertyElementName'?
                                          KAUDIOOBJECTPROPERTYELEMENT };
                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                                          kAudioObjectPropertyElementName
RtAudio.cpp:583:39: note: expanded from macro 'KAUDIOOBJECTPROPERTYELEMENT'
  #define KAUDIOOBJECTPROPERTYELEMENT kAudioObjectPropertyElementMain

If I roll back before that commit (e.g. to release tag 5.2.0 everything builds just fine on macOS 10.15 with no deprecation warnings. Perhaps the macro guard should only be using kAudioObjectPropertyElementMain for macOS 12.0 and above?

garyscavone commented 2 years ago

This is hard to test, as I'm not having problems on my system. Perhaps you can modify the code around line 580 in RtAudio.cpp as follows to see if it works?

if defined( MAC_OS_X_VERSION_10_12 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 )

define KAUDIOOBJECTPROPERTYELEMENT kAudioObjectPropertyElementMain

else

define KAUDIOOBJECTPROPERTYELEMENT kAudioObjectPropertyElementMaster // deprecated with 10.12

endif

ndonald2 commented 2 years ago

No, unfortunately that doesn't work either for me, on macOS 10.15. It still wants to use kAudioObjectPropertyElementMain which isn't defined in the system libs.

I'm a little confused about the logic here. From the available documentation it seems kAudioObjectPropertyElementMain only exists in macOS 12.0 and above, not 10.12 and above. Wouldn't it be something along these lines? (this at least compiles correctly for me on 10.15 but I can't easily test on 12.0 right now)

#if defined( MAC_OS_VERSION_12_0 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_0 )
#define KAUDIOOBJECTPROPERTYELEMENT kAudioObjectPropertyElementMain
#else
#define KAUDIOOBJECTPROPERTYELEMENT kAudioObjectPropertyElementMaster // deprecated with 10.12
#endif
garyscavone commented 2 years ago

I just tried compiling on my 11.6.5 system and both definitions (either Main or Master) seem to work. However, a few months ago, this particular system did not like kAudioObjectPropertyElementMain (I may have upgraded Xcode since then). I definitely have not upgraded to macOS 12.0 on either of my systems and kAudioObjectPropertyElementMain seems to work on both. Maybe there was a fix made in the CoreAudio library to fix this issue (but you might still have a problem if you are running an older version of the library)?

ndonald2 commented 2 years ago

Hmm, I'm not sure how to explain it then. I am unable to compile latest master branch of RtAudio on both 10.15 (Catalina) and 10.14 (Mojave) with the most recent compatible Xcode on each system installed.

Maybe there was a fix made in the CoreAudio library to fix this issue (but you might still have a problem if you are running an older version of the library)?

Perhaps the most recent versions of Xcode that run on macOS 11.0+ include the macOS 12.0 SDK for development so this symbol is defined in the linked SDK? But I'm not sure if it's possible to target macOS 12+ when building from <= 10.15 as the development OS.


On a personal note, hi! I was a McGill master's student class of 2011, you actually were my thesis reviewer :) nice to see you again virtually and hope you're well. As you can see I still use and love STK/RtAudio!

garyscavone commented 2 years ago

If I understand correctly, you can get RtAudio to compile if you use the statements you suggested above that refer to MAC_OS_VERSION_12_0? If so, I'll just use that and hopefully it will work for others.