Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

TEMPO

Keyword Abbreviation Token (hex) Version(s) Classification
TEMPO T{Shift+E} FE 05 7.0 Command and Statement

 
  Syntax   
TEMPO playRate
 
Parameters Type Legal Value(s) Default Value Note(s)
playRate Unsigned Byte 1 ~ 255 16
 
 
  Purpose  
Audio state management.  Sets the PLAY speed of music.

 
  Remarks  
TEMPO sets the speed of musical notes (and rests) generated by the PLAY statment.  A higher playRate means the notes will play faster (shorter duration).
 
Each of the audio chip's voices (see PLAY) has an associated secret variable we'll call duration that determines how long a note (or rest) will play.  The duration is initialized by PLAY as 1152 * note (or rest) duration.  Some examples: a whole note initializes duration with 1152 = 1152 * 1/1, and a quarter note initializes duration with 288 = * 1/4.  The BASIC IRQ, 60 or 50 times per second (NTSC or PAL machine, respectively), will decrement the duration of each (active) voice by the playRate .  Once the duration underflows the note (or rest) is complete and PLAY will then proceed to initializtion the duration for the next note/rest of the same voice in the musical score (if any).
 
Hopefully you see the flaw in this logic!  The duration is not set according to the NTSC/PAL standard of the machine.  So a program written on an NTSC machine will PLAY too slow on a PAL machine, and conversly a program written on a PAL machine will PLAY to fast on an NTSC machine, unless you you PEEK another secret variable to determine what machine (NTSC or PAL) is actually running the program and adjust the playRate accordingly.
 
The default playRate is only set on power-up.  In particular, it is not set when a user RUNs a program so you should be sure to set a TEMPO in any program using PLAY.  With the default playRate, the PLAY speed for NTSC works out to 1152 / 4 / (60 * 16) = 0.3 ms / quarter note = 3.3.3 quarter notes per second, and for PAL it works out as 1152 / 4 / (50 * 16) = 0.36 ms / quarter note = 2.7.7 quarter notes per second.  That is a very noticable difference.
 
Sorry if that was too math-heavy for you.  Here is a simple formula (where FPS is 60 or 50 for NTSC or PAL respectively):
 quarter notes per second = playRate * FPS / 288
or to reverse that formula:
 playRate = quarter notes per second * 288 / FPS
 
 
If the playRate is omitted or is an invalid expression, SYNTAX ERROR occurs.  If playRate is not numeric, TYPE MISMATCH ERROR occurs; VAL may be used to convert a string value.  A floating-point playRate will be converted with INT.  If the result is not a Legal Value (see table above), ILLEGAL QUANTITY ERROR occurs.
 
BASIC provides no function to read the current playRate.  If you need to determine the value, you will have to PEEK yet another secret variable.
 
Example for C128 (sets 3.5 quarter notes per second, regardless of NTSC/PAL machine)
TEMPO 17 : REM assume NTSC

READY.
BANK 15 : IF PEEK(2563) AND 128 THEN TEMPO 20

READY.
 
 
  Compare With  
 
  Contrast With  
  See Also  

© H2Obsession, 2014
Comments