Sound - BB4W Tutorial 006


The following gives a quick description to get you going.

SOUND a, b, c, d

Parameter
Specifies
Range
Comments
a
Channel
1,2,3 for music
0 for noise effects
See BB4W Help File
under SOUND for much more detail
b
Volume
-15 is loudest (yes minus 15)
-1 is softest
0 for silence ( can be useful!)

c
Pitch
52 gives middle C
56 gives C# a semitone higher
48 gives B a semitone lower than middle C, etc
Add 4 to the pitch parameter to make it a semitone higher
d
Duration
For moderato use :
quaver 5
crochet 10
minim 20
smaller parameter gives a shorter sound
units are 0.05sec i.e. a duration of 20 lasts for one second

Example program:

      REM Sound
      REM Lugubrious Happy Birthday
      REM Richard Weston
      REM 16 Feb 2003
      MODE8:OFF
      REPEAT
        READ pitch,duration
        SOUND 1, -15, pitch, duration
        SOUND 1,0,0,1
        COLOUR 8+RND(7)
        PRINTTAB(pitch)"Happy Birthday!"
      UNTIL pitch<0
      END
      REM Tune Data (pitch,duration) Note the added rubato!
      DATA 4,5, 4,5, 12,10, 4,10, 24,10, 20,23
      DATA 4,5, 4,5, 12,10, 4,10, 32,10, 24,23
      DATA 4,5, 4,5, 52,10, 40,10, 24,10, 20,10, 12,26
      DATA 44,5, 44,5, 40,12, 24,13, 32,15, 24,40
      REM End Stop!
      DATA -1,0


Notes on numbered version below (Don't try to run this!) :

   10 REM BB4W Sound Demo********************
   20 REM Lugubrious Happy Birthday ***Documentation
   30 REM Richard Weston
   40 REM 16 Feb 2003**************************
   50 MODE8 : OFF **** note the colon " : " is equivalent to a new line. It saves space in the listing ****
   60 REPEAT ************ (UNTIL is at line 140)
   70   READ pitch,duration  *** reads from DATA statements starting at line 170
   90   SOUND 1, -15, pitch, duration ******** This line generates the sounds **********
  100  SOUND1,0,0,1 *********** This leaves a short gap to articulate the notes ********
  110  COLOUR 8+RND(7)  **********Lets be jolly, its a Happy Day! *******
  120     PRINTTAB(pitch)"Happy Birthday!"
  140 UNTIL pitch<0 ******* I've used a negative pitch as an end stop at Line 220 ********
  150 END ****** Tells the computer its work is done (for the moment) **********
  160 REM Tune Data (pitch,duration) Note the added rubato! ***** artistic license ********
  170 DATA 4,5, 4,5, 12,10, 4,10, 24,10, 20,23 *** I've inserted spaces so the data pairs stand out***
  180 DATA 4,5, 4,5, 12,10, 4,10, 32,10, 24,23
  190 DATA 4,5, 4,5, 52,10, 40,10, 24,10, 20,10, 12,26
  200 DATA 44,5, 44,5, 40,12, 24,13, 32,15, 24,40
  210 REM End Stop!
  220 DATA -1,0

Exercise: Without altering the data statements, make the tune play (say an octave) higher than at the moment.

Next Tutorial

Richard Weston's Homepage