FastLED 3.10.8
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 200 of file audio.cpp.hpp.

200 {
201 if (!isValid() || gain == 1.0f) return;
202 auto& samples = mImpl->pcm_mutable();
203 for (fl::size i = 0; i < samples.size(); ++i) {
204 fl::i32 val = static_cast<fl::i32>(static_cast<float>(samples[i]) * gain);
205 if (val > 32767) val = 32767;
206 if (val < -32768) val = -32768;
207 samples[i] = static_cast<fl::i16>(val);
208 }
209 mImpl->pcmDidChange();
210}
bool isValid() const FL_NO_EXCEPT
Definition audio.h:35
SampleImplPtr mImpl
Definition audio.h:62

References fl::FL_NO_EXCEPT, isValid(), and mImpl.

+ Here is the call graph for this function: