OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Samples at addresses the game chooses: a resident set and a swap area. More...

#include <snes.h>
#include <snes/audio.h>
#include <snes/profile.h>

Macros

#define ADDR_BELOW   0x1FB8
#define ADDR_BULK   0x4000
#define ADDR_LEAD   0x2000
 The places of the swap area.
#define ADDR_SWAP   0x3000
#define CASE_LATE1   5
#define CASE_ON   1
 Silence cases (q3_case): the voice left on, stopped at once, stopped 1 or 2 frames before, stopped late in a frame then 1 frame.
#define CASE_STOP   2
#define CASE_WAIT1   3
#define CASE_WAIT2   4
#define PH_DONE   6
#define PH_PLACE   1
 Phases, written to phase so a manifest knows where the run is.
#define PH_REFUSE   2
#define PH_REPLACE   3
#define PH_SILENCE   4
#define PH_TIMING   5
#define SIZE(name)
 Size of a data.asm sample.
#define SMP_ABOVE   3
#define SMP_BELOW   4
#define SMP_BULK   5
#define SMP_LEAD   1
 Sample slots.
#define SMP_PROBE   6
#define SMP_SWAP   2
#define VOICE_LEAD   0
 Voices: the one that plays on, the one whose sample is replaced, the witness.
#define VOICE_SWAP   1
#define VOICE_WITNESS   2

Functions

static void enter (u8 p, u16 c)
 Start a phase.
int main (void)
static void silence_case (u8 c)
 One silence case: pad plays on the swap voice, then bell replaces it in its place after the action the case names.
static u8 steps_to_end (u16 n)
 Run a load in steps of n bytes to its end, one step a frame.
static void tick (void)
 Wait one frame.
static void ticks (u8 n)
 Wait n frames.
static void tint (u16 c)
 Backdrop colour per phase.
static u16 vline (void)
 The scanline the PPU is drawing (latched by reading SLHV).
static u16 vpos (void)
 Scanlines since the last VBlank began (line 225 of 262, NTSC): with frame, which tick() bumps then, a clock that runs across frames.
static void witness_note (u8 i)
 Time one witness note: the frame and the scanline its key-on goes.

Variables

u16 addr_above
u16 begin_lines
u8 bell_brr []
u8 bell_brr_end []
u8 bulk_brr []
u8 bulk_brr_end []
u8 bulk_steps
u16 errors_refused
u16 frame
u16 free_above
u16 free_below
u16 free_lead
u16 free_refused
u16 free_start
u16 free_swap
u16 free_unload_above
u16 free_unload_below
u16 kon_frame [12]
u16 kon_line [12]
u8 kon_steady
u8 lead_active
u8 lead_brr []
 The hand-written BRR samples of data.asm.
u8 lead_brr_end []
u8 pad_brr []
u8 pad_brr_end []
u8 phase
 Oracles (WRAM): read by testing/manifests/audio_sample_swap*.toml.
u8 place_errs
u8 q3_case
u16 q3_gap_frames [6]
u16 q3_gap_lines [6]
u8 refusals [10]
u16 release_lines
u16 release_polls
u8 replace_play_during
u8 replace_steps
u8 swap_brr []
u8 swap_brr_end []
u8 swap_play_after

Detailed Description

Samples at addresses the game chooses: a resident set and a swap area.

audioLoadSample() puts each sample where the last one ended. A game whose samples do not all fit in the sound CPU's memory keeps some resident and replaces others during play, in places of its own. This ROM does it with audioLoadSampleAt() and audioLoadSampleBeginAt(), and measures what a game needs to know:

  1. Placing: two samples at $2000 and $3000, an ordinary load after them (it goes above), one just below the first (the allocator does not go back), and what audioUnloadSample() gives back.
  2. Refusals: a place below the sample area, at its end, wrapping past $FFFF, on another sample, on the load in steps; a size under 3; the slot being loaded. Each returns its code and changes nothing.
  3. Replacing during play: voice 0 keeps playing the sample at $2000 while the one at $3000 is replaced in steps, then played.
  4. Silence before overwriting: the voice playing the sample to be replaced is left on, stopped just before the first step, or stopped one or two frames before; a luna manifest reads its envelope when the first byte goes, and the ROM times the release itself.
  5. Timing of a note on another voice while a load in steps runs.

Nothing to press: the phases run on their own, the backdrop colour names the phase, and the results are globals the manifests read.

SNES Concepts
  • The sample directory: two 16-bit addresses per sample, any byte
  • A swap area of fixed places in ARAM, filled while voices play
  • Key-off is a release, not a cut: the voice reads its sample until the envelope is down
What to Observe
Backdrop: blue while placing, red for the refusals, green while voice 0 plays over the replacement, yellow for the silence cases, purple for the timing, grey when done.
Modules Used
console, dma, audio, profile
See also
lib/include/snes/audio.h
docs/tutorials/audio_samples.md

Macro Definition Documentation

◆ ADDR_BELOW

#define ADDR_BELOW   0x1FB8

ends where lead starts: touching is not overlapping

◆ ADDR_BULK

#define ADDR_BULK   0x4000

◆ ADDR_LEAD

#define ADDR_LEAD   0x2000

The places of the swap area.

◆ ADDR_SWAP

#define ADDR_SWAP   0x3000

◆ CASE_LATE1

#define CASE_LATE1   5

◆ CASE_ON

#define CASE_ON   1

Silence cases (q3_case): the voice left on, stopped at once, stopped 1 or 2 frames before, stopped late in a frame then 1 frame.

◆ CASE_STOP

#define CASE_STOP   2

◆ CASE_WAIT1

#define CASE_WAIT1   3

◆ CASE_WAIT2

#define CASE_WAIT2   4

◆ PH_DONE

#define PH_DONE   6

◆ PH_PLACE

#define PH_PLACE   1

Phases, written to phase so a manifest knows where the run is.

◆ PH_REFUSE

#define PH_REFUSE   2

◆ PH_REPLACE

#define PH_REPLACE   3

◆ PH_SILENCE

#define PH_SILENCE   4

◆ PH_TIMING

#define PH_TIMING   5

◆ SIZE

#define SIZE ( name)
Value:
((u16)(name##_end - name))
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:53

Size of a data.asm sample.

◆ SMP_ABOVE

#define SMP_ABOVE   3

an ordinary load after the placed ones

◆ SMP_BELOW

#define SMP_BELOW   4

placed below the allocator's pointer

◆ SMP_BULK

#define SMP_BULK   5

the 1728-byte load timed against a note

◆ SMP_LEAD

#define SMP_LEAD   1

Sample slots.

resident, at ADDR_LEAD

◆ SMP_PROBE

#define SMP_PROBE   6

the slot the refusals ask for

◆ SMP_SWAP

#define SMP_SWAP   2

the swap place: pad, then bell

◆ VOICE_LEAD

#define VOICE_LEAD   0

Voices: the one that plays on, the one whose sample is replaced, the witness.

◆ VOICE_SWAP

#define VOICE_SWAP   1

◆ VOICE_WITNESS

#define VOICE_WITNESS   2

Function Documentation

◆ enter()

void enter ( u8 p,
u16 c )
static

Start a phase.

◆ main()

int main ( void )

< resident, at ADDR_LEAD

< the swap place: pad, then bell

< an ordinary load after the placed ones

< an ordinary load after the placed ones

< placed below the allocator's pointer

< ends where lead starts: touching is not overlapping

< placed below the allocator's pointer

< an ordinary load after the placed ones

< the slot the refusals ask for

< the slot the refusals ask for

< the slot the refusals ask for

< the slot the refusals ask for

< the slot the refusals ask for

< the slot the refusals ask for

< resident, at ADDR_LEAD

< the swap place: pad, then bell

< the swap place: pad, then bell

< the swap place: pad, then bell

< the slot the refusals ask for

< the swap place: pad, then bell

< the slot the refusals ask for

< the swap place: pad, then bell

< resident, at ADDR_LEAD

< the 1728-byte load timed against a note

◆ silence_case()

void silence_case ( u8 c)
static

One silence case: pad plays on the swap voice, then bell replaces it in its place after the action the case names.

pad is first put back where bell will go (a blocking replacement), so each case starts from the same bytes. A control build whose swap_brr holds pad's bytes (data.asm) runs the same code at the same cycles: its sound differs from this one's only where the voice read a byte that changed.

< the swap place: pad, then bell

< the swap place: pad, then bell

< the swap place: pad, then bell

◆ steps_to_end()

u8 steps_to_end ( u16 n)
static

Run a load in steps of n bytes to its end, one step a frame.

◆ tick()

void tick ( void )
static

Wait one frame.

◆ ticks()

void ticks ( u8 n)
static

Wait n frames.

◆ tint()

void tint ( u16 c)
static

Backdrop colour per phase.

◆ vline()

u16 vline ( void )
static

The scanline the PPU is drawing (latched by reading SLHV).

◆ vpos()

u16 vpos ( void )
static

Scanlines since the last VBlank began (line 225 of 262, NTSC): with frame, which tick() bumps then, a clock that runs across frames.

◆ witness_note()

void witness_note ( u8 i)
static

Time one witness note: the frame and the scanline its key-on goes.

< resident, at ADDR_LEAD

Variable Documentation

◆ addr_above

u16 addr_above

where the ordinary load went

◆ begin_lines

u16 begin_lines

scanlines of one audioLoadSampleBeginAt() (it checks the 64 slots)

◆ bell_brr

u8 bell_brr[]
extern

◆ bell_brr_end

u8 bell_brr_end[]

◆ bulk_brr

u8 bulk_brr[]
extern

◆ bulk_brr_end

u8 bulk_brr_end[]

◆ bulk_steps

u8 bulk_steps

steps the bulk load took

◆ errors_refused

u16 errors_refused

audio_error_count after them

◆ frame

u16 frame

frames since the screen came on

◆ free_above

u16 free_above

...after the ordinary load (it goes above)

◆ free_below

u16 free_below

...after the sample placed just below lead (unchanged)

◆ free_lead

u16 free_lead

...after the sample at $2000

◆ free_refused

u16 free_refused

audioGetFreeMemory() after them: unchanged

◆ free_start

◆ free_swap

u16 free_swap

...after the sample at $3000

◆ free_unload_above

u16 free_unload_above

...after unloading the ordinary one (back)

◆ free_unload_below

u16 free_unload_below

...after unloading it (unchanged: not on top)

◆ kon_frame

u16 kon_frame[12]

frame of each witness note: 4 alone, 4 after a step, 4 before one

◆ kon_line

u16 kon_line[12]

scanline at which its key-on command was sent

◆ kon_steady

u8 kon_steady

1: the twelve notes went in twelve frames running

◆ lead_active

u8 lead_active

voice 0 still sounding after the replacement

◆ lead_brr

u8 lead_brr[]
extern

The hand-written BRR samples of data.asm.

◆ lead_brr_end

u8 lead_brr_end[]

◆ pad_brr

u8 pad_brr[]
extern

◆ pad_brr_end

u8 pad_brr_end[]

◆ phase

u8 phase

Oracles (WRAM): read by testing/manifests/audio_sample_swap*.toml.

◆ place_errs

u8 place_errs

the codes of the five placing calls, OR-ed: 0

◆ q3_case

u8 q3_case

the silence case whose first step is running, 0 between: a hook for a luna checkpoint (until_if) at that step

◆ q3_gap_frames

u16 q3_gap_frames[6]

per case: frames from the key-off to the first step

◆ q3_gap_lines

u16 q3_gap_lines[6]

per case: scanlines from the key-off (or the same point, voice left on) to the first step

◆ refusals

u8 refusals[10]

the code of each refused call, in order

◆ release_lines

u16 release_lines

scanlines from audioStopVoice() to a silent envelope

◆ release_polls

u16 release_polls

envelope reads it took

◆ replace_play_during

u8 replace_play_during

audioPlaySampleOn() on the slot mid-load: AUDIO_VOICE_NONE

◆ replace_steps

u8 replace_steps

steps of 24 bytes for the 72-byte bell

◆ swap_brr

u8 swap_brr[]
extern

◆ swap_brr_end

u8 swap_brr_end[]

◆ swap_play_after

u8 swap_play_after

audioPlaySampleOn() on the slot once whole