Audio Recorder For Apple II
Add digitally recorded sound and music to your programs with this fascinating program for your Apple II, II+, or Apple IIe computer. A cassette player and disk drive are required.
Digital music is a revolution. Ever since Thomas Edison invented the first phonograph, sound has been stored in analog form. But recently, new media have been invented and computer memories have grown large enough to store sound in a more accurate way—as a series of numbers. Digital recording and mastering make the music you buy sound better, especially if you have a digital compact disc (CD) player or the even newer digital audio tape (DAT) player. You may not know it, but your Apple can record and play back digital music. Although the sound quality leaves something to be desired (CD players use 16 bits of resolution; the Apple uses only 1—so the sound quality of a CD player will be 65,536 times better than that possible with your computer), it may be just what you need to add a blood-curdling scream or a rousing cheer to your latest game.
"Audio Recorder" makes digital recording and playback easy. The sound comes through the cassette port into your computer. When you're ready, the sound can be played back through the built-in speaker or saved to a disk for later use.
How does digital recording work on an Apple II? The sound source—a cassette player, for example—is connected to the cassette input port of your computer. A machine language program continuously monitors memory location 49248. The seventh bit of this memory location varies between 0 and 1 as the signal level at the cassette input port changes. The changing status of this bit is recorded in memory. Once the sound data is in memory, it can be manipulated or saved to disk. Later, the recorded sound is played back by toggling the bit in memory location 49200 that controls the speaker.
Note: Only the Apple II, II+, and IIe models have a cassette port, so those are the only ones which can record sounds with this program. However, the program can be used on any Apple II, including the IIc and IIGS, to play back recorded sounds saved on disk.
Typing It In
Audio Recorder is written in machine language, so it must be entered using the Apple version of the "MLX" machine language entry program, found elsewhere in this issue. Be sure you read and understand the instructions for using MLX before you begin entering data. When you run MLX, you'll be asked for a starting address and an ending address for the data you'll be entering. For Audio Recorder, use the following values:
STARTING ADDRESS? 0300 ENDING ADDRESS? 036C
Once you've typed in all the data, be sure to save a copy before leaving MLX.
You are now ready to record a song or a sound effect. Look at the back of the main board of your computer. Next to the video connector are two jacks labeled CASSETTE IN and OUT (the IIe has icons instead of words). Plug one end of a cable into the CASSETTE IN jack (for the IIe, the one with the arrow pointing away from the cassette icon) and the other into the external speaker or earphone jack of the tape recorder or other sound source. If you are using a tape player, insert a tape with music or sound effects into the player. Type BLOAD RECORDER (substitute whatever name you used for the Audio Recorder program). For the best possible quality, adjust the controls of your sound source so that it is near, but not at, its maximum volume. At the Applesoft ] prompt, type CALL 768, but don't press RETURN yet. Start your sound source; for example, if you are using a tape player, press the PLAY button. When you get to the sound that you want to record, press the Apple's RETURN key. When all the memory available for storing sounds has been filled you'll see the flashing cursor again. To play back your sound, type CALL 823. If you are dissatisfied with the results, try recording the sound again.
When you are ready to save a sound to disk, follow this procedure. If you are using DOS 3.3, first type POKE 43364,255. ProDOS users should not use this POKE. To save the song in either DOS, type:
BSAVE filename, A$800, L$8E00
To play back a song that has been saved to disk, type BLOAD RECORDER (if Audio Recorder is not already in memory); then BLOAD your song. At an Applesoft] prompt, type CALL 823 to play it back.
The recording may not always sound clear. If you are unhappy with the results, try changing the volume control of the sound source. For best results, use the highest quality equipment to which you have access. Another way to alter the quality of the recording is to change the sampling rate—the time between checks of the cassette port, or between bits being played back on the speaker. Fast sampling rates allow for more accurate recording or reproduction. But taking the samples faster means that memory will be filled more quickly, so less can be recorded. Conversely, slow sampling rates increase the length of the recording but diminish its quality. When choosing sampling rates, you must strike a balance between quality and length.
Audio Recorder provides separate sampling rates for recording and playback, so you can record at one speed and play back at another. The recording speed is controlled by the value in location 784 ($310) and the playback speed, by the value in 839 ($347). The default value for both of these locations is 4, which allows 40 seconds of sound to be saved. Changing the delay values to 1 gives the highest sampling rate, and hence the highest sound quality. However, at that rate only 15 seconds of sound can be recorded.
The following line would change the sampling rate to obtain the best sound:
DF = 1 : POKE 784,DF : POKE 839, DF
Feel free to experiment with other values for DF.
A Personalized Message
Here's one example of the many uses that you can find for Audio Recorder: Put your voice on a disk as a greeting card and then send it to a friend who has any Apple IIseries computer. To make your personalized greeting disk, type the following commands with a word processor and save it as an ASCII text file with the name BIRTHDAY. (Check your manual to find out if your word processor can save files as straight ASCII text.)
BLOAD GREETING BLOAD RECORDER TEXT : HOME : VTAB 3 : HTAB 2 : PRINT "Dear friend," VTAB 12 : HTAB 13 : PRINT "HAPPY BIRTHDAY !" VTAB 21 : HTAB 30 : PRINT "Yours," : HTAB 30 : PRINT "your name" CALL 823 CALL 976
Assuming that you have created a recording of your voice and saved it with the name GREETING, this series of commands will display a greeting card screen as your voice plays through the Apple speaker. To make the contents of the file execute automatically when they boot their computer, write a program like this and save it as your HELLO or STARTUP program:
10 PRINT CHR$(4) ; "EXEC BIRTHDAY"
About The Program
Audio Recorder consumes a lot of memory space—from 2048 ($800) to 38400 ($9600). Any BASIC program or any data stored in this area will be overwritten when sound data is recorded or loaded. Therefore, you must be sure that any important data in this area is saved before you run Recorder. The starting and ending address of the sound sample can be changed to make shorter samples or to relocate the sample data to memory locations that are otherwise unused—just the thing for a game sound effect.
Locations 769 ($301) and 829 ($33D) should both contain the page number where you would like the recording to start. Locations 819 ($333) and 872 ($368) should contain the page number where you want the recording to end. A page is a 256-byte block of memory; you can convert an address to a page number by dividing by 256. For example, location 2048 ($0800) corresponds to page number 8. Since only the high byte of the starting and ending address can be changed, the sound sample storage area must begin at an address which is an exact page boundary. The default starting page number is 8, for address 2048 ($0800). The default ending page number is 150, for location 38400 ($9600).
To create a version of Audio Recorder which uses different addresses for sound data, BLOAD a copy of the original version and then POKE the new page numbers into the addresses given above. Finally, save a copy of the modified version with a statement of the form
BSAVE filename, A$300, L$6C
You should take care not to overwrite your original copy of Audio Recorder. Save the modified copy with a different filename, or on a different disk.
For instructions on entering this program, please refer to the "Apple MLX" article elsewhere in this issue.
0300: A0 08 8C 28 03 A2 00 8E 9D 0308: 27 03 86 FF A0 08 48 A9 92 0310: 04 20 A8 FC 18 AD 60 C0 FD 0318: 45 FF 10 05 45 FF 85 FF 48 0320: 38 68 2A 88 D0 E8 9D 00 8F 0328: 08 E8 D0 E0 EE 28 03 AD 60 0330: 28 03 C9 96 D0 D6 60 A2 F2 0338: 00 8E 5C 03 A0 08 8C 5D 39 0340: 03 D0 18 A0 08 48 A9 04 C1 0348: 20 A8 FC 68 0A EA 90 05 D0 0350: 8D 30 C0 B0 00 EA EA EA B8 0358: 88 D0 EA BD 00 08 E8 D0 D2 0360: E2 EE 5D 03 AD 5D 03 C9 22 0368: 96 D0 D8 60 00 01 00 00 13