/* BassSound Library for OxygenBasic  22.o6.2o12  by P. Wirbelauer */ 

macro hiword(a)
0xffff and (a>>16)
end macro

macro loword(a)
a and 0xffff
end macro

sys Bass
Bass = LoadLibrary "Bass.dll"

Bind Bass
(
  BassInit           BASS_Init
  BassStart          BASS_Start
  BassFree           BASS_Free
  BassStop           BASS_Stop
  BassPause          BASS_Pause
  BassCreateFile     BASS_StreamCreateFile
  BassStreamPlay     BASS_StreamPlay
  BassStreamFree     BASS_StreamFree
  BassGlobalVolume   BASS_SetGlobalVolumes
  BassSetVolume      BASS_SetVolume
  BassGetVolume      BASS_GetVolume
  BassChannelStop    BASS_ChannelStop
  BassChannelPause   BASS_ChannelPause
  BassChannelResume  BASS_ChannelResume
  BassGetVersion     BASS_GetVersion
  BassMusicPlay      BASS_MusicPlay
  BassMusicLoad      BASS_MusicLoad
  BassMusicFree      BASS_MusicFree
  BassMusicVol       BASS_MusicSetChannelVol
  BassMusicPan       BASS_MusicSetPanSep
  BassMusicGetName   BASS_MusicGetName
)

Dim WavHnd(512) As sys

Sub InitSound() 
    BassInit -1,44100,0,0
    BassStart
    BassGlobalVolume -1,-1,-1
End Sub

Function GetBassVersion() As String
    sys Ver,vHi,vLo, string Version  
    Ver = BassGetVersion()
    vHi = HiWord(Ver)
    vLo = LoWord(ver)
    Version = str(vHi) + "." + str(vLo)
    Return Version
End Function

Function LoadSound(string SoundFile) As sys
    Static id as sys
    iF id <=512 Then id +=1 
    WavHnd(id) = BassCreateFile 0,Soundfile,0,0,0
    Return WavHnd(id)
End Function

Sub PlaySound(sys wav)
    BassStreamPlay wav,1,0
End Sub

Function LoadMusic(string MusicFile) as sys
    Return BassMusicLoad 0,MusicFile,0,0,4 
End Function   

Sub PlayMusic(sys Handle)
    BassMusicPlay Handle
End Sub    

Sub FreeSound()
    BassFree
    FreeLibrary bass
End Sub
