Vous trouverez un include minimum fonctionnant avec PB 5.50 suffisant pour la plupart des applications utilisant fmodex.
■ fmodex-min.pbi
Code : Tout sélectionner
;/ FMODEX-Min.pbi for fmodex
;/
;/ Based on the code of Froggerprogger - 27.02.2007 - http://www.purebasic.fr/english/viewtopic.php?f=12&t=25144
;/ Update : falsam, 13.06.2016 (PB 5.50)
;/ Contributor : El Papounet, nco2k, spikey
#FMOD_INIT_NORMAL = $0 ; All platforms - Initialize normally.
#FMOD_CREATESTREAM = $80 ; Decompress at runtime, streaming from the source provided (standard stream).
#FMOD_SOFTWARE = $40 ; Makes sound reside in software.
#FMOD_CHANNEL_FREE = -1 ; For a channel index, FMOD chooses a free voice using the priority system.
#FMOD_CHANNEL_REUSE = -2 ; For a channel index, re-use the channel handle that was passed in.
#FMOD_TIMEUNIT_MS = $1 ; Milliseconds.
Structure FMOD_TAG
type.l ; [out] The type of this tag.
datatype.l ; [out] The type of data that this tag contains
*name ; [out] The name of this tag i.e. "TITLE", "ARTIST" etc.
*_data ; [out] Pointer to the tag data - its format is determined by the datatype member
datalen.l ; [out] Length of the data contained in this tag
udated.l ; [out] True if this tag has been updated since last being accessed with Sound::getTag
EndStructure
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Global fmodLib = OpenLibrary(#PB_Any, "fmodex.dll")
CompilerElse
Global fmodLib = OpenLibrary(#PB_Any, "fmodex64.dll")
CompilerEndIf
If fmodLib
;- FMOD_System_Create
Prototype.l FMOD_System_Create_Prototype(*system)
Global FMOD_System_Create.FMOD_System_Create_Prototype = GetFunction(fmodLib, "FMOD_System_Create")
;- FMOD_System_Init_
Prototype.l FMOD_System_Init_Prototype (system.l, Maxchannels.l, flags.l, Extradriverdata.l);system.l, Maxchannels.l, flags.l, Extradriverdata.l
Global FMOD_System_Init.FMOD_System_Init_Prototype = GetFunction(fmodLib, "FMOD_System_Init")
;- FMOD_System_CreateStream_
Prototype.l FMOD_System_CreateStream_Prototype (system.l, Name_or_data.l, Mode.l, *exinfo, *Sound)
Global FMOD_System_CreateStream.FMOD_System_CreateStream_Prototype = GetFunction(fmodLib, "FMOD_System_CreateStream")
;- FMOD_System_PlaySound_
Prototype.l FMOD_System_PlaySound_Prototype (system.l, channelid.l, sound.l, paused.l, *channel)
Global FMOD_System_PlaySound.FMOD_System_PlaySound_Prototype = GetFunction(fmodLib, "FMOD_System_PlaySound")
;- FMOD_Sound_Release_
Prototype.l FMOD_Sound_Release_Prototype (sound.l)
Global FMOD_Sound_Release.FMOD_Sound_Release_Prototype = GetFunction(fmodLib, "FMOD_Sound_Release")
;- FMOD_Channel_SetVolume
Prototype.l FMOD_Channel_SetVolume_Prototype(channel.l, Volume.f)
Global FMOD_Channel_SetVolume.FMOD_Channel_SetVolume_Prototype = GetFunction(fmodLib, "FMOD_Channel_SetVolume")
;- FMOD_Channel_SetPaused_
Prototype.l FMOD_Channel_SetPaused_Prototype (channel.l, paused.l)
Global FMOD_Channel_SetPaused.FMOD_Channel_SetPaused_Prototype = GetFunction(fmodLib, "FMOD_Channel_SetPaused")
;- FMOD_Channel_GetPaused_
Prototype.l FMOD_Channel_GetPaused_Prototype (channel.l, *paused)
Global FMOD_Channel_GetPaused.FMOD_Channel_GetPaused_Prototype = GetFunction(fmodLib, "FMOD_Channel_GetPaused")
;- FMOD_Channel_Stop_
Prototype.l FMOD_Channel_Stop_Prototype (channel.l)
Global FMOD_Channel_Stop.FMOD_Channel_Stop_Prototype = GetFunction(fmodLib, "FMOD_Channel_Stop")
;- FMOD_System_Release
Prototype.l FMOD_System_Release_Prototype(system.l)
Global FMOD_System_Release.FMOD_System_Release_Prototype = GetFunction(fmodLib, "FMOD_System_Release")
;- FMOD_Channel_GetPosition_
Prototype.l FMOD_Channel_GetPosition_Prototype (channel.l, *Position, Postype.l)
Global FMOD_Channel_GetPosition.FMOD_Channel_GetPosition_Prototype = GetFunction(fmodLib, "FMOD_Channel_GetPosition")
;- FMOD_Channel_SetPosition_
Prototype.l FMOD_Channel_SetPosition_Prototype (channel.l, Position.l, Postype.l)
Global FMOD_Channel_SetPosition.FMOD_Channel_SetPosition_Prototype = GetFunction(fmodLib, "FMOD_Channel_SetPosition")
;- FMOD_Sound_GetLength_
Prototype.l FMOD_Sound_GetLength_Prototype (sound.l, *Length, Lengthtype.l)
Global FMOD_Sound_GetLength.FMOD_Sound_GetLength_Prototype = GetFunction(fmodLib, "FMOD_Sound_GetLength")
;- FMOD_Sound_GetNumTags_
Prototype.l FMOD_Sound_GetNumTags_Prototype (sound.l, *Numtags, *Numtagsupdated)
Global FMOD_Sound_GetNumTags.FMOD_Sound_GetNumTags_Prototype = GetFunction(fmodLib, "FMOD_Sound_GetNumTags")
;- FMOD_Sound_GetTag_
Prototype.l FMOD_Sound_GetTag_Prototype (sound.l, pNameOrNull.l, Index.l, *Tag)
Global FMOD_Sound_GetTag.FMOD_Sound_GetTag_Prototype = GetFunction(fmodLib, "FMOD_Sound_GetTag")
;- FMOD_Channel_GetSpectrum_
Prototype.l FMOD_Channel_GetSpectrum_Prototype (channel.l, *Spectrumarray, Numvalues.l, Channeloffset.l, Windowtype.l)
Global FMOD_Channel_GetSpectrum.FMOD_Channel_GetSpectrum_Prototype = GetFunction(fmodLib, "FMOD_Channel_GetSpectrum")
Else
Debug "fmodex.dll or fmodex64.dll is needed and is not found."
End
EndIf
■ Demo : Lecture un fichier mp3
Code : Tout sélectionner
;Fmod Ex : Jouer un titre musical
EnableExplicit
IncludeFile "fmodex.pbi"
Enumeration
#Mainform
#File
#OpenFile
#Play
#Pause
#Stop
#Volume
EndEnumeration
Define.l Event, GEvent, TiEvent
Global WindowStyle.i=#PB_Window_SystemMenu|#PB_Window_ScreenCentered
Global fmodsystem.i, Channel.i, Sound.i, Volume.f = 0.5, PauseStatus.b
Global File.s
Procedure Open_MainForm()
OpenWindow(#Mainform, 0, 0, 300, 100, "Play Mp3", WindowStyle)
StringGadget(#File, 10, 20, 230, 22, "", #PB_String_ReadOnly)
ButtonGadget(#OpenFile, 245, 20, 50, 22, "Select")
TextGadget(#PB_Any, 10, 50, 30, 20, "Vol")
TrackBarGadget(#Volume, 45, 45, 200, 24, 0, 100)
SetGadgetState(#Volume, 50)
ButtonGadget(#Play, 55, 70, 60, 22, "Start")
ButtonGadget(#Pause, 117, 70, 60, 22, "Pause")
ButtonGadget(#Stop, 183, 70, 60, 22, "Stop")
EndProcedure
Open_MainForm()
;Declare l'objet FMOD System
FMOD_System_Create(@fmodsystem)
;Initialiser le system (32 canaux) un seul suffirait pour cet exemple
FMOD_System_Init(fmodsystem, 1, #FMOD_INIT_NORMAL, 0)
Global name.s, namelen, position, postype
Repeat
Event = WaitWindowEvent(100)
GEvent = EventGadget()
Select Event
Case #PB_Event_Gadget
Select GEvent
Case #OpenFile
;Decharge le son precedent
If Sound <> 0
FMOD_Sound_Release(Sound)
EndIf
File = OpenFileRequester("Selectionner un fichier mp3","","Musique|*.mp3;*.wav;*.ogg;*.flac",0)
If File <> ""
SetGadgetText(#File, GetFilePart(File))
FMOD_System_CreateStream(fmodsystem, Ascii(File), #FMOD_SOFTWARE, 0, @sound)
EndIf
Case #Volume
Volume = GetGadgetState(#Volume)/100
FMOD_Channel_SetVolume(Channel, Volume)
Case #Play
;PlaySound va jouer le son sur un des canaux libre
;la variable Channel contiendra le handle du canal utilisé par le son.
FMOD_System_PlaySound(fmodsystem, #FMOD_CHANNEL_FREE, sound, 0, @channel)
;Et on ajuste le volume (le son est compris entre 0.0 et 1.0)
FMOD_Channel_SetVolume(Channel, Volume)
Case #Pause
;FMOD_Channel_GetPaused permet de savoir si le son sur le canal est en pause ou pas
FMOD_Channel_GetPaused(Channel, @PauseStatus)
If PauseStatus = #False
FMOD_Channel_SetPaused(Channel, #True) ;Pause
SetGadgetText(#Pause, "Reprendre")
Else
FMOD_Channel_SetPaused(Channel, #False) ;Reprise de la lecture
SetGadgetText(#Pause, "Pause")
EndIf
Case #Stop
FMOD_Channel_Stop(Channel)
EndSelect
Case #PB_Event_CloseWindow
FMOD_Channel_Stop(Channel)
FMOD_System_Release(fmodsystem)
End
EndSelect
ForEver
■ Demo : Lecture d'un flux shoutcast
Code : Tout sélectionner
;Tutorial : Jouer un flux shoutcast
EnableExplicit
IncludeFile "fmodex-min.pbi"
Enumeration
#Mainform
#Pause
#Volume
EndEnumeration
Define.l Event, GEvent, TiEvent
Global WindowStyle.i=#PB_Window_SystemMenu|#PB_Window_ScreenCentered
Global fmodsystem.i, Url.s, Channel.i, Sound.i, Volume.f = 0.5, PauseStatus.b
Procedure Open_MainForm()
OpenWindow(#Mainform, 0, 0, 300, 100, "Play Shoutcast", WindowStyle)
TextGadget(#PB_Any, 10, 50, 30, 20, "Vol")
TrackBarGadget(#Volume, 45, 45, 200, 24, 0, 10)
SetGadgetState(#Volume, 5)
ButtonGadget(#Pause, 117, 70, 50, 22, "Pause")
EndProcedure
Procedure Start()
Open_MainForm()
;Déclarer l'objet FMOD System
FMOD_System_Create(@fmodsystem)
;Initialiser le system (32 canaux) un seul suffirait pour cet exemple
FMOD_System_Init(fmodsystem, 32, #FMOD_INIT_NORMAL, 0)
;CreateStream permet de commencer la lecture avant le chargement complet de l'url
Url ="http://server1.chilltrax.com:9000"
FMOD_System_CreateStream(fmodsystem, Ascii(Url), #FMOD_CREATESTREAM, 0, @sound)
;On joue le son sur le canal 1
FMOD_System_PlaySound(fmodsystem, 1, sound, 0, @channel)
;Et on ajuste le volume (le son est compris entre 0.0 et 1.0)
FMOD_Channel_SetVolume(Channel, 0.5)
EndProcedure
start()
Repeat
Event = WaitWindowEvent(10)
GEvent = EventGadget()
Select Event
Case #PB_Event_Gadget
Select GEvent
Case #Volume
Volume = GetGadgetState(#Volume)/10
FMOD_Channel_SetVolume(Channel, Volume)
Case #Pause
;FMOD_Channel_GetPaused permet de savoir si le son sur le canal est en pause ou pas
FMOD_Channel_GetPaused(Channel, @PauseStatus)
If PauseStatus = #False
FMOD_Channel_SetPaused(Channel, #True) ;Pause
Else
FMOD_Channel_SetPaused(Channel, #False) ;Reprise de la lecture
EndIf
EndSelect
Case #PB_Event_CloseWindow
FMOD_Channel_Stop(Channel)
FMOD_System_Release(fmodsystem)
End
EndSelect
ForEver