View Full Version : TBASS_ChannelSeconds2Bytes not working?
Hello everybody,
I want to start playing a mp3 file from 10 seconds, but TBASS_ChannelSeconds2Bytes doesn't seem to work. What am I doing wrong?
Uses "TBASS", "CONSOLE"
function TBMain()
Dim Channel As DWord
Dim SamChannel As DWord
If TBASS_Init(-1, 44100, 0, 0, 0) = 0 Then Stop
Channel = TBASS_StreamCreateFile(%TBASS_FALSE,"song.mp3", 0, 0, %TBASS_STREAM_PRESCAN )
TBASS_ChannelSetPosition(Channel, TBASS_ChannelSeconds2Bytes ( Channel, 10) )
TBASS_ChannelPlay(Channel, %TBASS_TRUE)
WaitKey
TBASS_Free
end function
Also I am missing TBASS_ChannelSetSync in the documentation, is that function not available in ThinBasic?
ErosOlmi
07-11-2014, 00:20
Hi Martin,
yes, there is something wrong with TBASS_ChannelSeconds2Bytes function.
I'm checking what's wrong.
In any case check TBASS_ChannelPlay: second parameter must be %TBASS_FALSE otherwise it will always start from the beginning.
I will let you know about TBASS_ChannelSeconds2Bytes
Ciao
Eros
ErosOlmi
08-11-2014, 10:29
I got crazy but I should have fixed.
Despite BASS documentation of BASS_ChannelSeconds2Bytes (http://www.un4seen.com/doc/#bass/BASS_ChannelSeconds2Bytes.html) says it returns a QUAD, in reality it returns a DWORD.
Attached a fixed thinBasic_TBASS.DLL library. To use unzip thinBasic_TBASS.DLL into \thinBasic\Lib\ directory replacing your current one.
Fix will be present in next thinBasic release.
Script example:
Uses "TBASS", "CONSOLE"
Function TBMain()
Dim Channel As DWord
Dim SamChannel As DWord
Dim CurrentPos_Bytes As Quad
Dim CurrentPos_Seconds As Double
If TBASS_Init(-1, 44100, 0, 0, 0) = 0 Then Stop
'---Attention
'---"BlackBox.mp3" is inside the following directory: \thinBasic\SampleScripts\TBASS\
'---
Channel = TBASS_StreamCreateFile(%TBASS_FALSE, "BlackBox.mp3", 0, 0, %TBASS_STREAM_PRESCAN )
PrintL "TBASS_GetVersion.....................:", Hex$(TBASS_GetVersion)
PrintL "Channel..............................:", Channel
PrintL "TBASS_ChannelGetLength...............:", TBASS_ChannelGetLength(Channel)
PrintL "TBASS_ChannelSeconds2Bytes.15........:", TBASS_ChannelSeconds2Bytes (Channel, 15)
PrintL "Error................................:", TBASS_ErrorGetCode & " " & TBASS_ErrorToString(TBASS_ErrorGetCode)
PrintL "TBASS_ChannelBytes2Seconds 1700000...:", Format$(TBASS_ChannelBytes2Seconds (Channel, 1700000), "#0.00")
PrintL "Error................................:", TBASS_ErrorGetCode & " " & TBASS_ErrorToString(TBASS_ErrorGetCode)
PrintL "TBASS_ChannelSetPosition.............:", TBASS_ChannelSetPosition(Channel, TBASS_ChannelSeconds2Bytes (Channel, 15) )
PrintL "Error................................:", TBASS_ErrorGetCode & " " & TBASS_ErrorToString(TBASS_ErrorGetCode)
PrintL
PrintL
PrintL "---Press any key to stop. Execution will stop at the end of the ChannelPlay---"
TBASS_ChannelPlay(Channel, %TBASS_FALSE)
While Len(Console_InKeyB) = 0 And TBASS_ChannelIsActive(Channel)
CurrentPos_Bytes = TBASS_ChannelGetPosition(Channel)
CurrentPos_Seconds = TBASS_ChannelBytes2Seconds(Channel, CurrentPos_Bytes)
PrintAt "Current position in bytes............: " & CurrentPos_Bytes , 1, 15
PrintAt "Current position in seconds..........: " & Format$(CurrentPos_Seconds, "#0.00") , 1, 16
PrintAt "Current position in seconds to bytes.: " & TBASS_ChannelSeconds2Bytes(Channel, CurrentPos_Seconds) , 1, 17
Wend
TBASS_Free
End Function
ErosOlmi
08-11-2014, 10:31
Also I am missing TBASS_ChannelSetSync in the documentation, is that function not available in ThinBasic?
That function requires a callback (a pointer to compiled function) and so far thinBasic script functions cannot be used in those cases.
Maybe in future thinBasic releases I will find a way to link script functions pointers to compiled code.
Hi Eros,
Thanks A LOT for fixing this problem so fast. It works perfect now! :D
Martin
Forgive me, one more request:
Is it possible to add TBASS_StreamCreateURL ?
http://www.un4seen.com/doc/#bass/BASS_StreamCreateURL.html
ErosOlmi
10-11-2014, 09:32
I will see what I can do. That function has a callback used to get the progression of the loading.
Maybe I will just ignore for the moment.