diff options
| author | Tharo <17233964+Thar0@users.noreply.github.com> | 2024-08-28 02:09:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-27 18:09:48 -0700 |
| commit | 7210cfac2f6e5ca538d412c3811e4e2c11780db8 (patch) | |
| tree | 85f70d58ebdda8f6541b71b4cfc0ee80b40f2134 /include | |
| parent | 98d9571f51aa85279ae501707793848b1c3f6256 (diff) | |
[Audio 6/?] Build Soundfonts and the Soundfont Table (#1675)
* [Audio 6/?] Build Soundfonts and the Soundfont Table
* Fix bss
* Maybe fix warnings
* Improve lots of error messages
* Suggested changes from OoT PR
* Suggested changes
* Make soundfont_table.h generation depend on the samplebank xmls since they are read, report from which soundfont the invalid pointer indirect warning originates from
Diffstat (limited to 'include')
| -rw-r--r-- | include/attributes.h | 9 | ||||
| -rw-r--r-- | include/audio/soundfont.h | 22 | ||||
| -rw-r--r-- | include/audio/soundfont_file.h | 48 | ||||
| -rw-r--r-- | include/variables.h | 2 |
4 files changed, 71 insertions, 10 deletions
diff --git a/include/attributes.h b/include/attributes.h index 93341987c..9b3832fcb 100644 --- a/include/attributes.h +++ b/include/attributes.h @@ -8,9 +8,10 @@ #endif #endif -#define UNUSED __attribute__((unused)) -#define FALLTHROUGH __attribute__((fallthrough)) -#define NORETURN __attribute__((noreturn)) -#define NO_REORDER __attribute__((no_reorder)) +#define UNUSED __attribute__((unused)) +#define FALLTHROUGH __attribute__((fallthrough)) +#define NORETURN __attribute__((noreturn)) +#define NO_REORDER __attribute__((no_reorder)) +#define SECTION_DATA __attribute__((section(".data"))) #endif diff --git a/include/audio/soundfont.h b/include/audio/soundfont.h index 0141d9f8c..a8b32c060 100644 --- a/include/audio/soundfont.h +++ b/include/audio/soundfont.h @@ -5,22 +5,34 @@ struct EnvelopePoint; -typedef struct AdpcmLoop { +typedef struct AdpcmLoopHeader { /* 0x00 */ u32 start; - /* 0x04 */ u32 loopEnd; // numSamples position into the sample where the loop ends + /* 0x04 */ u32 loopEnd; // s16 sample position where the loop ends /* 0x08 */ u32 count; // The number of times the loop is played before the sound completes. Setting count to -1 indicates that the loop should play indefinitely. /* 0x0C */ u32 sampleEnd; // total number of s16-samples in the sample audio clip +} AdpcmLoopHeader; // size = 0x10 + +typedef struct AdpcmLoop { + /* 0x00 */ AdpcmLoopHeader header; /* 0x10 */ s16 predictorState[16]; // only exists if count != 0. 8-byte aligned } AdpcmLoop; // size = 0x30 (or 0x10) +typedef struct AdpcmBookHeader { + /* 0x0 */ s32 order; + /* 0x4 */ s32 numPredictors; +} AdpcmBookHeader; // size = 0x8 + /** + * A table of prediction coefficients that the coder selects from to optimize sound quality. + * * The procedure used to design the codeBook is based on an adaptive clustering algorithm. * The size of the codeBook is (8 * order * numPredictors) and is 8-byte aligned */ +typedef s16 AdpcmBookData[]; + typedef struct AdpcmBook { - /* 0x0 */ s32 order; - /* 0x4 */ s32 numPredictors; - /* 0x8 */ s16 codeBook[1]; // a table of prediction coefficients that the coder selects from to optimize sound quality. + /* 0x0 */ AdpcmBookHeader header; + /* 0x8 */ AdpcmBookData codeBook; } AdpcmBook; // size >= 0x8 typedef enum SampleCodec { diff --git a/include/audio/soundfont_file.h b/include/audio/soundfont_file.h new file mode 100644 index 000000000..a401bc11a --- /dev/null +++ b/include/audio/soundfont_file.h @@ -0,0 +1,48 @@ +#ifndef SOUNDFONT_FILE_H +#define SOUNDFONT_FILE_H + +#include "libc/stdbool.h" +#include "alignment.h" +#include "attributes.h" +#include "effects.h" +#include "load.h" +#include "soundfont.h" + +// Envelope definitions + +#define ENVELOPE_POINT(delay, target) { (delay), (target) } +#define ENVELOPE_DISABLE() { ADSR_DISABLE, 0 } +#define ENVELOPE_HANG() { ADSR_HANG, 0 } +#define ENVELOPE_GOTO(index) { ADSR_GOTO, (index) } +#define ENVELOPE_RESTART() { ADSR_RESTART, 0 } + +// Instrument definitions + +#define INSTR_SAMPLE_NONE { NULL, 0.0f } +#define INSTR_SAMPLE_LO_NONE 0 +#define INSTR_SAMPLE_HI_NONE 127 + +// Explicit padding is sometimes required where soundfont data was padded to 0x10 bytes (possibly due to source file +// splits in the original soundfonts?) +// It's less convenient for us to emit multiple files per soundfont, so instead we fill in the padding manually. + +#ifndef GLUE +#define GLUE(a,b) a##b +#endif +#ifndef GLUE2 +#define GLUE2(a,b) GLUE(a,b) +#endif + +#ifdef __sgi +// For IDO, we have to add explicit padding arrays +#define SF_PAD4() static u8 GLUE2(_pad, __LINE__) [] = { 0,0,0,0 } +#define SF_PAD8() static u8 GLUE2(_pad, __LINE__) [] = { 0,0,0,0,0,0,0,0 } +#define SF_PADC() static u8 GLUE2(_pad, __LINE__) [] = { 0,0,0,0,0,0,0,0,0,0,0,0 } +#else +// For other compilers, the soundfont compiler (sfc) emits alignment attributes that handle this automatically +#define SF_PAD4() +#define SF_PAD8() +#define SF_PADC() +#endif + +#endif diff --git a/include/variables.h b/include/variables.h index ea5efeb4b..57a7077a1 100644 --- a/include/variables.h +++ b/include/variables.h @@ -38,7 +38,7 @@ extern AudioSpec gAudioSpecs[21]; extern const u16 gAudioEnvironmentalSfx[]; extern const s16 gAudioTatumInit[]; extern const AudioHeapInitSizes gAudioHeapInitSizes; -extern u8 gSoundFontTable[]; +extern AudioTable gSoundFontTable; extern u8 gSequenceFontTable[]; extern u8 gSequenceTable[]; extern AudioTable gSampleBankTable; |
