Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 2f18a13

Browse files
committed
Cherry picking commit for PitchVariation so development runs with replacing-pawnis-sounds data branch
1 parent 8d5abb0 commit 2f18a13

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Entities/SoundContainer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace RTE {
3030
m_Pos = Vector();
3131
m_Volume = 1.0F;
3232
m_Pitch = 1.0F;
33+
m_PitchVariation = 0;
3334
}
3435

3536
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -52,6 +53,7 @@ namespace RTE {
5253
m_Pos = reference.m_Pos;
5354
m_Volume = reference.m_Volume;
5455
m_Pitch = reference.m_Pitch;
56+
m_PitchVariation = reference.m_PitchVariation;
5557

5658
return 0;
5759
}
@@ -95,6 +97,8 @@ namespace RTE {
9597
reader >> m_Volume;
9698
} else if (propName == "Pitch") {
9799
reader >> m_Pitch;
100+
} else if (propName == "PitchVariation") {
101+
reader >> m_PitchVariation;
98102
} else {
99103
return Entity::ReadProperty(propName, reader);
100104
}
@@ -138,6 +142,8 @@ namespace RTE {
138142
writer << m_Volume;
139143
writer.NewProperty("Pitch");
140144
writer << m_Pitch;
145+
writer.NewProperty("PitchVariation");
146+
writer << m_PitchVariation;
141147

142148
return 0;
143149
}

Entities/SoundContainer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ namespace RTE {
248248
/// </summary>
249249
/// <param name="newPitch">The new pitch sounds in this SoundContainer should be played at. Limited between 0.125 and 8 (8 octaves up or down).</param>
250250
void SetPitch(float newPitch) { m_Pitch = std::clamp(newPitch, 0.125F, 8.0F); if (IsBeingPlayed()) { g_AudioMan.ChangeSoundContainerPlayingChannelsPitch(this); } }
251+
252+
/// <summary>
253+
/// Gets the pitch variation the sounds in this SoundContainer are played at.
254+
/// </summary>
255+
/// <returns>The pitch variation the sounds in this SoundContainer are played at.</returns>
256+
float GetPitchVariation() const { return m_PitchVariation; }
251257
#pragma endregion
252258

253259
#pragma region Playback Controls
@@ -341,6 +347,7 @@ namespace RTE {
341347

342348
Vector m_Pos; //!< The current position of this SoundContainer's sounds.
343349
float m_Pitch; //!< The current natural pitch of this SoundContainer's sounds.
350+
float m_PitchVariation; //!< The randomized pitch variation of this SoundContainer's sounds. 1 means the sound will vary a full octave both ways.
344351
float m_Volume; //!< The current natural volume of this SoundContainer's sounds.
345352

346353
/// <summary>

Managers/AudioMan.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,16 @@ namespace RTE {
523523
int channelIndex;
524524
std::vector<const SoundSet::SoundData *> selectedSoundData;
525525
soundContainer->GetTopLevelSoundSet().GetFlattenedSoundData(selectedSoundData, true);
526+
float pitchVariationFactor = 1.0F + std::abs(soundContainer->GetPitchVariation());
526527
for (const SoundSet::SoundData *soundData : selectedSoundData) {
527528
result = (result == FMOD_OK) ? m_AudioSystem->playSound(soundData->SoundObject, channelGroupToPlayIn, true, &channel) : result;
528529
result = (result == FMOD_OK) ? channel->getIndex(&channelIndex) : result;
529530

530531
result = (result == FMOD_OK) ? channel->setUserData(soundContainer) : result;
531532
result = (result == FMOD_OK) ? channel->setCallback(SoundChannelEndedCallback) : result;
532533
result = (result == FMOD_OK) ? channel->setPriority(soundContainer->GetPriority()) : result;
533-
result = (result == FMOD_OK) ? channel->setPitch(soundContainer->GetPitch()) : result;
534+
float pitchVariationMultiplier = pitchVariationFactor == 1.0F ? 1.0F : RandomNum(1.0F / pitchVariationFactor, 1.0F * pitchVariationFactor);
535+
result = (result == FMOD_OK) ? channel->setPitch(soundContainer->GetPitch() * pitchVariationMultiplier) : result;
534536
if (soundContainer->IsImmobile()) {
535537
result = (result == FMOD_OK) ? channel->set3DLevel(0.0F) : result;
536538
result = (result == FMOD_OK) ? channel->setVolume(soundContainer->GetVolume()) : result;

0 commit comments

Comments
 (0)