This section contains information about how to create the .inst file.
In order for the Nintendo 64 audio system to playback samples correctly, it must have information for controlling aspects such as pitch and volume. These parameters are set by creating and editing a .inst file. Although some discussion of parameters follows, it is highly recommended that you review an example .inst file, because many of the parameters will be much clearer then.
The .inst file is a collection of objects, defined by text using C language syntax. The objects are:
The objects are related as follows: The basic unit representing a sample is a sound. That sound has an associated keymap, which specifies the velocity range, key range, and tuning of the sample. Also, the sound has an associated envelope that specifies the ADSR used to control the sample's volume. Sounds can be grouped into an instrument. Instruments are then grouped into a bank. Because program control changes are limited to values from 1 to 128, MIDI sequences can only use the first 128 instruments in a bank. Game applications can select higher values by calls to the audio API.
The sound player and sequence player use the bank files created from the .inst files in different ways. While the sequence player uses the bank to identify instruments, and then uses the keymaps to identify which sound to play for what MIDI notes, the sound player does none of this. The sound player does not use the bank structure, the instrument structure, or the keymap parameters. However, for the .inst file to compile, every .inst file must have a bank and an instrument. Also, every sound must point to a keymap. This keymap may be shared by all the sounds in the .inst file, so only one keymap is needed.
For these reasons, the example .inst sound effects files are set up with one bank, with only one instrument, that lists the sounds in sequential order. There is no concern for overlapping of keymaps in this case, because the sound player ignores them. However, there is one default keymap, in order to allow the file to compile. In order for the pitch of a sound effect to be altered from its recorded pitch, the application must set the pitch, not the .inst file.
The Nintendo 64 audio system supports the use of ADSR envelopes for controlling volume. Envelope time values are in microseconds. (Because microseconds are a much finer control than most synthesizers and samplers use, musicians will have to adjust their thinking to accommodate much larger numbers than are usually used by samplers. Remember, an attackTime of 100,000 will produce an attack of one tenth of a second.) Maximum volume values are 127. In order to avoid any pops or clicks at the ends of sounds, you should always end an envelope with a release volume of zero. This is particularly true in the case of looped samples.
When using the sound player to play sound effects, if the decay time is set to -1, then the envelope will never enter the release phase. (In other words, it will loop forever.) To stop the sound, the game will have to call alSndpStop().
Note: Keymaps are used only by the sequence player. They are ignored by the sound player.
In addition to an envelope, every sample has a keymap. This keymap defines what keys and velocities the sample will respond to. By using different keymap settings, it is possible to create instruments that play different samples for different keys and velocities.
In the keymap object, you set the minimum and maximum velocity values, as well as the minimum and maximum keys to respond. Note that you cannot create overlapping keymap zones. When the sequence player is trying to map a note to be played, it will search through the possible keymaps, and when it finds one that it can use, it will stop searching.
Note: The Nintendo 64 imposes an upper limit on the keyMax value of one octave more than the keyBase.
In addition to the velocity and key zone information contained in the keymap structure, all samples have a keyBase and a detune value. The keyBase sets the sample's pitch in semitones, and the detune value (detune is available in this version) is used to fine-tune the sample in cents. (A cent is 1/100th of a semitone.) If the sample rate of the sound matches the hardware playback rate, the keyBase is the MIDI note value of the sample's original pitch. If the sample rate does not match the hardware playback rate, the keyBase must be altered to compensate for the difference in rates.
As an example, if a note of F4 is recorded at 44100, and the playback rate is also 44100, then the keyBase should be set to 65 (since 65 is equivalent to MIDI note F4) and the detune is set to zero.
One of the more complicated aspects of the .inst files is the tuning of samples that are not sampled at the same rate as the hardware output rate. (remember that the hardware output rate is determined by software, and can be changed). Although the sample rate will be extracted from the AIFF file, you must adjust the keyBase parameter and the detune parameter if you want the sample to play back at the correct pitch.
In order to calculate keyBase and detune from a given sample rate, use the following formula:
N = semitones to add to keyBase N = 12log2(HardwareRate/SampleRate)
A much easier way to deal with the tuning issue is to refer to the values in Table 20-1, "Tuning to Hardware Playback Rates." In this case, pick an acceptable rate from the column that corresponds to your hardware rate. Record your sample at that rate (or resample your sample at that rate), and then add the number of semitones in the leftmost column to the MIDI note value of the samples pitch. Notice that this method insures a value of zero for the detune.
As an example, suppose that you had a hardware playback rate of 44100, but you wished to critically resample a sample of a trumpet playing Bb4 to a sample rate of about 32000 Hz. Instead of using 32000, you would resample to a rate of 33037. Actual pitch that you hear with a playback rate of 44100 is the keyBase written in the .inst file. In your .inst file, you would add 5 semitones to the midivalue. Since Bb4 is the same as MIDI note number 70, you would add 5 and your keyBase value would be 75.
|Add to MIDI Value||Hardware Playback Rate of
|Hardware Playback Rate of
|Hardware Playback Rate of
To extend Table20-1, or produce a table with a different hardware playback rate, use the following formula:
Sample Rate = S Hardware Rate = H Number of semitones to add to MIDI value = N
A sound structure is simply a reference to the sample, the keymap, the envelope, a value for pan, and a value for volume. Pan values are in the range of 0 to 127, with 0 equal to full left, 64 equal to center pan, and 127 equal to full right. Volumes are specified by values of 0 to 127.
The instrument structure is a list of sounds grouped into an instrument. If the instrument is a musical instrument to be used by the sequence player, it is limited to 128 sounds, since that is the maximum number of MIDI notes. However, if the instrument is for use by the sound player, it may have as many sounds in it as you like. In addition to the list of sounds, the instrument has an overall volume and pan. (The sound player ignores these volume and pan values. Instead the sound player uses the pan and volume values specified in the sound object.)
The instrument structure can be used to create Drum Kits. In this case, you create an instrument that uses multiple sounds and associated keymaps. (There is a good example of this in the General MIDI Bank provided with the developer's package.)
At the top level of the .inst file is the bank structure. A .inst file may contain as many banks as needed. The bank must be selected by the application, since there is currently no way to switch banks via MIDI.
The process for creating sample bank files is as follows: