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.

MUSIC SYNTHESIS SOFTWARE 647<br />

signed twos-complement numbers and unsigned numbers. In an unsigned<br />

number, the weight <strong>of</strong> each bit is two raised to the bit number power. Thus,<br />

a single byte in the 6502 can represent any number from 0 through +25 5.<br />

Unsigned numbers are therefore always positive. In programming, they are<br />

normally used to represent addresses but in signal processing they are most<br />

useful as multiplying coefficients in digital filters, etc. Besides doubled<br />

dynamic range compared with signed numbers, the use <strong>of</strong> unsigned numbers<br />

simplifies the associated multiplications.<br />

Signed twos-complement numbers are probably more familiar to most<br />

readers. The bit weights are the same as in unsigned numbers except that bit<br />

7 (the leftmost) has a weight <strong>of</strong> -128. The number is negative only if this<br />

bit is a 1; thus, it is called the sign bit. The remaining bits are called<br />

magnitude bits, although it must be remembered that they have been complemented<br />

in the case <strong>of</strong> a negative number. A signed single-byte number<br />

can therefore represent quantities between -128 and + 127. In signal processing,<br />

signed numbers are used to represent audio signal samples that<br />

invariably swing positive and negative.<br />

A signed twos-complement number can be negated, that is, N converted<br />

to -N or -N converted to N', by complementing every bit in the number<br />

and then incrementing the result by one. This will not work for the number<br />

-128, however, because the increment operation overflows and the result<br />

becomes -128 again. Since negation will be required <strong>of</strong>ten in signal processing,<br />

mere existence <strong>of</strong> the largest negative number in a sample stream may<br />

cause an overflow that gives rise to a full-amplitude noise spike. Avoidance <strong>of</strong><br />

such overflows usually requires an extra bit <strong>of</strong> precision in the numbers that<br />

may propagate when calculations are chained together. Thus, it is wise to<br />

prevent the occurrence <strong>of</strong> the largest negative number in synthesized samples<br />

and to search and correct ADC data by converting any - 128s to - 127<br />

(which amounts to slight clipping rather than a full-scale noise spike) or the<br />

equivalent when other word lengths are used.<br />

Fixed-point arithmetic is <strong>of</strong>ten equated with integer arithmetic because<br />

memory addresses are usually involved. In signal processing, fractions and<br />

mixed numbers are more common. There are at least two ways to think about<br />

such numbers. One involves the concept <strong>of</strong> a scale factor. The numbers<br />

being manipulated are considered to be the product <strong>of</strong> the actual quantity<br />

and a scale factor that the programmer keeps track <strong>of</strong>. The scale factor is<br />

chosen so that when it multiplies the numbers being handled, the results are<br />

pure integers, which are "compatible" with integer arithmetic. In the course<br />

<strong>of</strong> a chained calculation, the scale factors change so as to maintain the largest<br />

range <strong>of</strong> integers possible without overflowing the chosen word lengths.<br />

The other method, which will be used here, involves the concept <strong>of</strong> a<br />

binary point. The function, meaning, and consequences <strong>of</strong> binary-point position<br />

are the same as rhey are with decimal points and decimal arithmetic.<br />

The microcomputer can be likened to an old mechanical calculator or a slide

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

Saved successfully!

Ooh no, something went wrong!