src/audio/SDL_audio.c


Log

Author Commit Date CI Message
Ryan C. Gordon 8ff738f2 2022-07-26T12:40:47 audio: Report SDL_AUDIODEVICEREMOVED for unopened devices. Unopened devices, if removed, now send SDL_AUDIODEVICEREMOVED events with a `which` field set to zero. Apps can use this to decide if they need to refresh a list of devices being shown in an options menu, etc. It's safe to call SDL_CloseAudioDevice(0), so even if they try to clean up this bogus id, it should be safe. Fixes #5199.
Ethan Lee f3008e4a 2022-07-20T19:08:31 audio: 3- and 5-channel formats are now supported
Sam Lantinga b299cb3d 2022-07-17T08:31:16 Added a utility function to calculate the next power of 2 for a value
Ethan Lee 90b86b13 2022-07-17T10:35:09 audio: Handle non-power-of-two spec.samples when unsupported Fixes #3685
Ethan Lee 2f0816ad 2022-07-11T13:08:30 Add SDL_GetDefaultAudioInfo. This API is supported on pipewire, pulseaudio, wasapi, and directsound. Co-authored-by: Frank Praznik <frank.praznik@gmail.com>
Francisco Javier Trujillo Mata e4a80875 2022-06-24T16:43:20 Initial Audio driver
Sam Lantinga abe38bca 2022-06-18T13:08:58 Support SDL_AUDIODRIVER set to "dsound", which was used by SDL 1.2 Fixes https://github.com/libsdl-org/SDL/issues/5818
Sam Lantinga adc68758 2022-06-17T10:22:28 Added SDL_copyp to avoid size mismatch when copying values (thanks @1bsyl!) Closes https://github.com/libsdl-org/SDL/pull/5811
Ryan C. Gordon de019568 2022-04-09T23:43:57 audio: Prebake the resampler's kaiser table instead of doing it at runtime.
Ryan C. Gordon c1336b21 2022-04-17T12:43:32 hints: Make SDL_VIDEODRIVER and SDL_AUDIODRIVER formal hints. They were just environment variables before. Fixes #5528.
pionere a70bb259 2022-01-20T13:16:03 drop handle parameter of OpenDevice
pionere 3939ef72 2022-01-19T17:23:53 cleanup SDL_GetAudioDeviceSpec - drop unnecessary hascapture check - call SDL_InvalidParamError and return -1 in case the index is out of range - do not zfill SDL_AudioSpec - adjust documentation to reflect the behavior
pionere 113109f8 2022-01-19T17:18:47 cleanup SDL_GetAudioDeviceName - drop unnecessary hascapture check - call SDL_InvalidParamError in case the index is out of range
pionere c9e8d157 2022-01-19T12:59:35 re-use return value of SDL_SetError/WIN_SetErrorFromHRESULT/SDL_OutOfMemory II.
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 4a17612b 2022-01-17T12:04:32 get rid of BeginLoopIteration
pionere 0770c582 2022-01-17T11:48:26 get rid of PrepareToClose
Ryan C. Gordon e0236c02 2022-01-23T01:28:36 audio: Removed an unnecessary commented-out line.
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)
pionere 6fcfcc3d 2022-01-17T11:00:03 get rid of SkipMixerLock
Sam Lantinga 120c76c8 2022-01-03T09:40:00 Updated copyright for 2022
Sylvain 38cfe25b 2021-11-22T16:39:56 Remove 'malloc' from comment
Sylvain d31251b0 2021-11-21T22:30:48 use SDL's functions version inplace of libc version
Sylvain b6e8651a 2021-11-20T15:31:21 Audio 6.1 should be allowed now (see #4974)
Cameron Gutman 704edf63 2021-11-12T17:07:22 audio: Fix crash calling SDL_OpenAudio() after SDL_AudioInit() fails The SDL_WasInit() checks don't work when using SDL_AudioInit() directly, which is exactly what audio_initOpenCloseQuitAudio() in testautomation does.
Lee Salzman 7d90df0e 2021-08-29T15:24:23 Restore previous behavior of empty SDL_AUDIODRIVER trying all drivers. The recent change to make SDL_AUDIODRIVER support comma-separated lists broke the previous behavior where an SDL_AUDIODRIVER that was empty behaved the same as if it was not set at all. This old behavior was necessary to paper over differences in platforms where SDL_setenv may or may not actually delete the env var if an empty string is specified. This patch just adds a simple check to ensure SDL_AUDIODRIVER is not empty before using it, restoring the old interpretation of the empty var.
David Gow 3261f7f6 2021-08-26T16:15:30 audio: Support "pulse" as an alias for "pulseaudio" Originally, SDL 1.2 used "pulse" as the name for its PulseAudio driver. While it now supports "pulseaudio" as well for compatibility with SDL 2.0 [1], there are still scripts and distro packages which set SDL_AUDIODRIVER=pulse [2]. While it's possible to remove this in most circumstances or replace it with "pulseaudio" or a comma-separated list, this may still conflict if the environment variable is set globally and old binary builds of SDL 1.2 (e.g. packaged with older games) are being used. To fix this on SDL 2.0, add a hardcoded check for "pulse" as an audio driver name, and replace it with "pulseaudio". This mimics what SDL 1.2 does (but in reverse). Note that setting driver_attempt{,_len} is safe here as they're reset correctly based on driver_attempt_end on the next loop. [1] https://github.com/libsdl-org/SDL-1.2/commit/d9514097846381cd30fe08df65dbdd48de92a058 [2] https://bugzilla.opensuse.org/show_bug.cgi?id=1189778
Sam Lantinga a0af7ce7 2021-08-10T15:05:49 OSS is no longer the preferred audio backend on modern UNIX systems Fixes https://github.com/libsdl-org/SDL/issues/4207
Sebastian Krzyszkowiak 25f9ed87 2021-08-10T13:10:36 audio: Fix false positives in driver name comparison Without this change, driver names don't get matched correctly; for example "a" can get matched with "alsa" since it only checks whether the string matches up to the length of the requested driver name.
Luis Cáceres 45de0a1d 2021-04-02T06:28:10 Support comma-separated lists in SDL_AUDIODRIVER
Sylvain f1fab24e 2021-04-15T21:00:00 AAudio: add bootstrap in SDL_audio.c
Ethan Lee 9d294f1f 2021-03-27T00:53:10 audio: Allow AudioStreamGet to return 0 in RunAudio. While we should normally expect _something_ from the stream based on the AudioStreamAvailable check, it's possible for a device change to flush the stream at an inconvenient time, causing this function to return 0. Thing is, this is harmless. Either data will be NULL and the result won't matter anyway, or the data buffer will be zeroed out and the output will just be silence for the brief moment that the device change is occurring. Both scenarios work themselves out, and testing on Windows shows that this behavior is safe.
Ivan Epifanov 2d64e37e 2020-11-02T18:09:43 Initial rebase of xerpi's port
Ethan Lee 67e8522d 2021-02-27T17:37:25 Add SDL_GetAudioDeviceSpec. This API is supported by pipewire, pulseaudio, coreaudio, wasapi, and disk.
Ozkan Sezer ac8a3fda 2021-03-03T20:33:20 fix prepare_audiospec() possibly missing a bad SDL_AUDIO_CHANNELS env.
Frank Praznik adc0a931 2021-02-24T14:08:08 audio: Move Pipewire bootstrap after Jack Move the Pipewire audio driver below others in the list so it won't be mistakenly initialized when it's not the system mixer.
Frank Praznik 2f0b99a7 2021-02-13T11:56:05 audio: Add Pipewire playback/capture sink
Sam Lantinga 9130f7c3 2021-01-02T10:25:38 Updated copyright for 2021
Ozkan Sezer d2723875 2020-10-14T23:01:06 os2: integrate the port into main tree.
Manuel V?gele 554037a6 2020-09-26T09:30:08 audio: fix popping sounds caused by signed/unsigned conversion When converting audio from signed to unsigned values of vice-versa the silence value chosen by SDL was the value of the device, not of the stream that the data was being put into. After conversion this would lead to a very high or low value, making the speaker jump to a extreme positon, leading to an audible noise whenever creating, destroying or playing scilence on a device that reqired such conversion.
Sam Lantinga 4bb95e84 2020-02-11T16:14:02 Implemented OpenSL-ES audio recording on Android
Ryan C. Gordon f30ef6ed 2020-01-21T17:40:16 audio: Fixed a '//' style comment.
Ryan C. Gordon dbe5c14b 2020-01-21T15:49:37 audio: Calculate a legitimate SDL_AudioSpec::silence in SDL_LoadWAV_RW().
Sam Lantinga a8780c6a 2020-01-16T20:49:25 Updated copyright date for 2020
Ryan C. Gordon aef1ed4a 2019-09-25T15:40:27 audio: Set (something close to) the correct silence value for U16 audio. Partially fixes Bugzilla #4805.
Ozkan Sezer 7a47c292 2019-07-31T01:22:02 Fix bug 4746 - introduce SDL_zeroa macro.
Sam Lantinga 723d0143 2019-06-04T17:32:15 Fixed bug 4171 - SDL_GetQueuedAudioSize is broken with WASAPI Cameron Gutman I was trying to use SDL_GetQueuedAudioSize() to ensure my audio latency didn't get too high while streaming data in from the network. If I get more than N frames of audio queued, I know that the network is giving me more data than I can play and I need to drop some to keep latency low. This doesn't work well on WASAPI out of the box, due to the addition of GetPendingBytes() to the amount of queued data. As a terrible hack, I loop 100 times calling SDL_Delay(10) and SDL_GetQueuedAudioSize() before I ever call SDL_QueueAudio() to get a "baseline" amount that I then subtract from SDL_GetQueuedAudioSize() later. However, because this value isn't actually a constant, this hack can cause SDL_GetQueuedAudioSize() - baselineSize to be < 0. This means I have no accurate way of determining how much data is actually queued in SDL's audio buffer queue. The SDL_GetQueuedAudioSize() documentation says: "This is the number of bytes that have been queued for playback with SDL_QueueAudio(), but have not yet been sent to the hardware." Yet, SDL_GetQueuedAudioSize() returns > 0 value when SDL_QueueAudio() has never been called. Based on that documentation, I believe the current behavior contradicts the documented behavior of this function and should be changed in line with Boris's patch. I understand that exposing the IAudioClient::GetCurrentPadding() value is useful, but a solution there needs to take into account what of that data is silence inserted by SDL and what is actual data queued by the user with SDL_QueueAudio(). Until that happens, I think the best approach is to remove the GetPendingBytes() call until SDL is able to keep track of queued data to make sense of it. This would make SDL_GetQueuedAudioSize() possible to use accurately with WASAPI.
Sam Lantinga f3e76ea1 2019-05-23T13:47:30 Use the OpenSL ES audio driver by default on Android, as it has the lowest latency.
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 7dc92a76 2019-01-12T12:18:44 Initial Android OpenSL ES implementation, contributed by ANTA
Sylvain Becker d23c2f07 2019-01-10T18:05:56 Fixed bug 3930 - Android, set thread priorities and names SDLActivity thread priority is unchanged, by default -10 (THREAD_PRIORITY_VIDEO). SDLAudio thread priority was -4 (SDL_SetThreadPriority was ignored) and is now -16 (THREAD_PRIORITY_AUDIO). SDLThread thread priority was 0 (THREAD_PRIORITY_DEFAULT) and is -4 (THREAD_PRIORITY_DISPLAY).
Sam Lantinga 5e13087b 2019-01-04T22:01:14 Updated copyright for 2019
Ryan C. Gordon 04cbf132 2018-10-10T15:20:56 audio: All device names reported by SDL must be unique. This means that if you have two devices named "Soundblaster Pro" in your machine, one will be reported as "Soundblaster Pro" and the other as "Soundblaster Pro (2)". This makes it so you can't into a position where one of your devices can't be opened because another is sitting on the same name.
Ryan C. Gordon 0378529e 2018-10-10T14:55:24 audio: clean_out_device_list() already sets this flag to false for us.
Sam Lantinga f5a21ebf 2018-10-09T20:12:43 Added support for surround sound and float audio on Android
Sam Lantinga b2518761 2018-10-01T09:47:10 commit c6b28f46b8116552ec2b38d1d3c8535df28ba7a1 Author: Anthony Pesch <inolen@gmail.com> Date: Fri May 4 20:21:21 2018 -0400 Added SDL_AUDIO_ALLOW_SAMPLES_CHANGE flag enabling users of SDL_OpenAudioDevice to get the sample size of the actual hardware buffer vs having a stream created to handle the delta
Ryan C. Gordon 56f44cfa 2018-08-07T13:04:15 audio: Deal with device shutdown more carefully. This would cause problems in various ways, but specifically triggers an assert when you close a WASAPI capture device in an app running over RDP. Related to (but not the actual bug) in Bugzilla #3924.
Sam Lantinga f521b22e 2018-04-23T22:07:56 Added SDL_THREAD_PRIORITY_TIME_CRITICAL
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.
sezero 40b27fd5 2018-02-12T17:00:00 revert the recent typecast assignment changes (see bug #4079) also change the void* typedefs for the two vulkan function pointers added in vulkan_internal.h into generic function pointer typedefs.
Sam Lantinga 90e72bf4 2018-01-30T18:08:34 Fixed ISO C99 compatibility SDL now builds with gcc 7.2 with the following command line options: -Wall -pedantic-errors -Wno-deprecated-declarations -Wno-overlength-strings --std=c99
Sam Lantinga e3cc5b2c 2018-01-03T10:03:25 Updated copyright for 2018
Ryan C. Gordon 351d6d47 2017-12-06T12:24:32 audio: Port WASAPI to WinRT, remove XAudio2 backend. XAudio2 doesn't have capture support, so WASAPI was to replace it; the holdout was WinRT, which still needed it as its primary audio target until the WASAPI code code be made to work. The support matrix now looks like: WinXP: directsound by default, winmm as a fallback for buggy drivers. Vista+: WASAPI (directsound and winmm as fallbacks for debugging). WinRT: WASAPI
Ryan C. Gordon 1a3b95a1 2017-09-21T02:51:14 audio: Replaced the resampler. Again. This time it's using real math from a real whitepaper instead of my previous amateur, fast-but-low-quality attempt. The new resampler does "bandlimited interpolation," as described here: https://ccrma.stanford.edu/~jos/resample/ The output appears to sound cleaner, especially at high frequencies, and of course works with non-power-of-two rate conversions. There are some obvious optimizations to be done to this still, and there is other fallout: this doesn't resample a buffer in-place, the 2-channels-Sint16 fast path is gone because this resampler does a _lot_ of floating point math. There is a nasty hack to make it work with SDL_AudioCVT. It's possible these issues are solvable, but they aren't solved as of yet. Still, I hope this effort is slouching in the right direction.
Sam Lantinga d619d885 2017-08-28T21:42:39 Fixed bug 3662 - Error message when using the audio conversion setup without an initialized audio subsystem is a bit vague Simon Hug This issue actually raises the question if this API change (requirement of initialized audio subsystem) is breaking backwards compatibility. I don't see the documentation saying it is needed in 2.0.5.
Sam Lantinga 8e7998e1 2017-08-27T19:10:30 Fixed bug 3710 - SDL_OpenAudio(desired, obtained) doesn't update desired's size when obtained is NULL David Ludwig I've created a new set of patches. I am happy to create more, if it would help. One version only copies 'size'. A second version copies both 'size' and 'silence'. When looking over the documentation for SDL_OpenAudio in SDL_audio.h, it mentioned that both 'size' and 'silence' were things that SDL_OpenAudio would calculate. Regarding *both* patches, I did notice that SDL 1.2 appears to have always modified desired's size and silence fields. The SDL wiki, at https://wiki.libsdl.org/SDL_OpenAudio#Remarks , does note:
Sam Lantinga 96305832 2017-08-11T10:21:19 Fixed bug 3702 - Clear error messages of SDL_LoadObject for optional libraries Simon Hug Some code in SDL loads libraries with SDL_LoadObject to get more information or use newer APIs. SDL_LoadObject may fail, set an error message and SDL will continue with some fallback code. Since SDL will overwrite the error or exit the function with a return value that indicates success, the error form SDL_LoadObject for the optional stuff might as well be cleared right away.
Ryan C. Gordon d9039f23 2017-06-08T13:27:58 jack: Initial shot at a JACK audio target. http://jackaudio.org/ Fixes Bugzilla #2163. (with several more commits following to improve this code.)
Ryan C. Gordon a7fc2822 2017-05-24T19:56:59 audio: rename bsd target to netbsd. Apparently this is no longer a generic BSD audio target, and hasn't been for years, so rename it for NetBSD.
Ryan C. Gordon 4073a669 2017-05-18T15:33:17 audio: One more callbackspec fix (thanks, Simon!).
Ryan C. Gordon 226541cb 2017-04-26T01:43:40 audio: another wrong struct that causes NULL pointer crash (thanks, Simon!). Fixes Bugzilla #3632.
Juha Kuikka 7382cebb 2017-04-20T21:25:29 audio: Fix audio queue functions to use new spec structure. Using the old spec structure causes the audio queueing functions to fail due to bad callback pointers being checked.
Sam Lantinga d20d426c 2017-04-18T22:17:40 Fix crash in SDL audio thread, by Juha Kuikka Wrong audio spec structure was populated with the internal callback, causing the audio thread to call a NULL pointer.
Ryan C. Gordon c85c57a0 2017-03-29T14:23:39 wasapi: Handle lost audio device endpoints. This gracefully recovers when a device format is changed, and will switch to the new default device if the current one is unplugged, etc. This does not handle when a new default device is added; it only notices if the current default goes away. That will be fixed by implementing the stubbed-out MMNotificationClient_OnDefaultDeviceChanged() function.
Sam Lantinga c4d54504 2017-03-14T07:16:56 differentiate between capture / playback audio thread names
Ryan C. Gordon a4249b48 2017-02-26T00:56:13 Patched to compile on C89 compilers.
Ryan C. Gordon 3b9e4d0a 2017-02-26T00:39:22 audio: Try to keep callbacks firing at normal pace when device is lost.
Ryan C. Gordon a366c35f 2017-02-26T00:12:33 audio: run the audio callback even if device was lost. We will throw away the data anyhow, but some apps depend on the callback firing to make progress; testmultiaudio.c, if nothing else, is an example of this. Capture also will now fire the callback in these conditions, offering nothing but silence. Apps can check SDL_GetAudioDeviceStatus() or listen for the SDL_AUDIODEVICEREMOVED event if they want to gracefully deal with an opened audio device that has been unexpectedly lost.
Ryan C. Gordon 5728cb20 2017-02-26T00:10:02 audio: Make sure the disk and dummy targets are the last ones we try to init.
Ryan C. Gordon 6046fd4c 2017-02-14T03:03:27 wasapi: Initial WASAPI support, for Windows Vista and later. This should remain binary compatible with Windows XP, as we dynamically load anything we need and fall back to DirectSound/WinMM/XAudio2 if not available.
Ryan C. Gordon 175f1e8f 2017-02-13T16:55:00 audio: Added a ThreadDeinit() method to match ThreadInit. Not used by any targets at the moment, but will be shortly!
Sam Lantinga 886736a2 2017-02-11T16:38:16 Fixed bug 3584 - Small stack size for audio callback thread Walter van Niftrik We have found that since SDL 2.0.5 the audio callback thread is created with a very small stack size. In our application this is leading to stack overflows. We believe there is a bug at http://hg.libsdl.org/SDL/file/391fd532f79e/src/audio/SDL_audio.c#l1132, where the is_internal_thread flag appears to be inverted.
Sam Lantinga ede5c734 2017-01-24T19:38:01 Generalized the audio resampling hint for other resampling methods in the future
Ryan C. Gordon c7f9dcb6 2017-01-24T15:52:22 audio: Offer a hint for libsamplerate quality/speed tradeoff. This defaults to the internal SDL resampler, since that's the likely default without a system-wide install of libsamplerate, but those that need more can tweak this.
Ryan C. Gordon 57182930 2017-01-16T00:58:28 audio: Implemented SIMD support for audio data type converters. This currently adds an SSE2 implementation (but it's #ifdef'd out for now, until it's hooked up to the configure script and such).
Ryan C. Gordon a41103b1 2017-01-09T05:59:30 audio: Patched to compile if linking directly to libsamplerate.
Ryan C. Gordon 35166609 2017-01-08T14:28:44 audio: Patched to compile with libsamplerate support (again).
Ryan C. Gordon 19e937fc 2017-01-08T14:18:03 audio: libsamplerate loading now happens once at init time.
Sam Lantinga 37f404fb 2017-01-06T00:47:42 Fixed confusion between Ryan's new audio stream and the audio buffer we were calling stream in the callback
Ryan C. Gordon 748f4605 2017-01-06T03:38:14 audio: Add an assert to make sure non-streaming audio uses good buffer sizes.
Ryan C. Gordon b3e8db80 2017-01-06T01:07:34 audio: rename fake_stream to work_buffer. It's more than an alternative for when the OS can't provide a DMA buffer, now.
Ryan C. Gordon 992124d4 2017-01-06T01:02:58 audio: Fixed SDL_AudioStreamGet() function parameters. There was a draft of this where it did audio conversion into the final buffer, if there was enough room available past what you asked for, but that interface got removed, so the parameters didn't make sense (and we were using the wrong one in any case, too!).
Ryan C. Gordon f07a1a5a 2017-01-05T21:31:02 emscriptenaudio: Reworked to use SDL_AudioStream.
Ryan C. Gordon 3761b5f6 2017-01-05T20:11:19 Fixed a few compiler warnings.
Ryan C. Gordon 30178a9b 2017-01-05T19:29:38 audio: Added SDL_AudioStream. Non-power-of-two resampling now works!
Sam Lantinga 45b774e3 2017-01-01T18:33:28 Updated copyright for 2017
Sam Lantinga b2f6c4c1 2016-12-19T11:15:53 Fixed bus error when converting 16-bit to float for non-integral-multiple sample rates
Ryan C. Gordon c0231875 2016-12-06T12:23:17 audio: Fixed compiler warnings.
Ryan C. Gordon a0e003ee 2016-12-06T02:23:54 Refactored the audio queueing code to a generic SDL_DataQueue interface. This is not a public API (at the moment), but we will be needing this for other internal things soon.