19.1 Bank Files

Bank files store the audio and control information needed to create audio from sequencer MIDI events. On the Nintendo 64, this information is separately stored in two different files: the bank file and the wave table file.

The Bank (.bnk) file contains control information such as program number to instrument assignment, key mapping, tuning, and envelope descriptions. It is always loaded into the Nintendo 64 DRAM during playback.

The Wavetable (.tbl) file contains ADPCM compressed audio data. Because of the size of the data, it is streamed into DRAM (and then to the RCP) only when it is needed.

The formats for both files are optimized for the Nintendo 64 to be efficiently used with the Sequence Player and the Sound Player. They are not intended to be interchange file formats, and contain no textual information or other data not directly related to playing back audio. Many features commonly found in standard patch and wavetable formats (for example, AIFF files) were sacrificed in favor of smaller files in ROM.

Note: References to objects are stored as offsets in the Bank files, but the alBnkfNew() call converts the offsets to pointers.

UP

19.1.1 ALBankFile

Bank files must begin with an ALBankFile structure. This structure allows the software to locate data for a specific bank.

typedef struct {
        s16     revision;
        s16     bankCount;
        s32     bankArray[1];
} ALBankFile;
Table 19-1 ALBankFile Structure
Field Description
revision File format revision number.
bankCount Number of banks contained in the Bank file.
bankArray Array of offsets of the ALBank structures in the bank file.
UP

19.1.2 ALBank

The ALBank structure specifies the instruments that make up the bank, as well as the default sample rate and percussion instrument. Banks may contain any number of programs.

Note: The percussion field specifies an instrument for the Sequence Player to use as a default MIDI channel 10 (drum channel) instrument.

typedef struct {
        s16   instCount;
         u8   flags;
         u8   pad;
        s32   sampleRate;
        s32   percussion;
        s32   instArray[1];
} ALBank;
Table 19-2 ALBank Structure
Field Description
instCount Number of programs (instruments) in the bank.
flags 0: if instArray contains offset,
1: if instArray contains pointers.
pad Currently unused byte.
sampleRate The sample rate at which this bank is intended to be played.
percussion The offset (or pointer) to the default percussion instrument.
instArray Array of offsets (or pointers) to ALInstrument structures that make up this bank.
UP

19.1.3 ALInstrument

The ALInstrument structure contains pronunciation information.

typedef struct {
        u8      volume;
        u8      pan;
        u8      priority;
        u8      flags;
        u8      tremType;
        u8      tremRate;
        u8      tremDepth;
        u8      tremDelay;
        u8      vibType;
        u8      vibRate;
        u8      vibDepth;
        u8      vibDelay;
        s16     bendRange;
        s16     soundCount;
        s32     soundArray[1];
} ALInstrument;
Table 19-3 ALInstrument Structure
Field Description
volume Overall instrument playback volume.
pan Pan values.0=left, 64=center, 127=right
priority The priority for voices for this instrument. 0 = lowest priority, 10 = highest priority.
flags 0: If soundArray values are offsets,
1: If soundArray values are pointers
bendRange Pitch bend range in cents
soundCount Number of sounds in the soundArray array.
soundArray Offsets of (or pointers to) the ALSound objects in the instrument.
UP

19.1.4 ALSound

The ALSound structure contains information about the individual sounds that make up an instrument.

typedef struct Sound_s {
        s32     envelope;
        s32     keyMap;
        s32     wavetable;
        u8      samplePan;
        u8      sampleVolume;
        u8      flags;
} ALSound;
Table 19-4 ALSound Structure
Field Description
envelope Offset of (or pointer to ) the ALEnvelope object assigned to the sound.
keyMap Offset of (or pointer to) the ALKeyMap object assigned to this sound.
wavetable Offset of (or pointer to) ALWavetable objects assigned to the sound.
samplePan Pan position of the sound in the stereo field (128 scale).
sampleVolume Overall sample volume (128 scale)
flags If envelope, keyMap, and wavetable are specified as offsets, flags = 0. If they are pointers, flags = 1.

UP

19.1.5 ALEnvelope

The ALEnvelope structure describes the attack-decay-sustain-release (ADSR) envelope for a sound.

Note: Release volume is assumed to be 0.

typedef struct {
        s32     attackTime;
        s32     decayTime;
        s32     releaseTime;
        s16     attackVolume;
        s16     decayVolume;
} ALEnvelope;
Table 19-5 ALEnvelope Structure
Field Description
attackTime Time, in microseconds, to ramp from zero gain to attackVolume.
attackVolume Target volume for the attack segment of the envelope.
decayTime Time, in microseconds, to ramp from the attackVolume to the decayVolume.
decayVolume Target volume for the decay segment of the envelope.
The sustain loop holds at the decayVolume.
releaseTime Time, in microseconds, to ramp to zero volume.

UP

19.1.6 ALKeyMap

The ALKeyMap describes how the sound is mapped to the keyboard. It allows the sequencer to determine at what pitch to play a sound, given its MIDI key number and note on velocity.

Note: C4 is considered to be middle C (MIDI note number 60). Bank files may not contain keymaps that have overlapping key or velocity ranges.

typedef struct {
        u8      velocityMin;
        u8      velocityMax;
        u8      keyMin;
        u8      keyMax;
        u8      keyBase;
        u8      detune;
} ALKeyMap;
Table 19-6 ALKeyMap Structure
Field Description
velocityMin Minimum note on velocity for this map. (128 scale)
velocityMax Maximum note on velocity for this map.(128 scale)
keyMin Lowest note in this key map. Notes are defines as in the MIDI specification.
keyMax Highest note in this key map. Notes are defined as in the MIDI specification.
keyBase The MIDI note equivalent to the sound played at unity pitch.
detune Amount, in cent, to fine-tune this sample.

UP

19.1.7 ALWavetable

The ALWavetable structure describes the sample data to be played for the given sound. It is described in detail below, along with the structures it contains.

enum    {AL_ADPCM_WAVE = 0, AL_RAW16_WAVE};

typedef struct {
        s32             order;
        s32             npredictors;
        s16             book[1];        /* Must be 8-byte aligned */
}ALADPCMBook;

typedef struct {
        u32             start;
        u32             end;
        u32             count;
        ADPCM_STATE     state;
}ALADPCMloop;

typedef struct{
        u32             start;
        u32             end;
        u32             count;
}ALRawLoop;

typedef struct{
        ALADPCMloop     *loop;
        ALADPCMBook     *book;
}ALADPCMWaveInfo;

typedef struct{
        ALRawLoop       *loop;
}ALRAWWaveInfo;

typedef struct{
        s32             base;
        s32             len;
        u8              type;
        u8              flags;
        union{
                        ALADPCMWaveInfo adpcmWave;
                        ALRAWWaveInfo           rawWave;
        }waveInfo;
}ALWaveTable;
Table 19-7 ALWavetable Structure
Field Description
base Offset of (or pointer to) the start of the raw or ADPCM compressed wavetable in the table (.tbl) file.
len Length, in bytes, of the wavetable.
type The type (AL_ADPCM_WAVE or AL_RAW16_WAVE) of the wavetable structure.
flags If the base field contains an offset, flags =0. If it contains a pointer, flags = 1.
waveInfo Wavetable type specific information.

Table 19-8 ALADPCMWaveInfo Structure
Field Description
loop Offset or pointer to the ADPCM-specific loop structure.
book Offset or pointer to the ADPCM-specific code book.

Table 19-9 ALRawWaveInfo Structure
Field Description
loop Offset or pointer to the raw sound loop structure.

Table 19-10 ALADPCMLoop Structure
Field Description
start Sample offset of the loop start point.
end Sample offset of the loop end point
count Number of times the wavetable is to loop. A value of -1 specifies an infinite loop.
state ADPCM decoder state information.

Table 19-11 ALADPCMBook Structure
Field Description
order Order of the ADPCM predictor.
npnredictors Number of ADPCM predictors.
book Array of code book data.

Table 19-12 ALRawLoop Structure
Field Description
start Sample offset of loop start point.
end Sample offset of loop end point.
count Number of times the wavetable is to loop. A value of -1 specifies an infinite loop.

UP