Classic Computer Magazine Archive COMPUTE! ISSUE 55 / DECEMBER 1984 / PAGE 130

VIC Music Maker

Frank Colosimo

Here is a program that can help you more easily create sound effects or generate songs. The BASIC program generates its own DATA statements as notes are played, allows realtime playing of notes, and lets you adjust the tempo.

"VIC Music Maker" is an easy to use, multifunctional music program for VIC-20s of all memory sizes. Immediately after running, a menu is displayed which gives you a choice of four options. You can:

  1. Develop sound effects or play simple music using the keyboard.
  2. Play back music or sound effects previously added to the program.
  3. Generate DATA statements "recording" the music as you play it on the keys.
  4. Produce a tape file composed of DATA statements and a sound-generating subroutine which can easily be added to other programs.

After typing the program, check for errors, save a copy on tape or disk, and run it. A menu will direct you to select one of the four choices by pressing keys 1 through 4.

Playing And Recording

Press 1 to play music on the keyboard. You can try the tune at the end of this article or experiment to get sound effects. Pressing the S key returns you to the main menu.

Press 3 to "record" what you play in DATA statements. The program will ask you for a starting DATA line number. By default, the number 1000 is printed on the screen, and simply pressing RETURN produces DATA lines starting with this number. Avoid numbers that are used in the program lines.

While you're playing notes, DATA statements will be created on the screen. You can play up to 95 notes before the screen fills and the program ends. Pressing the S key (or reaching the maximum number of notes) causes the program to print one final DATA statement with a value of 99. This is the signal used by the playback loop to indicate end of data.

With your DATA lines on the screen, you can move the cursor up to each DATA line number and press RETURN. This will enter the lines into your program. If you hit a bad note or two, you can do a little editing on the numbers before entering them. Of course, if you do not want to keep a recording of your playing, you can simply rerun the program.

Automatic Music

Selecting option 2 from the menu plays back the music you recorded in the DATA statements. VIC Music Maker plays back notes until it encounters the number 99, signaling that the tune is done. The RESTORE command in line 220 allows only a single tune to be played. By removing it, you can have a number of tunes stored in DATA statements, and they'll be played one by one as you press key 2.

The fourth menu option lets you save a copy of your efforts on tape or disk and later merge it with another program. VIC Music Maker asks you to prepare a cassette or disk and input a filename. Then it requests the number of the last line to be saved. All lines between 800 and this line will be stored. Lines 800–940 contain the playback subroutine, so you'll have both the musical DATA statements and the routine to merge with your other program.

Note: VIC Music Maker, as listed, is designed for saving the music data on tape. To modify the program for disk, substitute the following lines for the lines in the listing:

660 PRINT" {DOWN}{GRN}OPEN1,8,1,"; CHR$(34); A$; CHR$(34); " : CMD1 : LIST800-"; A	 :rem 233

Merging Music With Other Programs

The tape or disk file saved by VIC Music Maker is a data file rather than a program file. It's not stored the same way as BASIC programs. To merge it with another program, or load it by itself, use the following procedure for tape:

  1. Place the cassette containing the file into the tape drive.
  2. Enter the direct command : POKE19,1 : OPEN 1
  3. Press RETURN, and when requested, start the tape.
  4. When the tape stops moving (after it finds the file), clear the screen, press the cursor-down key exactly three times to put you on line four, and enter the following line:
    PRINT" {HOME}" : POKE 198,1 : POKE 631,13 : POKE 153,1
  5. Press RETURN. When the tape comes to a final stop, enter CLOSE 1 and press RETURN.

The sound routine and DATA lines are now added to your own program already in memory. A few cautions are in order, however. First, the merge technique will wipe out any lines in your program if they have the same numbers as the incoming lines. Second, if DATA statements are used in your other program, you will probably have to remove the RESTORE from line 220 and check for proper order of the READ and DATA statements.

To merge data files from disk, first type in Program 2, "VIC Disk Merger." Save a copy before running it, because the BASIC loader portion automatically erases itself from memory when you type RUN. When you have a copy saved, type RUN and follow this procedure:

  1. Load the program to which you want to add the music DATA statements.
  2. Enter SYS 828," filename" (where filename is the name of the music data file).
  3. You'll see the data lines being entered on the screen. Ignore any error messages you might see.

That's it. The sound routine and DATA statements are now part of your program already in memory. Observe the same precautions noted for tape merges above.

How It Works

VIC Music Maker was written in response to trial-and-error efforts at generating songs and sound effects. I was fascinated with the idea of the computer writing its own program lines.

Lines 20 through 40 initialize A(0) - A(9), which are the frequency values that are POKEd into the sound generator to produce musical tones. The next few lines generate the menu and send the program to the routine that is selected.

Lines 140 through 170 let you play notes on the keyboard. As written, the program uses a single voice (S2 = 36876) and ten notes. The other voices, including the noise generator, could be substituted here.

Lines 200 through 240 generate what " plays" the DATA statements. There are two numbers for each note in the DATA lines. The first one is the element of array A that will be POKEd into the sound generator. The second is a duration figure. The value of T also is used as a factor in determining the duration of each note and provides an easy way to change the tempo of song playback. Simply adjust its value higher or lower.

The next section, from line 310 to 520, creates DATA statements on the screen as you play the notes. The duration of each note is obtained with the VIC's built-in timing variable, TI. The complex string expression in line 420 trims off all extra blanks that the VIC tries to print so the maximum number of notes can be squeezed into the DATA lines.

Lines 600–700 produce a tape file (or disk file, if you've substituted the lines above).

VIC Music Maker was written using fairly straightforward BASIC programming principles. This makes it a good program to study for those just starting to learn programming.

If you don't want to type in the program, send a cassette, a self-addressed, stamped envelope, and $3 to:

F. Colosimo
112 Shoreway Drive
Rochester, NY 14612

Sample Tune

Play the notes below using menu selection 1 or 3:

"A Bicycle Built For Two"

0 8 7 6
4 5 6 4 6 3
7 0 8 6
4 5 6 7 8 7
8 9 8 7 0 8 7 6
7 8 6 4 6 4 3
3 6 8 7 3 6 8 7
8 9 0 8 6 7 3 6