diff --git a/Source_Files/Sound/SoundManager.cpp b/Source_Files/Sound/SoundManager.cpp index e6f0eb7ba..4560b684b 100644 --- a/Source_Files/Sound/SoundManager.cpp +++ b/Source_Files/Sound/SoundManager.cpp @@ -814,7 +814,7 @@ std::shared_ptr SoundManager::ManageSound(const Sound& sound, const return returnedPlayer; } -std::shared_ptr SoundManager::BufferSound(SoundParameters parameters) +std::shared_ptr SoundManager::BufferSound(SoundParameters& parameters) { auto returnedPlayer = std::shared_ptr(); SoundDefinition* definition = GetSoundDefinition(parameters.identifier); @@ -1053,6 +1053,7 @@ void SoundManager::UpdateAmbientSoundSources() SoundParameters parameters; parameters.identifier = ambient_sounds[i].sound_index; parameters.soft_rewind = true; + parameters.soft_start = true; parameters.pitch = FIXED_ONE; parameters.flags = ambient_sounds[i].flags; parameters.stereo_parameters.is_panning = true; diff --git a/Source_Files/Sound/SoundManager.h b/Source_Files/Sound/SoundManager.h index 45f028bb7..e86f5ec77 100644 --- a/Source_Files/Sound/SoundManager.h +++ b/Source_Files/Sound/SoundManager.h @@ -127,7 +127,7 @@ class SoundManager SoundManager(); void SetStatus(bool active); SoundDefinition* GetSoundDefinition(short sound_index); - std::shared_ptr BufferSound(SoundParameters parameters); + std::shared_ptr BufferSound(SoundParameters& parameters); float CalculatePitchModifier(short sound_index, _fixed pitch_modifier); void AngleAndVolumeToStereoVolume(angle delta, short volume, short *right_volume, short *left_volume); short GetRandomSoundPermutation(short sound_index); diff --git a/Source_Files/Sound/SoundPlayer.cpp b/Source_Files/Sound/SoundPlayer.cpp index 275bb8775..8600dee79 100644 --- a/Source_Files/Sound/SoundPlayer.cpp +++ b/Source_Files/Sound/SoundPlayer.cpp @@ -185,8 +185,9 @@ SetupALResult SoundPlayer::SetUpALSourceIdle() { if (soundParameters.is_2d) { - bool softStopSignal = soft_stop_signal.load(); - float volume = softStopSignal ? 0 : 1; + const bool softStopSignal = soft_stop_signal.load(); + const bool softStartBegin = !sound_transition.allow_transition && soundParameters.soft_start; + float volume = softStopSignal || softStartBegin ? 0 : 1; if (soundParameters.stereo_parameters.is_panning) { auto pan = (acosf(std::min(soundParameters.stereo_parameters.gain_left, 1.f)) + asinf(std::min(soundParameters.stereo_parameters.gain_right, 1.f))) / ((float)M_PI); // average angle in [0,1] @@ -200,7 +201,7 @@ SetupALResult SoundPlayer::SetUpALSourceIdle() { } float finalVolume = ComputeVolumeForTransition(volume); - result.second = finalVolume == volume; + result.second = finalVolume == volume && !softStartBegin; if (softStopSignal && finalVolume == 0) softStopDone = true; diff --git a/Source_Files/Sound/SoundPlayer.h b/Source_Files/Sound/SoundPlayer.h index dad3079bc..abd523d76 100644 --- a/Source_Files/Sound/SoundPlayer.h +++ b/Source_Files/Sound/SoundPlayer.h @@ -46,12 +46,13 @@ struct SoundParameters { bool loop = false; bool is_2d = true; //if false it will use source_location3d to position sound (3D sounds) bool soft_rewind = false; //if true the sound can only rewind after it's done playing + bool soft_start = false; //if true the sound will use transitions to fade in from silence to proper computed volume uint16_t obstruction_flags = 0; + uint16_t flags = 0; sound_behavior behavior = _sound_is_normal; world_location3d source_location3d = {}; world_location3d* dynamic_source_location3d = nullptr; SoundStereo stereo_parameters = {}; //2D panning - uint16_t flags = 0; }; struct SoundBehavior {