Music

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Music

This program generates random music using the SOUND command. Each loop iteration reads 20 values from DATA statements — 17 random values scaled from 0–15 and three PAUSE durations — then applies them across SOUND parameters 0 through 13. The DATA lines 160 through 340 each contain a single `(RND*15)` expression, so the random values are re-evaluated each time the READ pointer cycles through them. A sentinel value of 1000 in the final DATA line at line 350 triggers the STOP condition checked at line 20.


Program Analysis

Program Structure

The program forms a tight read-play loop. Lines 10–50 read 20 values from the DATA pool into variables A through T. Lines 60–140 issue a series of SOUND commands using those variables, interspersed with three PAUSE calls. Line 150 sends execution back to line 10 to read the next batch. Line 350 provides a terminating sentinel (1000) that is caught by the check at line 20.

DATA and Randomization Technique

Each of lines 160–340 contains a single DATA (RND*15) expression. Because BASIC evaluates RND at the time the DATA is read — not when it is listed — each pass through the READ loop draws a fresh random integer between 0 and 15 for every parameter. This is an elegant way to produce endlessly varying output from a fixed DATA list without needing assignment statements or arrays.

Line 350 supplies the five terminal values 1000,0,0,0,0. The first value, 1000, is read into A and triggers the IF A=1000 THEN STOP guard at line 20 after one full cycle through all 19 random DATA lines. In practice the loop runs once and then halts — unless the DATA pointer wraps, which it does not do automatically; a RESTORE would be needed to loop indefinitely.

Timing

Three PAUSE statements at lines 80, 100, and 120 insert delays between SOUND bursts. Because the pause durations are themselves random values (0–15 television frames each), the rhythmic feel of the output varies unpredictably from cycle to cycle.

Content

Appears On

Related Products

Related Articles

Related Content

Image Gallery

Source Code

   10 READ A,B,C,D
   20 IF A=1000 THEN STOP 
   30 READ E,F,G,H,I
   40 READ J,K,L,M,N
   50 READ O,P,Q,R,S,T
   60 SOUND 7,A;6,B
   70 SOUND 0,C;1,D;8,E
   80 PAUSE O
   90 SOUND 2,F;3,G;9,H
  100 PAUSE P
  110 SOUND 4,I;5,J;10,K
  120 PAUSE Q
  130 SOUND 11,L;12,M;13,N
  140 SOUND 8,R;9,S;10,T
  150 GO TO 10
  160 DATA (RND*15)
  170 DATA (RND*15)
  180 DATA (RND*15)
  190 DATA (RND*15)
  200 DATA (RND*15)
  210 DATA (RND*15)
  220 DATA (RND*15)
  230 DATA (RND*15)
  240 DATA (RND*15)
  250 DATA (RND*15)
  260 DATA (RND*15)
  270 DATA (RND*15)
  280 DATA (RND*15)
  290 DATA (RND*15)
  300 DATA (RND*15)
  310 DATA (RND*15)
  320 DATA (RND*15)
  330 DATA (RND*15)
  340 DATA (RND*15)
  350 DATA 1000,0,0,0,0

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top