29.2 Influence of n_audio

The sequence and sound data developed for the past versions of the audio library can also be used with the n_audio library. However, because of the improvements outlined in Section 29.1, you will need to prepare the data following the guidelines below.

UP


29.2.1 Effect of the Envelope

As explained in Section 29.1.2 "The Envelope", the effect of the change from an exponential to a linear envelope is greatest at the time of release. The effect is such that it sounds like the release time has been extended because the attenuation rate is smaller at the beginning of the release. To compensate for this effect you can:

UP


29.2.2 Effect of Processing Every 184 Samples

Because the n_audio library uses a minimum fixed audio processing unit made up of 184 audio samples, you must:

UP


29.2.2.1 Set the Number of Samples Per Frame to a Multiple of 184

In n_audio the minimum audio processing unit is set to a fixed value of 184 samples per unit. The number of samples that can be processed by the RSP is also fixed at 184. Therefore, the number of samples that the application generates for each frame must be set to a multiple of 184 (see playseq).

For example, when the playback frequency is 32 kHz, the number of required data for 1 frame is

32000 / 60 = 533.33333 = 533

The closest multiple to 533 is

184 * 3 = 552

Thus, Frame A can be set up as shown in Figure 29-9.

Figure 29-9 Frame A
[Figure 29-9]

It is possible to set up a value larger than 552 as the size of frame A. However, if it is set up much larger than 533, the required time for processing the frame may become longer than the time for creating 533 pieces of data in the previous library, even though n_audio is used.

In Frame A,

552 - 533 = 19

samples become surplus samples and are carried over to the next frame. To adjust for the surplus samples, prepare Frame B as shown in Figure 29-10.

Figure 29-10 Frame B
[Figure 29-10]

Combine Frame A and Frame B as shown in Figure 29-11.

Figure 29-11 10-Frame Sequence Used to Adjust Samples Over Time
[Figure 29-11]

The total of output sample data numbers of these 10 frames is

184 * 3 * 9 + 184 * 2 = 5336

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

533 * 10 = 5330

Thus, it becomes possible to adjust the surplus data of the whole application by using these 10 frames as shown in Figure 29-11 repeatedly.

In this manner, you must provide the adjustment of surplus data in the application, and set the number of sampling data created for 1 frame to a multiple of 184.

Please refer to the sample program, "playseq.audio," for an example of the method used to decide the specific frame size within the application.

UP


29.2.2.2 Create Data that Do Not Require Audio Processing in the Middle of a Sub-Frame

Because we fixed the minimum unit of the audio process to 184 pieces of sampling data, gaps are produced depending upon the timing of the ON/OFF for sound, and the envelope transition points (see Example 29-3).

Example 29-3 A Timing Gap Between Envelope Changes
[Example 29-3]
When the envelope change (Attack - Decay) occurs within 1 sub-frame, the transition point is forced to move to the next complete sub-frame.

For example, if the playback frequency is 32kHz, the previous timing is a maximum of

(1 / 32000) * (184 / 2) = 0.002975 sec

off due to rounding errors. To prevent the timing gap, each event needs to occur on the multiple integer of the minimum audio processing unit. When the playback frequency is 32kHz,

(1 / 32000) * 184 = 0.00575 sec

becomes the minimum processing unit. Therefore, at this moment, we adjust the timing of envelope change by setting the envelope (within the ".inst" file) to

envelope
{
	attackTime 	= 17250;	/* <- 5750 usec * 3 */
    	attackVolume 	= 127;
    	decayTime	= 2501250;	/* <- 5750 usec * 435 */
    	decayVolume	= 0;
    	releaseTime	= 201250;	/* <- 5750 usec * 35 */
}

We adjust timing for each process using tempo value for the MIDI sequence data. Specifically, it becomes as follows: If you process a quarter note with 48 steps, the time "Qn" per quarter note becomes

Qn = 0.00575 * 48 = 0.276 sec

"Tempo" becomes

Tempo = (60 / Qn) = 217.39 bpm

We adjust the timing of sequence data using "one to this integer" as the actual tempo.

Although, there is sequencer software that will not allow the decimal value of tempo to be input. In these cases, we try to rewrite the tempo value of MIDI data directly.

UP