22.09.2015 Views

of Microprocessors

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DIGITAL TONE GENERATION TECHNIQUES 421<br />

full scale is sent out. Rectangular waves with the width specified by a<br />

parameter are ne-d.rly as easy; simply compare the sawtooth samples with the<br />

parameter rather than with zero.<br />

Conversion to a triangular waveform requires a little more manipulation,<br />

although it still parallels the analog operation. Full-wave rectification is<br />

equivalent to an absolute value function, thus the first step is to test the<br />

sawtooth sample and negate it if it is negative. A potential problem exists,<br />

however, because there is no positive equivalent <strong>of</strong> negative full scale in<br />

twos-complement arithmetic. If this value is seen, simply convert to the<br />

largest positive numbet which results in an ever so slightly clipped triangle<br />

wave. The next step is to center the triangle, which is accomplished by<br />

subtracting one-half <strong>of</strong> full scale from the absolute value. The result now is a<br />

triangle wave but with one-half <strong>of</strong> the normal amplitude. A final shift left by<br />

1 bit doubles the amplitude to full scale.<br />

Conversion to a sine wave is most difficult. The analog-rounding circuits<br />

used to do the job have as their digital equivalent either the evaluation<br />

<strong>of</strong> an equation representing the rounding curve or a table lookup. Of these<br />

two, table lookup is far faster but does require some memory for the table.<br />

The brute-force way to handle table lookup is to simply take a sawtooth<br />

sample and treat it as all integer index into a table <strong>of</strong> sines. The table entry<br />

would be fetched and returned as the sine wave satnple. Memory usage can be<br />

cut by a factor <strong>of</strong> four by realizing that the sine function is redundant. Thus,<br />

if the sawtooth sample, S, is between zero and one-halffull scale use the table<br />

entry directly. If it is between one-half and full scale, look into the table at<br />

1.°- S. If S is negative, negate the table entry before using it.<br />

Still, if the sawtooth samples have very many significant bits, the table<br />

size can become quite large. One could truncate S by just ignoring the less<br />

significant bits and looking up in a smaller table. Rounding is another<br />

possibility that is implemented simply by adding the value <strong>of</strong> the most<br />

significant bit ignored to the sample before truncation. As we shall see later,<br />

rounding has no effect on the audible portion <strong>of</strong> the error. Generally, truncation<br />

is accurate enough if a reasonable size table is used. For example, a<br />

256-entry table, which would require 512 bytes, using symmetry would be<br />

the equivalent <strong>of</strong> 1,024 entries. The distortion incurred by using this table<br />

would be approximately 54 dB below th~ signal level, or the equivalent <strong>of</strong><br />

0.2% distortion. Actually, the kind <strong>of</strong> distortion produced will sound more<br />

like noise so a SiN ratio is the more appropriate measure. At very low<br />

frequencies, the noise amplitude will appear to be modulated by the signal.<br />

Linear Interpolation<br />

The most accurate approach, however, is interpolation between the sine<br />

table entries. Linear interpolation gives good results for very gentle curves<br />

such as sine waves and, if done perfectly, could be expected to reduce the<br />

noise level to -103 dB based on a 256-entry table with symmetry, which is<br />

the limit <strong>of</strong> 16-bit samples anyway. Figure 13-1 shows generalized linear

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!