pokemon-speedrunning / gambatte-speedrun

Fork of https://github.com/sinamas/gambatte with Pokemon speedrunning-related changes.
GNU General Public License v2.0
94 stars 27 forks source link

[macOS] Replace deprecated CoreServices audio API with AudioToolbox #111

Open FtZPetruska opened 1 year ago

FtZPetruska commented 1 year ago

The CoreServices Audio API used to find/open/close audio components has been deprecated since macOS 10.8 (around 2012).

While the framework has not been removed yet, I found that when running on macOS 13 on my M1 mac, FindNextComponent would systematically fail to find any component.

The solution I found was to replace CoreServices with AudioToolbox. It provides a very similar API and is available since macOS 10.0 so it would not change the minimum supported version. Additionally, AudioToolbox already provides AudioUnit, so linking the latter is no longer needed.

The main difference is how errors are handled. Errors are returned in the OSStatus type, and should be checked against the noErr constant.

Additionally, the files/class were renamed from coreaudio to audiotoolbox, this is mainly for consistency so the name in the settings and in source actually corresponds to what is being used.

entrpntr commented 1 year ago

(I'm not very active with development anymore, but as the main contributor who's worked on Mac support, this is probably my area.)

This all looks fine on the surface. The OS-specific code from Gambatte is quite old (it in fact predates macOS 10.8), and if it's starting to cause issues on newer Macs, it's a good time to change it. The r717 release builds only worked on 10.13+ anyway. (FWIW, I do not get this issue on my M1 machine running macOS 13.1.)

Unrelated, but since Mac issues are somewhat rare I'll note it here: the current release builds take an excessive amount of user effort to get around security restrictions in newer macOS versions.

I'll try to take a look at this before too long and make sure there aren't issues on the Macs I have to test with.