Issue with using BASS / Dylibload

Windows specific questions.
Post Reply
UEZ
Posts: 992
Joined: May 05, 2017 19:59
Location: Germany

Issue with using BASS / Dylibload

Post by UEZ »

I know Bass.bi and it works well but I wanted to use Dylibload and load Bass.dll to use it but somehow it doesn't work as I expected - it's not playing the mp3 (Error: The file's format is not recognised/supported.).

Here the code what I did so far:

Code: Select all

#Include Once "windows.bi"
#Include Once "file.bi"

Const BASS_UNICODE = &h80000000, BASS_DEVICE_ENABLED = 1, BASS_FILEDATA_END = 0, BASS_FILEPOS_START = 3
Type HSTREAM As DWORD
Type QWORD As Longint

Type BASS_DEVICEINFO
	name As Const Zstring Ptr
	driver As Const Zstring Ptr
	flags As DWORD
End Type

Dim Shared BASS_Init As Function(Byval As Long, Byval As Dword, Byval As Dword, Byref As HWND, Byref As GUID Ptr) As BOOL
Dim Shared BASS_Free As Function() As BOOL
Dim Shared BASS_StreamCreateFile As Function(Byval As BOOL, Byval As Any Ptr, Byref As QWORD, Byref As QWORD, Byval As Dword) As HSTREAM
Dim Shared BASS_ChannelPlay As Function(Byval As HSTREAM, Byval As BOOL) As BOOL
Dim Shared BASS_StreamFree As Function(Byval As HSTREAM) As BOOL
Dim Shared BASS_ChannelStop As Function(Byval As HSTREAM) As BOOL
Dim Shared BASS_Stop As Function() As BOOL
Dim Shared BASS_SetVolume As Function(Byval As Single) As BOOL
Dim Shared BASS_ErrorGetCode As Function() As Integer
Dim Shared BASS_GetDeviceInfo As Function(As DWORD, As BASS_DEVICEINFO Ptr) As Integer
Dim Shared BASS_GetDevice As Function() As DWORD
Dim Shared BASS_StreamGetFilePosition As Function(Byval As HSTREAM, As DWORD) As QWORD

Dim Shared As Any Ptr _g__hLib_Bass = 0
Dim Shared As Boolean _g__bSound = True

Function _Bass_Startup() As Boolean
	#Ifdef __Fb_64bit__
		? "Loading Bass64.dll"
		If Fileexists("Bass64.dll") = 0 Then
			_g__bSound = False
			Return False
		Else
			_g__hLib_Bass = Dylibload("Bass64.dll")
		Endif
	#Else
		? "Loading Bass.dll"
		If Fileexists("Bass.dll") = 0 Then
			_g__bSound = False
			Return False
		Else
			_g__hLib_Bass = Dylibload("Bass.dll")
		Endif
	#Endif
	BASS_Init = Dylibsymbol(_g__hLib_Bass, "BASS_Init")
	If BASS_Init = 0 Then Return False
	BASS_Free = Dylibsymbol(_g__hLib_Bass, "BASS_Free")
	If BASS_Free = 0 Then Return False
	BASS_StreamCreateFile = Dylibsymbol(_g__hLib_Bass, "BASS_StreamCreateFile")
	If BASS_StreamCreateFile = 0 Then Return False
	BASS_StreamFree = Dylibsymbol(_g__hLib_Bass, "BASS_StreamFree")
	If BASS_StreamFree = 0 Then Return False
	BASS_ChannelPlay = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelPlay")
	If BASS_ChannelPlay = 0 Then Return False
	BASS_ChannelStop = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelStop")
	If BASS_ChannelStop = 0 Then Return False
	BASS_Stop = Dylibsymbol(_g__hLib_Bass, "BASS_Stop")
	If BASS_Stop = 0 Then Return False
	BASS_SetVolume = Dylibsymbol(_g__hLib_Bass, "BASS_SetVolume")
	If BASS_SetVolume = 0 Then Return False
	BASS_ErrorGetCode = Dylibsymbol(_g__hLib_Bass, "BASS_ErrorGetCode")
	If BASS_ErrorGetCode = 0 Then Return False
	BASS_GetDeviceInfo = Dylibsymbol(_g__hLib_Bass, "BASS_GetDeviceInfo")
	If BASS_GetDeviceInfo = 0 Then Return False
	BASS_GetDevice = Dylibsymbol(_g__hLib_Bass, "BASS_GetDevice")
	If BASS_GetDevice = 0 Then Return False	
	BASS_StreamGetFilePosition = Dylibsymbol(_g__hLib_Bass, "BASS_StreamGetFilePosition")
	If BASS_StreamGetFilePosition = 0 Then Return False
	Return True
End Function

Function _Bass_Shutdown() As Boolean
	If _g__hLib_Bass > 0 Then 
		Dylibfree(_g__hLib_Bass)
		Return True
	End If
	Return False
 End Function

Function _BASS_ErrorGetCode() As String
	Select Case BASS_ErrorGetCode()
		Case 0 : Return "No Error."
		Case 1 : Return "There is insufficient memory."
		Case 2 : Return "The file could not be opened."
		Case 3 : Return "Cannot find a free sound driver."
		Case 4 : Return "The sample buffer was lost."
		Case 5 : Return "Invalid handle."
		Case 6 : Return "Unsupported sample format."
		Case 7 : Return "Invalid position."
		Case 8 : Return "BASS_Init has not been successfully called."
		Case 9 : Return "BASS_Start has not been successfully called."
		Case 10 : Return "SSL/HTTPS support is not available."
		Case 14 : Return "Already initialized/paused/whatever."
		Case 17 : Return "The file does not contain audio, or it also contains video and videos are disabled."
		Case 18 : Return "Cannot get a free channel."
		Case 19 : Return "An illegal type was specified."
		Case 20 : Return "An illegal parameter was specified."
		Case 21 : Return "Could not initialize 3D support."
		Case 22 : Return "No EAX support."
		Case 23 : Return "Illegal device number."
		Case 24 : Return "Not playing."
		Case 25 : Return "Illegal sample rate."
		Case 27 : Return "The stream is not a file stream."
		Case 29 : Return "No hardware voices available."
		Case 31 : Return "The Mod music has no sequence Data."
		Case 32 : Return "No internet connection could be opened."
		Case 33 : Return "Could not create the file."
		Case 34 : Return "Effects are not available."
		Case 37 : Return "Requested data is not available."
		Case 38 : Return "The channel is a decoding channel"
		Case 39 : Return "A sufficient DirectX version is not installed."
		Case 40 : Return "Connection timed out."
		Case 41 : Return "The file's format is not recognised/supported."
		Case 42 : Return "The specified SPEAKER flags are invalid."
		Case 43 : Return "The plugin requires a different BASS version."
		Case 44 : Return "Codec is not available/supported."
		Case 45 : Return "The channel/file has ended."
		Case 46 : Return "Something else has exclusive use of the device."
		Case 47 : Return "The file cannot be streamed using the buffered file system."
		Case -1 : Return "Some other mystery problem!"
	End Select
	Return "Hmmmm."
End Function

Function _Bass_Init(Device As DWORD = -1, Freq As Dword = 44100, Flags As Dword = 0, Win As HWND = Null, clsid As GUID Ptr = Null) As Boolean
	Return BASS_Init(Device, Freq, Flags, Win, clsid)
End Function

Function _Bass_Free() As Boolean
	Return BASS_Free()
End Function

Function _BASS_StreamFree(hStream As HSTREAM) As Boolean
	Return BASS_StreamFree(hStream)
End Function

Function _BASS_StreamCreateFile(File As String, Flags As Dword = 0, Mem As Boolean = False, offset As QWORD = 0, Length As QWORD = 0) As HSTREAM
	Return BASS_StreamCreateFile(Mem, StrPtr(File), offset, Length, Flags)
End Function

Function _BASS_ChannelPlay(hStream As HSTREAM, Restart As BOOL = False) As Boolean
	Return BASS_ChannelPlay(hStream, Restart)
End Function

Function _BASS_SetVolume(Volume As Single) As Boolean
	Return BASS_SetVolume(Iif(Volume < 0, 0, Iif(Volume > 1.0, 1.0, Volume)))
End Function

Function _BASS_ChannelStop(hStream As HSTREAM) As Boolean
	Return BASS_ChannelStop(hStream)
End Function

Function _Bass_Stop() As Boolean
	Return BASS_Stop()
End Function

Function _BASS_GetDevice() As DWORD
	Return BASS_GetDevice()
End Function

Function _BASS_GetDeviceInfo(Device As DWORD, Info As BASS_DEVICEINFO Ptr) As Boolean
	Return BASS_GetDeviceInfo(Device, Info)
End Function

Function _BASS_StreamGetFilePosition(hStream As HSTREAM, mode As Dword) As QWORD
	Return BASS_StreamGetFilePosition(hStream, mode)
End Function

If _Bass_Startup() = False Then End


? "Bass init: " & _Bass_Init(-1, 44100)
? "Error: " & _BASS_ErrorGetCode()

Dim As DWORD a, count = 0
Dim As BASS_DEVICEINFO Info

? "-----------------------------"
For a = 0 To _BASS_GetDevice()
	? "Device" & a & ":"
	_BASS_GetDeviceInfo(a, @Info)
	? "Flages: " & Info.flags
	? "Name: " & *Info.name
	? "Driver: " & *Info.driver	
Next
? "-----------------------------"

Dim As String SOUNDFILE = "Test.mp3" '<----- change path to a mp3 file
? SOUNDFILE
Dim As HSTREAM hStream = _BASS_StreamCreateFile(SOUNDFILE)
? "Error: " & _BASS_ErrorGetCode()

'_BASS_SetVolume(0.15)
_BASS_ChannelPlay(hStream)

? "File pos: " & _BASS_StreamGetFilePosition(hStream, BASS_FILEPOS_START)
Sleep
_BASS_ChannelStop(hStream)
_BASS_StreamFree(hStream)
_Bass_Free()
_Bass_Shutdown()
Sleep
You need bass.dll and bass64.dll in the same dir as the code is located. Bass DLL can be downloader here: http://www.un4seen.com/download.php?bass24
Just rename the x64 bass.dll to bass64.dll and don't forget to change the path to a mp3 file in line 191.

Can you see where I'm wrong?
dodicat
Posts: 7987
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Issue with using BASS / Dylibload

Post by dodicat »

I downloaded the dll's
looks like

Dim Shared BASS_StreamCreateFile As Function(Byval As BOOL, Byval As Any Ptr, Byval As QWORD, Byval As QWORD, Byval As Dword) As HSTREAM

is OK.

i.e. all byval, no byref parameters.
UEZ
Posts: 992
Joined: May 05, 2017 19:59
Location: Germany

Re: Issue with using BASS / Dylibload

Post by UEZ »

dodicat wrote:I downloaded the dll's
looks like

Dim Shared BASS_StreamCreateFile As Function(Byval As BOOL, Byval As Any Ptr, Byval As QWORD, Byval As QWORD, Byval As Dword) As HSTREAM

is OK.

i.e. all byval, no byref parameters.
Does it mean that you can play a mp3 file using the code?
dodicat
Posts: 7987
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Issue with using BASS / Dylibload

Post by dodicat »

Tested a couple of tunes 32 bit,64 bit and gas64.
All OK.
Only those two byref parameters to byval in BASS_StreamCreateFile need changing.
UEZ
Posts: 992
Joined: May 05, 2017 19:59
Location: Germany

Re: Issue with using BASS / Dylibload

Post by UEZ »

dodicat wrote:Tested a couple of tunes 32 bit,64 bit and gas64.
All OK.
Only those two byref parameters to byval in BASS_StreamCreateFile need changing.
Ahh, got it. I've overseen the Byref values although I checked each function (not seen the forest for the trees). ^^
It's working now.

Thank you dodicat. :-)
Post Reply