Commit Graph

11 Commits

Author SHA1 Message Date
Jonathan Gamble
d821508775 LibMedia: Fix byte/frame mismatch in conversion to buffer size
Note that `pa_buffer_attr.tlength` is in bytes, not frames (see
`/usr/include/pulse/def.h`). I think the previous code asked for a
buffer that is 1/8 what the latency calculation wants (for float32
stereo), resulting in too frequent write callbacks, higher wakeup/CPU
churn, higher risk of crackles under load.
2026-01-17 02:20:20 -06:00
Zaggy1024
c75284591f LibMedia: Make PlaybackStream use the output's sample specification
Instead of specifying the sample rate, channel count/map, etc. to the
PlaybackStream, we'll now use the output device's sample specification
whenever possible. If necessary, the stream will fall back to sane
default.

This hugely simplifies AudioMixingSink, since it no longer has to take
care of reinitializing the stream with a new sample specification when
it encounters a track with a higher sample rate or more channels. We
wouldn't be likely to benefit from this anyway, since it turns out that
at least Windows's virtual surround doesn't work through WASAPI at all,
and WASAPI likely wouldn't support downmixing.

This commit breaks playback of audio files that don't match the system
default audio device's sample rate and channel count. The next commit
introduces a converter into the pipeline to allow mixing of any sample
specification.
2025-12-13 08:58:26 +01:00
Zaggy1024
5c9a34d84a LibMedia: Only use floats for audio data callbacks
We were already assuming that our streams were using floats, we may as
well hardcode this. If we ever encounter a platform API that doesn't
support or convert from float, we can always bring this back.

Also, since we don't support big-endian systems, remove that check in
PulseAudioWrappers.
2025-12-13 08:58:26 +01:00
Zaggy1024
fab987d937 LibMedia: Ensure that PulseAudioContext's atexit() is only called once 2025-11-24 15:09:34 -06:00
Zaggy1024
13cf0e72d8 LibMedia: Stop using threading-unsafe Weakable for PulseAudioContext
We can't control whether the instantiation mutex is held when
~Weakable() is called, so we need to implement this via a static raw
pointer instead to ensure that all operations on it are effectively
atomic.
2025-11-24 15:09:34 -06:00
Zaggy1024
3e485ba51c LibMedia: Move the PulseAudioStream constructor out of line 2025-11-24 15:09:34 -06:00
Zaggy1024
2c73848f78 LibMedia: Remove an explicit cast when constructing PulseAudioStream 2025-11-24 15:09:34 -06:00
Zaggy1024
b8bc129a3c LibMedia: Rename PulseAudioContext::instance() to the() 2025-11-24 15:09:34 -06:00
Zaggy1024
27742ef26d LibMedia+LibWeb: Never return errors when getting PlaybackStream time
We should be fine to just fall back to zero or the last returned value
if we encounter an error in PlaybackStream::total_time_played(), and
this also simplifies the using code.
2025-10-27 17:28:49 -07:00
Zaggy1024
7811c2e71b LibMedia: Ensure that the PulseAudioContext atexit() call succeeds 2025-09-04 19:37:56 +02:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00