- 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]>
73 lines
1.7 KiB
C
73 lines
1.7 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "audio.h"
|
|
#include "audio/mixer/audiomixer.h"
|
|
#include "util/memory.h"
|
|
#include "assert/assert.h"
|
|
|
|
audio_t AUDIO;
|
|
|
|
errorret_t audioInit() {
|
|
memoryZero(&AUDIO, sizeof(audio_t));
|
|
|
|
errorChain(audioPlatformInit());
|
|
errorChain(audioMixerInit());
|
|
|
|
errorOk();
|
|
}
|
|
|
|
audiostream_t * audioAquireStream(assetentry_t *asset) {
|
|
assertNotNull(asset, "Asset cannot be NULL.");
|
|
// Same check audioStreamInit() makes - see its own comment on why this
|
|
// is an assert (a programmer error, not untrusted data). Checking here
|
|
// too catches the mistake as early as possible, before any stream slot
|
|
// is handed out for it.
|
|
assertTrue(
|
|
audioStreamTypeForAssetType(asset->type) != AUDIO_STREAM_TYPE_NULL,
|
|
"Unsupported asset type for an audio stream."
|
|
);
|
|
|
|
for(uint8_t i = 0; i < AUDIO_STREAMS_MAX; i++) {
|
|
audiostream_t *stream = &AUDIO.streams[i];
|
|
if(stream->type == AUDIO_STREAM_TYPE_NULL) {
|
|
return stream;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
errorret_t audioUpdateEarly() {
|
|
errorChain(audioPlatformUpdate());
|
|
errorChain(audioMixerUpdateEarly());
|
|
|
|
for(uint8_t i = 0; i < AUDIO_STREAMS_MAX; i++) {
|
|
audiostream_t *stream = &AUDIO.streams[i];
|
|
errorChain(audioStreamUpdate(stream));
|
|
}
|
|
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t audioUpdateLate() {
|
|
errorChain(audioMixerUpdateLate());
|
|
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t audioDispose() {
|
|
for(uint8_t i = 0; i < AUDIO_STREAMS_MAX; i++) {
|
|
audiostream_t *stream = &AUDIO.streams[i];
|
|
errorChain(audioStreamDispose(stream));
|
|
}
|
|
|
|
errorChain(audioMixerDispose());
|
|
errorChain(audioPlatformDispose());
|
|
|
|
errorOk();
|
|
} |