Introduction

This chapter covers the new N_Audio Library which is an improved verison of the old SGI Audio Library. The new N-Audio Library provides faster audio processing. It is designed for use with the more recent versions of the N64 Operating System (versions 2.oh, 2.01, and above.).

Improvements to the Previous Audio Library
This chapter includes the following information about n_audio:

- A description of the improvements to the audio library.

- A discussion of how the improvements to the library affect the application.

- A discussion of how to use the n_audio library, including a sample program for the purpose of demonstration.

Following is a discussion of the changes / additions to the previous library.

Players
There are 2 types of players in the audio library. One is a sequence player which performs the MIDI sequences, and the other is a sound player which replays the sound effects. In the former audio library, the application could have any number of players, regardless of types.

In n_audio library, the game application is limited to having 2 sequence players and 1 sound player active (registered in the synthesizer driver) at any one time. Therefore, audio processing is simplified and sped up by changing the process from indirect reference to direct reference.

The Envelope
The former audio library used an exponential function for the envelope. This was changed to a linear function in n_audio, thereby minimizing the processing required by the audio driver, and speeding up audio processing.

Figure 28.1.1 Changes to the Envelope

Fixing the Minimum Unit of the Audio Process
In the former audio library, the RSP could create the maximum number (160) of sample data at one time. (We will call the unit that the RSP processes at one time (160 samples) "1 sub-frame".)

However, as shown in the example below, the audio command list is split and the RSP cannot create the maximum number (160) of sample data at one time. Therefore, the whole processing rate deteriorates.

Example 28-1 Partition of the Command List on the Former Audio Library

Therefore, in n_audio, we set up the minimum unit used by the audio process so that the audio command list is not split. And, we fixed this minimum unit to the maximum number of sample data that RSP can process at one time.

If the maximum number of sample data is 160 (the same number as the former library’s), the envelope change of the previous example is processed as follows.

Example 28-2 The Process for Partition of the Command List in the n_audio Library

If the envelope change (Attack - Decay) occurs within 1 sub-frame, the transition point is forced to move to the next complete subframe. Therefore, the audio command list is not split and processing for the CPU and RSP are sped up. In this way, we have set the minimum unit for the audio process and fixed this value in n_audio.

Processing of Every 184 Samples
When each player is used, the most common playback frequency is 32kHz. When the playback frequency is 32kHz, the required number of sample data for 1 frame becomes

32000 / 60 = 533.333 = 533

samples using the former library. The maximum number of RSP sample data is 160 using the former library. So, 533 samples are split into 4 sub-frames as illustrated in the following figure.

Figure 28.1.2 Partition of the Frame with the Former Audio Library

In this case, the last sub-frame needs to create only 53 samples.

On the other hand, in n_audio, we fixed the minimum unit of the audio process to the maximum number of sample data that the RSP could process at one time. Therefore, we must set the data number created in 1 frame to a multiple integer of the maximum data number of the RSP in n_audio. If the maximum data number is 160 (which is the same number as the former library’s), n_audio must create

160x4 = 640

samples for 1 frame, as follows.

Figure 28.1.3 Partition of the Frame in the n_audio Library (A)

At this moment, the sample data

160 - 53 = 107

is carried over to the next frame as the surplus sample data of this frame. To adjust for this surplus data, you would prepare frames as in the following figure.

Figure 28.1.4 Partition of the Frame in the n_audio Library (B)

If you use Frame A and Frame B as in the Figure 28.1.5, as time passes it is possible to adjust the previous surplus data.

Figure 28.1.5 Adjustment of the Surplus Sample Data in the n_audio Library

The total output sample data of these 3 frames is

(160x4) + (160x3) + (160x3) = 1600

The actual required number of sample data among 3 frames is

533x3 = 1599

Thus, with this calculation it becomes possible to adjust the surplus data of the entire application by using the previous 3 frames repeatedly.

For example, we can make a table of the time frame, the number of samples, and the number of surplus samples, as follows.

Table 1 Used Frames and Surplus Sample Data in the n_audio Library

Time | Frame | # of Samples | # of Surplus Samples
--- | --- | --- | ---
1 | A | 640 | 107
2 | B | 480 | 54
3 | B | 480 | 1
4 | A | 640 | 108
5 | B | 480 | 55
6 | B | 480 | 2
8 | 7 | 640 | 109
8 | B | 480 | 56
10 | A | 640 | 110
12 | B | 480 | 4
13 | A | 640 | 111
14 | B | 480 | 58
15 | B | 480 | 5
16 | A | 640 | 112
17 | B | 480 | 59
18 | B | 480 | 6
- | - | - | -
- | - | - | -
- | - | - | -
154 | A | 640 | 158
155 | B | 480 | 52
156 | B | 480 | 52
157 | A | 640 | 159
158 | B | 480 | 106
159 | B | 480 | 53
160 | B | 480 | 0
161 | A | 640 | 107
162 | B | 480 | 54
163 | B | 480 | 1
164 | A | 640 | 108
- | - | - | -
- | - | - | -
- | - | - | -

At time "160" in the table above, the application uses frame A if following the original order. However, because 1 surplus sample is produced by each frame A - frame B - frame B sequence, it uses frame B at time "160" to use the accumulated surplus samples.

This adjustment for the number of created data must be provided on the application side. Also, the table above has been created using theoretical data. The actual adjustment for surplus data does not always work exactly as represented here.

In Frame A above, you must create 107 more data than the original required number of sample data for 1 frame. Therefore, the processing time for Frame A increases. Though it depends on each case, it is possible for Frame A only, that the increased processing time due to the required processing data, will exceed the processing time allowed by "n_audio."

This problem is avoided as follows.

( 32000 / 60 ) x ( 1 / 3 ) = 177.777 = 178

The maximum number of sample data that the RSP can process at one time is 178. Using this value, the number of surplus data which is produced at each frame is minimized. However, the maximum number of sample data needs to be a multiple of 8 for convenience of the RSP process. Therefore, we increased the maximum number of sample data from 160 to 184 in n_audio.

At this time, the previous frame A becomes:

Figure 28.1.6 Partition of the Frame in the n_audio Library (A) - In the Case of 184

The number of output data in Frame A becomes:

184x3 = 552

Thus, in Frame A:

552 - 533 = 19

surplus samples are produced for 1 frame. To adjust these surplus samples for example, we prepare Frame B as follows.

Figure 28.1.7 Partition of the Frame in the n_audio Library (B) - in the Case of 184

And it is possible to adjust the surplus data by combining Frame A and Frame B as time passes.

Figure 28.1.8 Adjustment of Surplus Sample Data in the n_audio Library - in the Case of 184

The total of output sample data of these 10 frames is

(184x3x9)+(184x2)= 5336

and the actual number of required sample data among 10 frames is

533x10 = 5330

Thus, it becomes possible to adjust the surplus data of the whole application by using the 10 frames above (see Figure 28.1.2) repeatedly.

Please refer to the sample program (playseq.naudio) for an example of the method used to adjust surplus sample data. In the sample program, the application decides the frame to use dynamically, so it uses Frame B if the number of surplus sample data becomes the data number for 1 sub-frame (184) or more.

In this way, we changed the maximum number of sample data that the RSP can process at one time from 160 to 184 in n_audio, so that the minimum unit of the audio process is effective at a frequency of 32kHz.

Copyright © 1999 Nintendo of America Inc. All Rights Reserved Nintendo and N64 are registered trademarks of Nintendo Last Updated January, 1999