forked from speed-dreams/speed-dreams-code
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:
parent
dc8f0b0801
commit
262d46f1da
6 changed files with 45 additions and 17 deletions
|
@ -26,7 +26,6 @@ const int OpenALMusicPlayer::BUFFERSIZE = 4096*64;
|
||||||
OpenALMusicPlayer::OpenALMusicPlayer(SoundStream* soundStream):
|
OpenALMusicPlayer::OpenALMusicPlayer(SoundStream* soundStream):
|
||||||
device(NULL),
|
device(NULL),
|
||||||
context(NULL),
|
context(NULL),
|
||||||
previouscontext(NULL),
|
|
||||||
source(0),
|
source(0),
|
||||||
stream(soundStream),
|
stream(soundStream),
|
||||||
ready(false)
|
ready(false)
|
||||||
|
@ -70,8 +69,6 @@ void OpenALMusicPlayer::stop()
|
||||||
alDeleteBuffers(2, buffers);
|
alDeleteBuffers(2, buffers);
|
||||||
check();
|
check();
|
||||||
|
|
||||||
//alcMakeContextCurrent(previouscontext);
|
|
||||||
// previouscontext = NULL;
|
|
||||||
alcDestroyContext(context);
|
alcDestroyContext(context);
|
||||||
alcCloseDevice(device);
|
alcCloseDevice(device);
|
||||||
|
|
||||||
|
@ -95,7 +92,6 @@ bool OpenALMusicPlayer::initContext()
|
||||||
GfError("OpenALMusicPlayer: OpenAL could not create contect for device\n");
|
GfError("OpenALMusicPlayer: OpenAL could not create contect for device\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
previouscontext = alcGetCurrentContext();
|
|
||||||
alcMakeContextCurrent(context);
|
alcMakeContextCurrent(context);
|
||||||
alcGetError(device);
|
alcGetError(device);
|
||||||
|
|
||||||
|
@ -210,21 +206,11 @@ void OpenALMusicPlayer::start()
|
||||||
void OpenALMusicPlayer::pause()
|
void OpenALMusicPlayer::pause()
|
||||||
{
|
{
|
||||||
alSourceStop(source);
|
alSourceStop(source);
|
||||||
if(previouscontext == NULL){
|
|
||||||
previouscontext = alcGetCurrentContext();
|
|
||||||
}
|
|
||||||
alcMakeContextCurrent(previouscontext);
|
|
||||||
//previouscontext = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenALMusicPlayer::resume(int flag)
|
void OpenALMusicPlayer::resume(int flag)
|
||||||
{
|
{
|
||||||
alcMakeContextCurrent(context);
|
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
if(flag == 1){
|
|
||||||
previouscontext = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void OpenALMusicPlayer::rewind()
|
void OpenALMusicPlayer::rewind()
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,6 @@ class OpenALMusicPlayer
|
||||||
|
|
||||||
ALCdevice* device;
|
ALCdevice* device;
|
||||||
ALCcontext* context;
|
ALCcontext* context;
|
||||||
ALCcontext* previouscontext;
|
|
||||||
ALuint source; // audio source
|
ALuint source; // audio source
|
||||||
ALuint buffers[2]; // front and back buffers
|
ALuint buffers[2]; // front and back buffers
|
||||||
|
|
||||||
|
|
|
@ -302,6 +302,9 @@ void OpenalSound::resume()
|
||||||
{
|
{
|
||||||
if (paused) {
|
if (paused) {
|
||||||
paused = false;
|
paused = false;
|
||||||
|
#ifdef MENU_MUSIC
|
||||||
|
alSourcePlay (source);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,6 +313,9 @@ void OpenalSound::pause()
|
||||||
{
|
{
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
paused = true;
|
paused = true;
|
||||||
|
#ifdef MENU_MUSIC
|
||||||
|
alSourcePause (source);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,11 @@ OpenalSoundInterface::OpenalSoundInterface(float sampling_rate, int n_channels)
|
||||||
ALfloat far_away[] = { 0.0f, 0.0f, 1000.0f };
|
ALfloat far_away[] = { 0.0f, 0.0f, 1000.0f };
|
||||||
ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f };
|
ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f };
|
||||||
ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.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 );
|
dev = alcOpenDevice( NULL );
|
||||||
if( dev == NULL ) {
|
if( dev == NULL ) {
|
||||||
GfLogError("OpenAL: Could not open device (alcOpenDevice failed)\n");
|
GfLogError("OpenAL: Could not open device (alcOpenDevice failed)\n");
|
||||||
|
@ -56,6 +61,9 @@ OpenalSoundInterface::OpenalSoundInterface(float sampling_rate, int n_channels)
|
||||||
|
|
||||||
alcMakeContextCurrent( cc );
|
alcMakeContextCurrent( cc );
|
||||||
alcGetError(dev);
|
alcGetError(dev);
|
||||||
|
#ifdef MENU_MUSIC
|
||||||
|
}
|
||||||
|
#endif
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
// Figure out the number of possible sources, watch out for an API update, perhaps
|
// Figure out the number of possible sources, watch out for an API update, perhaps
|
||||||
|
@ -167,11 +175,17 @@ OpenalSoundInterface::~OpenalSoundInterface()
|
||||||
}
|
}
|
||||||
delete [] engpri;
|
delete [] engpri;
|
||||||
|
|
||||||
|
#ifdef MENU_MUSIC
|
||||||
|
if(originalcontext == NULL){
|
||||||
|
#endif
|
||||||
alcMakeContextCurrent(0);
|
alcMakeContextCurrent(0);
|
||||||
alcDestroyContext(cc);
|
alcDestroyContext(cc);
|
||||||
|
|
||||||
if (!alcCloseDevice(dev))
|
if (!alcCloseDevice(dev))
|
||||||
GfLogError("Failed to close OpenAL device: %s\n", alcGetString(dev, alcGetError(dev)));
|
GfLogError("Failed to close OpenAL device: %s\n", alcGetString(dev, alcGetError(dev)));
|
||||||
|
#ifdef MENU_MUSIC
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (car_src) {
|
if (car_src) {
|
||||||
delete [] car_src;
|
delete [] car_src;
|
||||||
|
@ -194,7 +208,12 @@ 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)
|
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];
|
ALfloat listener_pos[3];
|
||||||
#ifdef USE_OPENAL_DOPPLER
|
#ifdef USE_OPENAL_DOPPLER
|
||||||
ALfloat listener_speed[3];
|
ALfloat listener_speed[3];
|
||||||
|
@ -447,6 +466,20 @@ void OpenalSoundInterface::mute(bool bOn)
|
||||||
{
|
{
|
||||||
SoundInterface::mute(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.
|
// Needed in case update() is not called right after this.
|
||||||
alListenerf(AL_GAIN, getGlobalGain());
|
alListenerf(AL_GAIN, getGlobalGain());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,9 @@ class OpenalSoundInterface : public SoundInterface
|
||||||
|
|
||||||
SoundSource* car_src;
|
SoundSource* car_src;
|
||||||
SoundSource tyre_src[4];
|
SoundSource tyre_src[4];
|
||||||
|
#ifdef MENU_MUSIC
|
||||||
|
ALCcontext* originalcontext;
|
||||||
|
#endif
|
||||||
ALCcontext* cc;
|
ALCcontext* cc;
|
||||||
ALCdevice* dev;
|
ALCdevice* dev;
|
||||||
int OSI_MAX_BUFFERS;
|
int OSI_MAX_BUFFERS;
|
||||||
|
|
|
@ -302,8 +302,9 @@ void LegacyMenu::onRaceSimulationReady() {
|
||||||
addLoadingMessage("Loading graphics for all cars ...");
|
addLoadingMessage("Loading graphics for all cars ...");
|
||||||
|
|
||||||
loadCarsGraphics(_piRaceEngine->outData()->s);
|
loadCarsGraphics(_piRaceEngine->outData()->s);
|
||||||
_piSoundEngine->init(_piRaceEngine->outData()->s);
|
|
||||||
pauseMenuMusic();
|
pauseMenuMusic();
|
||||||
|
addLoadingMessage("Loading sound effects for all cars ...");
|
||||||
|
_piSoundEngine->init(_piRaceEngine->outData()->s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue