OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1
82
83#ifndef OPENSNES_AUDIO_H
84#define OPENSNES_AUDIO_H
85
86#include <snes/types.h>
87
88/* Removed on 2026-10-05 (1.0 plan, lot C): audioUpdate.
89 * The replacements are in docs/UPGRADING.md; `make check-upgrade` names them. */
90
91/*============================================================================
92 * Constants
93 *============================================================================*/
94
99
101#define AUDIO_MAX_SAMPLES 64
102
104#define AUDIO_MAX_VOICES 8
105
108#define AUDIO_VOICE_AUTO 0xFF
109
113#define AUDIO_VOICE_NONE 0xFF
114
116#define AUDIO_VOL_MAX 127
117#define AUDIO_VOL_MIN 0
118
120#define AUDIO_PAN_LEFT 0
121#define AUDIO_PAN_CENTER 8
122#define AUDIO_PAN_RIGHT 15
123
125#define AUDIO_PITCH_DEFAULT 0x1000
126
128/* Pitch is a ratio to the sample's own rate (0x1000 = 1.0); these three
129 * double per octave and assume a sample that plays just under middle C at
130 * 0x1000 (~250 Hz). Until 2026-10-04 the comments were one octave off
131 * their names (C3 called "Middle C"). */
132#define AUDIO_PITCH_C3 0x085F
133#define AUDIO_PITCH_C4 0x10BE
134#define AUDIO_PITCH_C5 0x217C
135
137#define AUDIO_ATTACK_INSTANT 15
138#define AUDIO_ATTACK_FAST 12
139#define AUDIO_ATTACK_MEDIUM 8
140#define AUDIO_ATTACK_SLOW 4
141
143#define AUDIO_DECAY_NONE 0
144#define AUDIO_DECAY_FAST 7
145#define AUDIO_DECAY_MEDIUM 4
146#define AUDIO_DECAY_SLOW 1
147
149#define AUDIO_SUSTAIN_FULL 7
150#define AUDIO_SUSTAIN_HALF 3
151#define AUDIO_SUSTAIN_QUARTER 1
152
161#define AUDIO_RELEASE_INSTANT 31
162#define AUDIO_RELEASE_FAST 24
163#define AUDIO_RELEASE_MEDIUM 16
164#define AUDIO_RELEASE_SLOW 8
165
167#define AUDIO_ECHO_DELAY_MIN 1
168#define AUDIO_ECHO_DELAY_MAX 7
169
171#define AUDIO_OK 0
172#define AUDIO_ERR_NO_MEMORY 1
173#define AUDIO_ERR_INVALID_ID 2
174#define AUDIO_ERR_NOT_LOADED 3
175#define AUDIO_ERR_TIMEOUT 4
176
189extern u8 audio_error_last;
190
192
193/*============================================================================
194 * Data Types
195 *============================================================================*/
196
207
218
219/*============================================================================
220 * Initialization
221 *============================================================================*/
222
227
257
276
279
284
287
297
308
345
347
348/*============================================================================
349 * Sample Management
350 *============================================================================*/
351
356
377u8 audioLoadSample(u8 id, const u8 *brrData, u16 size, u16 loopPoint);
378
380#define AUDIO_LOAD_FAILED 0xFFFF
381
418u8 audioLoadSampleBegin(u8 id, const u8 *brrData, u16 size, u16 loopPoint);
419
434
492u8 audioLoadSampleAt(u8 id, u16 spcAddr, const u8 *brrData, u16 size,
493 u16 loopPoint);
494
545u8 audioLoadSampleBeginAt(u8 id, u16 spcAddr, const u8 *brrData, u16 size,
546 u16 loopPoint);
547
566
574
594
596
597/*============================================================================
598 * Playback Control
599 *============================================================================*/
600
605
615
629u8 audioPlaySampleEx(u8 sampleId, u8 volume, u8 pan, u16 pitch);
630
662u8 audioPlaySampleOn(u8 voice, u8 sampleId, u8 volume, u8 pan, u16 pitch);
663
696
707
716
718
719/*============================================================================
720 * Volume Control
721 *============================================================================*/
722
727
733
739
746u8 audioSetVoiceVolume(u8 voice, u8 volumeL, u8 volumeR);
747
754
777u8 audioSetVoiceVolumePitch(u8 voice, u8 volume, u16 pitch);
778
790void audioSetVoicePan(u8 voice, u8 pan);
791
798
800
801/*============================================================================
802 * ADSR Envelope Control
803 *============================================================================*/
804
809
819u8 audioSetADSR(u8 voice, u8 attack, u8 decay, u8 sustain, u8 release);
820
826u8 audioSetGain(u8 voice, u8 mode);
827
829
830/*============================================================================
831 * Echo/Reverb Effects
832 *============================================================================*/
833
838
862u8 audioSetEcho(u8 delay, s8 feedback, s8 volumeL, s8 volumeR);
863
873
883
891
911
913
914/*============================================================================
915 * Legacy API (backward compatibility)
916 *============================================================================*/
917
923
925#define audioStop() audioStopAll()
926
928#define audioStopSample(id) audioStopVoice(id)
929
931#define audioSetPan(id, pan) /* No-op, use audioPlaySampleEx instead */
932
934
935#endif /* OPENSNES_AUDIO_H */
u8 audioSetGain(u8 voice, u8 mode)
Set GAIN mode for a voice (alternative to ADSR).
u8 audioSetADSR(u8 voice, u8 attack, u8 decay, u8 sustain, u8 release)
Set ADSR envelope for a voice.
u16 audio_error_count
Refusals the audio module has answered since power-on.
u8 audio_error_last
Code of the latest refusal (AUDIO_ERR_*), 0 if none yet.
u8 audioEnableEcho(u8 voiceMask)
Enable echo for specific voices.
u8 audioDisableEcho(void)
Disable echo for all voices.
u8 audioSetEcho(u8 delay, s8 feedback, s8 volumeL, s8 volumeR)
Configure echo parameters.
u8 audioSetEchoFilter(const s8 fir[8])
Set FIR filter coefficients for echo.
u8 audioReleaseEcho(void)
Turn the echo off and give its ring back to the samples.
u8 audioQueueSetVoicePitch(u8 voice, u16 pitch)
Queue a voice pitch (14-bit); see audioQueueStopVoices(). The mirrors (audioGetVolume(),...
u8 audioIsReady(void)
Check if audio system is ready.
u8 audioCommandDone(void)
Has the sound CPU taken the last command? (never waits).
u8 audioQueueSetVolume(u8 volume)
Queue a master volume (0..AUDIO_VOL_MAX); see audioQueueStopVoices().
u8 audioInit(void)
Initialize the audio system.
u8 audioQueueStopVoices(u8 mask)
Queue a key-off of the voices of mask (bit n = voice n).
u8 audioQueueCount(void)
Orders queued and not yet sent.
u8 audioQueueDrain(u8 maxCmds)
Send queued orders, at most maxCmds, without waiting.
u8 audioStopAll(void)
Stop all audio playback.
u8 audioStopVoice(u8 voice)
Stop a specific voice.
u8 audioPlaySampleEx(u8 sampleId, u8 volume, u8 pan, u16 pitch)
Play a sample with custom settings.
u8 audioStopVoices(u8 mask)
Stop several voices with one command.
u8 audioPlaySampleOn(u8 voice, u8 sampleId, u8 volume, u8 pan, u16 pitch)
Play a sample on a voice YOU choose.
u8 audioPlaySample(u8 sampleId)
Play a sample with default settings.
void audioUnloadSample(u8 id)
Unload a sample from a slot.
u8 audioLoadSampleBeginAt(u8 id, u16 spcAddr, const u8 *brrData, u16 size, u16 loopPoint)
Start loading a sample in steps at an address the game chooses.
u16 audioLoadSampleStep(u16 maxBytes)
Send the next piece of the sample audioLoadSampleBegin() started.
u16 audioGetFreeMemory(void)
Get available SPC700 RAM for samples.
u8 audioLoadSampleAt(u8 id, u16 spcAddr, const u8 *brrData, u16 size, u16 loopPoint)
Load a sample at an address of the sound CPU's memory the game chooses.
u8 audioLoadSampleBegin(u8 id, const u8 *brrData, u16 size, u16 loopPoint)
Start loading a sample in steps, while the game runs.
u8 audioLoadSample(u8 id, const u8 *brrData, u16 size, u16 loopPoint)
Load a BRR sample into SPC700 RAM.
u8 audioGetSampleInfo(u8 id, AudioSample *info)
Get information about a loaded sample.
u8 audioGetVolume(void)
Get current master volume.
void audioGetVoiceState(u8 voice, AudioVoiceState *state)
Get current state of a voice.
void audioSetVoicePan(u8 voice, u8 pan)
Set the pan audioSetVoiceVolumePitch() splits a voice's volume with.
u8 audioSetVoiceVolume(u8 voice, u8 volumeL, u8 volumeR)
Set volume for a specific voice.
u8 audioSetVoiceVolumePitch(u8 voice, u8 volume, u16 pitch)
Set the volume and the pitch of a voice in one command.
u8 audioSetVoicePitch(u8 voice, u16 pitch)
Set pitch for a specific voice.
u8 audioSetVolume(u8 volume)
Set master volume.
signed char s8
8-bit signed integer (-128 to 127)
Definition types.h:44
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:53
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:47
BRR sample descriptor.
Definition audio.h:200
u8 flags
Definition audio.h:204
u16 spcAddress
Definition audio.h:201
u16 size
Definition audio.h:202
u8 reserved
Definition audio.h:205
u16 loopPoint
Definition audio.h:203
Voice state information.
Definition audio.h:211
u8 sampleId
Definition audio.h:213
u16 pitch
Definition audio.h:216
u8 volume
Definition audio.h:214
u8 pan
Definition audio.h:215
u8 active
Definition audio.h:212
OpenSNES Standard Types.