From 8fcc373b2a2abab27135a9956213e423896bfadd Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 15 Oct 2014 07:55:18 +1100 Subject: [PATCH] Add volume, speed, and position settings to be done by the sfx thread. Removed more unnecessary error checks (which mostly flood stdout with 'not playing ...' messages), and renamed volume, position and speed to setVolume, setPosition and setSpeed. --- src/audio/dummy_sfx.hpp | 39 ++++++------ src/audio/sfx_base.hpp | 43 +++++++------ src/audio/sfx_manager.cpp | 67 ++++++++++++++++----- src/audio/sfx_manager.hpp | 45 +++++++++++--- src/audio/sfx_openal.cpp | 51 +++++++++++++--- src/audio/sfx_openal.hpp | 9 ++- src/graphics/hit_sfx.cpp | 6 +- src/graphics/material.cpp | 4 +- src/items/attachment.cpp | 6 +- src/items/bowling.cpp | 2 +- src/items/powerup.cpp | 26 ++++---- src/items/rubber_ball.cpp | 2 +- src/items/swatter.cpp | 2 +- src/karts/kart.cpp | 48 +++++++-------- src/states_screens/options_screen_audio.cpp | 2 +- src/tracks/track_object_presentation.cpp | 6 +- 16 files changed, 230 insertions(+), 128 deletions(-) diff --git a/src/audio/dummy_sfx.hpp b/src/audio/dummy_sfx.hpp index a14accbf7..8f5572431 100644 --- a/src/audio/dummy_sfx.hpp +++ b/src/audio/dummy_sfx.hpp @@ -36,24 +36,27 @@ public: /** Late creation, if SFX was initially disabled */ virtual bool init() { return true; } - virtual void position(const Vec3 &position) {} - virtual void setLoop(bool status) {} - virtual void play() {} - virtual void reallyPlayNow() {} - virtual void stop() {} - virtual void reallyStopNow() {} - virtual void pause() {} - virtual void reallyPauseNow() {} - virtual void resume() {} - virtual void reallyResumeNow() {} - virtual void deleteSFX() { delete this; } - virtual void speed(float factor) {} - virtual void volume(float gain) {} - virtual SFXStatus getStatus() { return SFX_STOPPED; } - virtual void onSoundEnabledBack() {} - virtual void setRolloff(float rolloff) {} - virtual bool isPlaying() { return false; } - virtual const SFXBuffer* getBuffer() const { return NULL; } + virtual void setLoop(bool status) {} + virtual void setPosition(const Vec3 &p) {} + virtual void reallySetPosition(const Vec3 &p) {} + virtual void play() {} + virtual void reallyPlayNow() {} + virtual void stop() {} + virtual void reallyStopNow() {} + virtual void pause() {} + virtual void reallyPauseNow() {} + virtual void resume() {} + virtual void reallyResumeNow() {} + virtual void deleteSFX() { delete this; } + virtual void setSpeed(float factor) {} + virtual void reallySetSpeed(float factor) {} + virtual void setVolume(float gain) {} + virtual void reallySetVolume(float gain) {} + virtual SFXStatus getStatus() { return SFX_STOPPED; } + virtual void onSoundEnabledBack() {} + virtual void setRolloff(float rolloff) {} + virtual bool isPlaying() { return false; } + virtual const SFXBuffer* getBuffer() const { return NULL; } }; // DummySFX diff --git a/src/audio/sfx_base.hpp b/src/audio/sfx_base.hpp index 7fa948390..a23ef0dbb 100644 --- a/src/audio/sfx_base.hpp +++ b/src/audio/sfx_base.hpp @@ -52,26 +52,29 @@ public: virtual ~SFXBase() {} /** Late creation, if SFX was initially disabled */ - virtual bool init() = 0; - virtual void position(const Vec3 &position) = 0; - virtual void setLoop(bool status) = 0; - virtual bool isPlaying() = 0; - virtual void play() = 0; - virtual void reallyPlayNow() = 0; - virtual void stop() = 0; - virtual void reallyStopNow() = 0; - virtual void pause() = 0; - virtual void reallyPauseNow() = 0; - virtual void resume() = 0; - virtual void reallyResumeNow() = 0; - virtual void deleteSFX() = 0; - virtual void speed(float factor) = 0; - virtual void volume(float gain) = 0; - virtual void setMasterVolume(float gain) = 0; - virtual void onSoundEnabledBack() = 0; - virtual void setRolloff(float rolloff) = 0; - virtual const SFXBuffer* getBuffer() const = 0; - virtual SFXStatus getStatus() = 0; + virtual bool init() = 0; + virtual void setPosition(const Vec3 &p) = 0; + virtual void reallySetPosition(const Vec3 &p) = 0; + virtual void setLoop(bool status) = 0; + virtual bool isPlaying() = 0; + virtual void play() = 0; + virtual void reallyPlayNow() = 0; + virtual void stop() = 0; + virtual void reallyStopNow() = 0; + virtual void pause() = 0; + virtual void reallyPauseNow() = 0; + virtual void resume() = 0; + virtual void reallyResumeNow() = 0; + virtual void deleteSFX() = 0; + virtual void setSpeed(float factor) = 0; + virtual void reallySetSpeed(float factor) = 0; + virtual void setVolume(float gain) = 0; + virtual void reallySetVolume(float gain) = 0; + virtual void setMasterVolume(float gain) = 0; + virtual void onSoundEnabledBack() = 0; + virtual void setRolloff(float rolloff) = 0; + virtual const SFXBuffer* getBuffer() const = 0; + virtual SFXStatus getStatus() = 0; }; // SFXBase diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index a10b3b474..288e80c85 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -160,26 +160,59 @@ SFXManager::~SFXManager() } // ~SFXManager //---------------------------------------------------------------------------- -/** Adds a sound effect to the queue of sfx to be started by the sfx manager. - * Starting a sfx can sometimes cause a 5ms delay, so it is done in a - * separate thread. +/** Adds a sound effect command to the queue of the sfx manager. Openal + * commands can sometimes cause a 5ms delay, so it is done in a separate + * thread. + * \param command The command to execute. * \param sfx The sound effect to be started. */ void SFXManager::queue(SFXCommands command, SFXBase *sfx) { - // Don't add sfx that are either not working correctly (e.g. because sfx - // are disabled); - if(sfx && sfx->getStatus()==SFXBase::SFX_UNKNOWN) return; - SFXCommand *sfx_command = new SFXCommand(command, sfx); + queueCommand(sfx_command); +} // queue +//---------------------------------------------------------------------------- +/** Adds a sound effect command with a single floating point parameter to the + * queue of the sfx manager. Openal commands can sometimes cause a 5ms delay, + * so it is done in a separate thread. + * \param command The command to execute. + * \param sfx The sound effect to be started. + * \param f Floating point parameter for the command. + */ +void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f) +{ + SFXCommand *sfx_command = new SFXCommand(command, sfx, f); + queueCommand(sfx_command); +} // queue(float) + +//---------------------------------------------------------------------------- +/** Adds a sound effect command with a Vec3 parameter to the queue of the sfx + * manager. Openal commands can sometimes cause a 5ms delay, so it is done in + * a separate thread. + * \param command The command to execute. + * \param sfx The sound effect to be started. + * \param p A Vec3 parameter for the command. + */ +void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p) +{ + SFXCommand *sfx_command = new SFXCommand(command, sfx, p); + queueCommand(sfx_command); +} // queue (Vec3) + +//---------------------------------------------------------------------------- +/** Enqueues a command to the sfx queue threadsafe. Then signal the + * sfx manager to wake up. + * \param command Pointer to the command to queue up. + */ +void SFXManager::queueCommand(SFXCommand *command) +{ m_sfx_commands.lock(); - m_sfx_commands.getData().push_back(sfx_command); + m_sfx_commands.getData().push_back(command); m_sfx_commands.unlock(); // Wake up the sfx thread pthread_cond_signal(&m_cond_request); - -} // queue +} // queueCommand //---------------------------------------------------------------------------- /** Puts a NULL request into the queue, which will trigger the thread to @@ -228,10 +261,16 @@ void* SFXManager::mainLoop(void *obj) me->m_sfx_commands.unlock(); switch(current->m_command) { - case SFX_PLAY: current->m_sfx->reallyPlayNow(); break; - case SFX_STOP: current->m_sfx->reallyStopNow(); break; - case SFX_PAUSE: current->m_sfx->reallyPauseNow(); break; - case SFX_RESUME: current->m_sfx->reallyResumeNow(); break; + case SFX_PLAY: current->m_sfx->reallyPlayNow(); break; + case SFX_STOP: current->m_sfx->reallyStopNow(); break; + case SFX_PAUSE: current->m_sfx->reallyPauseNow(); break; + case SFX_RESUME: current->m_sfx->reallyResumeNow(); break; + case SFX_SPEED: current->m_sfx->reallySetSpeed( + current->m_parameter.getX()); break; + case SFX_POSITION: current->m_sfx->reallySetPosition( + current->m_parameter); break; + case SFX_VOLUME: current->m_sfx->reallySetVolume( + current->m_parameter.getX()); break; case SFX_DELETE: { current->m_sfx->reallyStopNow(); me->deleteSFX(current->m_sfx); diff --git a/src/audio/sfx_manager.hpp b/src/audio/sfx_manager.hpp index f559407d4..8f9edc25b 100644 --- a/src/audio/sfx_manager.hpp +++ b/src/audio/sfx_manager.hpp @@ -62,12 +62,15 @@ public: * for each sfx. */ enum SFXCommands { - SFX_PLAY = 1, - SFX_STOP = 2, - SFX_PAUSE = 3, - SFX_RESUME = 4, - SFX_DELETE = 5, - SFX_EXIT = 6, + SFX_PLAY = 1, + SFX_STOP, + SFX_PAUSE, + SFX_RESUME, + SFX_DELETE, + SFX_SPEED, + SFX_POSITION, + SFX_VOLUME, + SFX_EXIT, }; // SFXCommands /** @@ -98,15 +101,34 @@ private: private: LEAK_CHECK() public: + /** The sound effect for which the command should be executed. */ SFXBase *m_sfx; + /** The command to execute. */ SFXCommands m_command; + /** Optional parameter for commands that need more input. */ + Vec3 m_parameter; + // -------------------------------------------------------------------- SFXCommand(SFXCommands command, SFXBase *base) { - m_command = command; - m_sfx = base; - } + m_command = command; + m_sfx = base; + } // SFXCommand() + // -------------------------------------------------------------------- + SFXCommand(SFXCommands command, SFXBase *base, float parameter) + { + m_command = command; + m_sfx = base; + m_parameter.setX(parameter); + } // SFXCommand(float) + // -------------------------------------------------------------------- + SFXCommand(SFXCommands command, SFXBase *base, const Vec3 ¶meter) + { + m_command = command; + m_sfx = base; + m_parameter = parameter; + } // SFXCommand(Vec3) }; // SFXCommand - + // ======================================================================== /** Listener position */ Vec3 m_position; @@ -144,10 +166,13 @@ private: static void* mainLoop(void *obj); void deleteSFX(SFXBase *sfx); + void queueCommand(SFXCommand *command); public: static void create(); static void destroy(); void queue(SFXCommands command, SFXBase *sfx); + void queue(SFXCommands command, SFXBase *sfx, float f); + void queue(SFXCommands command, SFXBase *sfx, const Vec3 &p); // ------------------------------------------------------------------------ /** Static function to get the singleton sfx manager. */ static SFXManager *get() diff --git a/src/audio/sfx_openal.cpp b/src/audio/sfx_openal.cpp index a29d3ab44..5494222c9 100644 --- a/src/audio/sfx_openal.cpp +++ b/src/audio/sfx_openal.cpp @@ -136,13 +136,23 @@ SFXBase::SFXStatus SFXOpenAL::getStatus() } // getStatus; //----------------------------------------------------------------------------- -/** Changes the pitch of a sound effect. +/** Queues up a change of the pitch of a sound effect to the sfx manager. * \param factor Speedup/slowdown between 0.5 and 2.0 */ -void SFXOpenAL::speed(float factor) +void SFXOpenAL::setSpeed(float factor) { - if(m_status==SFX_UNKNOWN || isnan(factor)) return; + if(m_status==SFX_UNKNOWN) return; + assert(!isnan(factor)); + SFXManager::get()->queue(SFXManager::SFX_SPEED, this, factor); +} // setSpeed +//----------------------------------------------------------------------------- +/** Changes the pitch of a sound effect. Executed from the sfx manager thread. + * \param factor Speedup/slowdown between 0.5 and 2.0 + */ +void SFXOpenAL::reallySetSpeed(float factor) +{ + if(m_status==SFX_UNKNOWN) return; //OpenAL only accepts pitches in the range of 0.5 to 2.0 if(factor > 2.0f) { @@ -153,22 +163,32 @@ void SFXOpenAL::speed(float factor) factor = 0.5f; } alSourcef(m_sound_source,AL_PITCH,factor); - SFXManager::checkError("changing the speed"); -} // speed +} // reallySetSpeed //----------------------------------------------------------------------------- /** Changes the volume of a sound effect. * \param gain Volume adjustment between 0.0 (mute) and 1.0 (full volume). */ -void SFXOpenAL::volume(float gain) +void SFXOpenAL::setVolume(float gain) { + if(m_status==SFX_UNKNOWN) return; + assert(!isnan(gain)) ; + SFXManager::get()->queue(SFXManager::SFX_VOLUME, this, gain); +} // setVolume + +//----------------------------------------------------------------------------- +/** Changes the volume of a sound effect. + * \param gain Volume adjustment between 0.0 (mute) and 1.0 (full volume). + */ +void SFXOpenAL::reallySetVolume(float gain) +{ + if(m_status==SFX_UNKNOWN) return; m_gain = m_defaultGain * gain; if(m_status==SFX_UNKNOWN) return; alSourcef(m_sound_source, AL_GAIN, m_gain * m_master_gain); - SFXManager::checkError("setting volume"); -} // volume +} // reallySetVolume //----------------------------------------------------------------------------- @@ -329,7 +349,18 @@ bool SFXOpenAL::isPlaying() /** Sets the position where this sound effects is played. * \param position Position of the sound effect. */ -void SFXOpenAL::position(const Vec3 &position) +void SFXOpenAL::setPosition(const Vec3 &position) +{ + if (m_status == SFX_UNKNOWN) return; + SFXManager::get()->queue(SFXManager::SFX_POSITION, this, position); + +} // setPosition + +//----------------------------------------------------------------------------- +/** Sets the position where this sound effects is played. + * \param position Position of the sound effect. + */ +void SFXOpenAL::reallySetPosition(const Vec3 &position) { if(!UserConfigParams::m_sfx) return; @@ -364,7 +395,7 @@ void SFXOpenAL::position(const Vec3 &position) } SFXManager::checkError("positioning"); -} // position +} // reallySetPosition //----------------------------------------------------------------------------- diff --git a/src/audio/sfx_openal.hpp b/src/audio/sfx_openal.hpp index cc975e192..a4b59b587 100644 --- a/src/audio/sfx_openal.hpp +++ b/src/audio/sfx_openal.hpp @@ -93,9 +93,12 @@ public: virtual void resume(); virtual void reallyResumeNow(); virtual void deleteSFX(); - virtual void speed(float factor); - virtual void position(const Vec3 &position); - virtual void volume(float gain); + virtual void setSpeed(float factor); + virtual void reallySetSpeed(float factor); + virtual void setPosition(const Vec3 &position); + virtual void reallySetPosition(const Vec3 &p); + virtual void setVolume(float gain); + virtual void reallySetVolume(float gain); virtual void setMasterVolume(float gain); virtual void onSoundEnabledBack(); virtual void setRolloff(float rolloff); diff --git a/src/graphics/hit_sfx.cpp b/src/graphics/hit_sfx.cpp index 391d7118a..e9018a474 100644 --- a/src/graphics/hit_sfx.cpp +++ b/src/graphics/hit_sfx.cpp @@ -27,13 +27,13 @@ HitSFX::HitSFX(const Vec3& coord, const char* explosion_sound) : HitEffect() { m_sfx = SFXManager::get()->createSoundSource( explosion_sound ); - m_sfx->position(coord); + m_sfx->setPosition(coord); // in multiplayer mode, sounds are NOT positional (because we have // multiple listeners) so the sounds of all AIs are constantly heard. // Therefore reduce volume of sounds. float vol = race_manager->getNumLocalPlayers() > 1 ? 0.5f : 1.0f; - m_sfx->volume(vol); + m_sfx->setVolume(vol); m_sfx->play(); } // HitSFX @@ -53,7 +53,7 @@ HitSFX::~HitSFX() void HitSFX::setPlayerKartHit() { if(race_manager->getNumLocalPlayers()) - m_sfx->volume(1.0f); + m_sfx->setVolume(1.0f); } // setPlayerKartHit //----------------------------------------------------------------------------- diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index 725c0908c..7a4ddca5f 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -664,12 +664,12 @@ void Material::setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) con } if (speed > m_sfx_max_speed) { - sfx->speed(m_sfx_max_pitch); + sfx->setSpeed(m_sfx_max_pitch); return; } float f = m_sfx_pitch_per_speed*(speed-m_sfx_min_speed) + m_sfx_min_pitch; - sfx->speed(f); + sfx->setSpeed(f); } // setSFXSpeed //----------------------------------------------------------------------------- diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index 02513b4a4..3974ed3f2 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -142,7 +142,7 @@ void Attachment::set(AttachmentType type, float time, if (m_bomb_sound) m_bomb_sound->deleteSFX(); m_bomb_sound = SFXManager::get()->createSoundSource("clock"); m_bomb_sound->setLoop(true); - m_bomb_sound->position(m_kart->getXYZ()); + m_bomb_sound->setPosition(m_kart->getXYZ()); m_bomb_sound->play(); break; default: @@ -439,7 +439,7 @@ void Attachment::update(float dt) break; case ATTACH_BOMB: - if (m_bomb_sound) m_bomb_sound->position(m_kart->getXYZ()); + if (m_bomb_sound) m_bomb_sound->setPosition(m_kart->getXYZ()); // Mesh animation frames are 1 to 61 frames (60 steps) // The idea is change second by second, counterclockwise 60 to 0 secs @@ -474,7 +474,7 @@ void Attachment::update(float dt) m_time_left = 0.0f; if (m_bubble_explode_sound) m_bubble_explode_sound->deleteSFX(); m_bubble_explode_sound = SFXManager::get()->createSoundSource("bubblegum_explode"); - m_bubble_explode_sound->position(m_kart->getXYZ()); + m_bubble_explode_sound->setPosition(m_kart->getXYZ()); m_bubble_explode_sound->play(); // drop a small bubble gum diff --git a/src/items/bowling.cpp b/src/items/bowling.cpp index 7ac248ee4..4d0b8c935 100644 --- a/src/items/bowling.cpp +++ b/src/items/bowling.cpp @@ -173,7 +173,7 @@ bool Bowling::updateAndDelete(float dt) } if (m_roll_sfx->getStatus()==SFXBase::SFX_PLAYING) - m_roll_sfx->position(getXYZ()); + m_roll_sfx->setPosition(getXYZ()); return false; } // updateAndDelete diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index 9cdbcd8b0..22652271a 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -140,18 +140,14 @@ Material *Powerup::getIcon() const // Check if it's one of the types which have a separate // data file which includes the icon: return powerup_manager->getIcon(m_type); -} - - - - +} // getIcon //----------------------------------------------------------------------------- /** Does the sound configuration. */ void Powerup::adjustSound() { - m_sound_use->position(m_owner->getXYZ()); + m_sound_use->setPosition(m_owner->getXYZ()); // in multiplayer mode, sounds are NOT positional (because we have multiple listeners) // so the sounds of all AIs are constantly heard. So reduce volume of sounds. if (race_manager->getNumLocalPlayers() > 1) @@ -160,14 +156,16 @@ void Powerup::adjustSound() if (m_owner->getController()->isPlayerController()) { - m_sound_use->volume( 1.0f ); + m_sound_use->setVolume( 1.0f ); } else { - m_sound_use->volume( std::min(0.5f, 1.0f / race_manager->getNumberOfKarts()) ); + m_sound_use->setVolume( + std::min(0.5f, 1.0f / race_manager->getNumberOfKarts()) ); } } -} +} // adjustSound + //----------------------------------------------------------------------------- /** Use (fire) this powerup. */ @@ -205,7 +203,7 @@ void Powerup::use() case PowerupManager::POWERUP_SWITCH: { ItemManager::get()->switchItems(); - m_sound_use->position(m_owner->getXYZ()); + m_sound_use->setPosition(m_owner->getXYZ()); m_sound_use->play(); break; } @@ -310,9 +308,9 @@ void Powerup::use() // Meanwhile, don't play it near AI karts since they obviously // don't hear anything if(kart->getController()->isPlayerController()) - m_sound_use->position(kart->getXYZ()); + m_sound_use->setPosition(kart->getXYZ()); else - m_sound_use->position(m_owner->getXYZ()); + m_sound_use->setPosition(m_owner->getXYZ()); m_sound_use->play(); break; @@ -352,9 +350,9 @@ void Powerup::use() // Meanwhile, don't play it near AI karts since they obviously // don't hear anything if(m_owner->getController()->isPlayerController()) - m_sound_use->position(m_owner->getXYZ()); + m_sound_use->setPosition(m_owner->getXYZ()); else if(player_kart) - m_sound_use->position(player_kart->getXYZ()); + m_sound_use->setPosition(player_kart->getXYZ()); m_sound_use->play(); } break; diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index f3b6b5f19..b9ca9a3f7 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -543,7 +543,7 @@ float RubberBall::updateHeight() m_height_timer -= m_interval; if(m_ping_sfx->getStatus()!=SFXBase::SFX_PLAYING) { - m_ping_sfx->position(getXYZ()); + m_ping_sfx->setPosition(getXYZ()); m_ping_sfx->play(); } diff --git a/src/items/swatter.cpp b/src/items/swatter.cpp index 60513aba3..baf735112 100644 --- a/src/items/swatter.cpp +++ b/src/items/swatter.cpp @@ -275,7 +275,7 @@ void Swatter::squashThingsAround() assert(swatter_node); Vec3 swatter_pos = swatter_node->getAbsolutePosition(); - m_swat_sound->position(swatter_pos); + m_swat_sound->setPosition(swatter_pos); m_swat_sound->play(); // Squash karts around diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index fd66b8ebc..d017ba85d 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -183,19 +183,19 @@ void Kart::init(RaceManager::KartType type) { // players have louder sounds than AIs const float factor = std::min(1.0f, race_manager->getNumLocalPlayers()/2.0f); - m_goo_sound->volume( 1.0f / factor ); - m_skid_sound->volume( 1.0f / factor ); - m_crash_sound->volume( 1.0f / factor ); - m_boing_sound->volume( 1.0f / factor ); - m_beep_sound->volume( 1.0f / factor ); + m_goo_sound->setVolume( 1.0f / factor ); + m_skid_sound->setVolume( 1.0f / factor ); + m_crash_sound->setVolume( 1.0f / factor ); + m_boing_sound->setVolume( 1.0f / factor ); + m_beep_sound->setVolume( 1.0f / factor ); } else { - m_goo_sound->volume( 1.0f / race_manager->getNumberOfKarts() ); - m_skid_sound->volume( 1.0f / race_manager->getNumberOfKarts() ); - m_crash_sound->volume( 1.0f / race_manager->getNumberOfKarts() ); - m_beep_sound->volume( 1.0f / race_manager->getNumberOfKarts() ); - m_boing_sound->volume( 1.0f / race_manager->getNumberOfKarts() ); + m_goo_sound->setVolume( 1.0f / race_manager->getNumberOfKarts() ); + m_skid_sound->setVolume( 1.0f / race_manager->getNumberOfKarts() ); + m_crash_sound->setVolume( 1.0f / race_manager->getNumberOfKarts() ); + m_beep_sound->setVolume( 1.0f / race_manager->getNumberOfKarts() ); + m_boing_sound->setVolume( 1.0f / race_manager->getNumberOfKarts() ); } } @@ -756,12 +756,12 @@ void Kart::startEngineSFX() const float players_volume = (np * 2.0f) / (np*2.0f + np); if (m_controller->isPlayerController()) - m_engine_sound->volume( players_volume / np ); + m_engine_sound->setVolume( players_volume / np ); else - m_engine_sound->volume( (1.0f - players_volume) / nai ); + m_engine_sound->setVolume( (1.0f - players_volume) / nai ); } - m_engine_sound->speed(0.6f); + m_engine_sound->setSpeed(0.6f); m_engine_sound->setLoop(true); m_engine_sound->play(); } // startEngineSFX @@ -928,7 +928,7 @@ void Kart::collectedItem(Item *item, int add_info) m_kart_properties->getBubblegumSpeedFraction(), m_kart_properties->getBubblegumFadeInTime(), m_bubblegum_time); - m_goo_sound->position(getXYZ()); + m_goo_sound->setPosition(getXYZ()); m_goo_sound->play(); // Play appropriate custom character sound playCustomSFX(SFXManager::CUSTOM_GOO); @@ -1184,11 +1184,11 @@ void Kart::update(float dt) } */ - m_beep_sound->position ( getXYZ() ); - m_engine_sound->position ( getXYZ() ); - m_crash_sound->position ( getXYZ() ); - m_skid_sound->position ( getXYZ() ); - m_boing_sound->position ( getXYZ() ); + m_beep_sound->setPosition ( getXYZ() ); + m_engine_sound->setPosition ( getXYZ() ); + m_crash_sound->setPosition ( getXYZ() ); + m_skid_sound->setPosition ( getXYZ() ); + m_boing_sound->setPosition ( getXYZ() ); // Check if a kart is (nearly) upside down and not moving much --> // automatic rescue @@ -1447,7 +1447,7 @@ void Kart::handleMaterialSFX(const Material *material) { if (!m_controller->isPlayerController()) { - m_terrain_sound->volume( 0.0f ); + m_terrain_sound->setVolume( 0.0f ); } } @@ -1480,7 +1480,7 @@ void Kart::handleMaterialSFX(const Material *material) (m_terrain_sound->getStatus()==SFXBase::SFX_PLAYING || m_terrain_sound->getStatus()==SFXBase::SFX_PAUSED)) { - m_terrain_sound->position(getXYZ()); + m_terrain_sound->setPosition(getXYZ()); material->setSFXSpeed(m_terrain_sound, m_speed, m_schedule_pause); } @@ -2123,15 +2123,15 @@ void Kart::updateEngineSFX() if (f>1.0f) f=1.0f; float gears = 3.0f * fmod(f, 0.333334f); - m_engine_sound->speed(0.6f + (f +gears)* 0.35f); + m_engine_sound->setSpeed(0.6f + (f +gears)* 0.35f); } else { // When flying, fixed value but not too high pitch // This gives some variation (vs previous "on wheels" one) - m_engine_sound->speed(0.9f); + m_engine_sound->setSpeed(0.9f); } - m_engine_sound->position(getXYZ()); + m_engine_sound->setPosition(getXYZ()); } // updateEngineSFX //----------------------------------------------------------------------------- diff --git a/src/states_screens/options_screen_audio.cpp b/src/states_screens/options_screen_audio.cpp index b0ac7c419..c3cfc751b 100644 --- a/src/states_screens/options_screen_audio.cpp +++ b/src/states_screens/options_screen_audio.cpp @@ -138,7 +138,7 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name, assert(w != NULL); if (sample_sound == NULL) sample_sound = SFXManager::get()->createSoundSource( "pre_start_race" ); - sample_sound->volume(1); + sample_sound->setVolume(1); SFXManager::get()->setMasterSFXVolume( w->getValue()/10.0f ); UserConfigParams::m_sfx_volume = w->getValue()/10.0f; diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 3ef6c8d56..f8367f233 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -427,7 +427,7 @@ TrackObjectPresentationSound::TrackObjectPresentationSound(const XMLNode& xml_no m_sound = SFXManager::get()->createSoundSource(buffer, true, true); if (m_sound != NULL) { - m_sound->position(m_init_xyz); + m_sound->setPosition(m_init_xyz); if (!trigger_when_near && m_trigger_condition.empty()) { m_sound->setLoop(true); @@ -451,7 +451,7 @@ void TrackObjectPresentationSound::update(float dt) // muting when too far is implemented manually since not supported by OpenAL // so need to call this every frame to update the muting state if listener // moved - m_sound->position(m_xyz); + m_sound->setPosition(m_xyz); } } // update @@ -495,7 +495,7 @@ void TrackObjectPresentationSound::move(const core::vector3df& xyz, const core::vector3df& scale) { m_xyz = xyz; - if (m_sound != NULL) m_sound->position(xyz); + if (m_sound != NULL) m_sound->setPosition(xyz); } // move // ----------------------------------------------------------------------------