Files
oot/tools/audio
Anghelo Carvajal bc6d153a21 Allow atblgen to process sequence_order.in with empty lines in between lines for building on Macos (#2718)
The present changes are a direct copy-paste from https://github.com/zeldaret/mm/pull/1850

This fixes building on macos due to a kinda specific issue with Apple clang.

When trying to build on Macos (specifically MacOS 12, Monteray with Apple clang 13.0.0 (clang-1300.0.29.30), idk if other versions have this issue too) `make` stops with the following error from `atblgen`:
```
Failed to match line 1: ""
regexec error: "regexec() failed to match"
Error: Malformed build/n64-us/assets/audio/sequence_order.in?
```

`atblgen` makes the assumption that the `sequence_order.in` file has no extra data, spaces, empty lines, etc. but the file somehow ends up having empty lines between each line on macos.

This file is created by using the C preprocessor to process `include/tables/sequence_table.h`.
In normal circumstances this file should look like this snip,
```
(Sequence_0,NA_BGM_GENERAL_SFX)
(Sequence_1,NA_BGM_AMBIENCE)
(Sequence_2,NA_BGM_TERMINA_FIELD)
(Sequence_3,NA_BGM_CHASE)
(Sequence_4,NA_BGM_MAJORAS_THEME)
```
but it ends up looking like this instead
```
(Sequence_0,NA_BGM_GENERAL_SFX)

(Sequence_1,NA_BGM_AMBIENCE)

(Sequence_2,NA_BGM_TERMINA_FIELD)

(Sequence_3,NA_BGM_CHASE)

(Sequence_4,NA_BGM_MAJORAS_THEME)
```
which `atblgen` doesn't like.

I believe this happens because there are lines with comments between each macro in [`sequence_table.h`](https://github.com/zeldaret/mm/blob/0877ce4adf28a8e73e05c3c58682273b8bf28749/include/tables/sequence_table.h) and for some reason this Apple clang version decided to preserve those empty lines

The fix just makes `atblgen` skip empty lines.

I threw `atblgen` to valgrind to check the fix was working as intended and noted a bunch of memory that was being free before exit, so I fixed them.

I also noted the tools/audio makefile was not using `OPTFLAGS` when building those tools, so I fixed that too.
2026-03-09 21:04:17 +01:00
..
2024-12-13 19:26:36 -05:00
2024-12-13 19:26:36 -05:00
2024-12-13 19:26:36 -05:00
2024-12-13 19:26:36 -05:00

Z64 Audio Tools

The Z64 Audio Tools work together to implement the full audio asset pipeline

Licensing Information

  • The programs atblgen, sampleconv, sbc and sfc are (mostly) distributed under MPL-2.0. The VADPCM encoding and decoding portions of sampleconv are under CC0-1.0.
  • The programs sfpatch and afile_sizes are distributed under CC0-1.0.
  • The extraction tool is distributed under CC0-1.0.

sampleconv

Converts aifc <-> aiff / wav

Used in extraction and build to convert audio sample data between uncompressed mono 16-bit PCM and the compressed formats used by the audio driver.

SampleBank Compiler (sbc)

Converts samplebank xml + aifc -> asm

Samplebanks are converted to assembly files for building as it is easier to define the necessary absolute symbols, and they are pure unstructured data.

SoundFont Compiler (sfc)

Converts soundfont & samplebank xml + aifc -> C

Soundfonts are converted to C rather than assembly as it shares data structures with the audio driver code. Modifying the structures used by the driver without updating sfc to write them should error at compile-time rather than crash at runtime.

sfpatch

Usage: sfpatch in.elf out.elf

This tool patches the symbol table of an ELF file (in.elf) to make every defined symbol in the file an absolute symbol. This is a required step for building soundfonts from C source as all pointers internal to a soundfont are offset from the start of the soundfont file and not the audiobank segment as a whole. Making all defined symbols ABS symbols prevents the linker from updating their values later, ensuring they remain file-relative.

atblgen

Generates various audio code tables.

  • Samplebank table: Specifies where in the Audiotable file each samplebank begins and how large it is.
  • Soundfont table: Specifies where in the Audiobank files each soundfont begins, how large it is, which samplebanks it uses, and how many instruments/drums/sfx it contains.
  • Sequence font table: Contains information on what soundfonts each sequence uses. Generated from the sequence object files that embed a .note.fonts section that holds this information.

The sequence table is not generated as some things in that table are better left manually specified, such as sequence enum names and flags. This also lets us have the sequence table before assembling any sequence files which is nice for some sequence commands like runseq.

afile_sizes

Produces header files containing binary file sizes for a given set of object files. Used to produce headers containing soundfont and sequence files and the number of each for use in code files.

extraction

This collection of python files implements the extraction of audio data from a base ROM.

Files that are designed to be used externally include:

  • audio_extract.py is the main file for audio extraction, it expects an external script to call extract_audio_for_version with the necessary inputs.
  • disassemble_sequence.py is runnable but is not used in this way in either extraction or building. It may be used to manually disassemble a sequence binary.
  • tuning.py is runnable but is not used that way in either extraction or building. It may be used to manually determine alternative matches for the samplerate and basenote of a sample as the extraction procedure cannot always determine these uniquely.

See individual python source files for further details on their purposes.