Answered
0
0

Hi there!

As per the title, I’m having an issue with some audio popping when the sound is first played.

Initially when I had this issue, I greatly reduced it when calling playSound() by making it start paused, then when all the settings were… set, unpause.

That greatly reduced it. I’m guessing it has to do with looping sounds. I suspect it has to do with WAV files in particular maybe?

I dunno. It’s hard to diagnose, because it doesn’t always happen, I have to restart the level 3-4 times sometimes for the audio to pop, sometimes it happens on the first shot.

Anyway, here’s some code where all the magic happens:

bool C_AmbientFMOD::SetSound()

{
if (m_iszSound == NULL)
return false;

DevMsg("Setting sound: %s\n", m_iszSound);
const char *szSound = GetMusicSystem()->GetFullPathToSound( m_iszSound );

if (m_bLooping)
{
    if (!m_bGlobal)
        result = GetMusicSystem()->GetSoundSystem()->createSound(szSound, FMOD_LOOP_NORMAL | FMOD_3D | FMOD_3D_LINEARROLLOFF, 0, &sound);
    else
        result = GetMusicSystem()->GetSoundSystem()->createSound(szSound, FMOD_DEFAULT | FMOD_LOOP_NORMAL, 0, &sound);
}
else
{
    if (!m_bGlobal)
        result = GetMusicSystem()->GetSoundSystem()->createSound(szSound, FMOD_3D | FMOD_3D_LINEARROLLOFF, 0, &sound);
    else
        result = GetMusicSystem()->GetSoundSystem()->createSound(szSound, FMOD_DEFAULT, 0, &sound);
}

if (result != FMOD_OK)
    Msg("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));

channel = 0;

// Play sound right away if true
if (m_bActive)
{
    //local->FMODThink();
    result = GetMusicSystem()->GetSoundSystem()->playSound(FMOD_CHANNEL_FREE, sound, true, &channel);
    if (result != FMOD_OK)
        Msg("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
}

result = GetMusicSystem()->GetSoundSystem()->set3DListenerAttributes(0, 0, 0, 0, 0);
if (result != FMOD_OK)
    Msg("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));

if (channel) 
{
    ConVarRef conVolume(m_sVolConVar);
    if (m_fGlobalVolume != conVolume.GetFloat())
        m_fGlobalVolume = conVolume.GetFloat();

    result = channel->setVolume(m_fVolume * m_fGlobalVolume);

    if (result != FMOD_OK)
        Msg("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));

    if (!m_bGlobal)
    {
        result = channel->set3DMinMaxDistance(1, m_fRadius);

        if (result != FMOD_OK)
            Msg("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));

        Vector entPos = GetAbsOrigin();
        FMOD_VECTOR sourcePos = { entPos.x, entPos.z, entPos.y };
        result = channel->set3DAttributes(&sourcePos, 0);

        if (result != FMOD_OK)
            Msg("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
    }
}

channel->setPaused(false);
result = FMOD_OK;

return true;

}

Now then, FMOD’s system update is called every frame, which is after this gets processed. But I’ve tried calling the update() manually after setting stuff, that didn’t seem to do anything. I tried that local->FMODThink() which updates the local player’s listener attributes. And I can’t seem to fix the issue.

Anybody have any potential solutions?

  • Brett Paterson

    is it possible you’re setting it to the listener position and then repositioning it where it should be, and its audible in the wrong position for that frame?
    It shouldn’t be relevant, but why is there a set3DListenerAttributes(0, 0, 0, 0, 0); in there?
    Starting it paused, then altering properties, then unpausing it is what you are supposed to do every time, unless your default sound settings are good enough to go and play without needing to alter them after play.

  • Michael Barth

    That’s something I’ve forgotten to get rid off. But as per the listener properties getting set somewhere else, that’s why I tried local->FMODThink() which sets those properties. I can try spewing some debug output just before system update to get the current listener properties to see if there’s some weirdness going on.

    Maybe the local player’s position is invalid due to the Source Engine’s networking when the map starts. Thanks for giving me an idea!

  • Michael Barth

    I finally figured it out. I think it was a couple of things. It was not a networking issue, but I did notice that when you closed the map, the listener position was sticking and not getting reset to zero. Secondly, the code I posted was not the affected code. I also have a function called ToggleSound() which calls the channel’s playSound when playing also. I never modified it.

    I wrote this code so long ago I was missing potential NULL pointer checks lol. Makes me cringe.

  • Brett Paterson

    good to hear you fixed it!

  • You must to post comments
Best Answer
0
0

Solved in comments ^^^

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.