mcimolin
27-07-2010 18:18:21
In my application a crash sounds plays when ever a user drives into an object. The problem I'm having is
that when this happens, the sound plays twice. I've checked the audio file, and the effect only plays once
in it, and I've checked to make sure that I'm only calling the play() method once for the sounds and that
the sound is set to not repeat. I've even put in debug output statements to see if it was a logic error that
had the function being called more than once, but it is only being called once so I have no idea what is
making the sound play twice.
Here is the relevant code:
The audio core code:
The collision code that calls the audio core:
And the code that builds the object that both plays the sound and is the listener:
I'm using the latest version of OgreOggSound, the latest version of OpenAL, and Ogre 1.7.0 in
Visual Studio 2008.
Everything else is updating correctly on a collision other than the sound playing twice so I'm not sure
what to do here. Any help is greately appretiated.
that when this happens, the sound plays twice. I've checked the audio file, and the effect only plays once
in it, and I've checked to make sure that I'm only calling the play() method once for the sounds and that
the sound is set to not repeat. I've even put in debug output statements to see if it was a logic error that
had the function being called more than once, but it is only being called once so I have no idea what is
making the sound play twice.
Here is the relevant code:
The audio core code:
#include "AudioCore.h"
#include "HelpfulUtilities.h"
/*
Constructor
*/
AudioCore::AudioCore(){
mSoundManager = OgreOggSound::OgreOggSoundManager::getSingletonPtr();
}
/*
Destructor
*/
AudioCore::~AudioCore(){
mSoundManager->destroyAllSounds();
delete mSoundManager;
}
/*
Iinitializes the sound manager
*/
void AudioCore::init(){
mSoundManager->init();
sCrash = mSoundManager->createSound("Crash", "thud.wav", true, false);
sCrash->setVolume(0.5);
sBackground = mSoundManager->createSound("Background", "Background.ogg", true, true);
sBackground->setVolume(0.3);
mListener = mSoundManager->getListener();
}
/*
Plays a sound effect
*/
void AudioCore::playSoundEffect(){
sCrash->play();
}
/*
Plays the background music
*/
void AudioCore::playBackgroundSound(){
sBackground->play();
}
/*
Updates the sounds
*/
void AudioCore::update(Ogre::Real time){
mSoundManager->update(time);
}
/*
Returns sCrash
*/
OgreOggSound::OgreOggISound* AudioCore::getSoundEffect(){
return sCrash;
}
/*
Returns sBackground
*/
OgreOggSound::OgreOggISound* AudioCore::getBackgroundMusic(){
return sBackground;
}
/*
Returns a listener
*/
OgreOggSound::OgreOggListener* AudioCore::getListener(){
return mListener;
}
The collision code that calls the audio core:
int Application::updateScore(int collisions){
if(currentCollisions < collisions){
audioCore->playSoundEffect();
}
currentCollisions = collisions;
return(100 - currentCollisions);
}
And the code that builds the object that both plays the sound and is the listener:
void Application::startGame(int position, int chairType){
if(controller->gameReady() == false){
return;
}
wheelChair = new WheelChairVehicle(NxOgre::Vec3(0,10000000,0), mScene, mRenderSystem, mSceneMgr, chairType);
wheelChair->mActor->putToSleep();
chairPosition(position);
cameraPosition(position);
changeChairMode();
mScene->getScene()->setGroupCollisionFlag(1, 2, true);
mScene->getScene()->setActorGroupPairFlags(1, 2, NX_NOTIFY_ON_START_TOUCH);
reporter = new ContactReport();
//listener
mScene->getScene()->setUserContactReport(reporter);
controller->setGameReady(false);
wheelChair->mCameraNode->getParentSceneNode()->attachObject(audioCore->getListener());
wheelChair->mWheelChairNode->attachObject(audioCore->getBackgroundMusic());
wheelChair->mWheelChairNode->attachObject(audioCore->getSoundEffect());
toggleCameraMode();
audioCore->playBackgroundSound();
}
I'm using the latest version of OgreOggSound, the latest version of OpenAL, and Ogre 1.7.0 in
Visual Studio 2008.
Everything else is updating correctly on a collision other than the sound playing twice so I'm not sure
what to do here. Any help is greately appretiated.