Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
TEMPOT{Shift+E}FE 057.0Command and Statement

 
 Syntax  
TEMPO playRate
 
ParametersTypeLegal Value(s)Default ValueNote(s)
playRateUnsigned Byte1 ~ 25516
 
 
 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