MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ processing_function()

void MayaFlux::Buffers::FinalLimiterProcessor::processing_function ( const std::shared_ptr< Buffer > &  buffer)
overridevirtual

Processes a buffer by enforcing boundary conditions.

Parameters
bufferBuffer to process

This method applies a non-linear boundary enforcement algorithm to ensure all values stay within the valid range (typically -1.0 to 1.0) before being transmitted to hardware interfaces, while preserving the perceptual characteristics of the original signal.

Implements MayaFlux::Buffers::BufferProcessor.

Definition at line 168 of file RootAudioBuffer.cpp.

169{
170 auto audio_buffer = std::dynamic_pointer_cast<AudioBuffer>(buffer);
171 if (!audio_buffer) {
172 return;
173 }
174
175 auto& data = audio_buffer->get_data();
176
177 constexpr double threshold = 0.95;
178 constexpr double knee = 0.1;
179
180 for (double& sample : data) {
181 const double abs_sample = std::abs(sample);
182
183 if (abs_sample > threshold) {
184 const double excess = abs_sample - threshold;
185 const double compressed_excess = std::tanh(excess / knee) * knee;
186 const double limited_abs = threshold + compressed_excess;
187
188 sample = (sample >= 0.0) ? limited_abs : -limited_abs;
189 }
190 }
191}
Tendency< D, float > threshold(const Tendency< D, float > &t, float thresh)
Zero output below threshold, pass through above.
Definition Tendency.hpp:141