Macros | |
| #define | AUDIO_LOAD_FAILED 0xFFFF |
| What audioLoadSampleStep() returns when the driver stopped answering. | |
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. | |
| 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 | 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. | |
| void | audioUnloadSample (u8 id) |
| Unload a sample from a slot. | |
| #define AUDIO_LOAD_FAILED 0xFFFF |
What audioLoadSampleStep() returns when the driver stopped answering.
| 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
| u8 audioGetSampleInfo | ( | u8 | id, |
| AudioSample * | info ) |
Get information about a loaded sample.
| id | Sample ID |
| info | Pointer to AudioSample struct to fill |
Load a BRR sample into SPC700 RAM.
| id | Sample slot (0-63) |
| brrData | Pointer to BRR sample data |
| size | Size in bytes (must be multiple of 9) |
| loopPoint | Loop 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. |
Load a sample at an address of the sound CPU's memory the game chooses.
audioLoadSample() places each sample where the last one ended. A game whose samples do not all fit keeps a resident set and replaces others, during play, in places of its own: a swap area. This call writes the sample at spcAddr, whole, then its directory entry, as audioLoadSample() does.
id's own place: a slot can be replaced where it was, by a sample of any size the area allows.id is "not
loaded" (playing it is refused); if the driver stops answering half way it stays so.The place is checked against the 64 slots before anything is sent: about 20 scanlines, measured (audioLoadSampleBeginAt() alike), on top of the bytes' own time (about 650 master cycles a byte, as audioLoadSample()).
Errors (nothing is sent and nothing changes):
id is 64 or more, or is the slot being loaded in steps;size is 0, or the place is refused: below $0B00, at or above the end of the sample area, running past that end (a place that would wrap past $FFFF included), or overlapping another loaded sample or the load in steps.| id | Sample slot (0-63) |
| spcAddr | Where the sample's first byte goes |
| brrData | Pointer to the BRR data |
| size | Size in bytes (1 at least; a BRR sample is a multiple of 9) |
| loopPoint | As for audioLoadSample() |
Start loading a sample in steps, while the game runs.
audioLoadSample() does not return before the whole sample is in the sound CPU's memory: about 560 bytes a frame, ten frames of a stopped game for 5.6 KB. This pair sends the same bytes a piece at a time, when the game says so: voices that are playing go on, and voice commands (play, volume, pitch, stop) pass between two steps.
audioLoadSampleBegin() takes the place in memory and sends nothing; each audioLoadSampleStep() sends a piece. The slot is "not loaded" — playing it is refused — until a step returns 0.
brrData must stay valid until the last step (it is ROM data in every case we know).| id | Sample slot (0-63) |
| brrData | Pointer to the BRR data |
| size | Size in bytes (3 at least) |
| loopPoint | As for audioLoadSample() |
Start loading a sample in steps at an address the game chooses.
audioLoadSampleBegin() at the address of audioLoadSampleAt(), with the same rules for the place; then audioLoadSampleStep() sends it and its last step writes the directory entry, and audioUnloadSample(id) before that gives the load up, as for audioLoadSampleBegin().
Replacing a slot that is loaded: from this call to the last step the slot is "not loaded", so a note asked of it meanwhile is refused (audioPlaySampleOn() returns AUDIO_VOICE_NONE); a voice that was already playing it goes on reading the place, which now holds the new bytes as they arrive.
Silence the place before its first byte goes (here and for audioLoadSampleAt()). A key-off is a release, not a cut: the S-DSP takes 8 off the voice's envelope every sample, from at most $7FF, so 256 samples, 8 ms, and the voice reads its sample all that time (anomie's S-DSP doc: release E-=8 every sample; BRR decoding never stops for a voice, KOFF only sets the envelope). Measured on luna with examples/audio/sample_swap, against a build whose replacement holds the old bytes: audioStopVoice() then the first step at once (36 scanlines later), the output differs for 8 ms; stopped at scanline 200 then one WaitForVBlank() (62 scanlines), it differs for 2 ms; stopped one frame (294 scanlines) or two before, it does not. The envelope reads 0 133 scanlines after audioStopVoice(). So:
A note on another voice in the frame of a step goes at its usual time if it is sent before the step, and later by the step's own time if sent after it (105 scanlines for 192 bytes, measured): send the frame's notes first.
Errors (nothing is taken and nothing changes):
id is 64 or more, or a load in steps is already under way;size is under 3, or the place is refused, as for audioLoadSampleAt().| id | Sample slot (0-63) |
| spcAddr | Where the sample's first byte goes |
| brrData | Pointer to the BRR data; must stay valid until the last step |
| size | Size in bytes (3 at least) |
| loopPoint | As for audioLoadSample() |
Send the next piece of the sample audioLoadSampleBegin() started.
| maxBytes | How much to send at most. Bytes travel three at a time, so the step is maxBytes rounded down to a multiple of 3 (3 at least); the last step takes up to two bytes more rather than leave them alone. The cost of a step is what the game chooses here, plus a fixed part: see docs/tutorials/audio_samples.md for the measured figures. |
| void audioUnloadSample | ( | u8 | id | ) |
Unload a sample from a slot.
| id | Sample slot (0-63) |
On the sample audioLoadSampleBegin() started and no step has finished: gives that load up.
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 ends where the next audioLoadSample() would go (the most recently loaded one, among the samples audioLoadSample() placed), and loading a slot that is already loaded with audioLoadSample() leaks the old block. A sample placed with audioLoadSampleAt() below that point gives nothing back: its place is reused by loading another sample there with audioLoadSampleAt(). (The "voices will be stopped" sentence that stood here was never implemented.)