0
0

Hi there,

I am trying to create a simple fmod plugin but I am unable to make it work. I always get the "File Not Found" error, and I can assure you the files are in the same folder as the dll …

Here is the code, just in case you see some tremendous error

[code:1paz6oby]
// EnneFMODPlugin.cpp
//

include "HeroScriptExtensionInterface.h"

include "plugininterface.h"

include "ScriptAdapter.h"

include "fmod.h"

include "fmod_errors.h"

if defined(WIN32)

define HSEIDECL __declspec(dllexport)

else

define HSEIDECL

endif

void Ennelog( const char* msg )
{
FILE* f = fopen( "enneFMODplugin.txt", "a+" );
if ( f )
{
fprintf ( f, msg );
fclose(f);
}
}
void EnnelogW(const wchar_t* msg )
{
FILE* f = _wfopen( L"enneFMODplugin.txt", L"a+" );
if ( f )
{
fwprintf( f, msg );
fclose(f);
}
}

FMOD_SYSTEM *FMODSystem; //global FMOD system for this plugin

void ERRCHECK(FMOD_RESULT result, int line)
{
if (result != FMOD_OK)
{
char message[1024]={0};
sprintf(message,"FMOD error! (%d) %s line %d\n—————————————–\n", result, FMOD_ErrorString(result), line);

    Ennelog(message);
}

}

class ENNE_FMOD_PlaySoundFunction : public ScriptAdapter::PluginExternalFunction
{
ScriptAdapter::ParamString sound;
ScriptAdapter::ReturnBool returnvalue;

public:
ENNE_FMOD_PlaySoundFunction(HeroScript::PluginInterface * pi)
: PluginExternalFunction(pi)
, sound(this)
, returnvalue(
this)
{
RegisterFunction(_T("ENNE_FMOD_PlaySound"));
}

virtual void FunctionCalled()
{       
    FMOD_RESULT result;
    FMOD_SOUND *newsound;

    char theSound[1024];
    wcstombs(theSound,sound.Get(),1024);

    //--- debug
    char message[1024];
    sprintf(message,"Trying to play sound |%s|...\n", theSound);
    Ennelog(message);

    sprintf(message,"FMODSystem %s...\n", FMODSystem);
    Ennelog(message);

    sprintf(message,"newsound %s...\n", newsound);
    Ennelog(message);
    //---

    result = FMOD_System_CreateSound(FMODSystem, theSound, FMOD_DEFAULT, 0, &newsound);
    ERRCHECK(result, __LINE__);


    if (result == FMOD_OK)
    {
        Ennelog("Sound Created OK, let's Play It!");

        FMOD_CHANNEL *channel;
        result = FMOD_System_PlaySound(FMODSystem, FMOD_CHANNEL_FREE, newsound, false, &channel);
        ERRCHECK(result, __LINE__);
    }

    returnvalue.Set(true);      
}

};

void InitFMOD()
{
FMOD_RESULT result;
unsigned int version;
int numdrivers;
FMOD_SPEAKERMODE speakermode;
FMOD_CAPS caps;
char name[256];

/*
Create a System object and initialize.
*/

Ennelog("Initializing FMOD\n");

result = FMOD_System_Create(&FMODSystem);
ERRCHECK(result, __LINE__);

result = FMOD_System_GetVersion(FMODSystem, &version);
ERRCHECK(result, __LINE__);

if (version < FMOD_VERSION)
{
    printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
}

Ennelog("Version OK\n");

result = FMOD_System_GetNumDrivers(FMODSystem, &numdrivers);
ERRCHECK(result, __LINE__);

if (numdrivers == 0)
{
    result = FMOD_System_SetOutput(FMODSystem, FMOD_OUTPUTTYPE_NOSOUND);
    ERRCHECK(result, __LINE__);

    Ennelog("Numdrivers == 0\n");
}
else
{
    Ennelog("Numdrivers <> 0\n");

    result = FMOD_System_GetDriverCaps(FMODSystem,0, &caps, 0, 0, &speakermode);
    ERRCHECK(result, __LINE__);

    /*
    Set the user selected speaker mode.
    */
    result = FMOD_System_SetSpeakerMode(FMODSystem, speakermode);
    ERRCHECK(result, __LINE__);
    if (caps & FMOD_CAPS_HARDWARE_EMULATED)
    {
        /*
        The user has the 'Acceleration' slider set to off! This is really bad
        for latency! You might want to warn the user about this.
        */
        result = FMOD_System_SetDSPBufferSize(FMODSystem, 1024,10);
        ERRCHECK(result, __LINE__);

        Ennelog("SetSpeakerMode HARDWARE EMULATED OK\n");
    }


    result = FMOD_System_GetDriverInfo(FMODSystem, 0, name, 256, 0);
    ERRCHECK(result, __LINE__);
    if (strstr(name, "SigmaTel"))
    {
        /*
        Sigmatel sound devices crackle for some reason if the format is PCM 16bit.
        PCM floating point output seems to solve it.
        */
        result = FMOD_System_SetSoftwareFormat(FMODSystem, 48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
        ERRCHECK(result, __LINE__);
    }

    Ennelog("GetDriverInfo OK\n");
}

result = FMOD_System_Init(FMODSystem, 100, FMOD_INIT_NORMAL, 0);
if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)
{
    /*
    Ok, the speaker mode selected isn't supported by this soundcard. Switch it
    back to stereo...
    */
    result = FMOD_System_SetSpeakerMode(FMODSystem, FMOD_SPEAKERMODE_STEREO);
    ERRCHECK(result, __LINE__);

    Ennelog("SpeakerMode STEREO OK\n");

    /*
    ... and re-init.
    */
    result = FMOD_System_Init(FMODSystem, 100, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result, __LINE__);
}


Ennelog("Init OK\n");

}

class Enne_FMODPlugin : public HSEI::HeroScriptExtensionInterface
{
private:
bool mInitialized;
G::UINT64 mPumpCounter;
ENNE_FMOD_PlaySoundFunction * mEnne_FMOD_PlaySound;
bool mFinished;

public:
Enne_FMODPlugin()
: mEnne_FMOD_PlaySound(NULL)
, mInitialized(false)
, mPumpCounter(0)
{

}

~Enne_FMODPlugin()
{       
    delete mEnne_FMOD_PlaySound;
    FMOD_System_Release(FMODSystem);
}

virtual bool init(HeroScript::PluginInterface * scriptInterface)
{
    if ( !mInitialized )
    {
        InitFMOD(); 

        mInitialized = true;
        mEnne_FMOD_PlaySound= new ENNE_FMOD_PlaySoundFunction(scriptInterface);
        return true;
    }
    else
    {
        return false;
    }
}

virtual void pump()
{
    FMOD_System_Update(FMODSystem);
}

};

namespace
{
Enne_FMODPlugin * pPlugin = NULL;
}

extern "C"
{
HSEIDECL HSEI::HeroScriptExtensionInterface * getInterface(int version_number)
{
if ( version_number == HEROSCRIPTEXTENSIONINTERFACE_VERSION )
{
if ( NULL == pPlugin )
{
pPlugin = new Enne_FMODPlugin();
}
return pPlugin;
}
else
{
return NULL;
}
}

HSEIDECL int releaseInterface(HSEI::HeroScriptExtensionInterface * aInterface)
{
    if ( pPlugin == aInterface )
    {
        delete pPlugin;
        pPlugin = NULL;
        return 1;
    }
    return 0;
}

};

[/code:1paz6oby]

Thanks in advance!
Oakshiro

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.