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.

LOW-COST SYNTHESIS TECHNIQUES 761<br />

interesting to novices) that it is frequently used as a programming example in<br />

elementary microprocessor technology courses. The basic idea is to provide an<br />

addressable flip-flop, either alone or as one <strong>of</strong> the bits <strong>of</strong> an output port,<br />

which an assembly language program can set to a one or a zero at will. The<br />

logic level voltage then is either connected to an on-board transistor switch<br />

driving a speaker or an external amplifier/speaker.<br />

To produce a pulse <strong>of</strong> a constant frequency, the student is instructed to<br />

write a program to set the flip-flop to a one, immediately set it to a zero, and<br />

then enter a delay loop, which perhaps decrements a register until it becomes<br />

zero. After the delay, the program would jump to the beginning for another<br />

pulse. When the student has mastered this, techniques for making the delay<br />

variable, perhaps by reading the delay parameter from an input port, are then<br />

introduced. The utility <strong>of</strong> subroutines might be illustrated by altering the<br />

program for square or rectangular output using a single timing subroutine<br />

called with a different delay argument for the high and low portions <strong>of</strong> the<br />

waveform. Depending on the course, multitask programming might be<br />

introduced by having the student write a program to simulate two or three<br />

such oscillators, simultaneously producing different frequencies.<br />

While this seems trivial compared with what has been covered earlier in<br />

this book, there are legitimate applications beyond being a teaching aid. In<br />

1976-77, three-voice music programs using timed loops were state <strong>of</strong> the art<br />

in microcomputer music. Even today on many machines, such as the IBM PC<br />

and Apple II, it is the only viable way to produce sound without hardware<br />

add-ons. The musical Christmas cards and car horns mentioned earlier are<br />

really nothing more than minimal 4-bit single-chip microcomputers maskprogrammed<br />

to play square-wave note sequences from stored scores using<br />

simple timed loops. Almost any computer program, even business programs,<br />

can benefit from the judicious use <strong>of</strong> sound, and usually a few dozen bytes <strong>of</strong><br />

extra code are all that is needed.<br />

Besides playing buzzy little melodies, single-bit timed-loop routines<br />

can produce a wide variety <strong>of</strong> sound effects as well. White noise is readily<br />

generated by programming one <strong>of</strong> the shift-register random-bit generators<br />

described in Chapter 15 and sending the bits to an output port. Some control<br />

over the noise spectrum can be secured by running the generator at different<br />

sample rates. Laser zaps and police siren effects can be produced by rapidly<br />

varying the delay parameter in a timed loop tone routine.<br />

Figure 20-1 shows a simple but very effective "strange sound"<br />

generation program. The basic idea is to use two 16-bit simulated registers<br />

where the second (REG2) is successively added to the first (REG1). Each time<br />

REG1 overflows, the value <strong>of</strong> REG2 is incremented. After each inner loop,<br />

the lower half <strong>of</strong> REG1 is written to an output port. Each bit <strong>of</strong> this port will<br />

have a different sound sequence and more can be had by modifying the<br />

program to output the upper half <strong>of</strong> REG1 instead. The sounds produced by<br />

this routine are really wild and well worth the hour or so required to translate

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

Saved successfully!

Ooh no, something went wrong!