MayaFlux 0.3.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 258 of file NodeGraphManager.cpp.

259{
260 if (num_nodes == 0)
261 return;
262
263 sample /= std::sqrt(static_cast<double>(num_nodes));
264
265 const double threshold = 0.95;
266 const double knee = 0.1;
267 const double abs_sample = std::abs(sample);
268
269 if (abs_sample > threshold) {
270 const double excess = abs_sample - threshold;
271 const double compressed_excess = std::tanh(excess / knee) * knee;
272 const double limited_abs = threshold + compressed_excess;
273 sample = std::copysign(limited_abs, sample);
274 }
275}

Referenced by process_channel(), and process_sample().

+ Here is the caller graph for this function: