0
0

Fmod 4.27 – ALSA driver
Linux64 – opensuse 11.1

Hello,

My application hangs at termination in FMOD::SOUND::RELEASE and I’m trying to figure out what I am doing wrong. My assumption is that FMOD::SOUND::RELEASE is waiting for something ELSE to be released first.

I initialize the fmod system, I create a stream, play the stream, add a dsp, release the sound, close the system and release the system. If I don’t add any dsps my application doesn’t hang. If I release all dsp’s from a channel a sound is playing on before attempting to release the sound my application still hangs.

Are there any common things I should do to avoid this problem?

Here are some code snippets in the hope they will help:

[code:1k5lq5mw] static void InitFmod()
{
FMOD_RESULT error_state;

                            //create the fmod system
                            error_state = FMOD::System_Create(&_system);

                            if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                            {
                                    Terminate("AudioManager::AudioMetaData::AudioMetaData - could not create FMOD system.");
                            }//end if

if defined(linux) || defined(linux) || defined(__linux)

                            //on linux 5.1 and 7.1 sound is only supported in ALSA retVal->_mode by FMOD
                            error_state = _system->setOutput(FMOD_OUTPUTTYPE_ALSA);

                            if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                            {
                                    Terminate("AudioManager::AudioMetaData::AudioMetaData - could not set FMOD system output mode.");
                            }//end if

endif

                            //setup 7.1 surround sound
                            error_state = _system->setSpeakerMode(FMOD_SPEAKERMODE_7POINT1);

                            if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                            {
                                    Terminate("AudioManager::AudioMetaData::AudioMetaData - could not set FMOD speaker output mode.");
                            }//end if

                            //initialize the fmod system
                            error_state = _system->init(2048,FMOD_INIT_NORMAL,0);

                            if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                            {
                                    Terminate("AudioManager::AudioMetaData::AudioMetaData - could not initialize FMOD system.");
                            }//end if

                            //setup the master channel group
                            error_state = _system->getMasterChannelGroup(&_masterGroup);

                            if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                            {
                                    Terminate("AudioManager::AudioMetaData::AudioMetaData - could not create FMOD master channel group.");
                            }//end if
                    }//end function[/code:1k5lq5mw]

[code:1k5lq5mw] void AudioManager::DSP::InitDsp()
{
// this instance is static for two reasons
// 1) it’s more efficient to create this once
// 2) more importantly it avoids a segmentation fault
// if the audio is deconstructed to early it will
// destroy the fmod system which will result in errors
// for anything still using it.
static AUDIO audio(
new (SEMemory<AUDIO::element_type>::Allocate()) AUDIO::element_type,
SEMemory<AUDIO::element_type>::DeallocAndDecontruct);

ifndef NDEBUG

            FMOD_RESULT error_state;

            if (this-&gt;_dsp != 0)
            {
                    // clean up the dsp before it is re-used.

                    error_state = this-&gt;_dsp-&gt;release();

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - could not release dsp before re-initialization.&quot;);
                    }//end if

                    this-&gt;_initialized = false;
            }//end if

            // initialize the dsp according to its type
            switch (this-&gt;_type)
            {
            case mixer:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_MIXER,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case oscillator:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_OSCILLATOR,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case lowpass:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_LOWPASS,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case itlowpass:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_ITLOWPASS,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case highpass:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_HIGHPASS,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case echo:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_ECHO,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case flange:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_FLANGE,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case distortion:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_DISTORTION,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case normalize:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_NORMALIZE,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case parameq:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_PARAMEQ,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case pitchshift:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_PITCHSHIFT,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case chorus:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_CHORUS,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case reverb:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_REVERB,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case itecho:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_ITECHO,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case compressor:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_COMPRESSOR,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case sfxreverb:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_SFXREVERB,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case lowpass_simple:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_LOWPASS_SIMPLE,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case delay:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_DELAY,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case tremelo:
                    error_state = audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_TREMOLO,
                            &amp;this-&gt;_dsp);

                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::DSP::InitDsp - cannot create digital signal processor.&quot;);
                    }//end if
                    break;
            case unknown:
                    //I don't know what you want to do but at least we both
                    //agree you don't know what you want so
                    //I'm just not going to do anything until
                    //you figure it out.
                    break;
            default:
                    Terminate(&quot;AudioManager::DSP::InitDsp - request for unsupported dsp effect.&quot;);
                    break;
            }//end switch

            if (this-&gt;_type != unknown)
            {
                    //signal that the dsp has been initialized properly
                    this-&gt;_initialized = true;
            }//end if

            error_state = audio-&gt;_system-&gt;update();

            if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
            {
                    Terminate(&quot;AudioManager::DSP::InitDsp - could not update audio system.&quot;);
            }//end if

else

            if (this-&gt;_dsp != 0)
            {
                    // clean up the dsp before it is re-used.

                    this-&gt;_dsp-&gt;release();

                    this-&gt;_initialized = false;
            }//end if

            // initialize the dsp according to its type
            switch (this-&gt;_type)
            {
            case mixer:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_MIXER,
                            &amp;this-&gt;_dsp);
                    break;
            case oscillator:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_OSCILLATOR,
                            &amp;this-&gt;_dsp);
                    break;
            case lowpass:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_LOWPASS,
                            &amp;this-&gt;_dsp);
                    break;
            case itlowpass:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_ITLOWPASS,
                            &amp;this-&gt;_dsp);
                    break;
            case highpass:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_HIGHPASS,
                            &amp;this-&gt;_dsp);
                    break;
            case echo:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_ECHO,
                            &amp;this-&gt;_dsp);
                    break;
            case flange:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_FLANGE,
                            &amp;this-&gt;_dsp);
                    break;
            case distortion:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_DISTORTION,
                            &amp;this-&gt;_dsp);
                    break;
            case normalize:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_NORMALIZE,
                            &amp;this-&gt;_dsp);
                    break;
            case parameq:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_PARAMEQ,
                            &amp;this-&gt;_dsp);
                    break;
            case pitchshift:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_PITCHSHIFT,
                            &amp;this-&gt;_dsp);
                    break;
            case chorus:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_CHORUS,
                            &amp;this-&gt;_dsp);
                    break;
            case reverb:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_REVERB,
                            &amp;this-&gt;_dsp);
                    break;
            case itecho:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_ITECHO,
                            &amp;this-&gt;_dsp);
                    break;
            case compressor:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_COMPRESSOR,
                            &amp;this-&gt;_dsp);
                    break;
            case sfxreverb:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_SFXREVERB,
                            &amp;this-&gt;_dsp);
                    break;
            case lowpass_simple:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_LOWPASS_SIMPLE,
                            &amp;this-&gt;_dsp);
                    break;
            case delay:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_DELAY,
                            &amp;this-&gt;_dsp);
                    break;
            case tremelo:
                    audio-&gt;_system-&gt;createDSPByType(
                            FMOD_DSP_TYPE_TREMOLO,
                            &amp;this-&gt;_dsp);
                    break;
            case unknown:
                    //I don't know what you want to do but at least we both
                    //agree you don't know what you want so
                    //I'm just not going to do anything until
                    //you figure it out.
                    break;
            default:
                    Terminate(&quot;AudioManager::DSP::InitDsp - request for unsupported dsp effect.&quot;);
                    break;
            }//end switch

            if (this-&gt;_type != unknown)
            {
                    //signal that the dsp has been initialized properly
                    this-&gt;_initialized = true;
            }//end if

            audio-&gt;_system-&gt;update();

endif

    }//end fucntion[/code:1k5lq5mw]

[code:1k5lq5mw] void UploadAudio(
AUDIO &audio,
const VECPARAMS &params)
{
//create the sound
FMOD_RESULT error_state;
error_state = audio->_system->createSound(
audio->_filepath.c_str(),
audio->_mode,
0,
&audio->_sound);
if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
{
Terminate("AudioManager – UploadAudio – could not create FMOD sound.");
}//end if

                    //initialize spatial attributes
                    if (audio-&gt;_is3D)
                    {
                            audio-&gt;_sound-&gt;set3DMinMaxDistance(
                                    audio-&gt;_minDistance,
                                    audio-&gt;_maxDistance);

                            if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                            {
                                    Terminate(&quot;AudioManager - UploadAudio - could not create FMOD sound 3D min/max.&quot;);
                            }//end if
                    }//end if

                    //initialize dsp effects
                    for (unsigned int i(0);i &lt; audio-&gt;_dsp_effects.size();++i)
                    {
                            audio-&gt;_dsp_effects[i].InitDsp();

                            audio-&gt;_dsp_effects[i]._isActive = true;
                    }//end if
            }//end function[/code:1k5lq5mw]

[code:1k5lq5mw] AudioManager::AudioMetaData::~AudioMetaData()
{
FMOD_RESULT error_state;

            if (this-&gt;_sound != 0)
            {
                    error_state = this-&gt;_sound-&gt;release();
                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::AudioMetaData::~AudioMetaData - could not release FMOD sound.&quot;);
                    }//end if
            }//end if

            if (this-&gt;_system != 0)
            {
                    error_state = this-&gt;_system-&gt;close();
                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::AudioMetaData::~AudioMetaData - could not close FMOD system.&quot;);
                    }//end if

                    error_state = this-&gt;_system-&gt;release();
                    if (!FmodErrorChecker::CheckFmodErrorState(error_state,std::cerr))
                    {
                            Terminate(&quot;AudioManager::AudioMetaData::~AudioMetaData - could not release FMOD system.&quot;);
                    }//end if

                    this-&gt;_system = 0;
            }//end if
    }//end function[/code:1k5lq5mw]
  • You must to post comments
0
0

Is there anything I can provide to help in figuring this out?

  • You must to post comments
0
0

Have I asked my question in the wrong way or in the wrong forum?

Perhaps no one has a clue for me but I get the feeling I did something wrong…

  • You must to post comments
0
0

The only time I have this happen is creating sounds with the non blocking flag set and connecting to a remote file or web stream and trying to free it when it was still busy.

I think I resolved it by checking if the stream was ready
[code:jc1wyugo]
DWORD t = GetTickCount()+5000;
do
{
FMOD_OPENSTATE openstate = FMOD_OPENSTATE_READY;
UINT result = FMOD_Sound_GetOpenState((FMOD_SOUND*)(DWORD)sound,&openstate, 0, 0);

    if (openstate == FMOD_OPENSTATE_READY || openstate == FMOD_OPENSTATE_ERROR || result == FMOD_OK )
    {
          break;
    }
    else if(GetTickCount()&gt;t)
    {
        return; //fudge it, tried and failed for 10 seconds
    }
    FMODUpdate();
    Sleep(10);
} while (1);
FMOD_Sound_Release((FMOD_SOUND*)(DWORD)sound);

[/code:jc1wyugo]

If you are creating web stream sounds without the non blocking, then you have no means to check the stream state. And you will deadlock when freeing a sound that has connection troubles.

Also, make sure no channels are playing the sound and that no DSP are still attached to the channel before freeing. That may also cause problem, possibly

  • You must to post comments
0
0

[quote="icuurd12b42":2igov400]The only time I have this happen is creating sounds with the non blocking flag set and connecting to a remote file or web stream and trying to free it when it was still busy.

I think I resolved it by checking if the stream was ready

If you are creating web stream sounds without the non blocking, then you have no means to check the stream state. And you will deadlock when freeing a sound that has connection troubles.

Also, make sure no channels are playing the sound and that no DSP are still attached to the channel before freeing. That may also cause problem, possibly[/quote:2igov400]

I didn’t stop my channels BEFORE releasing any DSPs attached to them. Your suggestion fixed everything.

Thank you very much! You’ve saved what little I have left of my hair 😀

  • You must to post comments
0
0

Good. I never had that happen myself because I only free sounds when the game ends, after I stop all the channels; I dont think sounds take much memory when they are not playing… Good thing I thought of adding this tidbit.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.