[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I program sound on my IIGS from Basic?
NoAdsOnMyStuff writes ...
>
> Hi -
> I'd like to write an AppleSoft Basic program on my daughter's IIGS
> so that when she hits different keys, she gets different tones & sound
> effects. Anyone know how to do this? I'm guessing PEEKs and POKEs,
> but I don't know the values.
....
You can make tones by repeatedly PEEKing the address 49200. This is
the 'old Apple sound' speaker toggle address. Each PEEK(49200) pushes
the speaker cone in or out. So, repeated PEEKs, say in a FOR-NEXT loop,
produces a tone.
For example, the following 1-line program will produce a tone ...
100 FOR I= 1 TO 500: Q= PEEK(49200): NEXTI
In the above, "500" sets note duration. Frequency depends upon how
quickly the loop executes.
The program below works about the same way, except that you get to
input the value of the Duration variable (D). If you input a value less
than 1, the program ends.
10 INPUT "DURATION: ";D: IF D<1 THEN END
100 FOR I= 1 TO D: Q= PEEK(49200): NEXT I
200 GO TO 10
You can get some control of note frequency by introducing a delay
loop inside of the Duration loop. In the program below, the tone lowers
as L (for "wave length") increases.
10 INPUT "DURATION, WAVE LENGTH: ";D,L: IF D<1 THEN END
100 FOR I= 1 TO D: Q= PEEK(49200): FOR J= 0 TO L: NEXT J,I
200 GO TO 10
BASIC is pretty slow; so, you can not get much of a range of tones
or do much fine tuning. Also, in the above, duration will automatically
increase as L increases.
The usual way to produce tones from BASIC is to CALL machine
language routines which you BLOAD. You POKE values which set duration
and frequency and do the CALL. Machine code can toggle the speaker much
more rapidly than BASIC; so, you have a better selection of notes to
play.
Rubywand