src/audio/coreaudio/SDL_coreaudio.m


Log

Author Commit Date CI Message
Ryan C. Gordon 86786ed5 2023-05-08T14:25:01 coreaudio: Flush/stop the AudioQueue before disposing of it. Otherwise, a CoreAudio thread lingers forever, and coreaudiod eats CPU until the SDL process terminates. Fixes #7689.
Sam Lantinga 0d763800 2023-03-09T15:10:00 Code style: changed "sizeof foo" to "sizeof(foo)" (thanks @sezero!) (cherry picked from commit c6443d86c92e962683a1efe5f123a144988875b5)
Sam Lantinga 0479df53 2023-01-09T09:48:21 Updated copyright for 2023
Pierre Wendling d0bbfdbf 2022-12-01T16:07:03 Clang-Tidy fixes (#6725) (cherry picked from commit 3c501b963dd8f0605a6ce7978882df39ba76f9cd)
Sam Lantinga b8d85c69 2022-11-30T12:51:59 Update for SDL3 coding style (#6717) I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594 (cherry picked from commit 5750bcb174300011b91d1de20edb288fcca70f8c)
Ryan C. Gordon b0dc6709 2022-11-07T14:26:48 coreaudio: Don't use deprecated kAudioObjectPropertyElementMaster symbol. Fixes #6449.
Ryan C. Gordon e7ab581d 2022-10-19T09:14:16 coreaudio: Dispose of AudioQueue before waiting on the thread. Otherwise the thread might block for a long time (more than 10 seconds!). It's not clear to me why this happens, or why its safe to do this with a resource that's still in use, but we have, until recently, always disposed of the AudioQueue first, so changing back is probably okay. Also changed the disposal to allow in-flight buffers to reach hardware; otherwise you lose the last little bit of audio that's already been queued but not played, which you can hear clearly in the loopwave test program. Fixes #6377.
daniel e41942e8 2022-10-05T13:36:25 fix compilation error SDL_coreaudio mixing declarations and code
Ryan C. Gordon e6640ef2 2022-09-30T14:53:07 coreaudio: Possibly fixed another shutdown race condition. Reference Issue #6159.
Jarod Hillman 40893821 2022-09-29T10:33:07 coreaudio: Add support for SDL_GetDefaultAudioInfo (#6277) Co-authored-by: Ethan Lee <flibitijibibo@gmail.com> Co-authored-by: Ozkan Sezer <sezeroz@gmail.com>
Ryan C. Gordon f6565c32 2022-09-28T09:27:45 coreaudio: Remove redundant variable.
Ryan C. Gordon 411582c7 2022-09-28T09:22:17 coreaudio: Don't crash on shutdown in a race condition. Fixed #6159.
Ethan Lee 90b86b13 2022-07-17T10:35:09 audio: Handle non-power-of-two spec.samples when unsupported Fixes #3685
Pierre Wendling 6c536afd 2022-06-27T15:43:17 Fix C89 declaration for macOS modules. Since Clang 14, `-Wdeclaration-after-statement` is enforced on every standard.
Ryan C. Gordon dc62fec5 2022-05-20T21:07:25 audio: Fix locking in backends that manage their own callback threads. Otherwise you might get a race where an app pauses the device, but the audio callback still manages to run after the pause is in place.
pionere a70bb259 2022-01-20T13:16:03 drop handle parameter of OpenDevice
pionere 47ddb04e 2022-01-20T12:31:02 cleanup/sync the main loop of *_OpenDevice functions to pick audio format II.
pionere 2eafe434 2022-01-20T12:18:59 cleanup/sync the main loop of *_OpenDevice functions to pick audio format
pionere 1043dd8c 2022-01-19T12:58:04 adjust handling of iscapture - drop iscapture parameter of OpenDevice - use SDL_bool for iscapture
pionere 60deadba 2022-01-17T17:22:30 re-use return value of SDL_SetError/WIN_SetErrorFromHRESULT/SDL_OutOfMemory
pionere 0dda8a7f 2022-01-17T11:21:01 cleanup init functions of audio - use SDL_bool if possible - assume NULL/SDL_FALSE filled impl - skip zfill of current_audio at the beginning of SDL_AudioInit (done before the init() calls)
Sam Lantinga 120c76c8 2022-01-03T09:40:00 Updated copyright for 2022
Per Nyblom 86ee383f 2021-05-25T09:59:45 Removed duplicate SDL_AtomicGet()
Ethan Lee 67e8522d 2021-02-27T17:37:25 Add SDL_GetAudioDeviceSpec. This API is supported by pipewire, pulseaudio, coreaudio, wasapi, and disk.
Sam Lantinga 9130f7c3 2021-01-02T10:25:38 Updated copyright for 2021
Sam Lantinga cb361896 2020-12-09T07:16:22 Fixed bug 5235 - All internal sources should include SDL_assert.h Ryan C. Gordon We should really stick this in SDL_internal.h or something so it's always available.
Sam Lantinga ff53521b 2020-06-04T12:26:57 Fixed Bluetooth audio output on Apple TV
Sam Lantinga a990a34a 2020-04-14T22:26:02 Cleanly switch between audio recording, playback, and both, on iOS
Sam Lantinga 2ae1c0f5 2020-04-14T09:52:27 Allow Bluetooth headphones for iOS playandrecord mode
Sam Lantinga f3e60967 2020-04-02T12:27:29 Fixed setting the "playandrecord" audio hint on Apple TV The Apple TV doesn't have record capability by default, so activating the audio session with AVAudioSessionCategoryPlayAndRecord fails.
Ryan C. Gordon 55b4f18e 2020-03-29T01:54:00 coreaudio: The default SDL audio device now tracks the system output default. So if you go into System Preferences on a MacBook and toggle between a pair of connected bluetooth headphones and built-in internal speakers, SDL will switch the device it is playing sound through, to match this setting, on the fly. Likewise if the default output device is a USB thing and is unplugged; as the default device changes at the system level, SDL will pick this up and carry on with the new default. This is different from our unplug detection for specific devices, as in those cases we want to send the app a disconnect notification, instead of migrating transparently as we now do for default devices. Note that this should also work for capture devices; if the device changes, SDL will start recording from the new default. Fixes Bugzilla #4851.
Sam Lantinga abdc5cbf 2020-03-26T19:30:17 Allow background music to play in the "play and record" case on iOS
Sam Lantinga e3b0713e 2020-02-24T12:07:18 Don't call setPreferredOutputNumberOfChannels on iOS, it breaks audio output
Sam Lantinga 2c9871a4 2020-02-24T10:25:57 Fixed surround sound support on Apple TV
Sam Lantinga f4e23553 2020-02-14T15:19:34 Fixed audio not coming out of the phone speakers while recording on iOS
Sam Lantinga 922b3dc3 2020-02-14T14:18:12 Fixed re-setting the audio session category when closing an audio device
Sam Lantinga a8780c6a 2020-01-16T20:49:25 Updated copyright date for 2020
Ryan C. Gordon 693755f0 2019-09-25T15:07:07 coreaudio: Apple doesn't support U16 data, so convert in that case.
Sam Lantinga 455944c8 2019-08-22T16:12:16 Fixed whitespace
Sam Lantinga b521df66 2019-08-22T16:09:42 [SDL][IOS] Audio fix - applies stream to sound data when resampling or reformatting is required.
Sam Lantinga abcfe804 2019-05-14T14:20:54 [SDL] iOS fix bug with audio interrupted by a phone call not restoring.
Ryan C. Gordon 2fbfe8b9 2019-03-25T12:59:30 coreaudio: Set audio callback thread priority. Fixes Bugzilla #4155.
Ryan C. Gordon 6a3356ab 2019-03-25T12:24:38 Backed out changeset cec31de4e126 This was meant to migrate CoreAudio onto the same SDL_RunAudio() path that most other audio drivers are on, but it introduced a bug because it doesn't deal with dropped audio buffers...and fixing that properly just introduces latency. I might revisit this later, perhaps by reworking SDL_RunAudio to allow for this sort of API better, or redesigning the whole subsystem or something, I don't know. I'm not super-thrilled that this has to exist outside of the usual codepaths, though. Fixes Bugzilla #4481.
Sam Lantinga 5e13087b 2019-01-04T22:01:14 Updated copyright for 2019
Sam Lantinga 8325df25 2018-05-24T07:30:24 Fixed bug 4169 - Crash due to audio session observer race condition Jona The following explains why this bug was happening: This crash was caused because the audio session was being set as active [session setActive:YES error:&err] when the audio device was actually being CLOSED. Certain cases the audio session being set to active would fail and the method would return right away. Because of the way the error was handled we never removed the SDLInterruptionListener thus leaking it. Later when an interruption was received the THIS_ object would contain a pointer to an already released device causing the crash. The fix: When only one device remained open and it was being closed we needed to set the audio session as NOT active and completely ignore the returned error to successfully release the SDLInterruptionListener. I think the user assumed that the open_playback_devices and open_capture_devices would equal 0 when all of them where closed but the truth is that at the end of the closing process that the open devices count is decremented.
Ryan C. Gordon dc8b55e5 2018-04-16T02:11:09 coreaudio: Use the standard SDL audio thread instead of spinning a new one. Fixes corner cases, like the audio callback not firing if the device is disconnected, etc.
Sam Lantinga e3cc5b2c 2018-01-03T10:03:25 Updated copyright for 2018
Ryan C. Gordon fa156741 2017-10-13T01:15:29 coreaudio: changed device close procedure to prevent long hangs in some cases. The audioqueue thread needs to keep running, and processing the CFRunLoop until the AudioQueue is disposed of, otherwise CoreAudio will hang waiting for final data to feed the device. At least, I think this is how it all works. It definitely fixes the bug here! Since AudioQueueDispose() calls AudioQueueStop() internally, there's no need for our thread to handle this, either, which is good because the AudioQueue would be disposed by this point. So now the AudioQueue is disposed first, and then our thread is joined, and everything works out okay. Just in case, we mark the device "paused" before setting everything in motion, so any further callbacks from CoreAudio will write silence and not fire the app's audio callback again. Fixes Bugzilla #3868.
Sam Lantinga fe6b8f1c 2017-09-22T11:25:52 Fixed Mac OS X build
Sam Lantinga 407e1693 2017-09-22T11:15:14 Fixed audio being silent on older iOS devices Tested on an iPod running iOS 6.1
Sam Lantinga c08a7a74 2017-09-15T17:27:32 Added a hint SDL_HINT_AUDIO_CATEGORY to control the audio category, determining whether the phone mute switch affects the audio
Ryan C. Gordon 6844d92c 2017-05-24T13:28:13 coreaudio: we don't need to track number of allocated audio buffers anymore. CoreAudio takes care of iterating through the buffers and freeing them now, so we don't have to manage this ourselves.
Ryan C. Gordon fc4402e5 2017-05-24T13:25:31 coreaudio: Better handling of audio buffer queue management. We don't fill buffers just to throw them away during shutdown now, we let the AudioQueue free its own buffers during disposal (which fixes possible warnings getting printed to stderr by CoreAudio), and we stop the queue after running any queued audio during shutdown, which prevents dropping the end of the audio playback if you opened the device with an enormous sample buffer. Fixes Bugzilla #3555.
Ryan C. Gordon 3fd35f6b 2017-05-24T01:28:03 coreaudio: looks like we need more like a 10ms buffer minimum, not 50ms.
Ryan C. Gordon 793c788b 2017-05-24T00:12:22 coreaudio: dynamically allocate AudioQueueBuffers. We need more than two buffers to flip between if they are small, or CoreAudio won't make any sound; apparently it needs X milliseconds of audio queued when it needs to play more or it drops any queued buffers. We are currently guessing 50 milliseconds as a minimum, but there's probably a more proper way to get the minimum time period from the system. Fixes Bugzilla #3656.
Ryan C. Gordon c878b59b 2017-05-10T16:18:43 audio: fixed more "spec" references that should have been "callbackspec". This should catch all the ones for audio targets that have provided their own audio threads.
Alex Szpakowski 75fb07a6 2017-05-03T18:05:29 iOS: Only mark interrupted audio devices as non-interrupted if AudioQueueStart is successful.
Sam Lantinga 71a4e8ed 2017-02-23T12:10:02 Stop CoreAudio from doing expensive audio rate conversion
Sam Lantinga 45b774e3 2017-01-01T18:33:28 Updated copyright for 2017
Philipp Wiesemann 8e88f081 2016-09-21T23:06:49 Mac: Fixed whitespace around function return type.
Alex Szpakowski f0fca288 2016-09-18T19:22:09 Handle audio interruptions on iOS/tvOS. Fixes bugs 2569 and 2960.
Alex Szpakowski 4209a1fd 2016-09-15T19:59:57 CoreAudio iOS/tvOS: Use AVFoundation instead of AudioSession. Fixes audio on tvOS. Note that linking with AVFoundation is now required if you don't disable SDL_audio compilation on iOS and tvOS.