Toujours sur mon projet de webradio. Après Sound, FMOD, je teste la librairie BASS.
J'ai bien réussi à l'intégrer dans mon projet. Le seul hic, c'est que je ne parviens pas à régler le volume sonore du fichier lu. J'aimerai pourvoir régler également le volume quand le son est lu.
Code : Tout sélectionner
; Quick example to list the recording inputs.
;
; The assert stuff is there to help detect if the wrong BASS.DLL is loaded, if a function can not be found the assert will detect this during debug.
;
; BASS_Load_Library() and BASS_Free_Library() implemenation is for Windows only, for Linux and MacOS you need to make your own.
EnableExplicit ;Used to ensure strict coding
IncludeFile "bass.pbi"
;- Prototype Macros
Macro GetFunctionProtoQuote
"
EndMacro
Macro GetFunctionProto(dll, name)
Global name.name
name = GetFunction(dll, GetFunctionProtoQuote#name#GetFunctionProtoQuote)
CompilerIf #PB_Compiler_Debugger ; Only enable assert in debug mode
If name = #Null
Debug "Assert on line " + #PB_Compiler_Line + ", GetFunction(" + GetFunctionProtoQuote#dll#GetFunctionProtoQuote + ", " + GetFunctionProtoQuote#name#GetFunctionProtoQuote + ")"
EndIf
CompilerEndIf
EndMacro
; BASS_Load_Library
Threaded _BASS_Load_Library_DLL_.i
Procedure BASS_Free_Library()
If IsLibrary(_BASS_Load_Library_DLL_)
CloseLibrary(_BASS_Load_Library_DLL_)
EndIf
EndProcedure
Procedure.i BASS_Load_Library(dllpath$)
Protected dll.i, result.i
If IsLibrary(_BASS_Load_Library_DLL_)
ProcedureReturn #False
EndIf
_BASS_Load_Library_DLL_ = OpenLibrary(#PB_Any, dllpath$)
dll = _BASS_Load_Library_DLL_
If IsLibrary(dll) = #False
ProcedureReturn #False
EndIf
GetFunctionProto(dll, BASS_GetVersion)
If BASS_GetVersion = #Null
;BASS_GetVersion() not found, is this really bass.dll ?
BASS_Free_Library()
ProcedureReturn #False
EndIf
;Make sure BASS API and bass.dll are compatible.
result = BASS_GetVersion()
If (result & $FFFF0000) <> (#BASSVERSION & $FFFF0000) Or (result < #BASSVERSION)
BASS_Free_Library()
ProcedureReturn #False
EndIf
;You should only use the GetFunctionProto() for the BASS functions you actually need/use,
;these are macros thus you will save some memory/exe size by removing the functions you don't use,
;during debugging the GetFunctionProto() macro will also check if the BASS function exists in the loaded library to catch wrong library versions.
GetFunctionProto(dll, BASS_SetConfig)
GetFunctionProto(dll, BASS_GetConfig)
GetFunctionProto(dll, BASS_SetConfigPtr)
GetFunctionProto(dll, BASS_GetConfigPtr)
GetFunctionProto(dll, BASS_ErrorGetCode)
GetFunctionProto(dll, BASS_GetDeviceInfo)
GetFunctionProto(dll, BASS_Init)
GetFunctionProto(dll, BASS_SetDevice)
GetFunctionProto(dll, BASS_GetDevice)
GetFunctionProto(dll, BASS_Free)
GetFunctionProto(dll, BASS_GetDSoundObject)
GetFunctionProto(dll, BASS_GetInfo)
GetFunctionProto(dll, BASS_Update)
GetFunctionProto(dll, BASS_GetCPU)
GetFunctionProto(dll, BASS_Start)
GetFunctionProto(dll, BASS_Stop)
GetFunctionProto(dll, BASS_Pause)
GetFunctionProto(dll, BASS_SetVolume)
GetFunctionProto(dll, BASS_GetVolume)
GetFunctionProto(dll, BASS_PluginLoad)
GetFunctionProto(dll, BASS_PluginFree)
GetFunctionProto(dll, BASS_PluginGetInfo)
GetFunctionProto(dll, BASS_Set3DFactors)
GetFunctionProto(dll, BASS_Get3DFactors)
GetFunctionProto(dll, BASS_Set3DPosition)
GetFunctionProto(dll, BASS_Get3DPosition)
GetFunctionProto(dll, BASS_Apply3D)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
GetFunctionProto(dll, BASS_SetEAXParameters)
GetFunctionProto(dll, BASS_GetEAXParameters)
CompilerEndIf
GetFunctionProto(dll, BASS_MusicLoad)
GetFunctionProto(dll, BASS_MusicFree)
GetFunctionProto(dll, BASS_SampleLoad)
GetFunctionProto(dll, BASS_SampleCreate)
GetFunctionProto(dll, BASS_SampleFree)
GetFunctionProto(dll, BASS_SampleSetData)
GetFunctionProto(dll, BASS_SampleGetData)
GetFunctionProto(dll, BASS_SampleGetInfo)
GetFunctionProto(dll, BASS_SampleSetInfo)
GetFunctionProto(dll, BASS_SampleGetChannel)
GetFunctionProto(dll, BASS_SampleGetChannels)
GetFunctionProto(dll, BASS_SampleStop)
GetFunctionProto(dll, BASS_StreamCreate)
GetFunctionProto(dll, BASS_StreamCreateFile)
GetFunctionProto(dll, BASS_StreamCreateURL)
GetFunctionProto(dll, BASS_StreamCreateFileUser)
GetFunctionProto(dll, BASS_StreamFree)
GetFunctionProto(dll, BASS_StreamGetFilePosition)
GetFunctionProto(dll, BASS_StreamPutData)
GetFunctionProto(dll, BASS_StreamPutFileData)
GetFunctionProto(dll, BASS_RecordGetDeviceInfo)
GetFunctionProto(dll, BASS_RecordInit)
GetFunctionProto(dll, BASS_RecordSetDevice)
GetFunctionProto(dll, BASS_RecordGetDevice)
GetFunctionProto(dll, BASS_RecordFree)
GetFunctionProto(dll, BASS_RecordGetInfo)
GetFunctionProto(dll, BASS_RecordGetInputName)
GetFunctionProto(dll, BASS_RecordSetInput)
GetFunctionProto(dll, BASS_RecordGetInput)
GetFunctionProto(dll, BASS_RecordStart)
GetFunctionProto(dll, BASS_ChannelBytes2Seconds)
GetFunctionProto(dll, BASS_ChannelSeconds2Bytes)
GetFunctionProto(dll, BASS_ChannelGetDevice)
GetFunctionProto(dll, BASS_ChannelSetDevice)
GetFunctionProto(dll, BASS_ChannelIsActive)
GetFunctionProto(dll, BASS_ChannelGetInfo)
GetFunctionProto(dll, BASS_ChannelGetTags)
GetFunctionProto(dll, BASS_ChannelFlags)
GetFunctionProto(dll, BASS_ChannelUpdate)
GetFunctionProto(dll, BASS_ChannelLock)
GetFunctionProto(dll, BASS_ChannelPlay)
GetFunctionProto(dll, BASS_ChannelStop)
GetFunctionProto(dll, BASS_ChannelPause)
GetFunctionProto(dll, BASS_ChannelSetAttribute)
GetFunctionProto(dll, BASS_ChannelSetAttributeEx)
GetFunctionProto(dll, BASS_ChannelGetAttribute)
GetFunctionProto(dll, BASS_ChannelGetAttributeEx)
GetFunctionProto(dll, BASS_ChannelSlideAttribute)
GetFunctionProto(dll, BASS_ChannelIsSliding)
GetFunctionProto(dll, BASS_ChannelSet3DAttributes)
GetFunctionProto(dll, BASS_ChannelGet3DAttributes)
GetFunctionProto(dll, BASS_ChannelSet3DPosition)
GetFunctionProto(dll, BASS_ChannelGet3DPosition)
GetFunctionProto(dll, BASS_ChannelGetLength)
GetFunctionProto(dll, BASS_ChannelSetPosition)
GetFunctionProto(dll, BASS_ChannelGetPosition)
GetFunctionProto(dll, BASS_ChannelGetLevel)
GetFunctionProto(dll, BASS_ChannelGetLevelEx)
GetFunctionProto(dll, BASS_ChannelGetData)
GetFunctionProto(dll, BASS_ChannelSetSync)
GetFunctionProto(dll, BASS_ChannelRemoveSync)
GetFunctionProto(dll, BASS_ChannelSetDSP)
GetFunctionProto(dll, BASS_ChannelRemoveDSP)
GetFunctionProto(dll, BASS_ChannelSetLink)
GetFunctionProto(dll, BASS_ChannelRemoveLink)
GetFunctionProto(dll, BASS_ChannelSetFX)
GetFunctionProto(dll, BASS_ChannelRemoveFX)
GetFunctionProto(dll, BASS_FXSetParameters)
GetFunctionProto(dll, BASS_FXGetParameters)
GetFunctionProto(dll, BASS_FXReset)
ProcedureReturn #True
EndProcedure
;Example:
If BASS_Load_Library("C:\Users\user\Desktop\bass_purebasic\bass\bass.dll") = #False
Debug "Failed to load bass.dll"
End
EndIf
Debug Hex(BASS_GetVersion(), #PB_Long)
;2040B00 (BASS 2.4.11.0) or later is needed for the device type info example below.
BASS_SetConfig(#BASS_CONFIG_UNICODE, #True)
Define i.i, info.BASS_DEVICEINFO, name$
i=0
While BASS_RecordGetDeviceInfo(i, info)
If (info\flags & #BASS_DEVICE_ENABLED)
name$ = PeekS(info\name, 31, #PB_UTF8) ;Device name is max 32 chars (including zero terminator).
Select (info\flags & #BASS_DEVICE_TYPE_MASK) ;Windows and OSX
Case #BASS_DEVICE_TYPE_DIGITAL
Debug "Digital: " + name$
Case #BASS_DEVICE_TYPE_DISPLAYPORT ;On Windows this may show as HDMI instead.
Debug "DisplayPort: " + name$
Case #BASS_DEVICE_TYPE_HANDSET
Debug "HAndset: " + name$
Case #BASS_DEVICE_TYPE_HDMI
Debug "HDMI: " + name$
Case #BASS_DEVICE_TYPE_HEADPHONES
Debug "Headphones: " + name$
Case #BASS_DEVICE_TYPE_HEADSET
Debug "Headset: " + name$
Case #BASS_DEVICE_TYPE_LINE
Debug "Line: " + name$
Case #BASS_DEVICE_TYPE_MICROPHONE
Debug "Microphone: " + name$
Case #BASS_DEVICE_TYPE_NETWORK
Debug "NEetwork: " + name$
Case #BASS_DEVICE_TYPE_SPDIF
Debug "SPDIF: " + name$
Case #BASS_DEVICE_TYPE_SPEAKERS
Debug "Speakers: " + name$
Default
Debug "Unknown: " + name$
EndSelect
EndIf
i+1
Wend
; ---
;- STRUCTURES
; ---
XIncludeFile ("mon_formulaire.pbf")
Structure BASS_structure
Fichier$
Sample.l
Channel.l
NbCanaux.l
Position.l
Longueur.l
EndStructure
Global MonSon.Bass_structure
Procedure.s Convertir_temps_pour_affichage (ms)
Protected Resultat$
Protected Minutes
Protected Secondes
Protected Heures
Protected Secondes$
Protected Minutes$
Protected Heures$
Secondes = Mod (Int (ms / 1000),60)
Minutes = Mod (Int(ms / 60000),60)
Heures = Mod (Int(ms / 3600000),60)
If Secondes < 10
Secondes$ = "0" + Str(Secondes)
Else
Secondes$ = Str(Secondes)
EndIf
If Minutes < 10
Minutes$= "0" + Str(Minutes)
Else
Minutes$ = Str(Minutes)
EndIf
If Heures < 10
Heures$ = "0" + Str(Heures)
Else
Heures$ = Str(Heures)
EndIf
If Heures > 0
Resultat$ = heures$ + ":" + minutes$ + ":" + secondes$
Else
If Minutes > 0
Resultat$ = minutes$ + ":" + secondes$
Else
If Secondes > 0
Resultat$ = secondes$ + "s"
EndIf
EndIf
EndIf
ProcedureReturn Resultat$
EndProcedure
Procedure BASS_Aller_a_position (*Son.BASS_structure, Position)
BASS_ChannelSetPosition(*Son\Channel,Position,#BASS_POS_BYTE)
EndProcedure
Procedure BASS_Donner_position (*Son.BASS_structure)
Protected Resultat
Protected p
If *Son\Channel <> 0
p = BASS_ChannelGetPosition(*Son\Channel,#BASS_POS_BYTE)
Resultat = BASS_ChannelBytes2Seconds (*Son\Channel,p) * 1000
;Resultat = p * 8192 / *Son\Longueur
EndIf
ProcedureReturn Resultat
EndProcedure
Procedure BASS_Donner_temps_total (*Son.BASS_structure)
Protected Resultat
Protected p
p = *Son\Longueur
Resultat = BASS_ChannelBytes2Seconds (*Son\Channel,p) * 1000
ProcedureReturn Resultat
EndProcedure
Procedure BASS_Channel_joue (*Son.BASS_structure)
Protected Retour
If *Son\Channel And BASS_ChannelIsActive(*Son\Channel) = #BASS_ACTIVE_PLAYING
Retour = #True
Else
Retour = #False
EndIf
ProcedureReturn Retour
EndProcedure
Procedure BASS_pauser_lecture (*Son.BASS_structure)
If BASS_ChannelIsActive(*Son\channel) = #BASS_ACTIVE_PLAYING
BASS_ChannelPause(*Son\channel)
EndIf
EndProcedure
Procedure BASS_reprendre_lecture (*Son.BASS_structure)
If BASS_ChannelIsActive(*Son\channel) = #BASS_ACTIVE_PAUSED
BASS_ChannelPlay(*Son\channel,0)
EndIf
EndProcedure
Structure Sample_struct
l.w
r.w
EndStructure
Procedure BASS_charger_son (*Son.BASS_structure)
Protected filename.s
Protected sample
Protected info.BASS_SAMPLE
filename.s = *Son\Fichier$
*Son\sample = BASS_SampleLoad(0, @filename, 0, 0, 65535, #BASS_UNICODE| #BASS_SAMPLE_SOFTWARE)
BASS_SampleGetInfo(*Son\sample, @info)
*Son\NbCanaux = info\chans
If *Son\NbCanaux >= 2
*Son\NbCanaux = 2
EndIf
*Son\Longueur = info\length.l
Dim Buffer.Sample_struct(*Son\Longueur >> *Son\NbCanaux)
*Son\channel = BASS_SampleGetChannel(*Son\sample,1)
EndProcedure
Procedure BASS_jouer_son(*Son.BASS_structure)
BASS_ChannelPlay(*Son\channel, 0)
EndProcedure
Procedure Bass_arreter_son (*Son.BASS_structure)
BASS_ChannelStop(*Son\channel)
EndProcedure
Procedure BASS_liberer_son(*Son.BASS_structure)
BASS_SampleFree(*Son\sample)
EndProcedure
Procedure BASS_bChannel_joue (*Son.BASS_structure)
Protected Retour
If *Son\channel And BASS_ChannelIsActive(*Son\channel) = #BASS_ACTIVE_PLAYING
Retour = #True
Else
Retour = #False
EndIf
ProcedureReturn Retour
EndProcedure
Procedure BASS_bChannel_pause (*Son.BASS_structure)
Protected Retour
If *Son\channel And BASS_ChannelIsActive(*Son\channel) = #BASS_ACTIVE_PAUSED
Retour = #True
Else
Retour = #False
EndIf
ProcedureReturn Retour
EndProcedure
Procedure BASS_bChannel_arret (*Son.BASS_structure)
Protected Retour
If *Son\channel And BASS_ChannelIsActive(*Son\channel) = #BASS_ACTIVE_STOPPED
Retour = #True
Else
Retour = #False
EndIf
ProcedureReturn Retour
EndProcedure
Procedure Afficher_infos()
Protected Phrase$
Phrase$ = "..."
If Bass_bChannel_joue(@MonSon) = #True
Phrase$ = "JOUE " + MonSon\Fichier$
EndIf
If Bass_bChannel_pause(@MonSon) = #True
Phrase$ = "PAUSE"
EndIf
If Bass_bChannel_arret(@MonSon) = #True
Phrase$ = "ARRET"
EndIf
Phrase$ = Phrase$ + " Tps : " + Convertir_temps_pour_affichage (Bass_donner_position (@MonSon)) + "/" + Convertir_temps_pour_affichage (BASS_Donner_temps_total (@MonSon))
SetGadgetText (Text_message, Phrase$)
EndProcedure
; ---
;-PROGRAMME PRINCIPAL
; ---
BASS_Init(-1, 44100, 0, 0, #Null)
OpenWindow_principale(0,0)
MonSon\Fichier$ = "C:\Users\user\Desktop\bass_purebasic\bass\superbus.ogg"
Bass_jouer_son (@MonSon)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case Button_charger
Bass_charger_son (@MonSon)
Case Button_jouer
Bass_jouer_son (@MonSon)
Case Button_arreter
Bass_arreter_son(@MonSon)
Bass_liberer_son(@MonSon)
Case Button_pauser
BASS_pauser_lecture(@MonSon)
Case Button_reprendre
BASS_reprendre_lecture(@MonSon)
EndSelect
EndSelect
Afficher_infos()
ForEver
BASS_SampleFree(@MonSon)
BASS_Free_Library()
Dans ce zip mon exemple de test :
https://lesfloralies.info/telech/pureba ... s_test.zip
Merci à vous pour votre aide.