Ticket #3578: sound.patch

File sound.patch, 1.9 KB (added by Thomas, 8 years ago)
  • source/soundmanager/scripting/SoundGroup.cpp

     
    3838#include "ps/XML/Xeromyces.h"
    3939#include "soundmanager/items/ISoundItem.h"
    4040#include "soundmanager/SoundManager.h"
     41#include "simulation2/system/Component.h"
     42#include "simulation2/components/ICmpVisual.h"
    4143
     44#include <boost/random/mersenne_twister.hpp>
     45#include <boost/random/uniform_real.hpp>
     46
    4247#include <algorithm>
    4348
    4449
     
    4651
    4752#define PI 3.14126f
    4853
     54typedef boost::mt19937 rng_t;
    4955
     56
    5057static const bool DISABLE_INTENSITY = true; // disable for now since it's broken
    5158
    5259void CSoundGroup::SetGain(float gain)
     
    96103}
    97104
    98105#if CONFIG2_AUDIO
    99 static float RandFloat(float min, float max)
    100 {
    101     return float(rand(min*100.0f, max*100.0f) / 100.0f);
     106static float RandFloat(rng_t* rng, float min, float max) {
     107    boost::uniform_real<> uni_dist(min, max);
     108    return float(uni_dist(rng));
    102109}
    103110#endif // CONFIG2_AUDIO
    104111
     
    203210        hSound->SetRollOff(itemRollOff);
    204211    }
    205212
     213
     214    rng_t rng;
     215    if (TestFlag(eRandPitch) || TestFlag(eRandGain)) {
     216        // Seed random number generator
     217        CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), source);
     218        rng.seed(cmpVisual ? cmpVisual->GetActorSeed() : rand(0, 1000));
     219    }
     220
    206221    if (TestFlag(eRandPitch))
    207         hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper));
     222        hSound->SetPitch(RandFloat(&rng, m_PitchLower, m_PitchUpper));
    208223    else
    209224        hSound->SetPitch(m_Pitch);
    210225
    211226    ALfloat theGain = m_Gain;
    212227    if (TestFlag(eRandGain))
    213         theGain = RandFloat(m_GainLower, m_GainUpper);
     228        theGain = RandFloat(&rng, m_GainLower, m_GainUpper);
    214229
    215230    hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain);
    216231    ((CSoundManager*)g_SoundManager)->PlayGroupItem(hSound, theGain);