GLBasic forum

Codesnippets => Inline / 3rd party => Topic started by: djbios on 2012-Jan-07

Title: FMOD
Post by: djbios on 2012-Jan-07
hi everybody

is it possibile to use Fmod Ex with GLBasic? Any suggestion/experience?

thanks
Title: Re: FMOD
Post by: Wampus on 2012-Jan-07
A basic FMOD player with tracker music examples is included in the GLBasic samples folder. Try GLBasic > Samples > _Projects_ > fmod_player

The example doesn't use the newer FMOD Ex but from the example you should be able to work out how you can make use of the newer API.
Title: Re: FMOD
Post by: Wampus on 2012-Jan-10
Hey djbios, I'm actually looking into the use of FMOD Ex today, so I'll let you know what I find.
Title: Re: FMOD
Post by: Albert on 2012-Jan-10
Hi!

I've a project with FMod EX. I tried to make a complete wrapper to capable to play samples made with the FMOD Designer (or whatever that name) .
It's not complete (I abbandonned the project as soon as I saw how much is an FMOD licence).
Title: Re: FMOD
Post by: Wampus on 2012-Jan-11
Hell, not complete is a lot better than then mess I've managed to create in the last hour. Are you willing to upload what you have? :)
Title: Re: FMOD
Post by: Albert on 2012-Jan-13
Ok!

Here it is then.

This wrapper only contains that calls what I needed and tested currently.

This is how to use (the zip contains it also):

Simple mp3 playback:
Code (glbasic) Select
LOCAL OK, OKs, play

//FMOD Init
OK = FMOD_Init(32,0)

//load mp3
LOCAL Snd%
OKs = FMOD_CreateSound("wave.mp3",0,Snd%)

//play on channel 1
LOCAL chan%
LOCAL chan2%
play = FMOD_PlaySound(0,Snd%,0,chan%)

//loop
WHILE KEY(2)=0
   PRINT "Press Space to play the mp3 on the second chanel",0,0
   PRINT "FMOD_INIT: " + OK,10,15
   PRINT "FMOD_CreateSound: " + OKs,10,30
   PRINT "SOUND: " + Snd,10,45
   PRINT "FMOD_PlaySound: " + play,10,60
   PRINT "Channel 1: " + chan%,10,75
   PRINT "Channel 2: " + chan2%,10,90
   PRINT "FMOD_SYSTEM running", 20, 185, TRUE
   PRINT "press '1' TO test quit", 20, 200, TRUE
   SHOWSCREEN
   
   //keyboard
   IF (KEY(57)) THEN play = FMOD_PlaySound(1,Snd%,0,chan2) //play on channel 2
WEND

//FMOD close
FMOD_Close()


EventSystem (using .fev and .fsb files exported from FMOD Designer)
Code (glbasic) Select
// ----- EVENTSYSTEM -----
LOCAL OKES, OKsES, OKevent, OKparam, playES, OKupdate, OKstate

//EventSystem init
OKES = FMOD_ES_Init(64,0)

//load .fev
LOCAL SndES%=0
OKsES = FMOD_ES_CreateSound("sanyiteszt.fev",0,SndES%)
IF (OKsES<>0)
   PRINT "CreateSound ERROR:" + OKsES, 50, 200
   SHOWSCREEN
   MOUSEWAIT
ENDIF

//load some events
LOCAL event%[]
DIM event%[5]
LOCAL group%
OKevent = FMOD_ES_GetEvent("sanyiteszt/random/wingflap_randoms", 0, event%[0])
OKevent = FMOD_ES_GetEvent("sanyiteszt/random/bird_randoms", 0, event%[1])
OKevent = FMOD_ES_GetEvent("sanyiteszt/loop/forest_calm", 0, event%[2])
OKevent = FMOD_ES_GetEvent("sanyiteszt/loop/fire_01", 0, event%[3])
OKevent = FMOD_ES_GetEvent("sanyiteszt/loop/cave_ambience", 0, event%[4])
IF (OKevent<>0)
   PRINT "GetEvent ERROR:" + OKevent, 50, 200
   SHOWSCREEN
   MOUSEWAIT
ENDIF

LOCAL state%=0
LOCAL Statestr$
LOCAL param0%
LOCAL db%

// Query parameters count for one event
OKparam = FMOD_E_GetNumParameters(event%[3], db%)
IF (OKparam<>0)
   PRINT "GetNumParameters ERROR:" + OKparam, 50, 200
   SHOWSCREEN
   MOUSEWAIT
ENDIF
//display
PRINT "GetNumParameters:" + db%, 00, 200
PRINT "click to continue", 00, 250, TRUE
SHOWSCREEN
MOUSEWAIT

// Get parameter
OKparam = FMOD_E_GetParameter(event%[3], "temp_parameter", param0%)
IF (OKparam<>0)
   PRINT "GetParameter ERROR:" + OKparam, 50, 200
   SHOWSCREEN
   MOUSEWAIT
ENDIF

//loop
WHILE KEY(1)=0
//display statuses
PRINT "INIT: "+OKES,10,0
PRINT "LOAD: "+OKsES,10,15
PRINT "PROJECT:"+SndES,10,30
//PRINT "GetGroup:"+OKgroup,10,40
PRINT "GetEvent:"+OKevent,10,45
PRINT "Start:"+playES,10,60
OKupdate = FMOD_ES_Update()
PRINT "update: "+OKupdate,150,10

//display the 5 events status
FOR I=0 TO 4
OKstate = FMOD_E_GetState(event%[I], state%)
PRINT "getstate "+I+": "+OKstate + " state: "+state%,10,100+15*I
Statestr$=""
IF bAND(state%,1) THEN Statestr$=Statestr$+"Ready "
IF bAND(state%,2) THEN Statestr$=Statestr$+"Loading "
IF bAND(state%,4) THEN Statestr$=Statestr$+"Error "
IF bAND(state%,8) THEN Statestr$=Statestr$+"Playing "
IF bAND(state%,16) THEN Statestr$=Statestr$+"CHANNELSACTIVE "
IF bAND(state%,32) THEN Statestr$=Statestr$+"INFOONLY "
IF bAND(state%,64) THEN Statestr$=Statestr$+"STARVING "
PRINT Statestr$,350,100+15*I
NEXT

//display instructions
PRINT "FMOD_EVENTSYSTEM running, 1-5 to play", 20, 185, TRUE
PRINT "press ESC TO quit", 20, 200, TRUE
PRINT "Press left/right to test SetValue/GetValue", 20, 230, TRUE

//keyboard
IF (KEY(2)) THEN playES = FMOD_ES_PlaySound(event%[0])
IF (KEY(3)) THEN playES = FMOD_ES_PlaySound(event%[1])
IF (KEY(4)) THEN playES = FMOD_ES_PlaySound(event%[2])
IF (KEY(5)) THEN playES = FMOD_ES_PlaySound(event%[3])
IF (KEY(6)) THEN playES = FMOD_ES_PlaySound(event%[4])         
IF (KEY(205))
LOCAL v
FMOD_EP_GetValue(param0%, v) //Test read parameter   
INC v,0.01
FMOD_EP_SetValue(param0%, v); //Test write parameter
//Write to the screen
FMOD_EP_GetValue(param0%, v)   
PRINT "PARAM: " + v, 10, 250
   ENDIF
   IF (KEY(203))
LOCAL v
FMOD_EP_GetValue(param0%, v) //Test read parameter   
DEC v,0.01
FMOD_EP_SetValue(param0%, v); //Test write parameter
//Write to the screen   
FMOD_EP_GetValue(param0%, v)
PRINT "PARAM: " + v, 10, 250
ENDIF
SHOWSCREEN
WEND

//EventSystem_Unload?
//EventSystem_Release?


[attachment deleted by admin]
Title: Re: FMOD
Post by: Wampus on 2012-Jan-14
Very cool Albert. Again, its a pity the fmod license is so expensive!

I checked and the latest fmodex dlls are not backwards compatible with the code. They will crash out when the FMOD event system check is attempted but I'm sure someone wanting to use them can work it out.
Title: Re: FMOD
Post by: bigsofty on 2012-Jan-14
Nice code!  :good

BTW I think the indie license is a lot cheaper, esp. per app.
Title: Re: FMOD
Post by: Schranz0r on 2012-Feb-11
Ahhh... based on my old example Version :)

Nice! Keep workin on it ! :)
Title: Re: FMOD
Post by: Albert on 2012-Feb-12
Quote from: Schranz0r on 2012-Feb-11
Nice! Keep workin on it ! :)

No way!