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

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.

Detailed Description

Function Documentation

◆ audioPlaySample()

u8 audioPlaySample ( u8 sampleId)

Play a sample with default settings.

Parameters
sampleIdSample slot (0-63)
Returns
Voice number (0-7) or 0xFF on failure

Plays at full volume, center pan, default pitch.

◆ audioPlaySampleEx()

u8 audioPlaySampleEx ( u8 sampleId,
u8 volume,
u8 pan,
u16 pitch )

Play a sample with custom settings.

Parameters
sampleIdSample slot (0-63)
volumeVolume level (0-127)
panPan position (0=left, 8=center, 15=right)
pitchPitch value ($1000 = normal)
Returns
Voice number (0-7) or 0xFF on failure
#define AUDIO_PAN_RIGHT
Definition audio.h:122
u8 audioPlaySampleEx(u8 sampleId, u8 volume, u8 pan, u16 pitch)
Play a sample with custom settings.

◆ audioPlaySampleOn()

u8 audioPlaySampleOn ( u8 voice,
u8 sampleId,
u8 volume,
u8 pan,
u16 pitch )

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).

Parameters
voiceVoice 0-7, or AUDIO_VOICE_AUTO for the round-robin choice
sampleIdSample slot (0-63)
volumeVolume level (0-127)
panPan position (0=left, 8=center, 15=right)
pitchPitch value ($1000 = normal)
Returns
The voice used (0-7), or AUDIO_VOICE_NONE: voice out of range, sample not loaded, driver not ready
audioSetADSR(7, 4, 7, 7, 0); // slow attack, on voice 7
audioPlaySampleOn(7, SFX_ENGINE, 90, AUDIO_PAN_CENTER, 0x1000);
u8 audioSetADSR(u8 voice, u8 attack, u8 decay, u8 sustain, u8 release)
Set ADSR envelope for a voice.
#define AUDIO_PAN_CENTER
Definition audio.h:121
u8 audioPlaySampleOn(u8 voice, u8 sampleId, u8 volume, u8 pan, u16 pitch)
Play a sample on a voice YOU choose.

◆ audioStopAll()

u8 audioStopAll ( void )

Stop all audio playback.

audioStopVoices(0xFF): every voice in one command.

Returns
AUDIO_OK, or AUDIO_ERR_TIMEOUT as for audioStopVoices()

◆ audioStopVoice()

u8 audioStopVoice ( u8 voice)

Stop a specific voice.

audioStopVoices() with the one bit of voice.

Parameters
voiceVoice number (0-7)
Returns
AUDIO_OK, AUDIO_ERR_INVALID_ID for a voice of 8 or more (nothing is sent), or AUDIO_ERR_TIMEOUT as for audioStopVoices()

◆ audioStopVoices()

u8 audioStopVoices ( u8 mask)

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.

Parameters
maskVoices to stop, one bit per voice number (0-7)
Returns
AUDIO_OK (also for a mask of 0, which sends nothing), or AUDIO_ERR_TIMEOUT when the previous command was never acknowledged (nothing is sent then), as for audioStopVoice()
audioStopVoices((1 << 0) | (1 << 2) | (1 << 5)); // voices 0, 2 and 5
u8 audioStopVoices(u8 mask)
Stop several voices with one command.