MayaFlux 0.3.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 164 of file RootAudioBuffer.cpp.

165{
166 auto audio_buffer = std::dynamic_pointer_cast<AudioBuffer>(buffer);
167 if (!audio_buffer) {
168 return;
169 }
170
171 auto& data = audio_buffer->get_data();
172
173 constexpr double threshold = 0.95;
174 constexpr double knee = 0.1;
175
176 for (double& sample : data) {
177 const double abs_sample = std::abs(sample);
178
179 if (abs_sample > threshold) {
180 const double excess = abs_sample - threshold;
181 const double compressed_excess = std::tanh(excess / knee) * knee;
182 const double limited_abs = threshold + compressed_excess;
183
184 sample = (sample >= 0.0) ? limited_abs : -limited_abs;
185 }
186 }
187}