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。谢谢你的回答。
答案 0 :(得分:0)
我正在寻找它,我发现了错误。 Fmod创建它自己的副本,因此每次播放声音时它都会复制内存。 使用此:
System->createSound((const char*)FSB,
FMOD_SOFTWARE | FMOD_CREATECOMPRESSEDSAMPLE | FMOD_OPENMEMORY_POINT,
&exinfo, &Sound);
而不是:
System->createSound((const char*)FSB, FMOD_OPENMEMORY, &exinfo, &Sound);