質問

I have lots of short audio files (mp3) I want to play with FMOD in c++.
In my program there's something like this:

FMOD::System *fmodSystem;
FMOD::Channel *channel;
FMOD::System_Create(&fmodSystem);

fmodSystem->init(100, FMOD_INIT_NORMAL, 0); 

while(true)
{
    FMOD::Sound *sound;
    fmodSystem->createSound("random filename.mp3", FMOD_DEFAULT, FMOD_DEFAULT, &sound);
    fmodSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);   
    fmodSystem->update();
    Sleep(100);
}

For each new sound I see a decrease of free memory. That seems quite normal because I never free the FMOD:Sound objects. I can't free these objects because the fmodSystem->playSound method is asynchronous.

So how can I solve this memory problem?

役に立ちましたか?

解決

I hadn't figured out, how to release sounds after they have finished playing, but I started to cache all sounds in an array of FMOD::Sound.

FMOD::Sound *sounds[84];

Now my application consumes about 100 MB of RAM but there isn't an increase.

他のヒント

FMOD::Sound *sound = 0;
bool Playing = false;

while(true)
{
    if(channel)channel->isPlaying(&Playing);

    if(!Playing)
    {
        if(sound)sound->release();
        fmodSystem->createSound("random filename.mp3", FMOD_DEFAULT, FMOD_DEFAULT, &sound);
        fmodSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);   
    }
    fmodSystem->update();
    Sleep(100);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top