public TrackHelper(System.IO.BinaryReader reader) { int playWaveEvents = reader.ReadInt32(); mEntries = new PlayWaveHelper[playWaveEvents]; for (int i = 0; i < playWaveEvents; i++) { mEntries[i] = new PlayWaveHelper(reader); } mVolume = (float)reader.ReadInt32() / 100.0f; mVariation = reader.ReadByte(); mFiltered = reader.ReadBoolean(); mFilterFrequency = (float)reader.ReadDouble(); GSGE.Debug.assert(mFilterFrequency <= 20000); mFilterQFactor = reader.ReadDouble(); mPitchVariationMin = (float)reader.ReadInt32() / 100.0f; mPitchVariationMax = (float)reader.ReadInt32() / 100.0f; mVolumeVariationMin = (float)reader.ReadInt32() / 100.0f; mVolumeVariationMax = (float)reader.ReadInt32() / 100.0f; GSGE.Debug.assert(mPitchVariationMin < 24); mLoopCount = reader.ReadInt32(); // funnel fixed sound cues to a specific variation so I don't have to deal with it for others if (mEntries.Length == 1) { mVariation = 0; } else if (mVariation == 4) { shuffle = new int[mEntries.Length]; shuffleIdx = mEntries.Length; } // give it an invalid initial cue idx so nothing is assumed about its previous play currIdx = mEntries.Length; }
public TrackHelper(System.IO.BinaryReader reader) { int playWaveEvents = reader.ReadInt32(); mEntries = new PlayWaveHelper[playWaveEvents]; for (int i = 0; i < playWaveEvents; i++) { mEntries[i] = new PlayWaveHelper(reader); } mVolume = (float)reader.ReadInt32() / 100.0f; mVariation = reader.ReadByte(); mFiltered = reader.ReadBoolean(); mFilterFrequency = (float)reader.ReadDouble(); GSGE.Debug.assert(mFilterFrequency <= 20000); mFilterQFactor = reader.ReadDouble(); mPitchVariationMin = (float)reader.ReadInt32() / 100.0f; mPitchVariationMax = (float)reader.ReadInt32() / 100.0f; mVolumeVariationMin = (float)reader.ReadInt32() / 100.0f; mVolumeVariationMax = (float)reader.ReadInt32() / 100.0f; GSGE.Debug.assert(mPitchVariationMin < 24); mLoopCount = reader.ReadInt32(); // funnel fixed sound cues to a specific variation so I don't have to deal with it for others if (mEntries.Length == 1) mVariation = 0; else if (mVariation == 4) { shuffle = new int[mEntries.Length]; shuffleIdx = mEntries.Length; } // give it an invalid initial cue idx so nothing is assumed about its previous play currIdx = mEntries.Length; }
// get some new randomness in this sucker public void Reroll() { try { // new sound instance plz _sound = null; int totWeight = 0; for (int i = 0; i < mData.mEntries.Length; i++) { totWeight += mData.mEntries[i]._weight; } int weight = 0; switch (mData.mVariation) { case 0: //kOrdered mData.currIdx++; if (mData.currIdx >= mData.mEntries.Length) { mData.currIdx = 0; } break; case 2: //kRandom weight = GSGE.RandomMath.RandomInt(totWeight); totWeight = 0; mData.currIdx = 0; for (int i = 0; i < mData.mEntries.Length; i++) { totWeight += mData.mEntries[i]._weight; if (weight < totWeight) { mData.currIdx = i; break; } } break; case 3: //kRandomNoImmediateRepeat if (mData.currIdx >= 0 && mData.currIdx < mData.mEntries.Length) { totWeight -= mData.mEntries[mData.currIdx]._weight; } else { mData.currIdx = 0; } weight = GSGE.RandomMath.RandomInt(totWeight); totWeight = 0; for (int i = 0; i < mData.mEntries.Length; i++) { if (i == mData.currIdx) { continue; } totWeight += mData.mEntries[i]._weight; if (weight < totWeight) { mData.currIdx = i; break; } } break; case 4: //kShuffle mData.shuffleIdx++; if (mData.shuffleIdx >= mData.mEntries.Length) { mData.shuffleIdx = 0; int i; // reorder next random set List <int> ls = new List <int>(); for (i = 0; i < mData.mEntries.Length; i++) { ls.Add(i); } i = 0; while (ls.Count > 0) { int idx = GSGE.RandomMath.RandomInt(ls.Count); mData.shuffle[i] = ls[idx]; ls.RemoveAt(idx); i++; } } mData.currIdx = mData.shuffle[mData.shuffleIdx]; break; default: throw new NotImplementedException(); } } catch (Exception) { mData.currIdx = 0; } if (0 <= mData.currIdx && mData.currIdx < mData.mEntries.Length) { PlayWaveHelper pwh = mData.mEntries[mData.currIdx]; AudioEngine audioengine = AudioManager.GetAudioManager().GetAudioEngine(); foreach (WaveBank wavebank in audioengine.Wavebanks) { if (wavebank.IsLoaded && wavebank.BankName == pwh._bankname) { if (0 <= pwh._index && wavebank.mSounds.Length > pwh._index) { SoundData sd = wavebank.mSounds[pwh._index]; sd.Looping = mData.mLoopCount == 255; _sound = new Sound(sd); } break; } } //GSGE.Debug.assert(_sound != null); mVolVar = RandomMath.RandomBetween(mData.mVolumeVariationMin, mData.mVolumeVariationMax) + mData.mVolume; mPitchVar = RandomMath.RandomBetween(mData.mPitchVariationMin, mData.mPitchVariationMax); } }