Added more configuration options for SFX. Potentially fixed looping music glitch.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2411 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
stevo14 2008-11-06 07:17:11 +00:00
parent eac019825d
commit 1b5fc11393
7 changed files with 47 additions and 21 deletions

View File

@ -249,12 +249,18 @@ void MusicOggStream::update()
if(!check()) return;
active = streamIntoBuffer(buffer);
alSourceQueueBuffers(m_soundSource, 1, &buffer);
if(!active)
{
// no more data. Seek to beginning (causes the sound to loop)
ov_time_seek(&m_oggStream, 0);
active = streamIntoBuffer(buffer);//now there really should be data
//fprintf(stdout,"Music buffer under-run.\n");
}
alSourceQueueBuffers(m_soundSource, 1, &buffer);
if(!check()) return;
}
// check for underrun
if (active)
{
// we have data, so we should be playing...
@ -262,15 +268,14 @@ void MusicOggStream::update()
alGetSourcei(m_soundSource, AL_SOURCE_STATE, &state);
if (state != AL_PLAYING)
{
fprintf(stderr,"WARNING: Alsa source state: %d\n", state);
fprintf(stderr,"WARNING: Music not playing when it should be. Source state: %d\n", state);
alGetSourcei(m_soundSource, AL_BUFFERS_PROCESSED, &processed);
alSourcePlay(m_soundSource);
}
}
else
{
// no more data. Seek to beginning -> loop
ov_time_seek(&m_oggStream, 0);
fprintf(stderr,"WARNING: Attempt to stream music into buffer failed twice in a row.\n");
}
} // update

View File

@ -39,6 +39,7 @@
#include "user_config.hpp"
#include "file_manager.hpp"
#include "translation.hpp"
#include "race_manager.hpp"
SFXManager* sfx_manager= NULL;
@ -49,6 +50,9 @@ SFXManager::SFXManager()
// The sound manager initialises OpenAL
m_initialized = sound_manager->initialized();
m_sfx_buffers.resize(NUM_SOUNDS);
m_sfx_positional.resize(NUM_SOUNDS);
m_sfx_rolloff.resize(NUM_SOUNDS);
m_sfx_gain.resize(NUM_SOUNDS);
if(!m_initialized) return;
loadSfx();
} // SoundManager
@ -119,8 +123,17 @@ void SFXManager::loadSfx()
void SFXManager::loadSingleSfx(const lisp::Lisp* lisp,
const char *name, SFXType item)
{
std::string wav;
lisp->get(name, wav);
const lisp::Lisp* sfxLisp = lisp->getLisp(name);
std::string wav; float rolloff = 0.1f; float gain = 1.0f; int positional = 0;
sfxLisp->get("filename", wav );
sfxLisp->get("roll-off", rolloff );
sfxLisp->get("positional", positional );
sfxLisp->get("volume", gain );
m_sfx_rolloff[item] = rolloff;
m_sfx_positional[item] = positional;
m_sfx_gain[item] = gain;
std::string path = file_manager->getSFXFile(wav);
@ -181,7 +194,11 @@ void SFXManager::loadSingleSfx(const lisp::Lisp* lisp,
*/
SFXBase *SFXManager::newSFX(SFXType id)
{
SFXBase *p=new SFXOpenAL(m_sfx_buffers[id]);
bool positional = false;
if(race_manager->getNumLocalPlayers() < 2)
positional = (bool)m_sfx_positional[id];
SFXBase *p=new SFXOpenAL(m_sfx_buffers[id], positional, m_sfx_rolloff[id], m_sfx_gain[id]);
m_all_sfx.push_back(p);
return p;
} // newSFX

View File

@ -63,6 +63,9 @@ private:
/** The buffers for all sound effects. These are shared among all
* instances of SFXOpenal. */
std::vector<ALuint> m_sfx_buffers;
std::vector<int> m_sfx_positional;
std::vector<float> m_sfx_rolloff;
std::vector<float> m_sfx_gain;
std::vector<SFXBase*> m_all_sfx;
bool m_initialized;
void loadSfx();

View File

@ -37,11 +37,12 @@
#include "file_manager.hpp"
#include "user_config.hpp"
SFXOpenAL::SFXOpenAL(ALuint buffer) : SFXBase()
SFXOpenAL::SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain) : SFXBase()
{
m_soundBuffer = buffer;
m_soundSource = 0;
m_ok = false;
m_positional = false;
alGenSources(1, &m_soundSource );
if(!SFXManager::checkError("generating a source")) return;
@ -50,9 +51,14 @@ SFXOpenAL::SFXOpenAL(ALuint buffer) : SFXBase()
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 0.0);
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, 0.1f );
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE );//sound position is *not* relative to the camera.
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
alSourcef (m_soundSource, AL_GAIN, gain );
if(positional)
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
else
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
m_positional = positional;
m_ok = SFXManager::checkError("setting up the source");
} // SFXOpenAL
@ -146,7 +152,7 @@ void SFXOpenAL::play()
*/
void SFXOpenAL::position(const Vec3 &position)
{
if(!sfx_manager->sfxAllowed()||!m_ok) return;
if(!sfx_manager->sfxAllowed()||!m_ok||!m_positional) return;
alSource3f(m_soundSource, AL_POSITION,
(float)position.getX(), (float)position.getY(), (float)position.getZ());

View File

@ -35,8 +35,9 @@ private:
ALuint m_soundBuffer; // Buffers hold sound data.
ALuint m_soundSource; // Sources are points emitting sound.
bool m_ok;
bool m_positional;
public:
SFXOpenAL(ALuint buffer);
SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain);
virtual ~SFXOpenAL();
virtual void play();
virtual void loop();

View File

@ -207,7 +207,8 @@ void Camera::update (float dt)
m_xyz = c.getXYZ();
m_hpr = c.getHPR();
m_context -> setCamera(&c.toSgCoord());
sound_manager->positionListener(m_xyz, kart_xyz - m_xyz);
if(race_manager->getNumLocalPlayers() < 2)
sound_manager->positionListener(m_xyz, kart_xyz - m_xyz);
} // update
//-----------------------------------------------------------------------------

View File

@ -171,13 +171,6 @@ void PlayerKart::update(float dt)
if(!history->replayHistory())
steer(dt, m_steer_val);
//position the generic sounds at the kart's position
m_bzzt_sound->position(getXYZ());
m_wee_sound->position(getXYZ());
m_ugh_sound->position(getXYZ());
m_grab_sound->position(getXYZ());
m_full_sound->position(getXYZ());
if(RaceManager::getWorld()->isStartPhase())
{
if(m_controls.accel!=0.0 || m_controls.brake!=false ||