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

Functions

u16 audioGetFreeMemory (void)
 Get available SPC700 RAM for samples.
u8 audioGetSampleInfo (u8 id, AudioSample *info)
 Get information about a loaded sample.
u8 audioLoadSample (u8 id, const u8 *brrData, u16 size, u16 loopPoint)
 Load a BRR sample into SPC700 RAM.
void audioUnloadSample (u8 id)
 Unload a sample from a slot.

Detailed Description

Function Documentation

◆ audioGetFreeMemory()

u16 audioGetFreeMemory ( void )

Get available SPC700 RAM for samples.

The sample area starts at $0B00 of the sound CPU's 64 KB (below it: the driver and the sample directory) and ends

  • at $FFC0, 62,656 bytes, as long as the game has configured no echo;
  • at $C000, 46,336 bytes, from the first audioSetEcho(): the echo ring lives above. audioSetEcho() answers AUDIO_ERR_NO_MEMORY when samples already loaded reach into it, so a game that wants an echo calls audioSetEcho() before loading, or keeps its samples under 46 KB.
Returns
Free bytes available, under the limit that applies now

◆ audioGetSampleInfo()

u8 audioGetSampleInfo ( u8 id,
AudioSample * info )

Get information about a loaded sample.

Parameters
idSample ID
infoPointer to AudioSample struct to fill
Returns
AUDIO_OK if loaded, AUDIO_ERR_NOT_LOADED otherwise

◆ audioLoadSample()

u8 audioLoadSample ( u8 id,
const u8 * brrData,
u16 size,
u16 loopPoint )

Load a BRR sample into SPC700 RAM.

Parameters
idSample slot (0-63)
brrDataPointer to BRR sample data
sizeSize in bytes (must be multiple of 9)
loopPointLoop offset in bytes from the start of the sample (a multiple of 9, one BRR block). It is where a sample that loops comes back to — 0 for a loop from the very start. WHETHER the sample loops is the loop flag of its last BRR block (opensnes-sample sets it), not this value: a one-shot sample ignores it.
Returns
AUDIO_OK on success, or error code
extern u8 explosion_brr[];
extern u8 explosion_brr_end[];
audioLoadSample(0, explosion_brr, explosion_brr_end - explosion_brr, 0);
u8 audioLoadSample(u8 id, const u8 *brrData, u16 size, u16 loopPoint)
Load a BRR sample into SPC700 RAM.
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:47

◆ audioUnloadSample()

void audioUnloadSample ( u8 id)

Unload a sample from a slot.

Parameters
idSample slot (0-63)

It does NOT stop a voice that is playing the sample — stop it first. The allocator is a bump pointer: SPC memory comes back only when the sample unloaded is the most recently loaded one, and loading a slot that is already loaded leaks the old block. (The "voices will be stopped" sentence that stood here was never implemented.)