update menu music code by beaglejoe

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5049 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 0a59c496ad4866a2f5396b3afed96c62a5e70588
Former-commit-id: 400e616609ccabb60b00278b8e481179cc5d9de8
This commit is contained in:
torcs-ng 2012-11-16 17:42:09 +00:00
parent dc8f0b0801
commit 262d46f1da
6 changed files with 45 additions and 17 deletions

View file

@ -26,7 +26,6 @@ const int OpenALMusicPlayer::BUFFERSIZE = 4096*64;
OpenALMusicPlayer::OpenALMusicPlayer(SoundStream* soundStream):
device(NULL),
context(NULL),
previouscontext(NULL),
source(0),
stream(soundStream),
ready(false)
@ -70,8 +69,6 @@ void OpenALMusicPlayer::stop()
alDeleteBuffers(2, buffers);
check();
//alcMakeContextCurrent(previouscontext);
// previouscontext = NULL;
alcDestroyContext(context);
alcCloseDevice(device);
@ -95,7 +92,6 @@ bool OpenALMusicPlayer::initContext()
GfError("OpenALMusicPlayer: OpenAL could not create contect for device\n");
return false;
}
previouscontext = alcGetCurrentContext();
alcMakeContextCurrent(context);
alcGetError(device);
@ -210,21 +206,11 @@ void OpenALMusicPlayer::start()
void OpenALMusicPlayer::pause()
{
alSourceStop(source);
if(previouscontext == NULL){
previouscontext = alcGetCurrentContext();
}
alcMakeContextCurrent(previouscontext);
//previouscontext = NULL;
}
void OpenALMusicPlayer::resume(int flag)
{
alcMakeContextCurrent(context);
alSourcePlay(source);
if(flag == 1){
previouscontext = NULL;
}
}
void OpenALMusicPlayer::rewind()
{

View file

@ -48,7 +48,6 @@ class OpenALMusicPlayer
ALCdevice* device;
ALCcontext* context;
ALCcontext* previouscontext;
ALuint source; // audio source
ALuint buffers[2]; // front and back buffers

View file

@ -302,6 +302,9 @@ void OpenalSound::resume()
{
if (paused) {
paused = false;
#ifdef MENU_MUSIC
alSourcePlay (source);
#endif
}
}
@ -310,6 +313,9 @@ void OpenalSound::pause()
{
if (!paused) {
paused = true;
#ifdef MENU_MUSIC
alSourcePause (source);
#endif
}
}

View file

@ -39,6 +39,11 @@ OpenalSoundInterface::OpenalSoundInterface(float sampling_rate, int n_channels)
ALfloat far_away[] = { 0.0f, 0.0f, 1000.0f };
ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f };
ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };
#ifdef MENU_MUSIC
originalcontext = alcGetCurrentContext();
if(originalcontext == NULL){
#endif
dev = alcOpenDevice( NULL );
if( dev == NULL ) {
GfLogError("OpenAL: Could not open device (alcOpenDevice failed)\n");
@ -56,6 +61,9 @@ OpenalSoundInterface::OpenalSoundInterface(float sampling_rate, int n_channels)
alcMakeContextCurrent( cc );
alcGetError(dev);
#ifdef MENU_MUSIC
}
#endif
alGetError();
// Figure out the number of possible sources, watch out for an API update, perhaps
@ -167,11 +175,17 @@ OpenalSoundInterface::~OpenalSoundInterface()
}
delete [] engpri;
#ifdef MENU_MUSIC
if(originalcontext == NULL){
#endif
alcMakeContextCurrent(0);
alcDestroyContext(cc);
if (!alcCloseDevice(dev))
GfLogError("Failed to close OpenAL device: %s\n", alcGetString(dev, alcGetError(dev)));
#ifdef MENU_MUSIC
}
#endif
if (car_src) {
delete [] car_src;
@ -194,6 +208,11 @@ Sound* OpenalSoundInterface::addSample (const char* filename, int flags, bool lo
void OpenalSoundInterface::update(CarSoundData** car_sound_data, int n_cars, sgVec3 p_obs, sgVec3 u_obs, sgVec3 c_obs, sgVec3 a_obs)
{
#ifdef MENU_MUSIC
if(silent){
return;
}
#endif
ALfloat listener_pos[3];
#ifdef USE_OPENAL_DOPPLER
@ -447,6 +466,20 @@ void OpenalSoundInterface::mute(bool bOn)
{
SoundInterface::mute(bOn);
#ifdef MENU_MUSIC
if(bOn){
for (unsigned int i=0; i<sound_list.size(); i++) {
sound_list[i]->pause();
}
}
else{
for (unsigned int i=0; i<sound_list.size(); i++) {
sound_list[i]->resume();
}
}
#else
// Needed in case update() is not called right after this.
alListenerf(AL_GAIN, getGlobalGain());
#endif
}

View file

@ -44,6 +44,9 @@ class OpenalSoundInterface : public SoundInterface
SoundSource* car_src;
SoundSource tyre_src[4];
#ifdef MENU_MUSIC
ALCcontext* originalcontext;
#endif
ALCcontext* cc;
ALCdevice* dev;
int OSI_MAX_BUFFERS;

View file

@ -302,8 +302,9 @@ void LegacyMenu::onRaceSimulationReady() {
addLoadingMessage("Loading graphics for all cars ...");
loadCarsGraphics(_piRaceEngine->outData()->s);
_piSoundEngine->init(_piRaceEngine->outData()->s);
pauseMenuMusic();
addLoadingMessage("Loading sound effects for all cars ...");
_piSoundEngine->init(_piRaceEngine->outData()->s);
}
}