How can i get smaller memory usage with fmod_event

549 views Asked by At
FMOD::EventSystem       *EventSystem = 0;
FMOD::System            *System;
FMOD::EventProject      *Project;
FMOD::Event             *pEvent;
FMOD::Sound             *Sound;
FMOD_RESULT             result = FMOD_OK;

if(!FEV || !FSB)
    return 0;

result = FMOD::EventSystem_Create(&EventSystem);
    if(result != FMOD_OK)
        return 1;
EventSystem->getSystemObject(&System);

result = EventSystem->init(maxChannels, FMOD_INIT_NORMAL, 0, FMOD_EVENT_INIT_NORMAL);
    if(result != FMOD_OK)
        return 2;

FMOD_EVENT_LOADINFO loadinfo;
memset(&loadinfo, 0, sizeof(FMOD_EVENT_LOADINFO));
loadinfo.size = sizeof(FMOD_EVENT_LOADINFO);
loadinfo.loadfrommemory_length = FEV_len;

result = EventSystem->load((char*)FEV, &loadinfo, NULL);
    if(result != FMOD_OK)
        return 3;

result = EventSystem->getEvent(Event, FMOD_EVENT_ERROR_ON_DISKACCESS, &pEvent);
if(result == FMOD_ERR_FILE_UNWANTED)
{
    FMOD_CREATESOUNDEXINFO exinfo = {0};
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = FSB_len;

    result = System->createSound((const char*)FSB, FMOD_OPENMEMORY, &exinfo, &Sound);
        if(result != FMOD_OK)
            return 4;

    result = EventSystem->preloadFSB(FSB_name, 0, Sound);

    result = EventSystem->getEvent(Event, FMOD_EVENT_ERROR_ON_DISKACCESS, &pEvent);
        if(result != FMOD_OK)
            return 5;
}
else if(result != FMOD_OK)
    return 6;

for(int a=0; a<LoopsCount; a++)
{
    pEvent->start();

    FMOD_EVENT_STATE State = FMOD_EVENT_STATE_PLAYING;
    while(State == FMOD_EVENT_STATE_PLAYING)
    {
        pEvent->getState(&State);
        result = EventSystem->update();
        Sleep(300);
    }
}

EventSystem->unloadFSB(FSB_name, 0);

Sound->release();
EventSystem->release();

return 10;

How i can get smaller memory usage? if i run this code it will take 166MB of RAM. After the sound will be played, all this memory is released and memory usage is decreased to 9Mb of RAM. FSB has 40mb. Thanks for answers.

1

There are 1 answers

0
Quest On BEST ANSWER

i was looking on it and i've found the error. Fmod create it's own copy, so it will duplicate memory everytime when u play sound. Use this:

System->createSound((const char*)FSB, 
    FMOD_SOFTWARE | FMOD_CREATECOMPRESSEDSAMPLE | FMOD_OPENMEMORY_POINT, 
    &exinfo, &Sound);

instead of this:

System->createSound((const char*)FSB, FMOD_OPENMEMORY, &exinfo, &Sound);