OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
Initialization

Functions

u8 audioInit (void)
 Initialize the audio system.
u8 audioIsReady (void)
 Check if audio system is ready.

Detailed Description

Function Documentation

◆ audioInit()

u8 audioInit ( void )

Initialize the audio system.

Uploads the SPC700 driver (built into the lib as audio_driver_blob) through the IPL boot-ROM protocol and starts it, then verifies the command channel with a PING. Call once during game initialization; check audioIsReady() afterwards.

Note
Blocks for the duration of the upload (~a frame for the small driver). Interrupts stay enabled; the NMI handler does not touch the APU ports.
Returns
AUDIO_OK, or AUDIO_ERR_TIMEOUT if the driver did not answer the handshake (audioIsReady() then reads 0). Returned nothing until 2026-09-21; so did the setters below, which now return the AUDIO_* code of the command they sent (AUDIO_ERR_INVALID_ID for a voice out of range) instead of swallowing it. Existing callers that ignore the value are unaffected.

Return codes of the functions that send a command (volume, pitch, envelope, key on / off, echo taps): a command is sent and the function returns at once; the driver's acknowledgement is awaited by the NEXT command, before it writes. So AUDIO_OK means "sent", and AUDIO_ERR_TIMEOUT from one of these functions means the command BEFORE it was never acknowledged (the one just asked for was then not sent). Loading a sample, audioSetEcho() and the functions that read a state back wait for their own acknowledgement, as before.

◆ audioIsReady()

u8 audioIsReady ( void )

Check if audio system is ready.

audioInit() blocks until the driver answers, so there is no "still initialising" state to poll: 0 after audioInit() means the SPC700 driver never answered (and every audio call is then a no-op).

Returns
Non-zero if the driver answered audioInit()'s ping, 0 otherwise