Split audio update into early/late phases, add asset<->stream type map, switch volume/pan to float, add stream loop limit

- audioUpdate()/audioMixerUpdate() split into Early (before rendering, per-stream buffering) and Late (end of frame, starts newly-queued mixer sounds) phases, wired into engineUpdate() around displayUpdate(); mixer is now actually initialized/disposed/updated from audio.c.
- New src/dusk/audio/stream/audiostreamtype.{h,c}: asset-loader-type <-> audio-stream-type map (with file extension), plus audioStreamAssetTypeForPath()/audioStreamTypeForAssetType()/audioStreamAssetTypeForStreamType() lookups.
- audiostream_t/audiomixerchanneldata_t volume and directionality/pan switched from integer (0-0xFF / -128..127) to float (0.0-1.0 / -1.0..1.0), removing the manual scaling each platform backend had to do.
- audiostream_t gains loopLimit/loopRestartCount so a stream can be told to stop (fire onEnd) after a fixed number of loop restarts instead of looping forever; wired into the shared restart path (Linux/Dolphin) and PSP's own read-ahead loop decision.

Built and verified on Linux, PSP (Docker) and GameCube (Docker).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
2026-09-02 14:39:27 -05:00
co-authored by Claude Sonnet 5
parent b564d0b1c1
commit 619ce932f9
13 changed files with 268 additions and 63 deletions
+9 -2
View File
@@ -232,9 +232,15 @@ void audioStreamPSPTopUp(audiostream_t *stream) {
// detection ("racing through content"). A short read that isn't
// genuinely the end just means less got queued this call; the next
// TopUp() call (next engine frame) naturally retries.
// A limit of 0 means unlimited - see loopRestartCount's own comment for
// why counting decided (not yet necessarily audible) restarts here is
// still the right thing to compare against loopLimit.
const bool_t loopLimitReached = stream->loopLimit > 0 &&
stream->loopRestartCount >= stream->loopLimit;
const bool_t reachesSegmentEnd = stream->platform.readPosition >= currentEndFrame;
const bool_t willLoop = reachesSegmentEnd &&
(stream->state & AUDIO_STREAM_STATE_LOOPING);
(stream->state & AUDIO_STREAM_STATE_LOOPING) && !loopLimitReached;
if(reachesSegmentEnd) {
if(willLoop) {
@@ -243,6 +249,7 @@ void audioStreamPSPTopUp(audiostream_t *stream) {
return;
}
stream->platform.readPosition = stream->platform.loopToFrame;
stream->loopRestartCount++;
threadMutexLock(&stream->platform.ringLock);
if(stream->platform.loopMarkerCount < AUDIO_PSP_LOOP_MARKER_MAX) {
@@ -379,7 +386,7 @@ void audioStreamPSPThreadFeed(thread_t *thread) {
float_t leftFactor, rightFactor;
audioStreamGetPanFactors(stream, &leftFactor, &rightFactor);
const int baseVolume = (stream->volume * PSP_AUDIO_VOLUME_MAX) / 0xFF;
const int baseVolume = (int) (stream->volume * PSP_AUDIO_VOLUME_MAX);
const int leftVolume = (int) (baseVolume * leftFactor);
const int rightVolume = (int) (baseVolume * rightFactor);