0
0

When I call the function below several times, system suddently does not play sound. I mean I can’t hear any sound, when I call this function frequently like 2000 millisecond once.

[code:2qu6xy32]void SoundManager::PlayFMODSound(int soundIndex, SceneNode *soundNode, int *channelIndex)
{
int channelIndexTemp;
FMOD_RESULT result;
FMOD_VECTOR initialPosition;
FMOD::Channel *channel;
SoundInstance *soundInstance;

if (soundIndex == INVALID_SOUND_INDEX)
    return;

if (channelIndex)
{
    channelIndexTemp = *channelIndex;
}else{
    channelIndexTemp = INVALID_SOUND_CHANNEL;
}
assert((soundIndex > 0) && (soundIndex < (int)soundInstanceVector->capacity()));

// If the channelIndex already has a sound assigned to it, test if it's the same sceneNode.
if ((channelIndexTemp != INVALID_SOUND_CHANNEL) && (channelArray[channelIndexTemp].sceneNode != NULL))
{
    result = system->getChannel(channelIndexTemp, &channel);
    if (result == FMOD_OK)
    {
        bool isPlaying;

        result = channel->isPlaying(&isPlaying);
        if ((result == FMOD_OK) && (isPlaying == true) && (channelArray[channelIndexTemp].sceneNode == soundNode))
            return;  // Already playing this sound attached to this node.
    }
}

soundInstance = soundInstanceVector->at(soundIndex);
// Start the sound paused
result = system->playSound(FMOD_CHANNEL_REUSE, soundInstance->fmodSound, true, &channel);
if (result != FMOD_OK)
{
    Ogre::LogManager::getSingleton().logMessage(String("SoundManager::PlaySound could not play sound  FMOD Error:") + FMOD_ErrorString(result));
    if (channelIndex)
        *channelIndex = INVALID_SOUND_CHANNEL;
    return;
}

channel->getIndex(&channelIndexTemp);
channelArray[channelIndexTemp].sceneNode = soundNode;

if (soundNode)
{
    channelArray[channelIndexTemp].prevPosition = soundNode->getPosition();

    initialPosition.x = soundNode->getPosition().x;
    initialPosition.y = soundNode->getPosition().y;
    initialPosition.z = soundNode->getPosition().z;
    channel->set3DAttributes(&initialPosition, NULL);
}

result = channel->setVolume(1.0);
// This is where the sound really starts.
result = channel->setPaused(false);

if (channelIndex)
    *channelIndex = channelIndexTemp;

}[/code:2qu6xy32]

  • You must to post comments
0
0

unfortunately you haven’t told what system you are using. I experienced something very similar on my linux system with a HDA soundcard when using alsa. OSS however doesn’t seem to have this problem for this card.
My other system with a creative audigy works fine in both.
It also seems that the number of channels is directly involved. If limiting channels to 32 it seems to work almost flawlessly.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.