Commit Graph

14137 Commits (3976bbef2ad3896c4411c4fcd5bfc5e3bd64bb4b)

Author SHA1 Message Date
Ryan C. Gordon 1fc01b0300
audio: Try to definitely have a default device set up. 2023-07-30 11:56:03 -04:00
Ryan C. Gordon b60a56d368
audio: take first reported device if no default was specified. 2023-07-30 11:56:02 -04:00
Ryan C. Gordon a8323ebe68
audio: Better handling of ProvidesOwnCallbackThread backends. 2023-07-30 11:56:02 -04:00
Ryan C. Gordon 1dffb72c1d
pipewire: Hooked up default device change notifications. 2023-07-30 11:56:02 -04:00
Ryan C. Gordon a93fcf2444
audio: fixed flushed stream reporting bytes but not being able to get them.
This would happen when you had ~1 frame of audio left in the stream, and
resampling needs would cause this to not be enough to produce audio.

But since we're already flushed, we can just add silence padding to let the
app extract these last bits.
2023-07-30 11:56:02 -04:00
Ryan C. Gordon ad6c1781fc
pulseaudio: Minor cleanups. 2023-07-30 11:56:02 -04:00
Ryan C. Gordon cfc8a0d17d
pipewire: First shot at moving to the new SDL3 audio interfaces.
This needs a little work still, but it mostly works.
2023-07-30 11:56:01 -04:00
Ryan C. Gordon 13202642a3
aaudio: Fixed capitialization, plus some minor cleanups. 2023-07-30 11:56:01 -04:00
Ryan C. Gordon 3e9991b535
audio: Make sure we don't write to a NULL pointer.
(This _probably_ never happens in the current codebase, but just in case.)
2023-07-30 11:56:01 -04:00
Ryan C. Gordon 943351affb
pulseaudio: GetDefaultAudioInfo isn't a thing anymore. 2023-07-30 11:56:01 -04:00
Ryan C. Gordon 11dfc4d737
test: Update testautomation_audio for SDL3 audio API. 2023-07-30 11:56:00 -04:00
Ryan C. Gordon 29afc2e42b
test: Update testresample for SDL3 audio API. 2023-07-30 11:56:00 -04:00
Ryan C. Gordon 3a02eecced
test: Update testsurround for SDL3 audio API. 2023-07-30 11:56:00 -04:00
Ryan C. Gordon e1c78718d4
test: testaudiocapture is updated for the SDL3 audio API. 2023-07-30 11:56:00 -04:00
Ryan C. Gordon f48cb716c2
pulseaudio: a couple minor tweaks. 2023-07-30 11:55:59 -04:00
Ryan C. Gordon dac25fe9eb
audio: Seperate audio capture into Wait/Read operations.
Before it would just block in read operations, but separating this out
matches what output devices already do, and also lets us separate out the
unlocked waiting part from the fast part that holds the device lock.
2023-07-30 11:55:59 -04:00
Ryan C. Gordon 3e10c0005d
audio: Capture devices should respect logical device pausing. 2023-07-30 11:55:59 -04:00
Ryan C. Gordon 7e700531c5
audio: Allow SDL_OpenAudioDevice to accept a NULL spec.
This means "I don't care what format I get at all" and will just use
the device's current (and/or default) format.

This can be useful, since audio streams cover the differences anyhow.
2023-07-30 11:55:59 -04:00
Ryan C. Gordon bb1cbbd33a
test: Update testaudioinfo for SDL3 audio API. 2023-07-30 11:55:58 -04:00
Ryan C. Gordon 883aee32c5
audio: Let default formats differ for output and capture devices. 2023-07-30 11:55:58 -04:00
Ryan C. Gordon 62cf24eeb9
pulseaudio: Listen for server events in addition to sources and sinks.
This gets us default device change notifications more efficiently, presumably.
2023-07-30 11:55:58 -04:00
Ryan C. Gordon 924f370bd7
pulseaudio: Fix deadlock in HotplugThread.
If we wait for context subscription to finish, we might miss the signal
telling us to terminate the thread...this can happen if an app initializes
the audio subsystem and then quits immediately.

So just go right into the main loop of the thread; the subscription will
finish when it finishes and then events will flow.
2023-07-30 11:55:58 -04:00
Ryan C. Gordon 5d4e9e5f80
test: Updated testaudiostreamdynamicresample to SDL3 audio API. 2023-07-30 11:55:58 -04:00
Ryan C. Gordon f883b9fc64
test: Updated testaudiohotplug to SDL3 audio API. 2023-07-30 11:55:57 -04:00
Ryan C. Gordon 2be5f726d4
audio: Removed debug logging. 2023-07-30 11:55:57 -04:00
Ryan C. Gordon 323ecce123
docs: Added migration note about SDL_AUDIODEVICEREMOVED. 2023-07-30 11:55:57 -04:00
Ryan C. Gordon 47b0321ebf
test: Removed loopwavequeue.c; obsolete in SDL3. 2023-07-30 11:55:57 -04:00
Ryan C. Gordon 0e5a1d4f29
pulseaudio: Removed debug logging. 2023-07-30 11:55:57 -04:00
Ryan C. Gordon f598626e46
test: loopwave shouldn't use an audiostream callback. 2023-07-30 11:55:56 -04:00
Ryan C. Gordon eee407caf8
docs: migration guide note that SDL_LoadWAV has a different return type. 2023-07-30 11:55:56 -04:00
Ryan C. Gordon b03c493fc4
test: Updated testmultiaudio to new SDL3 audio API 2023-07-30 11:55:56 -04:00
Ryan C. Gordon fe1daf6fb5
audio: Mark disconnected default devices as "zombies".
Zombie devices just sit there doing nothing until a new default device
is chosen, and then they migrate all their logical devices before being
destroyed.

This lets the system deal with the likely outcome of a USB headset being
the default audio device, and when its cable is yanked out, the backend
will likely announce this _before_ it chooses a new default (or, perhaps,
the only device in the system got yanked out and there _isn't_ a new
default to be had until the user plugs the cable back in).

This lets the audio device hold on without disturbing the app until it can
seamlessly migrate audio, and it also means the backend does not have to
be careful in how it announces device events, since SDL will manage the
time between a device loss and its replacement.

Note that this _only_ applies to things opened as the default device
(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, etc). If those USB headphones are the
default, and one SDL_OpenAudioDevice() call asked for them specifically and
the other just said "give me the system default," the explicitly requested
open will get a device-lost notification immediately. The other open will
live on as a zombie until it can migrate to the new default.

This drops the complexity of the PulseAudio hotplug thread dramatically,
back to what it was previously, since it no longer needs to fight against
Pulse's asychronous nature, but just report device disconnects and new
default choices as they arrive.

loopwave has been updated to not check for device removals anymore; since
it opens the default device, this is now managed for it; it no longer
needs to close and reopen a device, and as far as it knows, the device
is never lost in the first place.
2023-07-30 11:55:56 -04:00
Ryan C. Gordon cdd2ba81de
audio: Fixed adding new physical devices to a double-linked list.
(Forgot to hook up existing node's `prev` field when adding the new device
to the head of the list. Doh.)
2023-07-30 11:55:55 -04:00
Ryan C. Gordon db39cbf208
audio: Allow SDL_GetAudioDeviceFormat() to query the default devices.
Officially removed SDL_GetDefaultAudioInfo(), as its functionality that
isn't obsolete is now offered elsewhere.
2023-07-30 11:55:55 -04:00
Ryan C. Gordon ee10bab3cd
audio: An enormous amount of work on managing default devices. 2023-07-30 11:55:55 -04:00
Ryan C. Gordon c7a44eea83
audio: Fixed logic error. 2023-07-30 11:55:55 -04:00
Ryan C. Gordon 089cd87cb5
audio: Make sure device count stays correct as hardware disconnects. 2023-07-30 11:55:54 -04:00
Ryan C. Gordon e50cb72eb6
docs: Note that audio opening doesn't implicitly init SDL now. 2023-07-30 11:55:54 -04:00
Ryan C. Gordon 97b2f747d0
docs: Corrections to audio section of README-migration.md 2023-07-30 11:55:54 -04:00
Ryan C. Gordon 464640440f
audio: Added SDL_GetAudioStreamBinding.
Now you can open a device, bind a stream, and forget about the device ID
until you're ready to shutdown, where you can query the stream for it.
2023-07-30 11:55:54 -04:00
Ryan C. Gordon 01f7b53865
audio: Readded (logical) device pausing. 2023-07-30 11:55:53 -04:00
Ryan C. Gordon fd4c9f4e11
audio: documentation improvements. 2023-07-30 11:55:53 -04:00
Ryan C. Gordon 4b78b789a7
audio: Switch SDL_audio.c and SDL_audiocvt.c to C99-ish syntax.
These files are completely different from SDL2, and no clean merging
is likely to happen there anyhow, so there's really no harm in just
switching them over completely to SDL3's new policy of allowing `//`
comments and mixed variable declarations.

Feels deeply sacrilegious, though.
2023-07-30 11:55:53 -04:00
Ryan C. Gordon d96a1db7d7
audio: Opening via a logical device ID should also track default device.
As these will change devices as the default device changes, in the future,
we would want the original and new logical device to stay together.
2023-07-30 11:55:53 -04:00
Ryan C. Gordon b2e020958f
audio: Wrap device access in opening of logical devices.
Now you open an audio device and attach streams, as planned, but each
open generates a new logical device. Each logical device has its own
streams that are managed as a group, but all streams on all logical
devices are mixed into a single buffer for a single OS-level open of
the physical device.

This allows multiple opens of a device that won't interfere with each
other and also clean up just what the opener assigned to their logical
device, so all their streams will go away on close but other opens will
continue to mix as they were.

More or less, this makes things work as expected at the app level, but
also gives them the power to group audio streams, and (once added) pause
them all at once, etc.
2023-07-30 11:55:53 -04:00
Ryan C. Gordon 7ee2459927
audio: Check for unlikely failure case in WAV loaded.
I don't think this can fail at the moment, but if WaveCheckFormat goes
out of sync with this switch statement at some point, this seems like
a good failsafe.
2023-07-30 11:55:52 -04:00
Ryan C. Gordon 3d65a2cefe
audio: Made SDL_LoadWAV a real function, not just a macro. 2023-07-30 11:55:52 -04:00
Ryan C. Gordon 26525f5fd3
audio: Readd SDL_AudioSpec, but just with format/channels/freq fields. 2023-07-30 11:55:52 -04:00
Ryan C. Gordon e6aaed7d79
include: Audio is not, and has not been, a raw mixing buffer for a long time. 2023-07-30 11:55:52 -04:00
Ryan C. Gordon 56b1bc2198
audio: SDL_AudioStream now has callbacks for Get and Put operations.
This allows code to feed a stream (or feed from a stream) on-demand,
which is to say: it can efficiently simulate the SDL2 audio callback.
2023-07-30 11:55:51 -04:00