Did anyone ever manage to draw a simple waveform with purebasic using the BASS library? I want to do this with a decoded channel and I know that BASS_ChannelGetLevel or BASS_ChannelGetData can be used for this. I tried some things based on examples I found on internet but so far without succes. Can anyone help me with this? I need it to improve my auto dj software ( https://www.smartmixplayer.com/ )
I have this code now, but it does not generate a waveform
Code: Select all
IncludeFile "include/bass.pbi"
Macro LOWORD(a) : ((a)&$FFFF) : EndMacro
Macro HIWORD(a) : (((a)>>16)&$FFFF) : EndMacro
OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 220, "waveform test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 600, 220)
BASS_Init(-1, 44100, 0, 0, #Null)
filename.s = "song.mp3"
channel = BASS_StreamCreateFile(0, @filename, 0, 0, #BASS_STREAM_PRESCAN|#BASS_UNICODE|#BASS_STREAM_DECODE)
length = BASS_ChannelBytes2Seconds(channel, #BASS_POS_BYTE)
MaxPixelHeight = 110
x=0
While BASS_ChannelIsActive(channel)
level = BASS_ChannelGetLevel(channel)
left = (LOWORD(level) / 3276) * 2
right = (HIWORD(level) / 3276) * 2
PixelYleft = (MaxPixelHeight / 2) - (left * MaxPixelHeight / 65535)
PixelYright = (MaxPixelHeight / 2) - (right * MaxPixelHeight / 65535)
If StartDrawing(CanvasOutput(0))
Line(x, 0, x, PixelYleft , 0)
Line(x, 110, x, PixelYright , 0)
StopDrawing()
EndIf
x+1
Wend
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Martin