mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-21 15:32:34 +00:00
Let I_FadeSong be used in the middle of an existing fade
- Doing this so two fades can be installed at the end of the credits; 1 for normal playback speed, 2 for skip behavior - I_FadeSong can now be used to speed up or slow down an existing fade - Previously, calling I_FadeSong this way would jump to the previous target volume first, before starting a new fade - Should make no regressions
This commit is contained in:
parent
df0e256c00
commit
4fe992b19d
1 changed files with 9 additions and 5 deletions
|
|
@ -63,10 +63,7 @@ public:
|
||||||
// the fade gain, even if it would clamp anyway.
|
// the fade gain, even if it would clamp anyway.
|
||||||
for (std::size_t i = 0; i < generated; i++)
|
for (std::size_t i = 0; i < generated; i++)
|
||||||
{
|
{
|
||||||
const float alpha = 1.0 - (gain_samples_target_ - std::min(gain_samples_ + i, gain_samples_target_)) /
|
buffer[total_written + i] *= current_fade_gain(i);
|
||||||
static_cast<double>(gain_samples_target_);
|
|
||||||
const float fade_gain = (gain_target_ - gain_) * std::clamp(alpha, 0.f, 1.f) + gain_;
|
|
||||||
buffer[total_written + i] *= fade_gain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gain_samples_ = std::min(gain_samples_ + generated, gain_samples_target_);
|
gain_samples_ = std::min(gain_samples_ + generated, gain_samples_target_);
|
||||||
|
|
@ -255,7 +252,7 @@ public:
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fade_to(float gain, float seconds) { fade_from_to(gain_target_, gain, seconds); }
|
void fade_to(float gain, float seconds) { fade_from_to(current_fade_gain(0), gain, seconds); }
|
||||||
|
|
||||||
void fade_from_to(float from, float to, float seconds)
|
void fade_from_to(float from, float to, float seconds)
|
||||||
{
|
{
|
||||||
|
|
@ -300,6 +297,13 @@ private:
|
||||||
bool fading_ {false};
|
bool fading_ {false};
|
||||||
uint64_t gain_samples_ {0};
|
uint64_t gain_samples_ {0};
|
||||||
uint64_t gain_samples_target_ {1};
|
uint64_t gain_samples_target_ {1};
|
||||||
|
|
||||||
|
float current_fade_gain(uint64_t i) const
|
||||||
|
{
|
||||||
|
const float alpha = 1.0 - (gain_samples_target_ - std::min(gain_samples_ + i, gain_samples_target_)) /
|
||||||
|
static_cast<double>(gain_samples_target_);
|
||||||
|
return (gain_target_ - gain_) * std::clamp(alpha, 0.f, 1.f) + gain_;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The special member functions MUST be declared in this unit, where Impl is complete.
|
// The special member functions MUST be declared in this unit, where Impl is complete.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue