Accept input-rate metadata changes when audio is deliberately disabled or uses the null backend and no device or resampler exists. This avoids rebuilding recording scratch and resynchronizing video for timing-only AV-info updates. Keep failed real backends on the reinitialization path.
Cover idle metadata, failed-backend recovery and scratch retention through real AV-info calls with threaded video on and off.
The looped WaveRT path already lent its ring. A packet pin now has the
frontend produce straight into the packet it sends, instead of into its
own buffer and copying it in.
A bypassed resample of a core's extra channels copied the input into
the output scratch only for the merge to read it there. Same format, so
the merge now borrows the input.
The Win64 build's -Wshorten-64-to-32 narrowings are made explicit where
the value is bounded: socket()/accept() handles kept as RetroArch's int
descriptors, ai_addrlen passed as socklen_t, UDP and pipe lengths,
COM/D3D counts and shader frame counters, WASAPI/XAudio2 buffer sizes.
net_socket clamps each send/recv to Winsock's int count on _WIN32 and
lets the existing loops move the rest; the remote-input descriptors are
plain ints on every platform, as socket_init returns them.
xaudio29.h declares its interfaces through a macro that, in C, leaves
out DECLARE_INTERFACE's second typedef of the forward-declared names.
The narrowings the Linux build reports under -Wshorten-64-to-32 are
made explicit where the value is bounded (read() returns into small
buffers, X11 property lengths, statestream index counts, clamped H.265
weights, VP9 transform outputs), and the joypad scan loops count with
the unsigned index their callees take. gl1 sizes its readback with
VIDEO_SCALE_AREA directly, and rdds' swap is three statements.
The VP9 casts sit only on the stores into the rvp9_tran output arrays,
so the decoder's object code stays instruction-identical under gcc and
clang.
Add borrowed ASF and RIFF/xWMA streams with bounded fragment assembly. Drain decoder planes directly into audio_transfer output and reuse the mixer's streaming voices. Route music input through VFS-backed moving windows.
The builtin player uses source-rate integer intervals, float callbacks when supported and a legacy S16 fallback. Respect partial callback acceptance and reset without retaining a growing output queue. Gate the feature with HAVE_RWMA, disabled by default, and preserve FFmpeg/MPV selection.
Test analytic PCM, packet fragments and refill, loop reset, implicit xWMA setup, truncated objects, sample-rate cadence, callback backpressure and codec-disabled builds.
RetroFW's jz4760 OSS driver moves a node to the codec in 16-byte DMA
units: it drops a write's remainder, and a write under one unit starts
a transfer of none. The threaded pipeline writes any number of frames,
so most writes lost one to three frames - static at its rate of writes -
and a short one could leave the device playing nothing it was given.
On RetroFW a write now goes out in whole units, its remainder held to
lead the next one.
samples/audio/oss_report models that DMA; built with RETROFW=1, which
CI now does, it checks every node is whole units and plays in order.
Fixes#20006
On the threaded pipeline audio_driver_pause_fade() armed the resume
ramp by writing fade_in_pending, a plain bool, on the main thread, and
the producer read and cleared it in audio_driver_submit_width() - on
the thread that submits, which for a core delivering from a thread of
its own is not the main thread. A data race; a resume could also lose
its ramp if the clear landed after a new arm.
fade_in_pending is now a retro_atomic_int_t. The main thread stores it;
whoever applies the ramp takes it with fetch-and against zero
(audio_driver_fade_take(); exchange is not on every retro_atomic.h
backend), in the producer and in audio_driver_arm_resume(). No lock,
and nothing waits.
ff_speedup gains a lane with the producer on a thread of its own while
the main thread ends frames, holds and releases fast-forward and
pauses, the consumer's share taken on the main thread. Under
ThreadSanitizer, which CI already runs ff_speedup with, it reported
this race and nothing else after the fast-forward measurement fix
(e24dafdc), and reports none now. The harness clock can run on real
time for a case with threads.
Three copies on the flush path that the next pass overwrote:
- Integer front pair at unity to an s16 device with a master gain:
the batch was copied into the output scratch, then the gain ran over
it in place. The gain now reads the batch and writes the scratch, one
pass (audio_driver_gain_s16(), the same Q16 multiply).
- In-process MIDI synth on the integer path: the game audio was copied
into the writable view, then the synth summed into it. The sum is now
written from the game audio, one pass, and a synth that rendered
nothing leaves the batch where it is, uncopied.
- In-process MIDI synth for a float core: copied in, then summed. The
sum is written in the pass that brings the audio in. The synth renders
before the path is chosen, so one that has nothing this batch no
longer forces an s16 core off its passthrough through two conversions.
Output is unchanged sample for sample. Measured on 800-frame stereo
batches: the float synth sum 167 -> 132 ns per batch; the s16 gain
saves the 23 ns copy, about 0.5% of that pass; a silent synth saves the
copy and, on the float path, an s16 -> float -> s16 round trip.
unity_identity gains lanes: the integer gain at an attenuation and at a
saturating boost against the Q16 oracle; the synth sum on the integer
pair and for a float core against what the copy and the add gave; and
a silent synth leaving the batch on its passthrough, which on the float
path failed before (one s16 -> float and one float -> s16 conversion).
The shared stubs' synth is replaced there by one the cases control.
The fast-forward speed measurement (last_flush_time and its two
averages) is taken by one thread: the submitter on the inline
pipeline, the main thread's frame end on the threaded pipeline and for
a callback core. Other threads wrote it too. Inline, the main thread's
frame end, pause and stop reset it while a core submitting from a
thread of its own was measuring. A callback core's audio thread reset
it beside the main thread's frame-end measurement. On the threaded
pipeline the producer read and reset it, and pipe_ff_frames was a
plain size_t added on the submitting thread and zeroed on the main one.
These are data races, and on 32-bit targets a 64-bit store can tear.
Now only the measuring thread writes the measurement. Any other thread
asks: one flag, stored only when not already up, which the measuring
thread takes before it next measures (audio_driver_ff_mult_sync(),
taken with fetch-and since exchange is not on every retro_atomic.h
backend). An idle frame costs one load. pipe_ff_frames is atomic: added
by the submitter, taken by what is there at the frame end, never stored
to zero. The producer knows the first frame of a hold from a flag of its
own instead of reading the main thread's measurement. A flush outside
fast-forward on the measuring thread still resets outright, which the
inline transport's source stamp overwrites as before.
This replaces the request-handler resets added for pause_fade in
0e35c138 with the same ask every other thread uses.
discrete_multichannel gains a lane with a core submitting from a
thread of its own while the main thread ends frames, holds and releases
fast-forward and pauses. Under ThreadSanitizer it reported nine races
on last_flush_time and pipe_ff_frames on the old code and none now; the
CI step builds it with TSan and runs that lane. Checks that read the
measurement straight after another thread's reset now accept the
pending ask.
audio_driver_pause_fade() reset the fast-forward flush measurement on
the main thread. That is right where the measurement is taken there:
the threaded pipeline's producer and a callback core measure at the
frame end. Inline, the thread that submits measures, and a core may
submit from a thread of its own; the main thread's reset then wrote
last_flush_time beside that thread's read-modify-write of it, a 64-bit
store that can tear on 32-bit targets.
Inline, the reset now rides the pause and resume requests pause_fade
already posts, applied by the submitter under the inline claim before
its next flush measures. The main thread resets only for the threaded
pipeline and callback cores, and always without HAVE_THREADS.
The ff_speedup and discrete_multichannel pause lanes pass unchanged.
A stall inside a fast-forward hold was measured as one long flush
interval, and a long enough one pushed the speed estimate past the time
stretch's duration range. The stretch then stayed off for the rest of
the hold: the threaded transport suspends and resumes only from a
drained ring, which fast-forward keeps full; and with Speedup off the
inline flush put back the stamp from before the interval, so every
later flush measured from it.
An interval longer than the average's whole window at 1x
(AUDIO_FF_EXP_AVG_SAMPLES expected intervals) is now a gap, not a speed:
the estimate seeds again at the configured ratio, as after a pause.
Shorter intervals are still measured. One of them can take the estimate
of a hold running at 1x or faster down to about half speed at most,
inside the stretch's range, and any single interval that could push it
out is a gap. The inline, threaded and callback-core paths share the
measurement.
Inline, the stamp is put back only for the Speedup fallback, which may
measure the interval again. Put back otherwise, it stays stale until it
ages into a gap.
The ff_speedup and discrete_multichannel harnesses stall a 2x hold for
three seconds, threaded with and without Speedup, and inline. Inline, a
slow spell of intervals under a gap also takes the estimate out of
range, and the stretch has to be back within a few frames of the hold
returning to 2x. pipeline_wakeups gains a lane on the real wrapper
without Audio Sync, where the consumer primes again after the stall; it
checks that the hold's audio and the stretch come back. The native
transport CI job runs it, also under ThreadSanitizer.
A pause inside a fast-forward hold left the flush timestamp from before
it, so the first flush after the resume measured the whole pause as one
interval. The speed estimate then read the core several times slower
than real time, outside the time stretch's duration range, and the
stretch stayed off until fast-forward was released; inline, only with
Speedup off.
Reset the measurement in audio_driver_pause_fade(), on the main thread
as the frame end resets it. Every pause and resume goes through it, and
so do the jump fades of a state load or core reset, where the reseed is
harmless. The next flush seeds the estimate at the configured ratio, as
the start of a hold does.
The ff_speedup and discrete_multichannel harnesses pause a 2x hold for
125 ms, threaded and inline, and check that the speed estimate and the
stretch hold through it.
free() returned when SNDCTL_DSP_RESET failed, which is what a device
that has gone away does, leaking the descriptor, the stage and the
driver. The reset is now best-effort and the device is closed and
freed either way.
samples/audio/oss_report wraps close and frees a heap driver whose
reset fails; LeakSanitizer in the CI lane catches the old early return.
RetroFW's jz4760 OSS driver has no poll method, so select() reports the
descriptor ready at once whether or not a fragment is free. Eight wakes
without room now latch that: from then on wait_writable() claims the
room and the blocking write sleeps in the driver on its fragment-done
interrupt, rather than handing back 0 for the audio thread to ask again
at once - at real-time priority on a single core, nothing else ran.
A non-blocking descriptor claims nothing. Logged once at teardown.
samples/audio/oss_report models that driver with wrapped ioctl, select
and write: a full poll-less device hands every pass to the write, and a
device whose select() does wait still skips the pass.
Fixes#20006
The test took 49 s, nearly all of it in two places that test nothing:
- each of the hundreds of audio re-inits built the sinc resampler's
tables from scratch;
- eight scheduler cases call a consumer pass with nothing queued,
which waits out the frontend's one-second idle bound each time.
The driver's resamplers now come from a cache in the test: one parent
per configuration, kept for the run, and the driver gets a sibling of
it -- its own fresh stream over the parent's tables, freed as usual. A
backend without siblings is made the usual way. And the test sets the
idle bound to 20 ms, far past anything a case waits for; the driver
keeps its one second unless a build defines AUDIO_PIPE_WAIT_MAX_US.
49 -> 12 s, 20 s under ASan and UBSan, every case passing.
A flush into a lent span fills it straight from the resampler only as
far as fit() says is sure to fit; without one it sizes from the ratio's
bound, which leaves a few frames of the span to the copy at the wrap.
Only sinc had a fit.
Both now run process()'s own clock without the samples: nearest steps
its fraction, CC its distance, in the same float operations, so the
answer is exact. Every CC arm, C, SSE and NEON, moves distance the
same way, so one model covers them; a CC stream made for downsampling
and run above a ratio of one is moved to the upsampler from its start,
as process() does. Builds whose float arithmetic is not repeatable --
x87 extended precision, fast-math -- and the PSP's VFPU arm have no
fit and keep the bound.
lend_write's fit case now runs all three backends, nearest and CC made
at one ratio and run at eight others, and also asks before any input
has been processed: 2296 fits exact. Mutations of each fit's step,
threshold and the CC switch are each caught.
The flush in parts left one copy at the driver's wrap: the input given
to the first span was sized from the output bound, which keeps a margin
of sixteen frames and one more over the ratio, so the resampler's
output fell some twenty-five frames short of the span and that sliver
was filled from the frontend's buffer.
The sinc resampler can say exactly what the next process() makes of
each input frame: a frame is pushed while the phase clock is a phase
or more, a frame comes out at each step of the integer ratio until it
is again, and nothing else enters into it on the nominal path. The
resampler interface gains an optional fit(): the most input frames
whose process() is sure to produce no more than the frames asked for,
exact for the stream's state where the backend can tell, 0 where it
cannot (the decimated fast-forward path, or a backend without one, and
the caller sizes from the bound as before). The flush sizes the first
span's input from it, so the span is filled to within the frames one
input frame makes - a frame or two at 1.5x, often none at all - and the
copy left at the wrap is that or nothing. The bypass fills its span
exactly as it is, a frame in being a frame out.
retro_resampler_t's new member is last, so a backend that does not set
it is NULL there; libretro-common is RetroArch's, for the cores to
sync.
lend_write_test checks the fit is exact: for every quality, with and
without HQ oversampling, at ratios above and below one, after runs
that leave the stream at any state, the input fit() names makes no
more than asked and one frame more makes more. Off by one either way
it fails; a fit that overshoots also publishes past the span, which
the device stand-in refuses.
Where the driver's ring wrapped inside a flush, a float stereo device
still took that flush the old way: the lend came back short and was
abandoned, the resampler wrote the frontend's buffer, and write()
copied every frame into the ring - about one flush in sixteen on a
typical ring, and the last copy the lend left on that path.
The flush now runs its output stage in parts. The resampler is given
as much input as is sure to fit the short span (audio_driver_input_
bound), writes it there carrying its state, and the span is published.
Its output falls a little short of the bound, so a sliver of a few
frames is left before the wrap: enough input to fill it is produced in
the frontend's buffer, the sliver copied from there - the one small
copy left - and the frames over are carried to the head of the next
span, where the rest of the flush is produced past the wrap. The
mixer, the clamp, the resume ramp and the pause mute run on each part
in turn, each carrying its state, so the stream is the one the whole
flush made: the lend test compares it bit for bit. The bypass's copy
splits the same way. An int16 device keeps narrowing into its spans
on the way out; a device that lends nothing, or no room after a
bounded wait, takes the staged write as before.
The produce, the finish and the sink accounting are their own
functions now, run once per part; audio_driver_input_bound() is built
for every configuration.
lend_write_test's rings wrap 1000 frames into a 1200-frame flush, and
one wraps twice: a float stereo device resampled or at unity, threaded
and inline, must give the written stream bit for bit with write()
never called. A ring that cuts a frame at its end still sends what is
left through write(). Dropping the carry, not shifting it, or letting
the fit overshoot the span each fail it.
A lend asks the driver for one span to hold a whole flush. Where the
driver's ring wraps inside it the span comes back short, the lend is
abandoned, and the flush is produced in the frontend's buffers and
copied in by write() - about one flush in sixteen on a typical ring.
The resampler's output cannot be split there, but every stage after it
makes the device's frames one at a time, its state carried from call
to call: the narrowing of a float mix for an int16 stereo device, the
upmix for a wider one (int16, float, or float narrowed for an int16
device, the core's own surround channels merged over it), and the
binaural render on headphones. audio_driver_stage_spans() runs such a
stage into as many spans as the driver lends - both sides of the wrap
- in whole frames; audio_driver_stage_write() takes the rest, a frame
the wrap would cut or what has no room, into the stage's own buffer at
the offset the whole would have had, so a short threaded write's tail
is still where audio_driver_retain_output() looks for it, and writes
it. The upmix and binaural lend, which took one span or none, is this
now; a float stereo device's resampler output still goes through
write() at the wrap. The extras merge takes the first frame of the
span it works on.
lend_write_test gains a device whose ring wraps inside the span, of
whole frames and of a size that cuts a frame at its end: int16 and
float stereo, 5.1 float and int16, headphones float and int16, a core
sending its own 5.1, threaded and inline. Each stream must equal the
written one bit for bit, with write() never called where the ring
holds whole frames. On the previous audio_driver.c those cases call
write(); a merge that ignores the span's first frame fails the 5.1
core's.
Every microphone flush ended the same way: its last stage - the
narrowing of float samples, or the left channel of the integer
resampler's stereo - produced the samples in final_frames, and
retro_spsc_write() then copied them into the ring the core reads.
microphone_enqueue() takes the ring's span at the head, in the one
span or two its wrap leaves, and has the stage write the samples
there: the float fast path, the integer resampler's left channel and
the float resampler's narrowing all reach the ring without the stop in
between. final_frames is gone from the arena and from
microphone_driver_state_t; the resampler's output bound is the smaller
of the two buffers still on the way. An int16 device at its rate keeps
its single copy, from what the driver read.
The copy it saves on an 800-sample flush, a 60 Hz frame at 48 kHz:
0.03 us, and an intermediate buffer of the largest flush.
mic_handshake_test gains a lane that puts the ring's head at every
place it can be and enqueues runs of every length up to the whole
ring, with both fills: the ring must hold exactly what the stage used
to produce on its own, and report the samples it took. Writing only
the first span, or taking the right channel, fails it.
The lend of the driver's buffer stopped at stereo: on a wider device
the upmix produced the device frames in upmix_buf (upmix_i16 for an
int16 device) and write() copied them into the driver's buffer, and
with Headphone Virtual Surround on the binaural render did the same
into its own two-channel buffer.
audio_driver_write_frames() now borrows the span for the frames the
widening stage is about to produce - the upmix, its int16 form, the
narrowing of a float mix for an int16 device, or the binaural render -
and has the stage write them there, the core's own surround channels
merged in place as before, then publishes them. Inline and blocking it
waits for the room first, as write() would have; a span cut short, or
no room after the wait, leaves the stage writing its own buffer and
write() taking it as it always has.
The copy it saves, each 60 Hz flush into a 64 ms device: 0.28 us for
5.1 float, 0.13 us for 5.1 int16, 0.09 / 0.05 us on headphones - and
the pass over the stage's own buffer before it.
lend_write_test runs a 5.1 device and Headphone Virtual Surround,
float and int16, resampled and rate-matched, threaded and inline,
checks the stage under test is the one running, and compares the lent
stream bit for bit with the written one: write() is never called,
and a driver cutting spans short still gets the same stream through
write(). On the previous audio_driver.c the wider cases each call
write().
The XAudio2 driver had no write_begin / write_end, so every flush's
output was produced in the frontend's own buffer and then copied by
xa_write() into the buffers XAudio2 plays - the copy WASAPI, DirectSound
and the other lending drivers no longer make.
The driver's sixteen buffers are cut from one allocation, so the free
ones after the head are one span up to the allocation's end.
xa_write_begin() lends that span, never more than the free room, and
xa_write_end() moves the head over what was published, submitting each
buffer it fills. The span stops where the free room does, so every
buffer it fills has a slot and write_end never waits. A span cut short
at the allocation's end leaves the frontend's staged write to wrap, as
for the other drivers. The submit is shared with xa_write().
samples/audio/xaudio_lend runs the shipping driver on wine's XAudio2
(Windows' own on Windows): lends stay within the free room and the
allocation, lends and writes make one stream, write_end publishes all
it is given at once even filling the whole room, an abandoned lend
takes nothing, and lent audio plays at the pace written audio does.
Lending past the room hangs it; a write_end that does not move the
head fails it. Linux-samples-audio runs it.
The inline pipeline's lend of the driver's buffer sizes what it borrows
with audio_driver_output_bound(), which was defined only with
HAVE_THREADS (or the harness's AUDIO_OUTPUT_BOUND_CHECK): a build
without threads stopped at audio_driver.c on an implicit declaration,
caught by the compile matrix's no-threads lanes. The bound is defined
for every build now; its inverse, which only the threaded pipe uses,
stays behind the guard.
With the threaded pipeline off, the flush always resampled into
output_samples_buf (or narrowed into output_samples_int16) and write()
then copied the whole chunk into the driver's ring, even though every
driver with a ring in front of the device - pulse, pipewire, alsa,
coreaudio, wasapi, sdl2, aaudio, opensl, jack, dsound, wdmks - lends
that ring through write_begin/write_end. Only the threaded consumer
took the lend.
The inline flush now takes it as well. A blocking device is first
waited on for the chunk's room through wait_writable(), the wait
write() would otherwise have made piece by piece. When the driver
cannot lend the whole chunk - the span is cut short by the ring's
wrap, or the bounded wait found too little room - the lend is
abandoned and the staged write runs and blocks as before. That saves
one copy of each flush's output, about 6.4 KB a frame for float
stereo at 48 kHz and 60 fps; the resampler still dominates the
flush's cost.
The lend write sample runs its four cases inline as well: the lent
stream is bit for bit the written one, write() is not called for a
resampled chunk, and every begin is balanced by an end.
In thread_video_t the main thread's per-push writes shared cache lines
with fields the video thread writes every frame: core_time with
miss_run, drain_cooldown and drain_pending; last_time with the lent
slots' busy flags; the handoff counts and the published pacing values
with repeat_request, repeat_group and margin_extra_us. In
audio_driver_state_t the pipe's consumer (pipe_gen, pipe_stalled, the
underrun and priming state, the source wait counts) and producer
(pipe_data_gen, the runloop snapshot, pipe_ctrl_avail, writer_held,
the fast-forward multiplier) were interleaved over the same four
lines. Each write by one thread took the line back from the other.
The main thread's fields now sit together behind a line of padding,
with the values it publishes on a line of their own, the way the
struct already separates its other shared fields. The audio pipe's
consumer and producer fields form two groups, each between full lines
of padding, under a new AUDIO_PIPE_LINE. A full line on each side
keeps the separation wherever the fields land, without relying on
the allocation's alignment. It costs 184 bytes in thread_video_t and
192 in audio_driver_state_t.
The threaded video sample's line separation lane and the audio
pipeline wakeups sample assert the new separations by offset, so a
field added above a pad cannot quietly put them back on one line.
A core with an audio callback runs behind the threaded wrapper, which
keeps the device blocking whatever the menu asks. At Menu Frame Rate
'Display Rate' the menu feeds silence by the clock, so it now writes
only what the device takes without waiting, keeping half its buffer,
and does not make up time the device could not take. The recording
still receives every frame. The menu runs at the display's rate behind
such cores again.
samples/audio/menu_callback_feed holds the feed against a device that
counts every write that would have blocked.
Fixes#19971
A kept device that does not match the next core's settings - a core
override of the audio latency, say - is closed before the pipeline is
rebuilt and before the next device opens, so it is released when the
next one may want the same device.
The threaded wrapper freed while parked now leaves from the park: it
no longer starts the device and runs one consumer pass on whatever
pipeline is current, nor reports a departed consumer or wakes it.
alive is published before the release from the park so the thread
sees it on the way out. Lane: pipeline_wakeups KEPT_DROP.
A callback may still be inside after ASIOStop, so teardown and the
reclaim of a parked instance waited for the in-callback count to reach
zero by yielding and then sleeping a millisecond at a time. The last
callback out now notifies an eventcount and the wait parks on it; the
200 ms deadline remains only for a driver whose callback never returns.
The eventcount is built for Win32 ASIO builds without threads too, as
it already is for DirectSound, XAudio and waveOut: the callback runs on
the driver's thread either way, so the write's park no longer falls
back to Sleep(1).
samples/audio/asio_teardown runs the driver's count and wait, pulled
out of asio.c, under TSan, ASan and wine; a build whose last callback
does not notify fails.
A resume fills the drained device with silence before the core's first
audio. With a blocking writer it now fills only to rate control's
setpoint, half the buffer, instead of to full, where the writes after it
waited for the surplus to play out: a hitch of a frame or more on every
return from the menu, a state load or any other jump, which a VRR display
shows. A non-blocking writer keeps the full top-up as its cushion.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LBQPGeAnyXTjoifK18NSfm
Leaving fast-forward drops what it left in the threaded pipeline's ring
behind a jump fade, and the device's writer drops core audio until the
device has played down to rate control's setpoint, so a blocking writer
is no longer held for as long as the queue takes to play out. That held
the core in device-period steps for seconds after every fast-forward,
which a VRR display shows as judder until the menu is toggled (#19940),
and cost every other configuration a hitch on exit. The five-frame
non-blocking window Sync to Exact Content Framerate used for this is
removed; it never drained the queue.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LBQPGeAnyXTjoifK18NSfm
The driver stage of a staged content load leaves the audio driver out
when its init would open the same device the same way for the next
core - same driver, device, output rate, latency, resampler and
threading, no DSP filter, time stretch or core audio callback, and the
core's float and multi-channel entries as they were. The device,
pipeline and mixer keep running through the rebuild of the rest; once
the video driver has settled the rates, the new core's rate is set in
place and the stream reset a core swap needs is done. When the rate
cannot be taken in place, the driver is opened again, the device kept
across as before. The driver lookup of the stage leaves a carried
driver's table alone.
The content_load harness's close keeps its tone playing with the
device never stopped, and a load with time stretch on sets the device
aside and takes it back.
The system sounds are loaded again after every driver stage. A slot
that already holds the sound from the same file now keeps it, and a
callback the load would have run - the menu music's play - runs on the
kept one; a slot the mixer lost loads again. A content load or a
driver reinit no longer cuts a menu sound that is playing over it, nor
restarts the menu music.
The content_load harness finds its tone where an install keeps its
sounds and loads it through the system sounds, so the reload at the
end of a confirmed Close Content runs against the sound playing over
it.
The wide-frame renders count the extra positions while filling their
slot table, from the bits the frame carries, so the copy loops never
read a slot the table does not hold. This clears GCC's
-Wmaybe-uninitialized on the pipeline render; the inline transport
takes the same shape.
audio_driver_set_core_float() decides a source format change at once
and hands it to the threaded pipeline's consumer as a request word, to
install before its next pass; the producer writes nothing into the ring
until it has. A populated ring keeps its native format, as before, and
the producer converts its writes meanwhile. The stage a running or
suspended transport needs in the new format is made by the producer and
the old one handed back to it to free; one that cannot be made drops
the transport, keeping the new source native.
That was the last control to park the audio thread, so
audio_thread_apply_control() goes. Harnesses that parked the consumer
to look at its state stop and start the wrapper instead, and
thread_handshake checks audio_thread_parked() across its round trips.
pipeline_format hands its format change to a consumer pass and checks
nothing takes effect before it.
Suspending, resuming, preparing and releasing the pitch-preserving
transport are decided on the producer's side, which keeps the transport
as it has decided it in pipe_transport_mode, and handed to the
consumer as a request word to install before its next pass. Nothing
waits and the device keeps running, so the speed changes that switch
the transport on and off no longer stop and start it.
The producer keeps writing meanwhile: the source in the ring is the
same whichever consumer takes it. A resume or a prepare still wants the
source drained, and puts its processing request into the metadata queue
behind what is already there rather than resetting the queue; the
consumer leaves it for a later pass while a short device write is
still to finish. A prepared stage is made by the producer, and the
replaced or released ones are handed back to it to free. With the
consumer parked the change is carried out in place, as before.
pipeline_wakeups' automatic transport lane checks the device is not
stopped across the suspension and the recovery.
audio_driver_set_input_rate() decides the change on the calling thread
and hands it to the threaded pipeline's consumer as a request word, as
the pause requests are, to install before its next pass. Until it has,
the producer writes nothing into the ring, so the ring, the slice and
the ratio are the consumer's alone and neither thread waits on the
other; the device is no longer stopped and started for it. With the
consumer parked, or gone, the caller installs the change itself.
A ring that has to grow is made by the caller and moved into by the
consumer with retro_spsc_grow_into(), which allocates nothing; the old
buffer and resamplers come back to the caller to free with the next
change or at teardown. The extra lanes of a multichannel core, which
used to refuse the change, are dropped with the front pair they share
tables with and remade at the new ratio by the next pass.
pipeline_rate_change hands each threaded change to a consumer pass and
checks nothing takes effect before it; pipeline_wakeups' kept-device
lane changes the rate under the real wrapper with the device running;
discrete_multichannel changes it with the extra lanes up; retro_spsc
moves a ring into a caller's buffer.
Without the threaded pipeline, the thread that submits the core's audio
holds the inline state: a submit takes inline_busy with a compare-and-
swap and records itself as the owner. The main thread's pause, resume,
format change and stop reset are published as request words, as the
threaded pipeline's already are, and carried out by that thread at its
next submit - before its gates, so a silenced core's thread writes its
pause tail - or at once by the main thread when it is the submitter, or
nothing has submitted yet. A callback core's thread settles them in its
loop. A submit that finds the main thread carrying a request out drops
its batch rather than wait. The core format the mixer follows is
published by the flush. audio_driver_sample_batch grows by the call
that settles requests on the submitting thread, and its hot-function
reference moves with it.
With that, every holder of the state lock is a pass that no other runs
beside, and the lock is only made where the atomics have no pointer
operations; elsewhere audio_driver_state_lock() counts the pass and
nothing more.
ff_speedup pauses a core that submits from its own thread and checks
the main thread writes no tail and that thread writes it at its next
submit.
With the threaded pipeline a pause or resume no longer takes the state
lock or writes to the device from the main thread. It publishes its
discard as before and a request word, and the consumer, the only thread
that writes to the device, carries the requests out before its next
pass, oldest first: the period-matched tail and its mute for a pause,
the mute reset and top-up for a resume. A consumer parked for data
returns to do it, and a stop settles what is left, writing no tail into
the stopped device. Without the threaded pipeline the tail is still
written where the call is made, under the lock.
pipeline_wakeups' pause boundary checks the pause writes nothing from
the main thread, and waits for the consumer's tail before counting stale
audio.
Both are published with pointer atomics, and a holder of the state lock
- a pass - counts itself in and out of pass_seq. The main thread swaps
the DSP filter in or out without waiting for a pass: what it takes out
is freed at once when no pass runs, and otherwise once pass_seq has
moved on, at the next swap or the next frame. Readers outside a pass
see what the filter allows through dsp_caps. The record tap is
installed with a store after its begin and comes out with a
compare-and-swap; removal ends it once no pass that could have seen it
remains, and both still answer "not yet" while a pass runs. A backend
without pointer atomics changes them under the lock.
mixer_lock builds with the DSP filter, swaps and frees it while a pass
holds the state lock, and checks nothing is freed before the pass ends.
The main and task threads hold mixer_streams[] with a compare-and-swap
owner word and park on an eventcount only behind one another; the mix
never takes it. A play's stop callback, on the mixing thread, only
reports the finish - its sound's tag into a per-slot word - and the
table's next holder, or the main thread once a frame, settles it:
retiring the sound, or starting the next stream of a sequential run.
That callback used to start the next stream itself, inside the mix and
under the state lock the mix holds, which deadlocks against itself on a
non-recursive mutex. A stop recognises its play by the voice's serial,
so a voice the mix has finished and handed on is left alone. The
volatile backend, whose compare-and-swap is not atomic, holds the table
with the state lock.
A WAV is loaded straight from the caller's bytes: its load copies the
samples it keeps, so the copy made before it is gone.
audio_mixer gains a per-sound tag for the callback to read. mixer_lock
finishes a sequential play from a mix holding the state lock, plays,
stops, adds and removes from two threads while a third finishes voices,
and checks a WAV is built from the caller's bytes.
The tree's 3DS layer (the custom crt0 and link spec, system and memory
setup, svchax, the old GPU command layer and the 3dsx/CIA launchers)
lives under os/ctr, beside os/gekko and os/wiiu.
The linear heap allocator is C: the same first-fit pool, so buffers
land where they did, with live allocations found by address in an
open-addressing table instead of a per-allocation tree node, and list
nodes taken from cache-line-aligned slabs and reused. On the same
trace it runs about half the instructions and practically no
malloc/free calls. With the whole heap allocated, a further allocation
now fails instead of starting the heap over and handing out its first
address again, and the free-space queries no longer fault.
samples/frontend/ctr_linear checks placement, alignment, coalescing,
the full-heap case and pages handed back from the heap's end.