Commit Graph

993 Commits

Author SHA1 Message Date
Sam Lantinga
ba65ef5ce7 Recover from -EPIPE in snd_pcm_avail() 2023-09-28 20:16:59 -07:00
Ryan C. Gordon
a2c5dc6507 pulseaudio: Added typedef needed for compat with ancient Pulse installs. 2023-09-28 12:10:16 -04:00
Ryan C. Gordon
f24551f6d1 pulseaudio: More workarounds for extremely old Pulse installs. 2023-09-28 11:53:00 -04:00
Ryan C. Gordon
441a5b707b audio: Adjusted const/static fields on some variables. 2023-09-28 10:24:42 -04:00
Ryan C. Gordon
280c2c1d7d pulseaudio: Revert "pulseaudio: Require PulseAudio 5.0 or later for SDL3."
This reverts commit 6fd0613ac8.

Turns out that the Steam Runtime is still on PulseAudio 1.1, and the only
thing we (currently) need a newer Pulse for is pa_threaded_mainloop_set_name,
so let's just go back to treating that symbol as optional.

We might need to force a higher version at some point, but it's not worth it
over this.
2023-09-28 10:19:24 -04:00
Ryan C. Gordon
4db2b968af audio: simple-copy path should check if device is paused.
Otherwise, we get into situations where all bound streams need to change
their output formats when a device pauses...and it makes the fast case
slow: when pausing a single input, it needs to silence and then convert a
silent buffer, instead of just zeroing out the device buffer and being done.
2023-09-27 16:24:33 -04:00
Ryan C. Gordon
505dc4c39c wasapi: Deal with device failures when we aren't holding the device lock.
Since these get proxied to a different thread, if we wait for that thread
to finish while holding the lock, and the management thread _also_ requests
the lock, we're screwed.

WaitDevice never holds the lock by design, so just mark devices as failed
and clean up or recover them in there.
2023-09-27 14:33:09 -04:00
Sam Lantinga
ea5f59c234 Removed unused code
It looks like we don't need to watch for hanging writes now that we're using the callback mechanism.
2023-09-27 10:18:34 -07:00
Sam Lantinga
a6854098f7 Fixed stuttering on Android when using the AAudio driver
The audio processing thread isn't scheduled in lock-step with the audio callback so sometimes the callback would consume the same data twice and sometimes the audio processing thread would write to the same buffer twice.

Also handle variable sizes in the audio callback so the Android audio system doesn't have to do additional buffering to match our buffer size requirements.
2023-09-27 10:18:34 -07:00
Ryan C. Gordon
a5175e5ed0 audio: Fixed bug when setting up mixing formats.
Reference Issue #8226.
2023-09-27 11:50:23 -04:00
Sam Lantinga
2e92e94ebb Make sure we update device->sample_frames in SDL_AudioDeviceFormatChangedAlreadyLocked()
WASAPI_GetDeviceBuf() will fail if we don't request the correct buffer size
2023-09-21 11:32:37 -07:00
Sam Lantinga
bac7eeaaae Added missing include 2023-09-20 14:13:50 -07:00
Ryan C. Gordon
a541e2ac10 audio: Change a few SDL_memcpy calls to SDL_copyp. 2023-09-20 17:02:44 -04:00
Ryan C. Gordon
54125c1408 audio: Only update bound audiostreams' formats when necessary.
Saves locks and copies during audio thread iteration. We've added asserts
that can evaporate out in release mode to make sure everything stays in sync.
2023-09-20 17:02:44 -04:00
Ryan C. Gordon
a4541a255e audio: SDL_GetAudioStreamQueued now returns bytes, not frames.
Reference #8266.
2023-09-20 14:15:47 -04:00
Ryan C. Gordon
f8fdb20d8f audio: Destroy all existing SDL_AudioStreams on shutdown. 2023-09-20 10:47:11 -04:00
Ryan C. Gordon
62d4459972 audio: Removed declarations of functions that don't exist anymore. 2023-09-20 10:21:03 -04:00
Ryan C. Gordon
34b931f7eb audio: Added SDL_GetAudioStreamQueued 2023-09-20 10:15:03 -04:00
Ryan C. Gordon
23206b9e3f audio: Added SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED
This fires if an opened device changes formats (which it can on Windows,
if the user changes this in the system control panel, and WASAPI can
report), or if a default device migrates to new hardware and the format
doesn't match.

This will fire for all logical devices on a physical device (and if it's
a format change and not a default device change, it'll fire for the
physical device too, but that's honestly not that useful and might change).

Fixes #8267.
2023-09-20 10:12:10 -04:00
Ryan C. Gordon
c7e6d7a1f7 audio: Changed debug logging output.
("preconverted bytes" makes it sounds like we already converted them before
the call instead of "bytes that haven't yet hit the stage where we convert
them. Just dump the wording completely.)
2023-09-20 10:04:23 -04:00
Ryan C. Gordon
87ec6acf2d audio: Added a FIXME 2023-09-20 10:04:19 -04:00
Ryan C. Gordon
ac88ffb7ea audio: don't allocate buffer in SDL_SetAudioPostmixCallback for NULL callback. 2023-09-20 10:03:02 -04:00
Ryan C. Gordon
2a950f6ae6 audio: Replace some SDL_memcpy calls with SDL_copyp. 2023-09-20 10:01:52 -04:00
Ryan C. Gordon
0dc0434a3e audio: Fixed race condition in subsystem shutdown.
This makes sure new devices can't be created when we're in the process of
shutting down.
2023-09-20 10:00:44 -04:00
Ryan C. Gordon
23f60203a3 audio: precalculate if we can use simple copies instead of the full mixer.
This just saves a bunch of conditionals (and an atomic get!) per iteration
of the audio thread.
2023-09-20 09:58:27 -04:00
Ryan C. Gordon
36b0f11414 audio: Optimize setting device formats during audio thread iteration.
The API entry point does a ton of unnecessary validation just to eventually
do a memcpy().
2023-09-20 09:09:15 -04:00
Sam Lantinga
6a381567b0 Support audio rate conversion up to 384KHz 2023-09-18 22:21:54 -07:00
Sam Lantinga
b2b548a1fc Don't hang if IAudioRenderClient_GetBuffer() fails indefinitely 2023-09-18 20:55:28 -07:00
Sam Lantinga
6d3e21c27c Fixed android build warnings 2023-09-18 13:22:15 -07:00
Sam Lantinga
fde8499f69 Use around 20ms for the audio buffer size
This value is well tested in production software. Larger values introduce audio latency and smaller values cause underflows on many setups.
2023-09-18 09:25:56 -07:00
Mathieu Eyraud
39c2f97373 Fix NULL dereference in SDL_OpenAudio 2023-09-18 09:44:59 -04:00
Brick
a62e62f97a Refactored SDL_audiocvt.c 2023-09-17 13:13:23 -07:00
Ryan C. Gordon
2f43f7bc53 audio: Allow querying of device buffer size. 2023-09-13 11:03:17 -04:00
Ryan C. Gordon
cf95721130 audio: Added a hint to let apps force device buffer size.
This is a hint because apps might (probably mistakenly) believe they need this
to migrate from SDL2, but most things don't need to specify this.
2023-09-13 10:42:08 -04:00
Ryan C. Gordon
47d8c77c67 audio: Choose better default sample frame counts.
This might still need tweaking, but this is probably better than it was.
2023-09-13 10:27:11 -04:00
Ryan C. Gordon
8b26e95f91 audio: Change SDL_AudioStreamCallback
Now it offers the total requested bytes in addition to the amount
immediately needed (and immediately needed might be zero if the stream
already has enough queued to satisfy the request.
2023-09-13 10:11:23 -04:00
Sam Lantinga
cd633b9a88 Renamed SDL_IsAudioDevicePaused() to SDL_AudioDevicePaused()
This aligns with the SDL3 convention of removing "Is" from self-explanatory function names

Also improved some documentation in SDL_audio.h
2023-09-12 12:11:09 -07:00
Sam Lantinga
1d1c6e6305 Turn off COREAUDIO debug logging by default 2023-09-11 09:03:48 -07:00
Ryan C. Gordon
3a992af446 audio: Added a postmix callback to logical devices.
You can see it in action in testaudio by mousing over a logical device; it
will show a visualizer for the current PCM (whatever is currently being
recorded on a capture device, or whatever is being mixed for output on
playback devices).

Fixes #8122.
2023-09-09 16:26:37 -04:00
Ryan C. Gordon
fafbea1ced audio: Move internal float32 mixing to a simplified function 2023-09-07 10:48:04 -04:00
Ryan C. Gordon
38c8fc05c5 audio: Remove ChooseMixStrategy.
This is adds complexity and fragility for small optimization wins.

The biggest win is the extremely common case of a single stream providing
the only output, so we'll check for that and skip silencing/mixing/converting.

Otherwise, just use a single mixer path.
2023-09-07 10:44:30 -04:00
Brick
f2ca9a615b Added SDL_AUDIO_FRAMESIZE 2023-09-05 17:56:58 -07:00
Brick
53122593f8 Added SDL_AUDIO_BYTESIZE 2023-09-05 17:56:58 -07:00
Ozkan Sezer
1d8dfbb223 avoid type redefinition errors after PR/8181 2023-09-04 21:29:40 +03:00
Sam Lantinga
3a932141e4 Restore audio format binary compatibility with SDL 2.0 2023-09-04 10:16:53 -07:00
Sam Lantinga
233789b0d1 Audio types have the same naming convention as other SDL endian types, e.g. [S|U][BITS][LE|BE]
Native endian types have no LE/BE suffix
2023-09-04 09:48:44 -07:00
Brick
0e552761b7 Renamed AudioStreamSpeed to AudioStreamFrequencyRatio 2023-09-04 07:46:18 -07:00
Brick
47bcb078f5 Fixed some incorrect SDL_AUDIO_F32 uses 2023-09-04 07:46:18 -07:00
Brick
a59152688a Try and avoid overflow when handling very large audio streams 2023-09-01 14:38:45 -04:00
Brick
e55844274d Added SDL_(Get|Set)AudioStreamSpeed 2023-09-01 14:38:45 -04:00