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

◆ normalize_sample()

void MayaFlux::Nodes::NodeGraphManager::normalize_sample ( double &  sample,
uint32_t  num_nodes 
)
private

Normalizes a sample to the range [-1, 1] based on the number of nodes.

Parameters
sampleReference to the sample value to normalize
num_nodesNumber of nodes in the processing chain

Ensures that the sample value is within the valid range for audio processing.

Definition at line 292 of file NodeGraphManager.cpp.

293{
294 if (num_nodes == 0)
295 return;
296
297 sample /= std::sqrt(static_cast<double>(num_nodes));
298
299 const double threshold = 0.95;
300 const double knee = 0.1;
301 const double abs_sample = std::abs(sample);
302
303 if (abs_sample > threshold) {
304 const double excess = abs_sample - threshold;
305 const double compressed_excess = std::tanh(excess / knee) * knee;
306 const double limited_abs = threshold + compressed_excess;
307 sample = std::copysign(limited_abs, sample);
308 }
309}
float threshold

References threshold.

Referenced by process_channel(), and process_sample().

+ Here is the caller graph for this function: