Latest Bass Library and MP3 files

General FreeBASIC programming questions.
Post Reply
wallyg
Posts: 270
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Latest Bass Library and MP3 files

Post by wallyg »

I just started a new project and tried to play an MP3 file and got BASS_ERROR_FILEFORM. Tried a different music file type (MO3) and it works just fine. I have also tried numerous other MP3 files with the same results. Got the latest BASS.dll from its website just this morning.

I run an up-to-date Windows 10 system with the latest WinFBE version of FB from C:\WinFBE_Suite\Toolchains\FreeBASIC-1.10.0-winlibs-gcc-9.3.0\fbc64.exe. Everything in 64 bit mode.

Code: Select all

If (BASS_GetVersion() < MAKELONG(2,2)) Then
    Print #2, "BASS version 2.2 or above required!"
    Close #2
    End 1
End IF
Print #2, "   Got good version of Bass Version " & Hex(BASS_GetVersion(),16)

If (BASS_Init(-1, 44100, 0, 0, 0) = 0) Then
    Print #2,"Could not initialize BASS"
    Close #2
    End 1
End If
Print #2, "   Initialized Bass ok"

dim as string song_file = "F:\SongModificationSystem\MusicTestFile2.mp3"
if fileExists(song_file) <> 0 then Print #2, "   Exists " & song_file

Dim As HMUSIC musicHandle = BASS_MusicLoad(0, strptr(song_file), 0, 0, BASS_SAMPLE_LOOP, 0)
if musicHandle = NULL then
    Print #2, "   Music file " & "MusicTestFile.mp3" & " not opened error code = " & str(BASS_ErrorGetCode())
    Close #2
    End 1
end if

----------------------------------    Output file    -----------------------------------------------
Start Bass Log
   Got good version of Bass Version 0000000002041100
   Initialized Bass ok
   Exists F:\SongModificationSystem\MusicTestFile2.mp3
   Music file MusicTestFile.mp3 not opened error code = 41
The MP3 file plays just fine in other music players

Does any BASS expert have any idea why I cannot play MP3 files with BASS (out of the box - no additional plugins)?

Thank you in advance for any suggestions.
wallyg
Posts: 270
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Latest Bass Library and MP3 files

Post by wallyg »

Since I cannot play my library of MP3s with Bass and Fmod is 32-bit only, does anyone know of a 64-bit Freebasic package that can play MP3s and read the MP3 tags?

Thank you
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Latest Bass Library and MP3 files

Post by dodicat »

You could use the windows built in player for video or audio.
viewtopic.php?p=297147&hilit=mciSendString#p297147
wallyg
Posts: 270
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Latest Bass Library and MP3 files

Post by wallyg »

Thank you for your information. But I am not familiar with windows programming. I use GTK and for GUI programming. I am looking for a library I can just drop in as a replacement for Bass which does not seem to be working for me. And not making major changes to the rest of the program.
Thank you all for all the help.

Wally
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: Latest Bass Library and MP3 files

Post by UEZ »

You may try this Bass2.bi:

Code: Select all

'Coded by UEZ build 2024-01-01
#Include Once "windows.bi"
#Include Once "file.bi"

Const BASS_UNICODE = &h80000000, BASS_DEVICE_ENABLED = 1, BASS_DEVICE_DEFAULT = 2, BASS_DEVICE_INIT = 4, BASS_DEVICE_LOOPBACK = 8, BASS_FILEDATA_END = 0, BASS_FILEPOS_START = 3, _
	  BASS_SAMPLE_8BITS = 1, BASS_SAMPLE_FLOAT = 256, BASS_SAMPLE_MONO = 2, BASS_SAMPLE_LOOP = 4, BASS_SAMPLE_3D = 8, BASS_SAMPLE_SOFTWARE = 16, _
	  BASS_SAMPLE_MUTEMAX = 32, BASS_SAMPLE_VAM = 64, BASS_SAMPLE_FX = 128, BASS_STREAM_PRESCAN = &h20000, BASS_STREAM_AUTOFREE = &h400001, _
	  BASS_STREAM_RESTRATE = &h800001, BASS_STREAM_BLOCK = &h100000, BASS_STREAM_DECODE = &h200000, BASS_MUSIC_RAMP = &h200, _
	  BASS_MUSIC_RAMPS = &h400, BASS_MUSIC_SURROUND = &h800, BASS_MUSIC_SURROUND2 = &h1000, BASS_MUSIC_FT2PAN = &h2000, _
	  BASS_MUSIC_FT2MOD = &h2000, BASS_MUSIC_PT1MOD = &h4000, BASS_MUSIC_NONINTER = &h10000, BASS_MUSIC_STOPBACK = &h80000, _
	  BASS_ASYNCFILE = &h40000000, BASS_CTYPE_SAMPLE = 1, BASS_CTYPE_RECORD = 2, BASS_CTYPE_STREAM = &h10000, BASS_CTYPE_STREAM_OGG = &h10002, _
	  BASS_CTYPE_STREAM_MP1 = &h10003, BASS_CTYPE_STREAM_MP2 = &h10004, BASS_CTYPE_STREAM_MP3 = &h10005, BASS_CTYPE_STREAM_AIFF = &h10006, _
	  BASS_CTYPE_STREAM_CA = &h10007, BASS_CTYPE_STREAM_MF = &h10008, BASS_CTYPE_STREAM_AM = &h10009, BASS_CTYPE_STREAM_DUMMY = &h18000, _
	  BASS_CTYPE_STREAM_DEVICE = &h18001, BASS_CTYPE_STREAM_WAV = &h40000, BASS_CTYPE_STREAM_WAV_PCM = &h50001, BASS_CTYPE_STREAM_WAV_FLOAT = &h50003, _
	  BASS_CTYPE_MUSIC_MOD = &h20000, BASS_CTYPE_MUSIC_MTM = &h20001, BASS_CTYPE_MUSIC_S3M = &h20002, BASS_CTYPE_MUSIC_XM = &h20003, _
	  BASS_CTYPE_MUSIC_IT = &h20004, BASS_CTYPE_MUSIC_MO3 = &h00100, BASS_DATA_AVAILABLE = 0, BASS_DATA_FIXED = &h20000000, _
	  BASS_DATA_FLOAT = &h40000000, BASS_DATA_FFT256 = &h80000000, BASS_DATA_FFT512 = &h80000001, BASS_DATA_FFT1024 = &h80000002, _
	  BASS_DATA_FFT2048 = &h80000003, BASS_DATA_FFT4096 = &h80000004, BASS_DATA_FFT8192 = &h80000005, BASS_DATA_FFT16384 = &h80000006, _
	  BASS_DATA_FFT32768 = &h80000007, BASS_DATA_FFT_INDIVIDUAL = &h10, BASS_DATA_FFT_NOWINDOW = &h20, BASS_DATA_FFT_REMOVEDC = &h40, _
	  BASS_DATA_FFT_COMPLEX = &h80, BASS_DATA_FFT_NYQUIST = &h100, BASS_POS_BYTE = 0, BASS_POS_MUSIC_ORDER = 1, BASS_POS_OGG = 3, _
	  BASS_ATTRIB_FREQ = 1, BASS_ATTRIB_VOL = 2, BASS_ATTRIB_PAN = 3, BASS_ATTRIB_EAXMIX = 4, BASS_ATTRIB_NOBUFFER = 5, BASS_ATTRIB_VBR = 6, _
	  BASS_ATTRIB_CPU = 7, BASS_ATTRIB_SRC = 8, BASS_ATTRIB_NET_RESUME = 9, BASS_ATTRIB_SCANINFO = 10, BASS_ATTRIB_NORAMP = 11, _
	  BASS_ATTRIB_BITRATE = 12, BASS_ATTRIB_BUFFER = 13, BASS_ATTRIB_MUSIC_AMPLIFY = &h100, BASS_ATTRIB_MUSIC_PANSEP = &h101, _
	  BASS_ATTRIB_MUSIC_PSCALER = &h102, BASS_ATTRIB_MUSIC_BPM = &h103, BASS_ATTRIB_MUSIC_SPEED = &h104, BASS_ATTRIB_MUSIC_VOL_GLOBAL = &h105, _
	  BASS_ATTRIB_MUSIC_ACTIVE = &h106, BASS_ATTRIB_MUSIC_VOL_CHAN = &h200, BASS_ATTRIB_MUSIC_VOL_INST = &h300, BASS_MUSIC_PRESCAN = BASS_STREAM_PRESCAN, _
	  BASS_LEVEL_STEREO = 2, BASS_FILEPOS_CURRENT = 0, BASS_FILEPOS_DECODE = BASS_FILEPOS_CURRENT, BASS_FILEPOS_DOWNLOAD = 1, BASS_FILEPOS_END = 2, _
	  BASS_FILEPOS_START = 3, BASS_FILEPOS_CONNECTED = 4, BASS_FILEPOS_BUFFER = 5, BASS_FILEPOS_SOCKET = 6, BASS_FILEPOS_ASYNCBUF = 7, BASS_FILEPOS_SIZE = 8, _
	  BASS_FILEPOS_BUFFERING = 9, BASS_TAG_ID3 = 0, BASS_TAG_ID3V2 = 1, BASS_TAG_OGG = 2, BASS_TAG_HTTP = 3, BASS_TAG_ICY = 4, BASS_TAG_META = 5, _
	  BASS_TAG_APE = 6, BASS_TAG_MP4 = 7, BASS_TAG_WMA = 8, BASS_TAG_VENDOR = 9, BASS_TAG_LYRICS3 = 10, BASS_TAG_CA_CODEC = 11, BASS_TAG_MF = 13, _
	  BASS_TAG_WAVEFORMAT = 14, BASS_TAG_AM_MIME = 15, BASS_TAG_AM_NAME = 16, BASS_TAG_RIFF_INFO = &h100, BASS_TAG_RIFF_BEXT = &h101, _
	  BASS_TAG_RIFF_CART = &h102, BASS_TAG_RIFF_DISP = &h103, BASS_TAG_RIFF_CUE = &h104, BASS_TAG_RIFF_SMPL = &h105, BASS_TAG_APE_BINARY = &h1000, _
	  BASS_TAG_MUSIC_NAME = &h10000, BASS_TAG_MUSIC_MESSAGE = &h10001, BASS_TAG_MUSIC_ORDERS = &h10002, BASS_TAG_MUSIC_AUTH = &h10003, _
	  BASS_TAG_MUSIC_INST = &h10100, BASS_TAG_MUSIC_SAMPLE = &h10300, BASS_POS_SCAN	= &h40000000, BASS_LEVEL_MONO = 1, BASS_LEVEL_STEREO = 2, BASS_LEVEL_RMS = 4, _
	  BASS_LEVEL_VOLPAN = 8, BASS_CONFIG_DEV_DEFAULT = 36, BASS_FX_DX8_CHORUS = 0, BASS_FX_DX8_COMPRESSOR = 1, BASS_FX_DX8_DISTORTION = 2, BASS_FX_DX8_ECHO = 3, BASS_FX_DX8_FLANGER = 4, _
	  BASS_FX_DX8_GARGLE = 5, BASS_FX_DX8_I3DL2REVERB = 6, BASS_FX_DX8_PARAMEQ = 7, BASS_FX_DX8_REVERB = 8, BASS_FX_VOLUME = 9


Type HSTREAM As DWORD
Type HPLUGIN As DWORD
Type HSAMPLE As DWORD
Type HMUSIC As DWORD
Type HFX As DWORD
Type HDSP As DWORD
Type QWORD As Longint
Type HPLUGIN As DWORD

Type BASS_DEVICEINFO
	As Zstring Ptr Name, driver
	As DWORD flags
End Type

Type BASS_CHANNELINFO
	As DWORD freq, chans, flags, ctype, origres
	As HPLUGIN plugin
	As HSAMPLE sample
	As Zstring Ptr filename
End Type

Type BASS_INFO
	As DWORD flags, hwsize, hwfree, freesam, free3d, minrate, maxrate
	As BOOL eax
	As DWORD minbuf, dsver, latency, initflags, speakers, freq
end type

Type BASS_LEVELS
	As Single Left, Right
End Type

Type ID3v1
	As Ubyte id(3), title(30), artist(30), album(30), Year(4), comment(30), genre
End Type

Type BASS_DX8_PARAMEQ
	As Single fCenter, _  	'Bandwidth, in semitones, in the range from 1 to 36. Default 18 semitones.
			  fBandwidth, _ 'Center frequency, in hertz, in the range from 80 to 16000. This value cannot exceed one-third of the frequency of the channel. Default 100 Hz.
			  fGain 		'Gain, in the range from -15 to 15. Default 0 dB.
End Type

Type BASS_FX_VOLUME_PARAM
	As Single fTarget, fCurrent, fTime
	As DWORD lCurve
End Type

Type BASS_DX8_REVERB
    As Single fInGain, fReverbMix, fReverbTime, fHighFreqRTRatio
End Type

Dim Shared BASS_Init As Function Stdcall(Byval As Long, Byval As DWORD, Byval As DWORD, Byval As HWND, Byval As GUID Ptr) As BOOL
Dim Shared BASS_GetDeviceInfo As Function Stdcall(As DWORD, As BASS_DEVICEINFO Ptr) As BOOL
Dim Shared BASS_GetInfo As Function Stdcall(As BASS_INFO) As BOOL
Dim Shared BASS_GetDevice As Function Stdcall() As DWORD
Dim Shared BASS_GetVersion As Function Stdcall() As DWORD
Dim Shared BASS_Free As Function Stdcall() As BOOL
Dim Shared BASS_Stop As Function Stdcall() As BOOL
Dim Shared BASS_SetVolume As Function Stdcall(Byval As Single) As BOOL
Dim Shared BASS_SetDevice As Function Stdcall(Byval As DWORD) As BOOL
Dim Shared BASS_SetConfig As Function Stdcall(Byval As DWORD, Byval As DWORD) As BOOL
Dim Shared BASS_ErrorGetCode As Function Stdcall() As Integer
Dim Shared BASS_StreamGetFilePosition As Function Stdcall(Byval As HSTREAM, As DWORD) As QWORD
Dim Shared BASS_StreamCreateFile As Function Stdcall(Byval As BOOL, Byval As Any Ptr, Byval As QWORD, Byval As QWORD, Byval As DWORD) As HSTREAM
Dim Shared BASS_StreamCreateURL As Function Stdcall(Byval As Any Ptr, Byval As DWORD, Byval As DWORD, Byval As Any Ptr, Byval As Any Ptr) As HSTREAM
Dim Shared BASS_StreamFree As Function Stdcall(Byval As HSTREAM) As BOOL
Dim Shared BASS_ChannelPlay As Function Stdcall(Byval As DWORD, Byval As BOOL) As BOOL
Dim Shared BASS_ChannelStop As Function Stdcall(Byval As DWORD) As BOOL
Dim Shared BASS_ChannelPause As Function Stdcall(Byval As DWORD) As BOOL
Dim Shared BASS_ChannelGetInfo As Function Stdcall(Byval As DWORD, Byval As BASS_CHANNELINFO) As BOOL
Dim Shared BASS_ChannelGetData As Function Stdcall(Byval As DWORD, Byval As Any Ptr, Byval As DWORD) As DWORD
Dim Shared BASS_ChannelGetLevel As Function Stdcall(Byval As DWORD) As DWORD
Dim Shared BASS_ChannelGetLevelEx As Function Stdcall(Byval As DWORD, Byval As Any Ptr, Byval As Single, Byval As DWORD) As BOOL
Dim Shared BASS_ChannelGetPosition As Function Stdcall(Byval As DWORD, Byval As DWORD) As DWORD
Dim Shared BASS_ChannelGetLength As Function Stdcall(Byval As DWORD, Byval As DWORD) As QWORD
Dim Shared BASS_ChannelGetTags As Function Stdcall(Byval As DWORD, Byval As DWORD) As Zstring Ptr
Dim Shared BASS_ChannelGetAttribute As Function Stdcall(Byval As DWORD, Byval As DWORD, Byval As Any Ptr) As BOOL
Dim Shared BASS_ChannelGetDevice As Function Stdcall(Byval As DWORD) As DWORD
Dim Shared BASS_ChannelBytes2Seconds As Function Stdcall(Byval As DWORD, Byval As QWORD) As Double
Dim Shared BASS_ChannelSeconds2Bytes As Function Stdcall(Byval As DWORD, Byval As Double) As QWORD
Dim Shared BASS_ChannelSetAttribute As Function Stdcall(Byval As DWORD, Byval As DWORD, Byval As Single) As BOOL
Dim Shared BASS_ChannelSetPosition As Function Stdcall(Byval As DWORD, Byval As QWORD, Byval As DWORD) As BOOL
Dim Shared BASS_ChannelSetDevice As Function Stdcall(Byval As DWORD, Byval As DWORD) As BOOL
Dim Shared BASS_MusicLoad As Function Stdcall(Byval As BOOL, Byval As Any Ptr, Byval As QWORD, Byval As DWORD, Byval As DWORD, Byval As DWORD) As HMUSIC
Dim Shared BASS_MusicFree As Function Stdcall(Byval As HMUSIC) As BOOL
Dim Shared BASS_ChannelSetFX As Function Stdcall(Byval As DWORD, Byval As DWORD, Byval As Integer) As HFX
Dim Shared BASS_FXSetParameters As Function Stdcall(Byval As HFX, Byval As Any Ptr) As BOOL
Dim Shared BASS_FXGetParameters As Function Stdcall(Byval As HFX, Byval As Any Ptr) As BOOL
Dim Shared BASS_ChannelRemoveFX As Function Stdcall(Byval As DWORD, Byval As HFX) As BOOL
Dim Shared BASS_PluginLoad As Function Stdcall(Byval As Any Ptr, Byval As DWORD) As HPLUGIN 
Dim Shared BASS_PluginFree As Function Stdcall(Byval As HPLUGIN) As BOOL

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

'Init-------------------------------------------------------------------------------------------------------------------------------------------
Function _Bass_Startup(sFolderDLL As String = Curdir, b64DllSuffix As BOOL = True) As BOOL
	Dim As String sb64 = "\Bass.dll"
	#Ifdef __Fb_64bit__
		If b64DllSuffix = True Then sb64 = "\Bass64.dll"
	#Endif
	If Fileexists(sFolderDLL & sb64) = 0 Then
		_g__bSound = False
		Return False
	Else
		_g__hLib_Bass = Dylibload(sFolderDLL & sb64)
	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_StreamCreateURL = Dylibsymbol(_g__hLib_Bass, "BASS_StreamCreateURL")
	If BASS_StreamCreateURL = 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_SetDevice = Dylibsymbol(_g__hLib_Bass, "BASS_SetDevice")
	If BASS_SetDevice = 0 Then Return False
	BASS_SetConfig = Dylibsymbol(_g__hLib_Bass, "BASS_SetConfig")
	If BASS_SetConfig = 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
	BASS_GetInfo = Dylibsymbol(_g__hLib_Bass, "BASS_GetInfo")
	If BASS_GetInfo = 0 Then Return False
	BASS_GetVersion = Dylibsymbol(_g__hLib_Bass, "BASS_GetVersion")
	If BASS_GetVersion = 0 Then Return False
	BASS_ChannelGetInfo = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetInfo")
	If BASS_ChannelGetInfo = 0 Then Return False
	BASS_ChannelGetData = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetData")
	If BASS_ChannelGetData = 0 Then Return False
	BASS_ChannelGetLevel = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetLevel")
	If BASS_ChannelGetLevel = 0 Then Return False	
	BASS_ChannelGetLevelEx = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetLevelEx")
	If BASS_ChannelGetLevelEx = 0 Then Return False
	BASS_ChannelGetPosition = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetPosition")
	If BASS_ChannelGetPosition = 0 Then Return False
	BASS_ChannelPause = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelPause")
	If BASS_ChannelPause = 0 Then Return False
	BASS_ChannelGetLength = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetLength")
	If BASS_ChannelGetLength = 0 Then Return False		
	BASS_ChannelGetTags = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetTags")
	If BASS_ChannelGetTags = 0 Then Return False		
	BASS_ChannelGetAttribute = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetAttribute")
	If BASS_ChannelGetAttribute = 0 Then Return False
	BASS_ChannelGetDevice = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelGetDevice")
	If BASS_ChannelGetDevice = 0 Then Return False	
	BASS_ChannelBytes2Seconds = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelBytes2Seconds")
	If BASS_ChannelBytes2Seconds = 0 Then Return False
	BASS_ChannelSeconds2Bytes = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelSeconds2Bytes")
	If BASS_ChannelSeconds2Bytes = 0 Then Return False
	BASS_ChannelSetAttribute = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelSetAttribute")
	If BASS_ChannelSetAttribute = 0 Then Return False	
	BASS_ChannelSetPosition = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelSetPosition")
	If BASS_ChannelSetPosition = 0 Then Return False
	BASS_ChannelSetDevice = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelSetDevice")
	If BASS_ChannelSetDevice = 0 Then Return False
	BASS_MusicLoad = Dylibsymbol(_g__hLib_Bass, "BASS_MusicLoad")
	If BASS_MusicLoad = 0 Then Return False
	BASS_MusicFree = Dylibsymbol(_g__hLib_Bass, "BASS_MusicFree")
	If BASS_MusicFree = 0 Then Return False	
	BASS_ChannelSetFX = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelSetFX")
	If BASS_ChannelSetFX = 0 Then Return False
	BASS_FXSetParameters = Dylibsymbol(_g__hLib_Bass, "BASS_FXSetParameters")
	If BASS_FXSetParameters = 0 Then Return False
	BASS_FXGetParameters = Dylibsymbol(_g__hLib_Bass, "BASS_FXGetParameters")
	If BASS_FXGetParameters = 0 Then Return False
	BASS_ChannelRemoveFX = Dylibsymbol(_g__hLib_Bass, "BASS_ChannelRemoveFX")
	If BASS_ChannelRemoveFX = 0 Then Return False
	BASS_PluginLoad = Dylibsymbol(_g__hLib_Bass, "BASS_PluginLoad")
	If BASS_PluginLoad = 0 Then Return False
	BASS_PluginFree = Dylibsymbol(_g__hLib_Bass, "BASS_PluginFree")
	If BASS_PluginFree = 0 Then Return False
	Return True
End Function

Function _Bass_Shutdown() As BOOL
	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 BOOL
	Return BASS_Init(Device, Freq, Flags, Win, clsid)
End Function

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

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

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

Function _BASS_SetDevice(Device As DWORD) As BOOL
	Return BASS_SetDevice(Device)
End Function

Function _BASS_SetConfig(Device As DWORD, Value As DWORD) As BOOL
	Return BASS_SetConfig(Device, Value)
End Function

'Device-----------------------------------------------------------------------------------------------------------------------------------------
Function _BASS_GetInfo(bi As BASS_INFO) As BOOL
	Return BASS_GetInfo(bi)
End Function

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

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

Function _BASS_GetVersion() As String
	Dim as String ver, t, h
    Dim as DWORD v = BASS_GetVersion()
    If v = 0 Then Return ""
    h = Hex(v, 8)
    For i as Ubyte = 1 to 8 Step 2
        t = Str(Val("&h" + Mid(h, i, 2)))
        'if Left(t, 1) = "0" Then t = Ltrim(t, "0")
        ver &= t & "."
    next
    Return RTrim(ver, ".")
End Function

'Stream-----------------------------------------------------------------------------------------------------------------------------------------
Function _BASS_StreamFree(hStream As HSTREAM) As BOOL
	Return BASS_StreamFree(hStream)
End Function

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

Function _BASS_StreamCreateURL(URL As String, Flags As Dword = 0, Offset As Dword = 0, Proc As Any Ptr = 0, UsrProc As Any Ptr = 0) As HSTREAM
	Return BASS_StreamCreateURL(Strptr(URL), offset, Flags, Proc, UsrProc)
End Function

Function _BASS_StreamCreateMem(pMem As Any Ptr, Length As QWORD = 0, Flags As Dword = 0, offset As QWORD = 0, Mem As BOOL = True) As HSTREAM
	Return BASS_StreamCreateFile(Mem, pMem, offset, Length, Flags Or BASS_UNICODE)
End Function

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

'Music------------------------------------------------------------------------------------------------------------------------------------------
Function _BASS_MusicLoad(File As String, Flags As DWORD = 0, Freq As DWORD = 0, offset As QWORD = 0, Length As DWORD = 0, Mem As BOOL = False) As HMUSIC
	Return BASS_MusicLoad(Mem, Strptr(File), offset, Length, Flags, Freq)
End Function

Function _BASS_MusicLoadMem(pMem As Any Ptr, Flags As DWORD = 0, Freq As DWORD = 0, offset As QWORD = 0, Length As DWORD = 0, Mem As BOOL = True) As HMUSIC
	Return BASS_MusicLoad(Mem, pMem, offset, Length, Flags, Freq)
End Function

Function _BASS_MusicFree(Handle As HMUSIC) As BOOL
	Return BASS_MusicFree(Handle) 
End Function

'Channel----------------------------------------------------------------------------------------------------------------------------------------
Function _BASS_ChannelPlay(Handle As DWORD, Restart As BOOL = True) As BOOL
	Return BASS_ChannelPlay(Handle, Restart)
End Function

Function _BASS_ChannelStop(Handle As DWORD) As BOOL
	Return BASS_ChannelStop(Handle)
End Function

Function _BASS_ChannelPause(Handle As DWORD) As BOOL
	Return BASS_ChannelPause(Handle)
End Function

Function _BASS_ChannelGetInfo(Handle As DWORD, ChanInfo As BASS_CHANNELINFO) As BOOL
	Return BASS_ChannelGetInfo(Handle, ChanInfo)
End Function

Function _BASS_ChannelGetData(Handle As DWORD, Buffer As Any Ptr, Length As DWORD) As DWORD
	Return BASS_ChannelGetData(Handle, Buffer, Length)
End Function

Function _BASS_ChannelGetLevel(Handle As DWORD) As DWORD
	Return BASS_ChannelGetLevel(Handle) 
End Function

Function _BASS_ChannelGetLevelEx(Handle As DWORD, Byref Levels As BASS_LEVELS, Length As Single = 0.05, Flags As DWORD = BASS_LEVEL_STEREO) As BOOL
	Return BASS_ChannelGetLevelEx(Handle, @Levels, Length, Flags) 
End Function

Function _BASS_ChannelGetPosition(Handle As DWORD, Mode As DWORD) As QWORD
	Return BASS_ChannelGetPosition(Handle, Mode) 
End Function

Function _BASS_ChannelGetLength(Handle As DWORD, Mode As DWORD = BASS_POS_BYTE) As QWORD
	Return BASS_ChannelGetLength(Handle, Mode) 
End Function

Function _BASS_ChannelGetAttribute(Handle As DWORD, Byref Value As Single, Attrib As DWORD = BASS_ATTRIB_BITRATE) As BOOL
	Return BASS_ChannelGetAttribute(Handle, Attrib, @Value) 
End Function

Function _BASS_ChannelBytes2Seconds(Handle As DWORD, Position As QWORD) As Double
	Return BASS_ChannelBytes2Seconds(Handle, Position) 
End Function

Function _BASS_ChannelSeconds2Bytes(Handle As DWORD, Position As Double) As QWORD
	Return BASS_ChannelSeconds2Bytes(Handle, Position)
End Function

Function _BASS_ChannelSetAttribute(Handle As DWORD, Attrib As DWORD, Value As Single) As BOOL
	Return BASS_ChannelSetAttribute(Handle, Attrib, Value) 
End Function

Function _BASS_ChannelSetDevice(Handle As DWORD, Device As DWORD) As BOOL
	Return _BASS_ChannelSetDevice(Handle, Device) 
End Function

Function _BASS_ChannelSetPosition(Handle As DWORD, Position As QWORD, Mode As DWORD) As BOOL
	Return BASS_ChannelSetPosition(Handle, Position, Mode) 
End Function

Function _BASS_ChannelGetTags(Handle As DWORD, Tags As DWORD) As Any Ptr
	Return BASS_ChannelGetTags(Handle, Tags) 
End Function

'ChannelFX--------------------------------------------------------------------------------------------------------------------------------------
Function _BASS_ChannelSetFX(Handle As DWORD, _Type As DWORD, Priority As Integer = 0) As HFX
	Return BASS_ChannelSetFX(Handle, _Type, Priority) 
End Function

Function _BASS_FXSetParameters(Handle As HFX, Params As Any Ptr) As BOOL
	Return BASS_FXSetParameters(Handle, Params) 
End Function

Function _BASS_FXGetParameters(Handle As HFX, Params As Any Ptr) As BOOL
	Return BASS_FXGetParameters(Handle, Params) 
End Function

Function _BASS_ChannelRemoveFX(Handle As DWORD, FX As HFX) As BOOL
	Return BASS_ChannelRemoveFX(Handle, FX) 
End Function

'Plugin-----------------------------------------------------------------------------------------------------------------------------------------

Function _BASS_PluginLoad(sFile As String, flags As DWORD = 0) As HPLUGIN
	Return BASS_PluginLoad(Strptr(sFile), flags)
End Function

Function _BASS_PluginFree(hPlugin As HPLUGIN) As BOOL
	Return BASS_PluginFree(hPlugin)
End Function

'-----------------------------------------------------------------------------------------------------------------------------------------------
Put Bass.dll and Bass64.dll into the same folder.

Example code:

Code: Select all

'Coded by UEZ
#Include "Bass2.bi"

Randomize
Dim Shared As QWORD iBytesLen, iEnd, iFileSize
Dim Shared As Single fBitrate
Dim Shared As Double length

#Define _Round(x) 		(Int(x + 0.5))

Function Stream() As hStream
	Dim As String SOUNDFILE = "https://remix.kwed.org/download.php/" & Str(CUlng(Rnd * 6943))
	Dim As HSTREAM hStream = _BASS_StreamCreateURL(SOUNDFILE, BASS_STREAM_BLOCK Or BASS_STREAM_AUTOFREE)
	'Var pID3 = BASS_ChannelGetTags(hStream, BASS_TAG_ID3V2)
	'? "Title: " & Str(*(@pID3[&h15]))
	_BASS_ChannelGetAttribute(hStream, fBitrate)
	iBytesLen = _BASS_ChannelGetLength(hStream)
	length = _BASS_ChannelBytes2Seconds(hStream, iBytesLen)
	iEnd = BASS_StreamGetFilePosition(hStream, BASS_FILEPOS_END)
	_BASS_ChannelSetAttribute(hStream, BASS_ATTRIB_VOL, 0.33)
	iFileSize = _BASS_StreamGetFilePosition(hStream, BASS_FILEPOS_SIZE)
	If iBytesLen <> -1 Then
	Shell "Cls"
		Locate 1, 1
		? "Playing: " & SOUNDFILE
		? "Bitrate: " & _Round(fBitrate) & " kbps / " & Wchr(&h00D8) & ": " & _Round(iFileSize * 8 / length / 1000) & " kbps"
		Print Using "Size: ########### bytes"; iBytesLen 
		Print Using "Length: ####.## seconds."; length
	Endif
	Return HSTREAM
End Function

If _Bass_Startup() = False Then End

_BASS_SetConfig(BASS_CONFIG_DEV_DEFAULT, True)
_Bass_Init()

Dim As HSTREAM hStream = Stream()

_BASS_ChannelPlay(hStream)

Dim As QWORD iCurrentPos

Dim As Integer iPosCursor = CsrLin

While True
	Locate iPosCursor, 1, 0
	Select Case Inkey()
		Case Chr(27) 'Esc
			Exit While
		Case Chr(32) 'space
			While Inkey() = Chr(27)
				Sleep (1)
			WEnd
			_BASS_ChannelStop(hStream)
			_BASS_StreamFree(hStream)
			hStream = Stream()
			iBytesLen = _BASS_ChannelGetLength(hStream)
			_BASS_ChannelPlay(hStream)
	End Select
	iCurrentPos = _BASS_ChannelGetPosition(hStream, BASS_POS_BYTE)
	If iBytesLen <> -1 Then
        Locate 5, 1
        Print Using "Played: ###.##%"; iCurrentPos / iBytesLen * 100
    end if
	If iCurrentPos >= iBytesLen Then  
		_BASS_ChannelStop(hStream)
		_BASS_StreamFree(hStream)
		hStream = Stream()
		iBytesLen = _BASS_ChannelGetLength(hStream)
		_BASS_ChannelPlay(hStream)	
	Endif
	Sleep(30)
wend

_BASS_ChannelStop(hStream)
_BASS_StreamFree(hStream)
_Bass_Free()
_Bass_Shutdown()
It works properly as x64 compiled.

All files can be found on my OneDrive here: BASS
Last edited by UEZ on Jan 03, 2024 7:28, edited 2 times in total.
wallyg
Posts: 270
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Latest Bass Library and MP3 files

Post by wallyg »

Thank you. I will give it a try tomorrow after all of today's festivities are over.

Thank you very much.

Tucson Wally
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Latest Bass Library and MP3 files

Post by dodicat »

Windows.
Simple audio player and the part which can be compiled to .a or .dll, and a .bi file. (sectioned off)
32 and 64 bits tested

Code: Select all

 
'declarations for .bi file if required
declare sub init(file As String)
declare Sub play(file As String)
declare Sub setvolume(vol As Long)
declare Sub finish()
declare Function progress(y As Long,char as string="*") As Long

'======================================= lib or dll if required  =============
#include "Windows.bi"
#include "win/mmsystem.bi"

Sub init(file As String) Export
    mciSendString("open  " +Chr(34)+file+Chr(34)+ " type mpegvideo alias file1", NULL, 0, 0)
End Sub

Sub play(file As String) Export
    mciSendString("play file1  from 0", NULL, 0,0)
End Sub

Sub setvolume(vol As Long) Export
    mciSendString("setaudio file1 volume to " & vol,(0), 0, 0)
End Sub

Sub finish() Export
    mciSendString("close file1", NULL, 0,0)
End Sub

Function progress(y As Long,char as string="*") As Long
    #define map(a,b,_x_,c,d) (((d)-(c))*((_x_)-(a))/((b)-(a))+(c))
    Dim As zstring * 20 position
    Dim As zstring * 20 length
    Dim As zstring * 20 ans
    mciSendString("status file1 position ",@position, 20,0)
    mciSendString("status file1 length",@length, 20,0)
    mciSendString("status file1 mode ",@ans,20,0)
    Var lngth=Val(length)
    Var pst=Vallng(position)
    Var wd=Loword(Width)
    Var xpos=Iif(Lngth,map(0,1,pst/Lngth,0,wd),0)
    Locate y,xpos
    Print char
    If ans="stopped" Then Return 0 
    Return 1
End Function

'========================================================================


'USAGE
'screen 17  ''optional
Dim As String filename="Finale.mp3"  '<<---------  file path here
Dim As Long vol=500


init(filename)
setvolume(vol)
play(filename)
Do
    Locate 2,2,0
    print filename
    print
    Print "Up arrow to increase volume"
    Print "Down arrow to decrease volume"
    Print "Left arrow to restart"
    Print "Press esc to finish"
    Var i=Inkey
    If i= Chr(255) + "K"  Then Print  "restart":play(filename):Cls 'LEFT ARROW
    If i= Chr(255) + "P"  Then  vol-=5:Print "Volume ";vol:setvolume(vol)'DOWN ARROW
    If i= Chr(255) + "H"  Then  vol+=5:Print "Volume ";vol:setvolume(vol)'UP ARROW
    If i=Chr(27) Then Exit Do
    If progress(12) =0 Then Exit Do  'optional 
    Sleep 50
Loop 

finish()
print
Print "Done"
Sleep



 
By the way I cannot get multikey to work on Win 11 terminal console, so I use inkey instead.
coderJeff
Site Admin
Posts: 4332
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Latest Bass Library and MP3 files

Post by coderJeff »

dodicat wrote: Jan 02, 2024 23:45 By the way I cannot get multikey to work on Win 11 terminal console, so I use inkey instead.
I tried to fix a while ago, but the fix was reported as not good, so had to revert. It still needs a solution.
thrive4
Posts: 72
Joined: Jun 25, 2021 15:32

Re: Latest Bass Library and MP3 files

Post by thrive4 »

Not exactly a bass expert but you could give this a whirl:
https://github.com/thrive4/app.fb.audioplayer-bass
https://github.com/thrive4/app.fb.audio ... s/releases

Compiled with the 32 bit version v2.4.16.7 (some what older version)
might help to attain if the issue is 64bits, a more recent version
of bass.dll or diagnosis in general.

Hope this helps.

Bye de bye an other audio route could be:
https://github.com/libsdl-org/SDL_mixer
multi platform and supports quite a number of audio formats
plus works pretty well with freebasic, all though the SDL2_mixer.bi
is a bit out of sync with the current SDL2_mixer.h ....

Ps not to be semantic but it might be usefull to move this thread to:
viewforum.php?f=14
aka 'Libraries & Headers'
adeyblue
Posts: 301
Joined: Nov 07, 2019 20:08

Re: Latest Bass Library and MP3 files

Post by adeyblue »

coderJeff wrote: Jan 03, 2024 3:36 It still needs a solution.
It was two posts under that one. Nevertheless, I did it. Here's a diff to current master.

Code: Select all

diff --git a/src/rtlib/win32/fb_private_console.h b/src/rtlib/win32/fb_private_console.h
index a511d98b6..950e1e503 100644
--- a/src/rtlib/win32/fb_private_console.h
+++ b/src/rtlib/win32/fb_private_console.h
@@ -42,6 +42,7 @@ void fb_hConsoleResetHandles( void );
 int fb_ConsoleGetRawX( void );
 int fb_ConsoleGetRawY( void );
 HANDLE fb_hConsoleCreateBuffer( void );
+int fb_ConsoleHasFocus( void );
 
 #define __fb_in_handle  fb_hConsoleGetHandle( TRUE )
 #define __fb_out_handle fb_hConsoleGetHandle( FALSE )
diff --git a/src/rtlib/win32/io_input.c b/src/rtlib/win32/io_input.c
index 6637ebaf6..bbeb83c89 100644
--- a/src/rtlib/win32/io_input.c
+++ b/src/rtlib/win32/io_input.c
@@ -10,6 +10,7 @@ static size_t key_head = 0, key_tail = 0;
 static INPUT_RECORD input_events[KEY_BUFFER_LEN];
 static unsigned key_scratch_pad = 0;
 static int key_buffer_changed = FALSE;
+static int console_has_focus = 1;
 
 typedef struct _FB_KEY_CODES {
     unsigned short value_normal;
@@ -383,10 +384,15 @@ static void fb_hInitControlHandler( void )
     FB_UNLOCK();
 }
 
+int fb_ConsoleHasFocus( void )
+{
+    return console_has_focus;
+}
+
 int fb_ConsoleProcessEvents( void )
 {
     int got_event = FALSE;
-	INPUT_RECORD ir;
+    INPUT_RECORD ir;
     DWORD dwRead;
 
     fb_hInitControlHandler();
@@ -418,6 +424,9 @@ int fb_ConsoleProcessEvents( void )
                     got_event = TRUE;
                 }
                 break;
+            case FOCUS_EVENT:
+                console_has_focus = ir.Event.FocusEvent.bSetFocus;
+                break;
             }
 
             FB_UNLOCK();
@@ -425,7 +434,7 @@ int fb_ConsoleProcessEvents( void )
 
     } while( dwRead != 0 );
 
-	return got_event;
+    return got_event;
 }
 
 /** Translates an ASCII character, Virtual scan code and Virtual key code to
diff --git a/src/rtlib/win32/io_multikey.c b/src/rtlib/win32/io_multikey.c
index c5e7ba3c6..6005f8ec1 100644
--- a/src/rtlib/win32/io_multikey.c
+++ b/src/rtlib/win32/io_multikey.c
@@ -2,6 +2,7 @@
 
 #include "../fb.h"
 #include <windows.h>
+#include "fb_private_console.h"
 
 const unsigned char __fb_keytable[][3] = {
 	{ SC_ESCAPE,    VK_ESCAPE,  0           },  { SC_1,         '1',        0           },
@@ -51,24 +52,6 @@ const unsigned char __fb_keytable[][3] = {
 	{ 0,            0,          0           }
 };
 
-static HWND find_window(void)
-{
-	TCHAR old_title[MAX_PATH];
-	TCHAR title[MAX_PATH];
-	static HWND hwnd = NULL;
-
-	if (hwnd)
-		return hwnd;
-
-	if (GetConsoleTitle(old_title, MAX_PATH)) {
-		sprintf(title, "_fb_console_title %f", fb_Timer());
-		SetConsoleTitle(title);
-		hwnd = FindWindow(NULL, title);
-		SetConsoleTitle(old_title);
-	}
-	return hwnd;
-}
-
 int fb_hVirtualToScancode(int vkey)
 {
 	int i;
@@ -79,46 +62,17 @@ int fb_hVirtualToScancode(int vkey)
 	return 0;
 }
 
-#if 0
-/* !!!TODO!!! need a way to find out if console is foreground in windows terminal */
-static int maybeDoFindWindow()
-{
-	static int inited = FB_FALSE;
-	static int do_find = FB_FALSE;
-	if( !inited )
-	{
-		OSVERSIONINFO info;
-		info.dwOSVersionInfoSize = sizeof(info);
-		GetVersionEx(&info);
-		if( ((info.dwMajorVersion << 8) | info.dwMinorVersion) <= 0x600 ) {
-			do_find = FB_TRUE;
-		}
-		inited = FB_TRUE;
-	}
-	return do_find;
-}
-#endif
-
 int fb_ConsoleMultikey( int scancode )
 {
-	int i;
+	fb_ConsoleProcessEvents();
 
-#if 1
-	/* !!!FIXME!!! this doesn't seem to work under windows terminal */
-	if ( find_window() != GetForegroundWindow() )
-		return FB_FALSE;
-#else
-	/* !!!TODO!!! need a way to find out if console is foreground in windows terminal */
-	if( maybeDoFindWindow() )
-	{
-		if ( find_window() != GetForegroundWindow() )
-			return FB_FALSE;
-	}
-#endif
+	if(fb_ConsoleHasFocus()) {
+		int i;
 
-	for( i = 0; __fb_keytable[i][0]; i++ ) {
-		if( __fb_keytable[i][0] == scancode ) {
-			return ((GetAsyncKeyState(__fb_keytable[i][1]) | GetAsyncKeyState(__fb_keytable[i][2])) & 0x8000) ? FB_TRUE : FB_FALSE;
+		for( i = 0; __fb_keytable[i][0]; i++ ) {
+			if( __fb_keytable[i][0] == scancode ) {
+				return ((GetAsyncKeyState(__fb_keytable[i][1]) | GetAsyncKeyState(__fb_keytable[i][2])) & 0x8000) ? FB_TRUE : FB_FALSE;
+			}
 		}
 	}
 	return FB_FALSE;
I tested it in the newest Win11 terminal from the Microsoft store and NT4.
coderJeff
Site Admin
Posts: 4332
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Latest Bass Library and MP3 files

Post by coderJeff »

adeyblue wrote: Jan 06, 2024 3:36 It was two posts under that one. Nevertheless, I did it. Here's a diff to current master.
Thank-you! That looks good to me for the focus event handling. I'll add and test one more bit (below), because it worked for a bit, and then didn't, which was really weird because even restarting all terminals/consoles didn't reset the state back to something working again.

Then I seen this (which has been the code for a long long time):

Code: Select all

return ((GetAsyncKeyState(__fb_keytable[i][1])
| GetAsyncKeyState(__fb_keytable[i][2])) & 0x8000)
? FB_TRUE : FB_FALSE;
A number of the __fb_keytable[x][2] entries are zero resulting in GetAsyncKeyState(0) being called.

This seems to work for me (win10 testing with multiple active consoles and terminals)

Code: Select all

return ((GetAsyncKeyState(__fb_keytable[i][1])
| (__fb_keytable[i][2] ? GetAsyncKeyState(__fb_keytable[i][2]) : 0 ))
& 0x8000) ? FB_TRUE : FB_FALSE;
Thank-you for posting the improvement. If you notice anything else, I'll add it in. Otherwise I will commit changes soon-ish.

EDIT:
This post gave a clue: https://github.com/microsoft/PowerToys/ ... -675610449
Seems that dragging a console tab out of windows terminal triggers key 0, setting it to down, probably until a windows restart. I'll test again after a pc restart.
adeyblue
Posts: 301
Joined: Nov 07, 2019 20:08

Re: Latest Bass Library and MP3 files

Post by adeyblue »

VK_ values of 0x0 and 0xff aren't defined. All the tables and documentation go from 0x1 to 0xfe, so I guess it was a case of Garbage In, Garbage Out that just happened to be fine all this time.
Post Reply