BASIC

Author Topic: FMOD  (Read 4001 times)

MrTAToad

  • Guest
FMOD
« on: 2008-Dec-29 »
Thanks to Schranz0r for sorting the double-pointer problem, the following code shows how to use the latest version of FMOD with currently Windows and Mac (Linux cant be used).

You will need FMOD to be installed (or to get the libraries from somewhere).  The DLL/dylib goes in with the executable.

The test code  is :

Code: GLBasic [Select]
OK = FMOD_Init(32,0)
LOCAL Snd%
OKs = FMOD_CreateSound("Music.mp3",0,Snd%)

LOCAL chan%
play = FMOD_PlaySound(0,Snd%,0,chan%)

WHILE KEY(57)=0
        PRINT OK,10,10
        PRINT OKs,10,20
        PRINT Snd,10,30
        PRINT play,10,40
        PRINT chan,10,50
SHOWSCREEN
WEND
FMOD_Close()
END

And the main interface code is :

Code: GLBasic [Select]
INLINE
        #include "fmod.h"

        FMOD_SYSTEM                     *fSystem;
        DGArray<FMOD_SOUND*>    fsound;
        DGArray<FMOD_CHANNEL*>  fchannel;
ENDINLINE

FUNCTION FMOD_Init%:maxChannels%,flags%
LOCAL result%

INLINE

        result=FMOD_System_Create(&fSystem);
        if (result==FMOD_OK)
        {
                result=FMOD_System_Init(fSystem,maxChannels,flags,0);
        }

        return result;
ENDINLINE
ENDFUNCTION

FUNCTION FMOD_CreateSound%:fileName$,mode%,BYREF sound%
LOCAL result%

INLINE
        FMOD_SOUND* xsound;

        result = FMOD_System_CreateSound(fSystem,fileName_Str.c_str(),mode,NULL,&xsound);
        if (result==FMOD_OK) { // all ok!

                REDIM(fsound(),LEN(fsound())+1);
                fsound(LEN(fsound())-1) = xsound;
                sound = LEN(fsound())-1; // set the handle to sound
        }

        return result;
ENDINLINE
ENDFUNCTION

FUNCTION FMOD_PlaySound%:channelID%,sound%,paused%,BYREF channel%
LOCAL result%

INLINE
        FMOD_CHANNEL* xchannel;

        result=FMOD_System_PlaySound(fSystem,(FMOD_CHANNELINDEX) channelID,fsound(sound),(bool) paused,&xchannel);
        if (result==FMOD_OK) { // all ok!

                REDIM(fchannel(),LEN(fchannel())+1);
                fchannel(LEN(fchannel())-1) = xchannel;
                channel = LEN(fchannel())-1; // set the handle to channel
        }
        return result;
ENDINLINE
ENDFUNCTION

FUNCTION FMOD_Close:
INLINE
        return FMOD_System_Close(fSystem);
ENDINLINE
ENDFUNCTION

At the moment its only just enough to get a tune working - but it does work...

For windows users, your project will need to have the following added :

cmp : -L"X:\Programming\GLBasic"
lnk : -L"X:\Programming\GLBasic" -lfmodex_vc

Mac just need :

cmp : -L"X:\Programming\GLBasic" -lfmodex

Linux cant be used because it needs a later version of STDC++, LIBC than included in GLBasic...
« Last Edit: 2008-Dec-29 by MrTAToad »

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5028
  • O Rly?
    • View Profile
Re: FMOD
« Reply #1 on: 2008-Dec-29 »
Nice  :good:
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad

  • Guest
Re: FMOD
« Reply #2 on: 2008-Dec-30 »
Its a shame about the Linux version - but Gernot would need to use a later version of GCC before it'll work...

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10720
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FMOD
« Reply #3 on: 2008-Dec-30 »
a newer gcc for linux? Oh dear. I'll try.

MrTAToad

  • Guest
Re: FMOD
« Reply #4 on: 2008-Dec-30 »
Yes - the newer FMOD requires STDC++.so.6, which in turn requires a later version of GCC and LIBC.  I think there was also something else needed as well too...