EXOS 2.1 Sound Driver Specification

5. Processing of Sounds

This section describes how the sound and envelope definitions are interpreted to actually produce a sound when the sound definition reaches the head of its queue. This involves controlling the pitch and amplitude throughout the duration of the sound and also deciding when to start the sound initially (synchronisation).


5.1 Overall Envelope Processing

If the envelope specified in a sound definition is not defined then the appropriate channel will be silent for the duration of the sound. The same thing applies if the envelope definition vanishes during the course of processing the sound.

If envelope number 255 is specified in the sound definition, then the pitch value and left and right amplitude values from the sound definition will be put into the appropriate DAVE chip registers (with the amplitude values divided by 4 to get them into the range 0..63) for the duration of the sound. This produces a simple 'beep' type sound.

The production of a sound under control of an envelope requires various current values to be kept. There is a current pitch value which is initialised to the pitch value given in the sound definition. There are also left and right current amplitude values, which are initialised to zero at the start of the sound.


5.2 Envelope Phase Processing

With the current pitch and amplitude values initialised, processing of the envelope can begin. Each phase of the envelope in turn is executed, each one lasting for the number of ticks specified in the envelope definition. At each tick, the current pitch and amplitude values are modified so that the change value in the envelope is spread linearly over the duration of the phase. The result at the end of each phase is that the signed change value has been added to the current value at the start of the phase, for each of the three parameters.

In the case of the current amplitude parameters the value is limited to the range 0 to 63. If an attempt is made by an envelope to make the amplitude to go above 63 then the actual amplitude will just stick at 63. For pitch valuse there is no checking, the value will simply wrap around from 65535 to 0 and vice versa.

At each tick the current values of pitch and amplitude are output to the DAVE chip registers. The details of how the register values are calculated are different for pitch and amplitude.

For amplitude, the current left amplitude (6 bits) is multiplied by the overall left amplitude specified in the sound definition (8 bits). The resulting 14 bit number is the required left amplitude. The top six bits of this value are written to the appropriate DAVE register. The right amplitude is of course treated similarly.

The 16 bit pitch value goes through a logaritmic conversion process to produce in a counter value to go into the appropriate DAVE registers. The top byte of the pitch defines a quarter­tone number from 0 to 255 (range 9-10 octaves). The counter value for this quarter­tone is found from a lookup table, with appropriate shifting depending on the octave. The top four bits of the lower byte of the pitch value are used to linearly interpolate between the selected counter value and the next one up. This gives a resolution of approximately 1/64 tone which is certainly adequate to produce smooth pitch changes.


5.3 Sound Duration Control

While all the above processing of envelopes is going on, another counter is timing the length of the sound itself. This is a 16 bit counter initialised at the start of the sound to the sound duration specified in the sound definition, and decremented at each tick. If the end of the envelope is reached before this counter reaches zero then the sound will be silenced and remain silent until the counter does reach zero.

If the sound duration counter reaches zero before the envelope has finished then two things happen. Firstly if the release phase of the envelope has not yet been reached then control skips to the start of the release phase. Secondly a flag is set to allow this sound to be over­ridden by another sound which is waiting in the queue or appears in the queue at a later time.


5.4 Synchronisation

This section describes the use of the sync count which is one of the fields in the flag byte in the sound definition. It is used to control when sounds which reach the head of a sound queue will start and is useful for ensuring that certain sounds (such as chords) start simultaneously with each other.

The sync count is a two bit count which is ignored when the sound is put in the queue. The sound driver maintains an internal sync counter which is normally zero. When a sound reaches the head of a queue and is thus ready to be played, the sync byte in the sound is examined in conjunction with the internal sync counter.

If the sync count in the sound is zero then the sound is just started in the normal way with no synchronisation. If the sync count in the sound is non­zero then the sound is held up and the internal sync counter is examined. If it is zero then the sync count from the sound is copied into it. If the internal sync counter is non­zero then it is decremented by one and if it goes to zero then all held up sounds are released simultaneously.

The effect of all this is that if three sounds are to be played simultaneously then they should be queued up on their appropriate channels each with a sync count of two (one less than the number of sounds). The sound driver will then ensure that they are started simultaneously even if one of them gets to the head of its queue slightly earlier. This facility can thus be used to iron out slight timing differences in multi­voice tunes.


Next Chapter: Other Control Functions.



David Bouman. (dsbouma@cs.vu.nl)