I took a look at getting it to work with Bmax, and here is some code for you:
'
' load the KSND DLL into memory
'
Const KSND_DLL:String = "ksnd.dll"
Global g_hndDLL:Int
g_hndDLL = loadlibrarya(KSND_DLL)
If g_hndDLL = Null Or g_hndDLL = 0 Then
RuntimeError "Unable to find the file: "+KSND_DLL
End If
Private
' player calls
Global KSND_CreatePlayer:Byte Ptr(samplerate:Int)"Win32" = GetProcAddress(g_hndDLL,"KSND_CreatePlayer")
Global KSND_FreePlayer(kplayer:Byte Ptr)"Win32" = GetProcAddress(g_hndDLL,"KSND_FreePlayer")
Global KSND_PlaySong(kplayer:Byte Ptr,ksong:Byte Ptr,position:Int)"Win32" = GetProcAddress(g_hndDLL,"KSND_PlaySong")
Global KSND_Stop(kplayer:Byte Ptr)"Win32" = GetProcAddress(g_hndDLL,"KSND_Stop")
Global KSND_Pause(kplayer:Byte Ptr,state:Int)"Win32" = GetProcAddress(g_hndDLL,"KSND_Pause")
Global KSND_GetPlayPosition:Int(kplayer:Byte Ptr)"Win32" = GetProcAddress(g_hndDLL,"KSND_GetPlayPosition")
Global KSND_SetVolume(kplayer:Byte Ptr,volume:Int)"Win32" = GetProcAddress(g_hndDLL,"KSND_SetVolume")
' song calls
Global KSND_LoadSong:Byte Ptr(kplayer:Byte Ptr,path:Byte Ptr)"Win32" = GetProcAddress(g_hndDLL,"KSND_LoadSong")
Global KSND_LoadSongFromMemory:Byte Ptr(kplayer:Byte Ptr,mem:Byte Ptr,length:Int)"Win32" = GetProcAddress(g_hndDLL,"KSND_LoadSongFromMemory")
Global KSND_FreeSong(ksong:Byte Ptr)"Win32" = GetProcAddress(g_hndDLL,"KSND_FreeSong")
Global KSND_GetSongLength:Int(ksong:Byte Ptr)"Win32" = GetProcAddress(g_hndDLL,"KSND_GetSongLength")
Public
Type TKSND
Field player:Byte Ptr ' handle to active player
Field song:Byte Ptr ' handle to currently playing song
Function init:TKSND(samplerate:Int)
Local tmp:TKSND = New TKSND
tmp.player = KSND_CreatePlayer(samplerate)
Return tmp
End Function
' Player methods
Method play(position:Int=0)
KSND_PlaySong(Self.player,Self.song,position)
End Method
Method pause(state:Int=0)
' 1 = pause, 0 = continue
KSND_Pause(Self.player,state)
End Method
Method stop()
KSND_Stop(Self.player)
End Method
Method free()
KSND_FreePlayer(Self.player)
End Method
Method setVolume(volume:Int)
KSND_SetVolume(Self.player,volume)
End Method
Method getPlayPosition:Int()
Return KSND_GetPlayPosition(Self.player)
End Method
' Song methods
Method loadSong(path:String)
' check if a song is already loaded
If Self.song <> Null Then Self.freeSong()
Self.song = KSND_LoadSong(Self.player,path.ToCString())
If Self.song = Null Then
RuntimeError "Unable to load song: "+path
Else
Print "song loaded"
End If
End Method
Method loadSongFromMemory(mem:Byte Ptr,length:Int)
' check if a song is already loaded
If Self.song <> Null Then Self.freeSong()
Self.song = KSND_LoadSongFromMemory(Self.player,mem,length)
If Self.song = Null Then
RuntimeError "Unable to load song!"
Else
Print "song loaded"
End If
End Method
Method freeSong()
KSND_FreeSong(Self.song)
End Method
Method getSongLength:Int()
Return KSND_GetSongLength(Self.song)
End Method
End Type
And here is an example of using the above code:
SuperStrict
Incbin "obspatial.kt" ' this is for including the song in the exe
Include "TKSND.BMX"
Graphics 800,600
' prepare a player
Global music:TKSND = TKSND.init(44100)
' use this when loading song from bank
Global bk:TBank = LoadBank("incbin::obspatial.kt") ' this loads the song into a bank
music.loadSongFromMemory(LockBank(bk),BankSize(bk))
bk = Null
' use this when loading song from disc
'music.loadSong("obspatial.kt")
' play the music
music.play()
Global mute:Int = 0
While Not KeyHit(KEY_ESCAPE)
Cls
Local sl:Int = music.getSongLength()
Local pp:Int = music.getPlayPosition()
DrawText("Song Length: "+sl,8,8)
DrawText("Play Position: "+pp,8,24)
If mute = 1 Then DrawText("MUTED",8,48)
' check for pause/continue
If KeyHit(KEY_P) Then music.pause(1)
If KeyHit(KEY_C) Then music.pause(0)
' check for mute/unmute
If KeyHit(KEY_M) Then
mute = 1-mute
If mute = 0 Then
music.setVolume(100)
Else
music.setVolume(0)
End If
End If
Flip
Wend
music.freeSong()
music.free()
End
The known bugs are that the method for getting the length of the song returns a wrong number in release mode, but works correct in debug mode. I am not really sure where the problem lies, but since it is not something that will prevent people from using the klystrack tunes in their productions I figured that I might as well release the code already. I hope someone finds it useful. Remember to copy the ksnd.dll file to your project folder.