20.4 Playback Parameters and the .inst File

This section contains information about how to create the .inst file.

UP

20.4.1 Setting Sample Parameters in 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.

UP

20.4.2 Differences Between Sound Player and Sequence Player Use of .inst Files

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.

UP

20.4.3 Envelopes

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().

UP

20.4.4 Keymaps and Velocity Zones

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.

UP

20.4.5 Tuning for Samples Recorded at the Hardware Playback Rate

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.

UP

20.4.6 Tuning for Samples Recorded at Varying Rates

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.

Table20-1
Add to MIDI Value Hardware Playback Rate of
44100
Hardware Playback Rate of
32000
Hardware Playback Rate of
22050
0 semitones 44100 32000 22050
1 semitones 41624.857 30203.978 20812.429
2 semitones 39288.633 28508.759 19644.317
3 semitones 37083.532 26908.685 18541.766
4 semitones 35002.193 25398.417 17501.097
5 semitones 33037.671 23972.913 16518.836
6 semitones 31183.409 22627.417 15591.705
7 semitones 29433.219 21357.438 14716.609
8 semitones 27781.259 20158.737 13890.626
9 semitones 26222.017 19027.314 13111.008
10 semitones 24750.288 17959.393 12375.144
11 semitones 23361.161 16951.410 11680.581
12 semitones 22020 16000 11025

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
[formula]
UP

20.4.7 Sounds

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.

UP

20.4.8 Instruments

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.)

UP

20.4.9 Banks

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.

UP

20.4.10 Creating Bank Files

The process for creating sample bank files is as follows:

  1. Record the samples and save as .AIFF files.

  2. Encode the samples using tabledesign and vadpcm_enc.

  3. Create the .inst file.

  4. Compile the bank using ic.

UP