Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - sound() sound a speaker tone of frequency/duration http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 sound()             Sound a speaker tone of frequency/duration
------------------------------------------------------------------------------
 Declaration
   io.hdr

 Syntax
   proc sound extern
   param value uint uFrequency, ;
         value uint uDuration

 Arguments
   uFrequency is the frequency of the generated sound.
   uDuration is the duration of the sound in 100th of a second..

 Return
   None.

 Description
   This procedure initiates the speaker to sound a tone of uFrequency for
   uDuration. Refer to the Sound table to determine the right frequency for
   a note.

   Higher notes can be approximated by doubling the frequency of the
   corresponding note. Lower notes can be approximated by halving the
   frequency.

 Example
   #define EXAMPLE_IO
   #include example.hdr

   // This application is a miniature juke box
   
   proc SONGPROC ptr
   
   vardef sfar
      char cFreq       := "0366567766412221076431206656776641222107643"
      char cSpeed      := "2020202020162020202033412020202016202020205"
      dbl  aNoteW[ 8 ]
      dbl  aDurW[ 7 ]
      int  aNoteB[10]  := 440, 392, 440, 1, 394, 349, 330, 294, 559, 294
      int  aDurB[10]   :=  10, 10, 120, 30, 8, 8, 8, 8, 100, 150
   enddef
   
   proc LoadWeiner static
   param value dbl eParam1, value dbl eParam2
   aNoteW[0] := eParam2 * 293.66
   aNoteW[1] := eParam2 * 329.63
   aNoteW[2] := eParam2 * 369.99
   aNoteW[3] := eParam2 * 392.00
   aNoteW[4] := eParam2 * 440.00
   aNoteW[5] := eParam2 * 466.16
   aNoteW[6] := eParam2 * 493.88
   aNoteW[7] := eParam2 * 523.25
   aDurW[ 0] := eParam1 * 0.063
   aDurW[ 1] := eParam1 * 0.125
   aDurW[ 2] := eParam1 * 0.188
   aDurW[ 3] := eParam1 * 0.250
   aDurW[ 4] := eParam1 * 0.375
   aDurW[ 5] := eParam1 * 0.750
   aDurW[ 6] := eParam1 * 0.875
   endproc
   
   proc PlayWeiner static
   // Play the "Weiner" tune from TV
   vardef
      dbl x, z, y
      int n
      uint nMax
   enddef
   nMax := len( cFreq )
   x    := 150
   z    := 1.5
   for y = 0 to 2
      LoadWeiner( x, z )
      for n := 0 to nMax
         sound( aNoteW[ ival( substr( cFreq, n, 1 ) ) ], ;
            aDurW[ ival( substr( cSpeed, n, 1 ) ) ])
      next
      z *= 1.7
      x += 5
   next
   endproc
   
   proc PlayBach static
   // Play the start of Bach's minuet in G
   vardef
      uint n
   enddef
   for n := 0 to 9
      sound( aNoteB[ n ], aDurB[ n ] )
   next
   endproc
   
   proc Finish static
   // Exit the application
   quit
   endproc
   
   vardef sfar // array of pointers to functions that play a song
      ptr( SONGPROC ) aSongs[ 3 ] := &Finish, &PlayBach, &PlayWeiner
   enddef
   
   proc Test_sound
   vardef
      _SLIST          pList
      uint            uChoice
      ptr( SONGPROC ) pSongProc
   enddef
   clear
   @ 8, 32 ?? "Select music to play"
   pList := pickinit()
   pickadd( pList, "Bach minuet in C" )
   pickadd( pList, "Weiner tune" )
   do while .t.
      uChoice := pickdisp( pList, 10, 32, 11, 48 )
      pSongProc := aSongs[ uChoice ]
      pSongProc()                          // execute music function
   enddo
   endproc

   proc main
   Test_sound()
   endproc

See Also: Sound table beep()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson