;Author: Amorel, amorel@xs4all.nl
;Date: February 2002
;
;LICENSE: You are free to use this source as long as you credit the original
;authors. Though if you don`t credit it`s unlikely something bad would happen,
;or would there? =)
;
;DISCLAIMER: If this source causes any harm you suck and the authors do not
;take credit and are not respsonsible.

#NTSCFREQ=3579545:#PALFREQ=3546895

;Using the floating type(.f) is no problem and it can even be used in
;the period command etc.

Dim freq_.f(127)
Dim period_.f(127)
calcvalue.l=440

;Calculate frequency table for native audio.
For teller.l=0 To 127

;this formula calculates the frequency in Hz of 127 notes covering
;10 octaves(a piano has only 8 octaves), the middle C on a piano is note
;freq_(60).
;This table covers also the whole range of midi notenumbers, but ofcourse
;in midi you don`t send frequencies but note numbers(0 to 127).

  freq_(teller)=(calcvalue/32)*(2^((teller-9)/12))
Next

; Function : NewNTSC {}

; Author : James L Boyd - jamesboyd@all-hail.freeserve.co.uk

; Exec-size saving replacement for NTSC.

Function.b newntsc {}
  lib$="graphics.library"
  *gb.GfxBase=OpenLibrary_(&lib$,0)
  If *gb
    If *gb\DisplayFlags AND #REALLY_PAL Then p.b=0 Else p=-1
    CloseLibrary_ *gb
  EndIf
  Function Return p
End Function

;lets calculate the period table using the previously calculated frequency table

ntsc_.b=newntsc{} ;check if the machine is an NTSC or a PAL system

If ntsc_
  For teller=0 To 127

  ;This formula is changed from an example formula in the rkrm hardware manual
  ;to get the period value
    period_(teller)=(#NTSCFREQ/freq_(teller))/16
  Next
Else
  For teller=0 To 127
    period_(teller)=(#PALFREQ/freq_(teller))/16
  Next
EndIf

;To use this you just do:

;Runerrsoff ;This to not get the debugger complaining
;SetPeriod soundnr,period_(arrayitem)
;Runerrson

End

