\ fourtap-sounds 2001/12/22 KDJ

\ Copyright 2001
\ Kristopher D. Johnson
\ 
\ THIS CODE IS PROVIDED "AS IS"
\ WITHOUT WARRANTY OF ANY KIND.
\ THE AUTHOR SHALL NOT BE LIABLE
\ FOR ANY CLAIM IN CONNECTION
\ WITH THIS CODE.
\ 
\ This code may be used, copied,
\ modified, or distributed for any
\ purpose, provided that the above
\ copyright notice and disclaimer of
\ warranty is retained on all copies.

needs sound
needs fourtap-util

.( fourtap-sounds... )
decimal

\ Volume
variable vol
8 vol !

\ Length of tone in MS
250 constant duration

\ Frequency of buzzer sound
110 constant wrong-freq

\ Sound frequencies for buttons
\ (Notes are C major scale)
create freqarray
  262 , 294 , 330 , 349 ,
  392 , 440 , 494 , 523 ,
  587 , 659 , 698 , 784 ,
  880 , 988 , 1046 , 1175 ,

: btn-freq ( 1..16 -- frequency )
  1- cells freqarray + @ ;

9 constant prefGameSoundLevelV20
31 constant prefGameSoundVolume
64 constant sndMaxAmp

: get-pref ( pref -- u. )
  >byte PrefGetPreference ;

: pref-vol-V20 ( -- vol )
  prefGameSoundLevelV20 get-pref
  ud>u if
    0 exit
  then
  sndMaxAmp ;

: pref-vol-V30 ( -- vol )
  prefGameSoundVolume get-pref ud>u
;

: pref-vol ( -- vol )
  3.0-features? if
    pref-vol-V30 exit
  then
  pref-vol-V20 ;

: init-vol ( -- )
  pref-vol vol ! ;

: volume ( -- n )
  vol @ ;

: btn-sound ( n -- )
  volume 0= if
    duration ms
    drop exit
  then
  >r volume duration r> btn-freq
  sound ;

: wrong-sound ( -- )
  volume [ duration 2* ] literal
  wrong-freq sound ;

: error-sound ( -- )
  2 SystemSound ;



