The first tool of the opensnes-* family (The opensnes-* tools: conventions). It turns a PCM .wav — a jump, a hit, a UI blip, a voice clip — into the .brr the SNES DSP plays, plus a header with its sizes, and it tells you what a sample costs before you commit to it. The encoder is the one opensnes-music bakes into soundbanks.
In: PCM WAV, 8- or 16-bit, mono or stereo (stereo is downmixed). Keep the source at 32 kHz or below: the DSP plays BRR at 32 kHz whatever the file said, so a 44.1 kHz source comes out lower and slower (the tool warns and says by how much).
Out: jump.brr (raw BRR, one 9-byte block per 16 samples, loop and end flags set), jump_data.as (the fragment the build assembles: the .brr in an ASSET_SECTION, between jump_brr and jump_brr_end) and jump.h:
A loop has to be a whole number of 16-sample blocks, because BRR is. When the one you give is not, the tool makes it so, in one of two ways:
A loop that does not start on a block boundary is preceded by silence so that it does. _brr_loop is the byte offset the loop comes back to; 0 means "from the start", not "no loop": _brr_loops says whether it loops.
In a project, put the settings beside the sound — res/jump.wav.toml with tool = "opensnes-sample" and an [encode] table, which --save writes for you — and the build converts it and links jump_data.as: there is no assembly to write. Load the sample with the sizes from the header:
Without a settings file, .incbin the .brr yourself in an ASSET_SECTION under the label jump_brr.
examples/audio/sfx_from_wav is the worked example, Samples, Voices and the Raw APU the tutorial.
--save writes res/hum.wav.toml next to the file:
From then on opensnes-sample encode res/hum.wav loops without being told, and a --loop on the command line overrides it for that run. The file is the one the build system reads (the tool line says which tool converts the asset); a key it does not know is refused, so a typo cannot fall back to a default in silence.
Nothing is converted or written; this is how you size a sound set against the 64 KB of audio RAM before recording more. A WAV is sized as encode writes it: with a loop (from --loop, or from the .wav.toml beside it) what follows the loop's end is left out, and a loop that is not a whole number of 16-sample blocks is repeated or resampled, so the figure is the size of the .brr, not of the file. The JSON of a WAV gives loops, loop_offset and tuning_x4096 next to aram_bytes, as encode --json does.
0 done; 1 the input was refused and the message names the limit (--loop 100 50 is out of range — the file has 220 samples, START < END); 2 usage; 3 the file system. A refused input writes nothing. --json puts the result — sources, outputs, blocks, ARAM bytes, loop — on stdout as one object; -q drops the summary line; -v says what is being done.
| wav2brr | opensnes-sample |
|---|---|
| wav2brr in.wav [out.brr] | opensnes-sample encode in.wav [--out DIR] (the name follows the input) |
| --loop START END | the same, and --save keeps it in in.wav.toml |
| -v prints the load line | in.h carries the sizes; inspect the figures |
Same bytes: the golden suite of opensnes-sample compares its .brr against wav2brr's goldens.