Commit Graph

592 Commits (e9908d840b7fb71b903876161c5ec111872f46eb)

Author SHA1 Message Date
Sam Lantinga abe38bca3e Support SDL_AUDIODRIVER set to "dsound", which was used by SDL 1.2
Fixes https://github.com/libsdl-org/SDL/issues/5818
2022-06-18 13:08:58 -07:00
Sam Lantinga adc6875870 Added SDL_copyp to avoid size mismatch when copying values (thanks @1bsyl!)
Closes https://github.com/libsdl-org/SDL/pull/5811
2022-06-17 10:22:28 -07:00
Ryan C. Gordon dc62fec5e9
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.
2022-05-20 21:08:29 -04:00
Pierre Wendling 501a499180 Add clang-format on/off comments where necessary.
Comments were added in places where INDENT-ON/OFF comments are. Places
like stdlib's asm don't need it as clang-format doesn't try to indent it.
2022-05-19 01:31:29 -07:00
Cameron Cawley 0cca71a846 Use SDLCALL for callbacks in public APIs 2022-05-18 15:01:27 -07:00
Ryan C. Gordon 29694869b1
audio: Revert one of the resampler optimizations.
This is the one that splits the "left wing" into two for loops to
bubble out the conditional that decides if it should read from the
left padding or the input buffer.

I still believe the optimization is good, but the basic logic of it
was incorrect, and needs to be reexamined and fixed before going
back into revision control.
2022-04-28 15:58:39 -04:00
Ryan C. Gordon 5066910bf5 audio: Make pregenerated resampler kaiser filter more precise. 2022-04-26 13:32:42 -04:00
Ryan C. Gordon 111c3add73 audio: Resampler optimizations.
- Calculate `j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING` once per loop
  iteration since we use it multiple times.
- Do the left-wing loop in two sections: while `srcframe < 0` and then
  the remaining calculations when `srcframe >= 0`. This bubbles a conditional
  out of every iteration of a tight loop, giving us a boost. We could
  _probably_ do this to the right-wing loop too, but it's less straightforward
  there.
- The real win: Use floats instead of doubles. This almost doubles the speed
  of the entire function on Intel CPUs, and for embedded things without
  hardware-level support for doubles, the speedup is enormous. This in
  theory might reduce audio quality, though, and I had to put a check in
  place to avoid a division-by-zero that we avoided at higher precision, but
  this is likely to be worth keeping for at least the Sony PSP and other
  smaller platforms, if not everyone.
2022-04-26 13:32:42 -04:00
Ryan C. Gordon de019568dc audio: Prebake the resampler's kaiser table instead of doing it at runtime. 2022-04-26 13:32:42 -04:00
Ryan C. Gordon f6eb4b0759
pulseaudio: Feed audio data in response to write callbacks.
Instead of waiting until the entire buffer from the SDL callback is ready
to be accepted by PulseAudio, we use pa_stream_set_write_callback and
feed some portion of the buffer as callbacks come in asking for more.

This lets us remove the halving of the buffer size during device open,
and also (hopefully) solves several strange hangs that happen in unusual
circumstances.

Fixes #4387
Fixes #2262
2022-04-26 13:22:32 -04:00
Sam Lantinga 9e264b921b Certain audio drivers, like the RME "Pro" Audio driver, have resampling quality issues when using WASAPI.
We'll use SDL's resampling algorithm so we have consistent quality between platforms and drivers.

Fixes https://github.com/libsdl-org/SDL/issues/5538
2022-04-18 09:20:47 -07:00
Ryan C. Gordon c1336b21ed hints: Make SDL_VIDEODRIVER and SDL_AUDIODRIVER formal hints.
They were just environment variables before.

Fixes #5528.
2022-04-17 11:31:55 -07:00
Ryan C. Gordon 727eef7064
audio: SDL_ConvertStereoToMono_SSE3 missed an unaligned load. 2022-04-09 10:13:37 -04:00
Ivan Epifanov 178ac19615 Vita: add audio capture support 2022-03-29 14:12:37 -07:00
Connor Clark aec86ba8bb emscriptenaudio: proxy calls to main thread 2022-03-28 12:04:04 -04:00
Ryan C. Gordon 4fe7b2cbd1
static analysis: Fixed several complaints from codechecker.
There are still some pending Objective-C specific issues.

Reference issue #4600.
2022-03-24 11:00:43 -04:00
Ivan Epifanov 0af2db6f29 Vita: support audio format fallback 2022-03-24 07:51:20 -04:00
Eddy Jansson 24ffcbd9ad audio: Set error message on dsp init failure.
if SDL_EnumUnixAudioDevices() fails to find any devices,
set an error message on the exit path. Without this,
SDL_Init() could fail without any message available
in SDL_GetError().
2022-03-20 10:31:19 -07:00
Sam Lantinga a485ffc3c8 Fix "SDL_FALSE is not defined" runtime error for emscripten. 2022-03-19 09:50:22 -07:00
Christian Kündig fbbd0270eb Fix "SDL_TRUE is not defined" runtime error for emscripten. 2022-03-18 16:42:12 -07:00
pionere 01bfde4520 simplify SetDSerror
- no need to keep the error in a static variable
- always print the error code
- reduce the required stack-size
- reduce the number of snprintf calls (and code size)
2022-03-17 08:44:06 -07:00
pionere 2c6a9c5194 minor optimization (SDL_audiocvt.c) 2022-03-16 07:58:28 -04:00
Ozkan Sezer 5905696e66 SDL_audiocvt.c: minor cleanup. 2022-03-15 23:10:04 +03:00
Wohlstand 7c421fec16 SDL_audiocvt.c: Don't byteswap 8-bit streams
Otherwise, this results an assert on big endian machines when attenpting to use SDL_LoadWAV_RW function to load 8-bit WAV files.
2022-03-14 08:41:07 -07:00
Wohlstand 08d27dfd7b SDL_openslES.c: Detect float support in runtime and use it
Allow using of the float output type on newer Android devices, but keep PCM16 output on older

Closes #5358
2022-02-22 08:31:14 -08:00
Frank Praznik 228db35287 audio: pipewire: Tidy up formatting 2022-02-08 14:33:34 -05:00
Frank Praznik 9da9e85cba audio: pipewire: Reset all hotplug values and pointers on shutdown
Ensure that all hotplug variables and pointers are reset to NULL or their original value when shutting down.
2022-02-08 14:33:34 -05:00
Frank Praznik 5b36a527ed audio: pipewire: Remove redundant locks
The io_list_check_add() and io_list_remove() functions are only ever called from within the Pipewire thread loop, so the locks are redundant.  io_list_sort() is called from within a lock in the device detection function, so those additional locks are redundant as well.
2022-02-08 14:33:34 -05:00
Frank Praznik 48b4d1c412 audio: pipewire: Convert atomic hotplug conditional variables to SDL_bool
The hotplug loop condition variables are always guarded by the loop mutex while the loop is running, so they don't need to be atomic.
2022-02-08 14:33:34 -05:00
Frank Praznik 53091e36a3 audio: pipewire: Remove the hard upper bound on rates and buffer sizes
Remove the hard upper limit of 8192 samples and instead use the buffer sizes provided by Pipewire to determine the size of the intermediate input buffer and whether double buffering is required for output streams. This allows for higher latency streams to potentially avoid double-buffering in the output case, and we can guarantee that the intermediate input buffer will always be large enough to handle whatever Pipewire may deliver.

As the buffer size calculations occur in a callback in the Pipewire processing thread itself, the stream readiness check has been modified to wait on two distinct flags set when the buffers have been configured and when the stream is ready and running.
2022-02-07 15:11:31 -05:00
Frank Praznik 66866249a2 audio: pipewire: Condition variable doesn't need to be atomic
The condition variable is guarded by a mutex, so no need for it to be atomic.
2022-02-07 15:11:31 -05:00
Frank Praznik 0b34f18045 audio: pipewire: Don't double free properties on init failure
The context and stream creation functions will destroy the passed properties object on failure, so no need to do it manually.

The pw_properties_free() function pointer is no longer needed, so it can be removed.
2022-01-30 23:23:03 -05:00
pionere a5c610b0a3 revert 'Changed to use 0xFE instead of 0xFF for better sound quality.' 2022-01-28 20:40:19 -05:00
pionere a70bb259c7 drop handle parameter of OpenDevice 2022-01-28 20:40:19 -05:00
pionere 47ddb04e17 cleanup/sync the main loop of *_OpenDevice functions to pick audio format II. 2022-01-28 20:40:19 -05:00
pionere 2eafe4340c cleanup/sync the main loop of *_OpenDevice functions to pick audio format 2022-01-28 20:40:19 -05:00
pionere 3939ef72f8 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
2022-01-28 20:40:19 -05:00
pionere 113109f839 cleanup SDL_GetAudioDeviceName
- drop unnecessary hascapture check
- call SDL_InvalidParamError in case the index is out of range
2022-01-28 20:40:19 -05:00
pionere f91211eb17 cleanup WASAPI_PrepDevice
- reorganize the loop which checks for the right wave-format
- use the return value of UpdateAudioStream
- ensure SetError is called in SDL_NewAudioStream
2022-01-28 20:40:19 -05:00
pionere c9e8d1573a re-use return value of SDL_SetError/WIN_SetErrorFromHRESULT/SDL_OutOfMemory II. 2022-01-28 20:40:19 -05:00
pionere 1043dd8c0d adjust handling of iscapture
- drop iscapture parameter of OpenDevice
- use SDL_bool for iscapture
2022-01-28 20:40:19 -05:00
pionere 60deadba59 re-use return value of SDL_SetError/WIN_SetErrorFromHRESULT/SDL_OutOfMemory 2022-01-28 20:40:19 -05:00
pionere ebdd536676 use SDL_InvalidParamError or SDL_assert instead of custom SDL_SetError 2022-01-28 20:40:19 -05:00
pionere 4a17612bff get rid of BeginLoopIteration 2022-01-28 20:40:19 -05:00
pionere 0770c5829c get rid of PrepareToClose 2022-01-28 20:40:19 -05:00
Ryan C. Gordon e0236c02ce audio: Removed an unnecessary commented-out line. 2022-01-28 20:40:19 -05:00
pionere 0dda8a7f4c 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)
2022-01-28 20:40:19 -05:00
pionere 6fcfcc3d6f get rid of SkipMixerLock 2022-01-28 20:40:19 -05:00
pionere bf66720a4d fix mixing of U16 audio 2022-01-28 20:40:19 -05:00
pionere 905e2e22ef cleanup of SDL_MixAudioFormat 2022-01-28 20:40:19 -05:00