// Public audio API: thin pass-through to the per-port HAL plus a // gate that makes every call safe when audio init failed (or has not // been called). Game code can fire-and-forget calls regardless of // whether the platform actually has audio working at runtime. #include #include "joey/audio.h" #include "hal.h" // CORESYS: hoisted out of _ROOT (see surface.c for rationale). JOEYLIB_SEGMENT("CORESYS") static bool gAudioReady = false; bool joeyAudioInit(void) { if (gAudioReady) { return true; } gAudioReady = halAudioInit(); return gAudioReady; } void joeyAudioShutdown(void) { if (!gAudioReady) { return; } halAudioShutdown(); gAudioReady = false; } void joeyAudioPlayMod(const uint8_t *data, uint32_t length, bool loop) { if (!gAudioReady || data == NULL || length == 0) { return; } halAudioPlayMod(data, length, loop); } void joeyAudioStopMod(void) { if (!gAudioReady) { return; } halAudioStopMod(); } bool joeyAudioIsPlayingMod(void) { if (!gAudioReady) { return false; } return halAudioIsPlayingMod(); } void joeyAudioPlaySfx(uint8_t slot, const uint8_t *sample, uint32_t length, uint16_t rateHz) { if (!gAudioReady || sample == NULL || length == 0) { return; } if (slot >= JOEY_AUDIO_SFX_SLOTS) { return; } halAudioPlaySfx(slot, sample, length, rateHz); } void joeyAudioStopSfx(uint8_t slot) { if (!gAudioReady || slot >= JOEY_AUDIO_SFX_SLOTS) { return; } halAudioStopSfx(slot); } void joeyAudioFrameTick(void) { if (!gAudioReady) { return; } halAudioFrameTick(); }