Commit graph

707 commits

Author SHA1 Message Date
Ethan Lee 90b86b132a audio: Handle non-power-of-two spec.samples when unsupported
Fixes #3685
2022-07-17 10:36:15 -04:00
Ethan Lee a09d62e4d8
directsound: Remove redundant SubFormat copy 2022-07-15 23:45:56 -04:00
Ethan Lee c5e408ae98 directsound: For channel counts > 2, generate a dwChannelMask for CreateSoundBuffer 2022-07-15 13:59:46 -04:00
Ethan Lee fff34f6304 windows: SDL_IMMDevice needed more deinit code from the Win32 path.
Fixes #5919
2022-07-15 09:49:29 -04:00
Frank Praznik 37aecda2c1 pipewire: Use PW_KEY_TARGET_OBJECT to specify stream connection nodes
Pipewire 0.3.44 introduced PW_KEY_TARGET_OBJECT, which is to be used to specify target connection nodes for streams.  This parameter takes either a node path (PW_KEY_NODE_NAME) or serial number (PW_KEY_OBJECT_SERIAL) to specify a target node.  The former is used in this case since the path is already being retrieved and stored for other purposes.

The target_id parameter in pw_stream_connect() is now deprecated and should always be PW_ID_ANY when PW_KEY_TARGET_OBJECT is used.
2022-07-14 12:23:50 -04:00
Frank Praznik 36d8460c9e pipewire: Dynamically allocate the buffer for node strings
Calculate and allocate the buffer for the IO node name and path strings dynamically instead of using arbitrary sized static buffers.
2022-07-11 18:03:56 -04:00
Frank Praznik 996cea31ee pipewire: Update default audio devices during runtime
Make the default device metadata node persist for the lifetime of the hotplug loop so the default source/sink devices will be updated if they change during runtime.
2022-07-11 18:03:56 -04:00
Frank Praznik 60da11f0e2 pipewire: Remove deprecated configuration key
With Pipewire now requiring a minimum version 0.3.24, the PW_KEY_CONTEXT_PROFILE_MODULES value is no longer required for legacy compatability and can be safely removed.
2022-07-11 18:03:56 -04:00
Ethan Lee ecfbdce64b pipewire: Require version 0.3.24 or newer at runtime 2022-07-11 13:34:35 -04:00
Ethan Lee 2f0816adb7 Add SDL_GetDefaultAudioInfo.
This API is supported on pipewire, pulseaudio, wasapi, and directsound.

Co-authored-by: Frank Praznik <frank.praznik@gmail.com>
2022-07-11 13:34:35 -04:00
Ethan Lee ae105ae1c7 windows: Move IMMDevice work to common file, implement DirectSound enumeration support 2022-07-11 12:54:34 -04:00
285424336 4aad594a8b Update SDL_qsa_audio.c
Fix qnx platform compile error, change SDL_Bool to SDL_bool.
2022-07-08 12:15:00 +03:00
Pierre Wendling 6c536afdb7 Fix C89 declaration for macOS modules.
Since Clang 14, `-Wdeclaration-after-statement` is enforced on every
standard.
2022-06-27 15:19:40 -07:00
Francisco Javier Trujillo Mata e4a8087551 Initial Audio driver 2022-06-27 15:18:48 -07:00
chalonverse 3b191580c3
Windows GDK Support (#5830)
* Added GDK

* Simplfied checks in SDL_config_wingdk.h

* Added testgdk sample

* Added GDK readme

* Fixed error in merge of SDL_windows.h

* Additional GDK fixes

* OpenWatcom should not export _SDL_GDKGetTaskQueue

* Formatting fixes

* Moved initialization code into SDL_GDKRunApp
2022-06-27 10:19:39 -07:00
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
Frank Praznik b3984df1c6 audio: pipewire: Use client config files instead of module names
Pipewire, as of 0.3.22, uses client config files to load modules instead of explicitly specifying them (PW_KEY_CONTEXT_PROFILE_MODULES is deprecated).  Use the new method to load the realtime module to boost the audio thread priority.
2022-01-19 14:20:19 -05:00
Ryan C. Gordon 5d07c03613
psp: Force channels to stereo if user requested anything other than mono.
Before it would only clamp to stereo if it also had to resample, which would
fail if the app specified 44100Hz and surround sound.
2022-01-09 08:13:34 -05:00
Francisco Javier Trujillo Mata f3255df9c0 Improve audio compatibility in PSP. Now it supports more formats and frequencies 2022-01-05 19:15:41 -05:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
e d0de4c625a Android: fixes build NDK 21d 2021-12-31 11:12:21 -08:00
thfrwn 2b6b69fb12 fix assertion failure in sndio audio caused by the recent hotplugging support 2021-12-13 11:26:35 -08:00
Ozkan Sezer 9409642e08 fix some warnings from vita builds (missing includes)
also some tidy-up to whitespace.
2021-12-07 21:24:24 +03:00
Ozkan Sezer 00014dc2ac fix some warnings from psp builds (missing includes.) 2021-12-07 18:47:10 +03:00
ALittleDruid 2f0edc2906 IAudioClient::SetEventHandle Parameter eventHandle Should not be NULL 2021-12-06 09:02:31 -08:00
Ryan C. Gordon d713a68071
pulseaudio: wait until at least 1/8th (!) of the mixbuffer is available.
This is to workaround systems where we hang in playback because the buffer
does not report the space for whatever reason. The system will instead block
in PlayDevice, which always immediately follows WaitDevice in modern times
so this works out, and it seems to keep the device moving forward.

For a future revision, we are either going to clean this up more properly,
or attempt to move to PulseAudio's pa_stream_set_write_callback() API, but
this will do for SDL 2.0.18.

Reference #4387 for discussion and further information.
2021-11-25 22:32:40 -05:00
Sylvain 2004aaf3bb SDL_wave: use SDL_free 2021-11-22 08:38:46 -08:00
Sylvain 155db97d14 Remove 'malloc' from comment 2021-11-22 08:38:46 -08:00
Sylvain 38cfe25bc5 Remove 'malloc' from comment 2021-11-22 08:38:46 -08:00
Sylvain 8fb19d212e Vita: unneeded include 2021-11-22 08:38:46 -08:00
Sylvain e702a4e520 PSP: un needed include 2021-11-22 08:38:46 -08:00
Sylvain d31251b014 use SDL's functions version inplace of libc version 2021-11-22 08:38:46 -08:00
Sylvain a0cb079a42
Fixed bug #4982 - Failed to open audio_device on OpenSLES / Android 5.x with freq 96khz+ 2021-11-21 15:45:08 +01:00
Sylvain b6e8651ae9
Audio 6.1 should be allowed now (see #4974) 2021-11-20 15:31:21 +01:00
Sylvain 5be8a22113 Add audio conversion from/to 61 2021-11-17 16:04:54 -08:00
Sylvain b649314d62
Add comment to audio clipping (see bug #4104) 2021-11-15 13:43:40 +01:00
Ozkan Sezer 5c067906ba wasapi: AvSetMmThreadCharacteristicsW takes an LPCWSTR param, not LPWSTR 2021-11-15 00:55:04 +03:00
Ozkan Sezer be7b663c2c audio/winmm/SDL_winmm.c (SetMMerror): constify. 2021-11-14 02:30:56 +03:00
Cameron Gutman c8061ed2d1 alsa: Fix possible uninitialized string 2021-11-13 10:33:37 -06:00
Cameron Gutman 704edf6323 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.
2021-11-12 17:07:22 -06:00
Cameron Gutman 78013aeef9 alsa: Fix use-after-free when reinitializing 2021-11-12 16:57:24 -06:00
Sam Lantinga c2dd50a9a0 Fixed whitespace 2021-11-12 08:28:02 -08:00
Misa 3bf7994fe2 Add and use SDL_FALLTHROUGH for fallthroughs
Case fallthrough warnings can be suppressed using the __fallthrough__
compiler attribute. Unfortunately, not all compilers have this
attribute, or even have __has_attribute to check if they have the
__fallthrough__ attribute. [[fallthrough]] is also available in C++17
and the next C2x, but not everyone uses C++17 or C2x.

So define the SDL_FALLTHROUGH macro to deal with those problems - if we
are using C++17 or C2x, it expands to [[fallthrough]]; else if the
compiler has __has_attribute and has the __fallthrough__ attribute, then
it expands to __attribute__((__fallthrough__)); else it expands to an
empty statement, with a /* fallthrough */ comment (it's a do {} while
(0) statement, because users of this macro need to use a semicolon,
because [[fallthrough]] and __attribute__((__fallthrough__)) require a
semicolon).

Clang before Clang 10 and GCC before GCC 7 have problems with using
__attribute__ as a sole statement and warn about a "declaration not
declaring anything", so fall back to using the /* fallthrough */ comment
if we are using those older compiler versions.

Applications using SDL are also free to use this macro (because it is
defined in begin_code.h).

All existing /* fallthrough */ comments have been replaced with this
macro. Some of them were unnecessary because they were the last case in
a switch; using SDL_FALLTHROUGH in those cases would result in a compile
error on compilers that support __fallthrough__, for having a
__attribute__((__fallthrough__)) statement that didn't immediately
precede a case label.
2021-11-12 07:26:14 +03:00
Sam Lantinga abc12a832c Revert "Add and use SDL_FALLTHROUGH for fallthroughs"
This reverts commit 66a08aa391.

This causes problems with older compilers:
https://github.com/libsdl-org/SDL/pull/4791#issuecomment-966630997
2021-11-11 15:58:44 -08:00
Misa 66a08aa391 Add and use SDL_FALLTHROUGH for fallthroughs
Case fallthrough warnings can be suppressed using the __fallthrough__
compiler attribute. Unfortunately, not all compilers have this
attribute, or even have __has_attribute to check if they have the
__fallthrough__ attribute. [[fallthrough]] is also available in C++17
and the next C2x, but not everyone uses C++17 or C2x.

So define the SDL_FALLTHROUGH macro to deal with those problems - if we
are using C++17 or C2x, it expands to [[fallthrough]]; else if the
compiler has __has_attribute and has the __fallthrough__ attribute, then
it expands to __attribute__((__fallthrough__)); else it expands to an
empty statement, with a /* fallthrough */ comment (it's a do {} while
(0) statement, because users of this macro need to use a semicolon,
because [[fallthrough]] and __attribute__((__fallthrough__)) require a
semicolon).

Applications using SDL are also free to use this macro (because it is
defined in begin_code.h).

All existing /* fallthrough */ comments have been replaced with this
macro. Some of them were unnecessary because they were the last case in
a switch; using SDL_FALLTHROUGH in those cases would result in a compile
error on compilers that support __fallthrough__, for having a
__attribute__((__fallthrough__)) statement that didn't immediately
precede a case label.
2021-11-11 07:23:25 -08:00
Sam Lantinga 6d5edfa733 Fixed crash on Android 8, due to bugs in AAudio implementation 2021-11-02 15:59:26 -07:00
Cameron Gutman c97c46877f core: Convert SDL_IOReady()'s 2nd parameter to flags 2021-10-30 21:23:45 -07:00
Ryan C. Gordon 8a4a282aaa
alsa: Make hotplug thread optional.
Even without the thread, it'll do an initial hardware detection at startup,
but there won't be any further hotplug events after that. But for many cases,
that is likely complete sufficient.

In either case, this cleaned up the code to no longer need a semaphore at
startup.

Fixes #4862.
2021-10-30 16:02:12 -04:00
Sylvain 072e3fdfc4
Fixed bug #4534: NEON implementation of Convert51ToStereo (Thanks Ryan!) 2021-10-14 23:17:08 +02:00
Sam Lantinga 2423c51471 Work around hang in AAudioStream_write() during extended shared object loading while running in a debugger. Observed on a OnePlus 8T (KB2005) running Oxygen OS 11.0.10.10.KB05AA.
The observed behavior is that any nonzero timeout value would hang until the device was paused and resumed. And a zero timeout value would always return 0 frames written even when audio fragments could be heard. Making a manual timeout system unworkable.
None of the straightforward systems imply that there's a detectable problem before the call to AAudioStream_write(). And the callback set within AAudioStreamBuilder_setErrorCallback() does not get called as we enter the hang state.
I've found that AAudioStream_getTimestamp() will report an error state from another thread. So this change codifies that behavior a bit until a better fix or more root cause can be found.
2021-10-13 09:33:51 -07:00
Ozkan Sezer e92a639b23 replaced many uses of libc calls with SDL_ counterparts in os2 sources.
TODO: core/os2 and geniconv sources _must_ be updated, as well..
2021-10-04 23:00:28 +03:00
Sam Lantinga 345c161feb Fixed some accidental uses of external C runtime functions 2021-09-22 09:06:45 -07:00
Ryan C. Gordon ce11caa80f
alsa: Map 7.1 audio channels to match what Windows and macOS expect.
This matches what we did a long time ago for 5.1 audio.

Fixes #55.

(FIFTY FIVE. Bug reported 15 years, 3 months, and 11 days ago! lol)
2021-09-21 16:49:44 -04:00
Ryan C. Gordon c45facf2ca
alsa: clean up macro salsa a little. 2021-09-21 11:13:46 -04:00
Sam Lantinga bf97c5a22f Make sure SDL file descriptors don't leak into child processes 2021-09-08 14:47:40 -07:00
David Gow a1ffeda0ed Add SDL_HINT_APP_NAME and DBUS inhibition hint
See SDL bug #4703. This implements two new hints:
- SDL_APP_NAME
- SDL_SCREENSAVER_INHIBIT_ACTIVITY_NAME

The former is the successor to SDL_HINT_AUDIO_DEVICE_APP_NAME, and acts
as a generic "application name" used both by audio drivers and DBUS
screensaver inhibition. If SDL_AUDIO_DEVICE_APP_NAME is set, it will
still take priority over SDL_APP_NAME.

The second allows the "activity name" used by
org.freedesktop.ScreenSavver's Inhibit method, which are often shown in
the UI as the reason the screensaver (and/or suspend/other
power-managment features) are disabled.
2021-08-30 09:15:11 -04:00
Lee Salzman 7d90df0ece 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.
2021-08-30 05:00:51 +03:00
David Gow 3261f7f6ce 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] d951409784
[2] https://bugzilla.opensuse.org/show_bug.cgi?id=1189778
2021-08-25 22:43:32 -10:00
Ryan C. Gordon 9504bb121d
pulseaudio: Fix some function signatures that expect const pointers.
This might have changed at some point in the Pulse API, or this might have
always been wrong, but we didn't notice because the dynamic loading code
hides it by casting things to void *. The static path, where it
assigns the function pointer directly, puts out a clear compiler warning,
though.
2021-08-23 00:47:25 -04:00
Oschowa 70c23b25f0 audio: pipewire: Reset hotplug atomic variables on deinit. 2021-08-19 22:26:25 -04:00
Oschowa bfa159313b audio: pipewire: Set PW_KEY_NODE_RATE to suggest a rate.
This can be used by recent pipewire to avoid resampling.
2021-08-18 12:40:13 -04:00
Charlie Birks 07a2d71e90 emscripten: Feed silence to device when paused 2021-08-14 12:24:35 +01:00
Joshua Root 1e92135297 Improve portability of SDL_Convert51ToStereo_AVX
Don't rely on checking __clang_major__ since it is not comparable
between different vendors. Don't use "#pragma clang attribute" since it
is only available in relatively recent versions, there's no obvious way
to check if it's supported, and just using __attribute__ directly (for
gcc as well) results in simpler code anyway.
2021-08-12 16:04:35 -07:00
Ozkan Sezer ed6eb07e79 SDL_wasapi.c: fixed build against older SDKs. 2021-08-12 01:40:50 +03:00
Ozkan Sezer 44a76710d1 Don't disable clang avx instrinsics on win32 if __AVX__ is defined.
C.f.: https://github.com/libsdl-org/SDL/issues/4533
2021-08-11 08:47:52 -07:00
Sam Lantinga ac32c522ad Try using the built-in WASAPI audio rate conversion
Fixes https://github.com/libsdl-org/SDL/issues/4608
2021-08-10 18:11:09 -07:00
Sam Lantinga a0af7ce731 OSS is no longer the preferred audio backend on modern UNIX systems
Fixes https://github.com/libsdl-org/SDL/issues/4207
2021-08-10 15:05:49 -07:00
Sebastian Krzyszkowiak 25f9ed87ff 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.
2021-08-10 08:34:07 -07:00
Sam Lantinga bec783571b Better fix for compiling using clang on Windows
This fixes https://github.com/libsdl-org/SDL/issues/4533
2021-08-06 14:20:55 -07:00
Sam Lantinga cae7bd9b65 Don't use AVX with clang if the compiler isn't building with AVX instructions
Fixes https://github.com/libsdl-org/SDL/issues/4533
2021-08-06 12:01:24 -07:00
Ryan C. Gordon 659e1f0a3f
audiocvt: The to-5.1 converters now soften FL and FR channels more.
This is experimental and might be tweaked further.

Reference #4104.

Also reference:

https://github.com/Keriew/augustus/issues/194#issuecomment-847655049
2021-07-29 17:55:59 -04:00
Jessica Clarke 8f38ba4d68 Fix casts that should be using uintptr_t
This is needed to support CHERI, and thus Arm's experimental Morello
prototype, where pointers are implemented using unforgeable capabilities
that include bounds and permissions metadata to provide fine-grained
spatial and referential memory safety, as well as revocation by sweeping
memory to provide heap temporal memory safety.

On most systems (anything with a flat memory hierarchy rather than using
segment-based addressing), size_t and uintptr_t are the same type.
However, on CHERI, size_t is just an integer offset, whereas uintptr_t
is still a capability as described above. Casting a pointer to size_t
will strip the metadata and validity tag, and casting from size_t to a
pointer will result in a null-derived capability whose validity tag is
not set, and thus cannot be dereferenced without faulting.

The audio and cursor casts were harmless as they intend to stuff an
integer into a pointer, but using uintptr_t is the idiomatic way to do
that and silences our compiler warnings (which our build tool makes
fatal by default as they often indicate real problems). The iconv and
egl casts were true positives as SDL_iconv_t and iconv_t are pointer
types, as is NativeDisplayType on most OSes, so this would have trapped
at run time when using the round-tripped pointers. The gles2 casts were
also harmless; the OpenGL API defines this argument to be a pointer type
(and uses the argument name "pointer"), but it in fact represents an
integer offset, so like audio and cursor the additional idiomatic cast
is needed to silence the warning.
2021-07-29 14:42:15 -07:00
Brick 53987e9b4f Optimized SDL_Convert51ToStereo_AVX 2021-07-28 16:11:04 -07:00
Ozkan Sezer cf85710cf8 SDL_audiocvt.c: disable AVX for clang < 5 and gcc < 4.9
See: https://github.com/libsdl-org/SDL/issues/4533
2021-07-28 22:55:10 +03:00
Splamy c72aef2664 Fixed microphone randomly stop working
WASAPI_WaitDevice is used for audio playback and capture, but needs to
behave slighty different.
For playback `GetCurrentPadding` returns the padding which is already
queued, so WaitDevice should return when buffer length falls below the
buffer threshold (`maxpadding`).
For capture `GetCurrentPadding` returns the available data which can be
read, so WaitDevice can return as soon as any data is available.

In the old implementation WaitDevice could suddenly hang. This is
because on many capture devices the buffer (`padding`) wasn't filled
fast enough to surpass `maxpadding`. But if at one point (due to unlucky
timing) more than maxpadding frames were available, WaitDevice would not
return anymore.

Issue #3234 is probably related to this.
2021-07-27 14:19:11 -04:00
Ryan C. Gordon 4ef8674df1
Revert "wasapi: Open capture devices the way we used to."
This reverts commit 0d0fee7569.
2021-07-27 14:18:44 -04:00
Ryan C. Gordon 0d0fee7569
wasapi: Open capture devices the way we used to.
This should work around the regression in #3234, since it basically reverts
the problem change, but only for capture devices.

Fixes #3234.
2021-07-27 14:13:31 -04:00
Ryan C. Gordon 736a424ff4
pulseaudio: Optionally add "monitor" sources to device list.
There's a new hint to enable this.

Fixes #2917.
2021-07-27 13:12:57 -04:00
Ryan C. Gordon 8d790b10f8
audiocvt: stereo-to-mono SSE3 now uses unaligned accesses.
On modern CPUs, there's no penalty for using the unaligned instruction on
aligned memory, but now it can vectorize unaligned data too, which even if
it's not optimal, is still going to be faster than the scalar fallback.

Fixes #4532.
2021-07-27 12:23:46 -04:00
Luis Cáceres 45de0a1d13 Support comma-separated lists in SDL_AUDIODRIVER 2021-07-26 15:14:54 -04:00
Joel Linn b2c8d3e9e4 audiocvt: 5.1 to Stereo conversion utilizing AVX 2021-07-24 15:39:17 -04:00
Joel Linn 638befc1a9 audiocvt: 5.1 to Stereo conversion utilizing SSE 2021-07-24 15:39:17 -04:00
Joel Linn db56526f14 audiocvt: Replace divisions
Division is expensive and the compiler can not replace it themselves.
Though we now we will be ok in terms of floating point edge behaviour.
2021-07-24 15:39:17 -04:00
Per Nyblom 86ee383fdd Removed duplicate SDL_AtomicGet() 2021-05-28 12:29:54 -04:00
Sam Lantinga db146e66c6 Fixed warnings building with Visual Studio 2021-05-25 10:34:04 -07:00
Ozkan Sezer 58884e4c1b SDL_audiocvt.c: fixed MSVC double->float conversion warnings. 2021-05-04 00:23:40 +03:00
Sylvain 8ac0fb52cb
OpenSLES: CloseDevice() is called at higher level, if OpenDevice() fails
- explicit initialization of static variables
2021-04-29 09:29:02 +02:00
Sylvain fcbf19b764
AAudio: make sure stream is not null to prevent crash in RequestStop (see #3710) 2021-04-28 21:04:47 +02:00
Sylvain f869518533
Audio: normalize conversion Stereo to 5.1, Quad to 7.1, 5.1 to 7.1 (bug #4104) 2021-04-27 11:07:51 +02:00
Sylvain 21349901ea
Audio: convert 5.1 to 7.1, use right-surround for r-front and r-back (see #4104) 2021-04-27 10:57:48 +02:00
Ivan Epifanov 058bbe0286 Set volume on device open 2021-04-24 14:13:09 -07:00
Sylvain f1fab24e35
AAudio: add bootstrap in SDL_audio.c 2021-04-15 21:00:00 +02:00
Sylvain 04b2f5f6ec
Android: add AAudio back-end, with playback and capture (see #3710)
https://developer.android.com/ndk/guides/audio/aaudio/aaudio
2021-04-15 20:54:58 +02:00
Sylvain 4118fe62fe
Android: OpenSLES, explicitly initialise the global variable 'bqPlayerPlay',
it may be read even if OpenSLES back-end hasn't been intialized
2021-04-15 20:52:43 +02:00
Ryan C. Gordon 0f4aba7bcd
audio: Fixed assertion failure if trying to use dummy backend. 2021-04-06 18:35:20 -04:00
Ryan C. Gordon 64853b7378
audio: Changed a disk and dummy backends to use _this instead of this. 2021-04-06 18:35:20 -04:00
Ethan Lee 9d294f1fca 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.
2021-03-29 08:58:02 -07:00
Ethan Lee 9b7babf96e wasapi: Remove assert added by 67e8522d 2021-03-29 08:55:13 -07:00
Frank Praznik 5f9effaa7e audio: pipewire: Block while waiting on stream state info
Initializing streams, particularly capture streams, can take many milliseconds, which is a bit much for a busy wait.  Use a blocking wait instead.
2021-03-29 08:49:25 -07:00
Frank Praznik 8deb406300 audio: pipewire: Avoid redundant locking
The pw_thread_loop already locks and unlocks the thread mutex at the start and end of each loop iteration, so these locks are unnecessary.
2021-03-29 08:49:25 -07:00
Frank Praznik 5bb2bbd40c audio: pipewire: Don't use uninitialized variables in callbacks
Some of the SDL_AudioDevice struct members aren't initialized until after returning from the OpenDevice function.  Since Pipewire uses it's own processing threads, the callbacks can be entered before all members of SDL_AudioDevice are initialized, such as work_buffer, callbackspec and the processing stream, which creates a race condition.  Don't use these members when in the paused state to avoid potentially using uninitialized values and memory.
2021-03-29 08:49:25 -07:00