Classic Computer Magazine Archive COMPUTE! ISSUE 56 / JANUARY 1985 / PAGE 138

IBM Personal Computing

Donald B. Trivette

Music For Amateurs

The theme of this month's COMPUTE! is music, so the editor suggested I write something about making music with the IBM PC and PCjr. Great idea, except I know less about music than Beethoven knew about BASIC. I did write a musical game called "Name These Notes." It's similar to the Name That Tune TV show. The first player who stops the music and identifies the correct tune gets the points. But before I could even test the program, I had to hire a music stu­dent to translate sheet music into computer music. Although the game is lots of fun, no software publisher will touch it—something about paying royalties on all those tunes, but that's another story. The point is that you don't have to know anything about scales or octaves or half notes to experiment with music on your IBM—or even to write a musical game.

Both the PC and the PCjr have the circuits necessary to generate tones, both have a tiny internal speaker for playing those tones, and both run a version of the BASIC programming language which includes a music-making command. Start up your PC or PCjr and try it.

The PLAY Statement

First you must get the proper version of BASIC running on your computer. Although the PC and PCjr have a built-in BASIC—a version of the language that is a permanent part of memory—that BASIC does not have the command that allows you to play music. Instead, you'll need the advanced disk version of BASIC on the PC (also known as BASICA), or Cartridge BASIC on the PCjr. BASICA for the PC is included on the DOS disk; Cartridge BASIC for Junior is an extra-cost option.

For the PC: First load DOS, then type BASICA at the A> prompt. For the Entry Model PCjr: Insert Cartridge BASIC in either front slot and switch on the computer. For the Enhanced Model PCjr: Insert Cartridge BASIC, load DOS, and type BASIC at the A> prompt.

Once the BASIC prompt Ok is displayed on the screen, you are ready to compose. We'll start with something simple. The BASIC music statement is named PLAY. Type PLAY "CDE" and press the Enter key. You'll hear the musical notes C, D, and E played by your computer. (If you typed the statement correctly but got a Syntax Error anyway, then you're running the wrong version of BASIC.) When typing notes, upper and lowercase characters and spaces are unimportant; "CDE" sounds just like "c d e". Should you be musically inclined, you'll recognize these notes as do, re, mi—the first three notes of the diatonic scale. Now type PLAY "CDEFGAB" and press the Enter key again. Those are the seven basic notes of the scale from which all music is composed on the computer (or any other musical instrument, for that matter).

There are lots of things that can be done with those seven notes. For example, if they are played in a low octave, they will sound, well, low; and if they're played in a high octave, they'll sound high. (That is the sum total of my knowledge regarding octaves.) The PC and PCjr can reproduce seven octaves. The PLAY statement defaults to octave 4, but gives you a way to change the octave. It's the O character (for Octave)—the fifteenth letter of the alphabet. The PCjr BASIC manual doesn't distinguish between the numeric 0 and the alphabetic O. This is sure to cause readers great frustration when they try running the examples in the book. The PC BASIC manual, on the other hand, is printed with slashed zeros to represent the numeric 0. To simplify, I'll use a lowercase o for the alphabetic character.

Changing Octaves Within Tunes

Now let's mix in a few octave changes to hear the effect. Try entering these lines:

PLAY "oO CDEFGAB"
PLAY "06 CDEFGAB"
PLAY "o2 CD o4 EF 06 AB"

Look up the PLAY statement in your BASIC manual to see all the things that can be done with the notes. They may be played sharp or flat (+ or -); for different lengths of time (Ln, where n = 1 for a whole note, 2 for a half note, 4 for a quarter note, etc.); in different tempos (Tn, where n = 32 to 255 quarter notes per minute); and in legato (ML), staccato (MS), or normal (MN). It's not necessary to know what these terms mean to have fun playing music. In fact, experimenting with these options is a good way to learn what they do mean. Try this:

PLAY "ms o3 CDEFGAB"
PLAY "ml o3 CDEFGAB"
PLAY "t50 ms o3 CDEFGAB"
PLAY "t250 ml o3 CDEFGAB"

Even the tone deaf will notice that music from the PC doesn't sound quite right. It sounds tinny and mechanical. Part of the problem is the small internal speaker—IBM is a computer company, not a music company—and part of the problem is that the PC has only one voice, or sound channel. In other words, it's monophonic: It can play only one note at a time, so it can't make chords or blend notes together.

Junior's Improved Sound

The PCjr is more musically accomplished than its big brother. It has an external speaker jack (marked A for Audio on the rear panel) which can be connected directly to your stereo system. By running an inexpensive cable (available from any audio store) to your amplifier, Junior can make beautiful music through your high-fidelity speakers. (For a simple way to modify your PC to hook it up to a stereo system, see "The Amplified PC," COMPUTE!'s PC & PCjr magazine, September 1984.)

Plus, there's an even more important difference between the PC and PCjr's sound capabilities. The PCjr has an extra polyphonic sound chip that allows it to play up to three voices at once. In fact, it's the same sound chip found in the discontinued Texas Instruments TI-99/4A home computer. The other members of the PC family do not have this chip and are restricted to monophonic music.

Junior's extra voices only work when the computer is connected to an external speaker system, a TV set, or to IBM's RGBjr Display, which has a speaker of its own. Otherwise, Junior's internal speaker works just like the PC's internal speaker—it supports but one voice.

If you have your PCjr connected to an external sound system, try this three-voice composition:

10 SOUND ON
20 PLAY "mn CDEFGAB","ml CDEFGAB","ms CDEFGAB"

It's not music to my ears either, but it does demonstrate what three scales, played at the same time, sound like. For a more melodious example, run the multiple-voice program from the PCjr BASIC manual on page 4-272. (My manual has some typographical ambiguities: In line 50, the three O's should be the alphabetic characters; in line 150, "1 = 1;" really means "L=L;".) Notice that to turn on Junior's external speaker and use more than one voice, you must first include the SOUND ON statement. There is no equivalent for that on the PC.

A PC/PCjr Music Utility

Enough about multiple voices. You've got to know what you are doing, musically, to program them in a pleasant way. To satisfy both groups of readers, the tunes in this column are in one voice only; they play on either the PC or the PCjr.

When I was working on "Name These Notes," I needed a utility program to display the notes on the screen as they were played. This helped the musician, who was reading the chicken scratches on sheet music, to catch typo­graphical errors on the screen. Things begin to get fuzzy when you've been staring at a screenful of "DDDP16DDG8A8B8DDDP" for an hour.

The program listing following this column is a modified version of that utility—a program that displays as it plays. It has two modes: a slow mode, in which the display may cause the music to be played more slowly (especially the "William Tell Overture"); and a fast mode that has no delay. I've put in a few tunes for which there are no royalty fees (I hope). If you can read sheet music, add a few tunes of your own. If you can't, try changing the tempo and octaves on these. The results can be fun. (If you have a PCjr, be sure DOS and Cartridge BASIC are running so you can save the program on disk.)

For the lazy but curious: If you just want to hear the tunes, you need only type the word PLAY and the character string of notes. For example, to hear "America," type PLAY "GGAF + 4.G8ABBo4…."

The first five lines, 10-50, are the character strings that make up the tunes; lines 60-80 are for your own compositions. For instance, to add the scales as tune number 6, type:

60 X$(6) = "Scales = CDEFGAB"

Notice that the title is separated from the notes by an equal sign. While BASIC doesn't care whether you put blank spaces between the musical notes, this program does. Should you type the scale as "CDE FGAB", only the first three notes will be displayed and played. The musical notes (A-G) must be in uppercase; the other characters may be upper- or lowercase. I used lowercase, except for the L (length), which might be easily confused with a 1.

BASIC limits the length of a character string—the stuff between the quote marks—to 255 characters. There is a way to play longer pieces using what the BASIC manual describes as an "X variable."

PLAY "T120 L12o2CFAL6o3CL12o2AL4o3C"

New Software

Now for some personal notes on software. There are two new programs for the PCjr that deserve mention this month. Managing Your Money (written by MECA and distributed by IBM) is now available on cartridge for $199. This is the same great program that runs on the PC; it will take care of all your home accounting, budgeting, investing, and tax problems. This may be the program that does for PCjr sales what VisiCalc did for the Apple.

IBM is also the distributor for King's Quest by Sierra, a new fantasy game ($50). If you want to see how good graphics can be on the PCjr, try this one. The animated characters, lifelike images, challenging puzzles, and tricky strategy make King's Quest a winner. (The version sold under the IBM logo will only run on the PCjr. However, Sierra markets identical versions for the Apple, Tandy, and IBM PC computers.) Looking for a last-minute Christmas gift for a PCjr owner? This is it. (Should any of you figure out the gnome's name, please write me.)

PC/PCjr Music Display Utility

Refer to "COMPUTEI's Guide To Typing In Programs" before entering this listing.

HM 10 X$ (1) = "Amer i ca = GGAF + 4 .G8ABBo4Co3 B4 .A8GAGF + G2.O4DDDD4.C8o3Bo4CCCC4.o3B8ABo4mlC8o3B8A8mnG8B4.O4C8DmlE8mnC8o3BAG2."
IF 20 X$ (2) = "America the Beautiful = GG4.E8EGG4.D8DEFGABG2.GG4.E8EGG4.D8 Do4DC + DEo3Ao4D2.o3Go4E4.E8DCC4.o3B8Bo4CDo3BAGo4C2."
GF 30 X$ (3) = "Silent Night = T65mIF8.mnG16F8D4.mlF8.mnG16F8D4.o4CC8o3A4.B-B-8F4.GG8mlB-8.mnA16G8mlF8.mnG1 6F8D4."
Gd 40 X$ (4) = "William Tell Overture = L 16o3DDDp 16DDDp 16DDG8AB8DDDp 16DDDp 16BBA8G-8D8DDp 16DDDp 16DDG8A8B8p 16Go4D4p8o3G8B8G8"
IB 50 X$ (5) = "Mary Had a Little Lamb = t 100o3L8GFE-FGGGp8FFF4GB-B-4GFE-FGGGGFFGFe-0."
HM 60 X$ (6) = "="
HE 70 X$ (7) = "="
IM 80 X$ (8) = "="
PE 90 X$ (9) = "End Program ="
LK 100 KEY OFF
KG 110 CLS : PRINT "Tunes"
LP 120 FOR I = 1 TO 9
HP 130 PRINT	I ;Mid$ (X$ (1), 1, INSTR (X$ (1). "=" -1)
NF 140 NEXT
PL 150 PRINT : PRINT "Enter tune number :";
EA 160 A$ = INKEY$ : IF A$ = "" THEN 160
NI 170 I = VAL (A$)
LJ 180 IF I = 0 THEN GOTO 110
NI 190 IF I = 9 THEN END
BC 200 B$ = X$ (1)
ID 210 PRINT
QJ 220 REM
LE 230 PRINT "Enter : F for fast or S for slow :";
CO 240 A$ = INKEY$ : IF A$ = "" THEN 240
HL 250 IF A$ = "F" OR A$ = "f" THEN GOTO 460
JN 260 PRINT
DK 270 '-- Begin Slow Mode --
GJ 280 TIT$ = MID$ (B$, 1, INSTR (B$, "=")-1) : PRINT TIT$
JN 290 PLAY "T 120O3MFMNL4"
NC 300 C$ = MID$ (B$, INSTR (B$,"=") + 1) + " "
EB 310 C$ = MID$ (C$, 1, INSTR (C$," ")-1)
IC 320 KK = LEN (C$) : KIK = 0 : T$=""
KB 330 FOR K1 = 1 TO KK
OL 340 IF KI MOD 25 = 0 THEN PRINT
GL 350 W$ = MID$ (C$, K1, 1)
BH 360 IF W$ < "A" OR W$ > "G" THEN GOTO 390
PD 370 COLOR 15 : PRINT T$;" "; : PLAY T$ : COLOR 7 : LOCATE, POST(0)-(LEN(T$) + 1) : PRINT T$;" ";
CM 380 T$ = ""
OL 390 T$ = T$ + W$
AB 400 NEXT KI
PI 410 COLOR 15 : PRINT T$;" " : PLAY T$ : COLOR 7 : LOCATE, POS(0)-(LEN(T$) + 1) : PRINT T$ : " ";
OI 420 PRINT : PRINT
OL 430 PRINT : PRINT "Press any key to continue.";
GK 440 A$ = INKEY$ : IF A$ = "" THEN 440
BE 450 GOTO 110
DP 460 '--End Slow Mode -- Begin Fast Mode --
CN 470 PRINT : PRINT : PRINT
GL 480 TIT$ = MID$(B$, 1, INSTR(B$, "=") : PRINT TIT$
IM 490 PLAY "T 120O3MFMNL4" + MID$(B$, INS TR(B$," = ") + 1)
BL 500 GOTO 110