|Previous Page > Listings Index > Ace Music - Your Computer, July, 1983|
Ace Music - Your Computer, July, 1983, page 101
and the Acsttes run
through some of their
THE VOCABULARY of the Ace contains only one word, Beep, that can be used to produce sounds. The control that the user has over the sounds that this word generates is limited to specifying its frequency and duration.
This makes it difficult to produce the kind of sounds that arcade-type games in particular require. The following Ace words were written to allow the user to produce a large range of sounds. At the heart of these words are three short machine-code routines that produce the sound. Associated with them is a variable space that holds the parameters of the sound for the machine code to pick up. A defining word, Sound, transfers data from words defined by it to the variable space when the defined word is called. Different sounds can be produced by the machine-code routine simply by defining Sound words with the required parameters. This also means that once fundamental words have been defined, new sounds can be added using the minimum of additional bytes.
It is mentioned on page 154 of the Ace manual that the diaphragm of the speaker is controllable by In and Out instructions: In pushes the diaphragm in and Out pushes it out. The motion of the diaphragm will be controlled by two machine code routines, Pause and Note.
Pause regulates the time period between pushing the diaphragm in and out and hence regulates the frequency at this time.
Pause LD B, C 65 C contains the delay time LOOP DJNZ LOOP 16 254 RET 201
This word is defined as follows:
CREATE PAUSE 65 c, 16 c, 254 c, 201 c,
Note moves the diaphragm and regulates the time for which this frequency is heard.
Note NOTE CALL PAUSE 205 PAUSE Delay IN A, (0) 219 Diaphragm in CALL PAUSE 205 PAUSE Delay
OUT A, (0) 211 Diaphragm out DEC E 29 E contains length of note JRNZ NOTE 32 243 NOTE is continued if E # 0 RET 201
CREATE NOTE 205 c, PAUSE, 219 c, 205 c, PAUSE, 211 c, 29 c, 32 C, 243 c, 201 c,
Because Create puts the first data address on the stack, the. definition of Note using Pause will work. Note that, as the address of Pause is of two bytes, a comma is used instead of c followed by a comma.
These words are used by another machine- code word, Noise, which collects the variables from the variable area and then calls Note, varying the length and frequency of the sound as required.
The word Note requires five parameters so we first create a word with five bytes of memory available.
CREATE VAR 0, 0, 0 c,
The five parameters stored in Var are:
Name Location Use LENGTH VAR Specifies length used by Note at start of sound START VAR + 1 Specifies delay time used by Pause at start of sound STOP VAR + 2 Specifies delay time at which the sound stops FINC VAR + 3 Amount by which the delay time is changed each cycle LINC VAR + 4 Amount by which the length is changed each cycle
The increment parameters are added to the length and frequency parameters each cycle so(continued on next page - 102)
Below, figure 2, and right figure 1. Noise LD C, 1 14 1 C = initial delay time = 1 LD H, 1 38 1 H = final delay time = 1 LD L, 6 46 1 L = initial length = 6 LD D, 0 220 D = length increment = 0 CYCLE LD E, L 93 Transfer length to E for CALL NOTE 205 NOTE use of Note. LD A, L 125 Add the length increment ADD A, D 130 to the length and LD L, A 111 restore in L. LD A, C 121 Add the time delay increment ADD A, 13 198 13 to the time delay and LD C, A 79 restore in C. CP H 188 Compare present time delay JRNZ CYCLE 32 242 with final time delay. If JP (IY) 253 233 not equal then cycle, or else return to Forth
Noise LD A, (START) 58 VAR + 1 LD C, A 79 C = initial delay time. LD A, (STOP) 58 VAR + 2 LD H, A 103 H = final delay time. LD A, (LENGTH) 58 VAR + 0 LD L, A 111 L = initial Note length. LD A, (LINC) 58 VAR + 4 LD D, A 87 D = length increment. CYCLE LD E, L 93 Transfer length to E for CALL NOTE 205 NOTE use of Note. LD A, L 125 Add the length increment ADD A, D 130 to the length and LD L, A 111 restore in L. LD A, (FINC) 58 VAR + 3 Add the time delay increment ADD A, C 129 to the time delay and LD C, A 79 restore in C. CP H 188 Compare present time delay JRNZ CYCLE 32 241 with Stop time delay. If JP (IY) 253 233 not equal then Cycle else return to Forth
Ace Music - Your Computer, July, 1983, page 102
that the frequency and length of the frequency changes during the sound. The sound stops when the delay time equals Stop. This means that when defining a sound the user must be sure that this will eventually occur. Stop will eventually be reached for all values of Finc other than powers of two. For powers of two the delay time must equal Stop within one cycle of its 0 to 255 range or the sound will continuously cycle through the same values of frequency. If this occurs, then remove the power supply and reload the program. Let us now look at the word Noise - see figure 1.
This word is defined by:
CREATE NOISE 58 c, VAR 1 +, 79 c, 58 c, VAR 2+, 103c, 58c, VAR , 111 c, 58c, VAR 4+, 87 c, 93 c, 205 c, NOTE, 125 c, 130 c, 111 c, 58c, VAR 3+, 129c, 79c, 188c, 32c, 241 c, 253 c, 233 c,
The defining word Sound that uses Noise is defined as follows:
DEFINER SOUND DOES> 5 0 DO DUP I + C@ VAR I + C! LOOP DROP NOISE CALL ;
When a word is defined using Sound the parameters of the sound are stored using c followed by a comma. For example, if we want to define a sound A that has the parameters Length 1, Start 1, Stop 255, Finc 1, Linc 0 then this would be done:
SOUND A 1 c, 1 c, 255 c, 1 c, 0 c,
When this word A is called, Sound transfers these numbers to Var and then calls Noise so that the sound is produced. Note that Noise Call is used instead of defining a word like Code because Noise is the only one of the machine-code routines that we wish to call directly. The other two routines cannot be called directly by the user because they end with Ret instead of JP (IY).
We shall now look at some of the sounds that can be generated using these words. The word A that we just defined gives a short sound whose frequency starts high and then decreases with the length remaining constant at 1. This sound can be lengthened by increasing the length parameter or by introducing a length increment. It can only be shortened by decreasing the difference between Start and Stop. The word A can be used as it is for various purposes, or can be combined with another sound to give a siren effect. This new sound will be similar to A, but the frequency rises instead of falls.
SOUND B 1 c, 255 c, 1 c, 255 c, 0 c,
Finc equal to 255 is the same as Finc equal to -1. Therefore the frequency will rise. B can also be used alone, but with A can give a siren:
: SIREN BEGIN B A INKEY UNTIL ;
This gives a continuous siren until a key is pressed, but obviously the structure can be changed to give a siren of a specific duration. A different siren effect can be produced by defining a new Sound word.
SOUND C 6 c, 1 c, 1 c, 5 c, 0 c,
If this is speeded up, then it gives the effect of a machine gun. It can be speeded up by first changing the length as in:
SOUND D 1 c, 1 c, 1 c, 5 c, 0 c,
or by increasing Finc so that more cycles of the 0-255 range are made before the time delay equals Stop as in:
SOUND E 6 c, 1 c, 1 c, 13 c, 0 c,
The programs can be used to produce other types of sound also. For example, the following word and words of its type can be used to make the noise that is used when something is completed successfully.
SOUND F 35 c, 44 c, 248 c, 15 c, 0 c,
Another interesting sound can be produced using:
SOUND G 10 c, 240 c, 124 c, 45 c, 0 c,
So far all the sounds that we have looked at so far have a Linc equal to zero. This is because a non-zero value of Linc can, if not thought about, give sounds that are much too long. For example,
SOUND H 6 c, 1 c, 1 c, 13 c, 13 c,
Finc can be used to give reasonable length sounds such as
SOUND K 10 c, 250 c, 242 c 18 c, 1 c,
but the parameters must be thought of more carefully than when Finc equals zero.
If you find a sound to use and wish to use only that sound in one particular vocabulary then memory space can be saved by embedding the parameters into the routine Noise. For example if you want to use only Sound E then define Pause and Note as before but chance Noise as shown in figure 2.