FastLED 3.9.15
Loading...
Searching...
No Matches

◆ applyGain()

void fl::audio::Sample::applyGain ( float gain)

Apply a digital gain multiplier to all PCM samples in-place.

Clamps to i16 range to prevent overflow.

Definition at line 191 of file audio.cpp.hpp.

191 {
192 if (!isValid() || gain == 1.0f) return;
193 auto& samples = mImpl->pcm_mutable();
194 for (fl::size i = 0; i < samples.size(); ++i) {
195 fl::i32 val = static_cast<fl::i32>(static_cast<float>(samples[i]) * gain);
196 if (val > 32767) val = 32767;
197 if (val < -32768) val = -32768;
198 samples[i] = static_cast<fl::i16>(val);
199 }
200}
bool isValid() const FL_NOEXCEPT
Definition audio.h:35
SampleImplPtr mImpl
Definition audio.h:62

References isValid(), and mImpl.

+ Here is the call graph for this function: