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;
我怎样才能获得更小的内存使用量?如果我运行此代码,它将占用 166MB 的 RAM。播放声音后,所有这些内存都被释放,内存使用量减少到 9Mb 的 RAM。FSB有40mb。感谢您的回答。