( music DAY 13.04.2001 )

needs sound sound

: freq:
   6 0
   do
     nextword evaluate w,
   loop
;

decimal
create freqHz
freq: 65 69 73 78 82 87 
freq: 92 98 104 110 117 123 
freq: 131 139 147 156 165 175 
freq: 185 196 208 220 233 247 
freq: 262 277 294 311 330 349 
freq: 370 392 415 440 466 494 
freq: 523 554 587 622 659 698 
freq: 740 784 831 880 932 988 
freq: 1047 1109 1175 1245 1319 1397 
freq: 1480 1568 1661 1760 1865 1976


variable octave    ( -1 0 1 2 3 )
variable volume
variable duration

: v volume ! ;
: o octave ! ;
: o++ octave 1+! ;
: o-- -1 octave +! ;

: note:
   create w,
   does> ( addr )
         volume @ duration @
         rot w@ 
         octave @ 1+ 12 w*
         + 2* freqHz + w@
         sound
;

1000 value tempo

: whole tempo duration ! ;

: half tempo 2/ duration ! ;

: quarter tempo 2/ 2/ 
          duration ! ;

: eighth tempo 3 rshift
         duration ! ;

api: PrefGetPreference

: musinit
   osver @ 1- 0x03003000 >
   if 31 else 9 then
   ( prefGameSoundVolume)
   PrefGetPreference v
   1 o quarter
;
musinit

0  note: C
2  note: D
4  note: E
5  note: F
7  note: G
9  note: A
11 note: B

1  note: C#
1  note: Db
3  note: D#
3  note: Eb
6  note: F#
6  note: Gb
8  note: G#
8  note: Ab
10 note: A#
10 note: Bb

: mute
  1 duration @ 32000 sound
;

\eof 

: test
    1 o
    C D E F G A B
    o++ C
;

: dog
   quarter 1 o
   C C o-- B B
   A A A B o++
   C C o-- B B half A A
;

: dog2
  quarter 2 o
  B B A A G G G A
  B B A A half G G
  quarter
  F F E E D D D E
  F F E E half D D
;

: rip
  whole 1 o
  D D half D whole D
  F half E whole E half D whole D half C# whole D 
;
