[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I program sound on my IIGS from Basic?
On Mon, 8 Jun 1998 02:01:38 +1200, dempson@actrix.gen.nz (David
Empson) wrote:
>NoAdsOnMyStuff <CantStandSpam@my.email.address> wrote:
>> 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?
...
>The best solution is to use a small machine language routine that does
>the required access pattern to the speaker, with behavioural
>modifications controlled by the BASIC program. This program can be set
>up by using the BLOAD command (from a binary image on disk), or (if
>small enough) by POKEing it directly into memory.
Here's the bulk of my ultra-famous article
(343001a1.18354420@129.3.17.35) of days past--the first part tells how
to make a boinkier sound than the usual Apple .1 sec 1kHz(?) beep:
10 Q = -16336
20W=PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)
+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)
+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)
+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)+PEEK(Q)
I *think* that's the right amount of +PEEK(Q)'s, anyway :) As you can
see, it's much less boring making this kind of line with Program
Writer, which lets you do macros. Try it, even at 1MHz, it's a cool
sound :) Depending on which model Apple // you have, changing this
from a PEEK thing to a POKE thing may make different sounds. I
believe the //e will show the change, but the //c and IIgs won't.
FWIW, I think I saw this on a Beagle Bros. disk.
Some more FAQ stuff:
---
Other beep tones and music require machine-language subroutines which
are currently beyond the scope of
this FAQ.
---
This can be surprisingly easy, too. If I remember correctly, the
routine for music is 9 bytes long. It's so short, I usually make it
again every time I use it. Here I go, starting at 3:51 PM. Okay, I'm
done at 4:03 PM (no, I'm NOT an excellent assembly programmer, doi!)
Using the IIgs's miniassembler, I find that it took me a rusty 12
minutes, and more than 9 bytes :) Here's a routine, as needed by
Applesoft BASIC guys:
10 FOR A = 768 TO 768 + 21 : REM 21 BYTES LONG. OH, WELL.
20 READ B : POKE A, B : GOTO 40
30 DATA 234, 234, 173, 0, 3, 174, 1, 3, 202, 224, 0, 208, 251, 172,
48, 192, 58, 201, 0, 208, 240, 96
35 REM PLAY SOME NOTES
40 FOR A = 1 TO 255 STEP 16
50 POKE 769, A
60 CALL 770
70 NEXT
The 234's are just NOPs, so if you want to BSAVE MUSIC,A$300,L21 when
you're done, and then BRUN MUSIC to load it, all it'll do is play a
note instead of crashing--you should BLOAD this program to load it if
you don't want that note played. If you want to save 2 bytes, you can
save the music routine with BSAVE MUSIC,A$302,L19, but it'll probably
crash if you BRUN it. POKE 768,x is how you change the note's length.
x ranges from 0 to 255, with 1 being shortest, 255 being longest, and
0 being a hair longer than 255 (note: changing pitch changes the
length a little bit, so you may need to alter your value of y to
compensate). POKE 769,y changes the pitch of the note, with 1 being
really righ-pitched, and 255 being low, and 0 being a hair lower than
255. Remember, system speed changes the way this routine sounds,
pitchwise, and lengthwise.
And that's the tunes according to Edhel :)