Functions | |
| u8 | audioPlaySample (u8 sampleId) |
| Play a sample with default settings. | |
| u8 | audioPlaySampleEx (u8 sampleId, u8 volume, u8 pan, u16 pitch) |
| Play a sample with custom settings. | |
| u8 | audioPlaySampleOn (u8 voice, u8 sampleId, u8 volume, u8 pan, u16 pitch) |
| Play a sample on a voice YOU choose. | |
| u8 | audioStopAll (void) |
| Stop all audio playback. | |
| u8 | audioStopVoice (u8 voice) |
| Stop a specific voice. | |
| u8 | audioStopVoices (u8 mask) |
| Stop several voices with one command. | |
Play a sample with default settings.
| sampleId | Sample slot (0-63) |
Plays at full volume, center pan, default pitch.
Play a sample with custom settings.
| sampleId | Sample slot (0-63) |
| volume | Volume level (0-127) |
| pan | Pan position (0=left, 8=center, 15=right) |
| pitch | Pitch value ($1000 = normal) |
Play a sample on a voice YOU choose.
audioPlaySample() and audioPlaySampleEx() pick the voice round-robin and only tell you afterwards. That is too late for anything that must be set BEFORE key-on — audioSetADSR() / audioSetGain() shape the attack — and it lets a long sound be stolen by the eighth effect after it. Choosing the voice fixes both: reserve, say, voice 7 for the engine hum, aim its envelope once, and keep effects on the automatic voices. (Added 2026-09-21; AUDIO_VOICE_AUTO had been defined since v2 with nothing to pass it to.)
An explicit voice does not advance the round-robin counter.
A note is two commands, VSET then KON, when its volume and its pitch both differ from what the voice holds (three when its pan changed too); only the one that changed, or none, is sent otherwise (testing/fixtures/stress/audio_note).
| voice | Voice 0-7, or AUDIO_VOICE_AUTO for the round-robin choice |
| sampleId | Sample slot (0-63) |
| volume | Volume level (0-127) |
| pan | Pan position (0=left, 8=center, 15=right) |
| pitch | Pitch value ($1000 = normal) |
| u8 audioStopAll | ( | void | ) |
Stop all audio playback.
audioStopVoices(0xFF): every voice in one command.
Stop a specific voice.
audioStopVoices() with the one bit of voice.
| voice | Voice number (0-7) |
Stop several voices with one command.
Keys off every voice whose bit is set in mask: bit 0 is voice 0, bit 7 voice 7 (0x05 stops voices 0 and 2). One command to the sound CPU, whatever the number of voices, where a loop of audioStopVoice() sends one per voice and waits for each to be taken before sending the next: stopping four voices this way is one handshake instead of four.
Like every key-off it starts the voices' release, it does not cut them: the S-DSP takes 8 off the envelope every sample, so a voice at full envelope is silent about 8 ms later (see audioLoadSampleBeginAt()).
Cost: the call itself is the port writes (the acknowledgement is awaited by the next command). The sound CPU holds the key-off 132 of its cycles, about 2 scanlines, the same for one voice or eight, so a command sent right after waits for it. Measured on luna (testing/fixtures/stress/koff_hold), up to the end of a state read that follows: the read alone 7 scanlines; four voices stopped by one audioStopVoices() then the read, 11; by four audioStopVoice() then the read, 25.
| mask | Voices to stop, one bit per voice number (0-7) |
mask of 0, which sends nothing), or AUDIO_ERR_TIMEOUT when the previous command was never acknowledged (nothing is sent then), as for audioStopVoice()