Sub Process_Globals
Private streamer As AudioStreamer
End Sub
Sub Service_Create
streamer.Initialize("streamer", 8000, True, 16, streamer.VOLUME_MUSIC)
streamer.StartPlaying
End Sub
Public Sub Beep (DurationMs As Double, Frequency As Int)
Dim sampleRate As Int = 8000
Dim numSamples As Int = sampleRate * DurationMs / 1000
Dim gsnd(2 * numSamples) As Byte
For i = 0 To numSamples - 1
Dim d As Double = Sin(2 * cPI * i / (sampleRate / Frequency))
Dim val As Short = d * 32767
gsnd(2 * i) = Bit.And(val, 0x00ff)
gsnd(2 * i + 1) = Bit.UnsignedShiftRight(Bit.And(val, 0xff00), 8)
Next
streamer.Write(gsnd)
End Sub