TR123e - EMCT Computing Final Project Version 1.0
Research Project Translation from gen~ to embedded Moog synth
Loading...
Searching...
No Matches
MoogLadderFilterScalar Class Reference

High-fidelity scalar implementation of Huovilainen Moog ladder filter. More...

#include <MoogLadderFilterBase.h>

Public Member Functions

 MoogLadderFilterScalar (float sampleRate)
 Construct scalar Moog filter with sample rate configuration.
void reset ()
 Reset all filter state variables to zero.
void setSampleRate (float sr)
 Update sample rate and recalculate dependent coefficients.
void setParams (float cutoffHz, float resonance, int mode)
 Configure filter parameters with unified interface.
float process (float in1, float in2, float in3, float in4)
 Process audio sample through complete Huovilainen algorithm.
 MoogLadderFilterScalar (float sampleRate)
 Construct scalar Moog filter with exact Gen~ parameter mapping.
void reset ()
 Reset all filter state to match Gen~ reset behavior.
void setSampleRate (float sr_)
 Update sample rate and recalculate derived coefficients.
void setParams (float cutoffHz, float resonanceVal, int modeSel)
 Set filter parameters with exact Gen~ parameter mapping.
float process (float in1, float in2, float in3, float in4)
 Process audio sample with exact Gen~ algorithm implementation.
 MoogLadderFilterScalar (float sampleRate)
 Construct enhanced scalar filter with sample rate configuration.
void reset ()
 Reset all filter state with enhanced clearing.
void setSampleRate (float sr)
 Update sample rate with enhanced coefficient recalculation.
void setParams (float cutoffHz, float resonance, int mode)
 Set parameters with corrected semantics and improved validation.
float process (float in1, float in2, float in3, float in4)
 Process audio with corrected input mapping and enhanced stability.

Private Attributes

float s1
 Comprehensive filter state variable set.
float s2
float s3
float s4
float s5
float s6
float s7
float s8
 Filter stage states with improved precision.
float slim
 Saturation limiter state for nonlinear feedback modeling.
float previn
 Previous input sample for feedback calculations.
float fc
 Filter parameter storage.
float rc
 Resonance and frequency control parameters.
float expr1
float expr2
 Sample rate dependent coefficients with improved calculation.
float sr
 System configuration parameters.
int mode
 Filter mode selection state.

Detailed Description

High-fidelity scalar implementation of Huovilainen Moog ladder filter.

Enhanced scalar Moog ladder filter with improved stability and interface.

Direct scalar translation of Gen~ moogLadderFilter with complete fidelity.

This class provides a complete scalar implementation of the Huovilainen Moog ladder filter model, serving as the reference implementation for algorithmic validation and performance comparison. The implementation maintains exact compatibility with the original Gen~ code while providing optimized C++ structure and comprehensive state management.

@design_characteristics

  • Reference Quality: Exact algorithmic preservation for validation purposes
  • Educational Clarity: Clear implementation suitable for academic study
  • Performance Baseline: Establishes unoptimized performance metrics
  • Debugging Foundation: Provides known-good implementation for comparison
  • Research Platform: Suitable for algorithm development and analysis

@implementation_fidelity The scalar implementation maintains:

  • Exact coefficient preservation from original research
  • Identical processing order and mathematical operations
  • Complete state variable correspondence with Gen~ implementation
  • Bit-exact output compatibility for validation purposes
  • Full six-mode filter response calculation capability

@performance_profile

  • Computational Cost: ~120-150 floating-point operations per sample
  • Memory Footprint: ~80 bytes (comprehensive state variable set)
  • Cache Behavior: Sequential access patterns optimized for modern CPUs
  • Branch Prediction: Moderate branching from mode selection and conditionals
  • Optimization Potential: Excellent foundation for vectorization analysis

@applications

  • Algorithm validation and correctness verification
  • Research and development of optimization techniques
  • Educational demonstration of complex filter algorithms
  • Reference standard for quality assurance testing
  • Debugging and troubleshooting optimized implementations

This class provides an exact scalar implementation of the Huovilainen Moog ladder filter as originally implemented in Max/MSP Gen~. Every coefficient, calculation order, and state variable has been preserved to ensure bit-exact compatibility with the original visual programming implementation.

@design_principles

  • Absolute Fidelity: Exact replication of Gen~ behavior
  • Reference Quality: Serves as validation standard for optimizations
  • Educational Clarity: Demonstrates direct translation methodology
  • Research Accuracy: Preserves original algorithm characteristics
  • Performance Baseline: Establishes unoptimized performance metrics

@state_variable_mapping The implementation maintains exact correspondence with Gen~ history operators:

  • s1-s8: Filter stage states and intermediate calculations
  • slim: Saturation limiter state for nonlinear feedback
  • previn: Previous input sample for feedback calculations
  • rc/fc: Resonance and frequency control parameters

@mathematical_preservation All empirical coefficients from the original research are preserved:

  • Saturation curve coefficients: 0.062, 0.993, 0.5
  • Polynomial approximation terms: -0.74375, 0.3, 1.25, etc.
  • Stage coupling factors: 0.3 scaling throughout ladder
  • Mode calculation weightings: 0.19, 0.57, -0.52 for LP24

@applications

  • Reference implementation for algorithm validation
  • Educational demonstration of translation methodology
  • Performance baseline for optimization analysis
  • Research tool for algorithm behavior study
  • Debugging reference for optimized implementations

This class provides a refined scalar implementation of the Huovilainen Moog ladder filter with improved utility functions, corrected parameter handling, and enhanced numerical stability while maintaining exact algorithmic compatibility with the original Gen~ implementation.

@enhancement_focus

  • Numerical Stability: Improved denormal protection and precision handling
  • Interface Consistency: Standardized parameter mapping and method signatures
  • Utility Improvements: Enhanced clamping and validation functions
  • Production Readiness: Optimized for reliable long-term operation
  • Validation Reference: Serves as corrected reference for optimization verification

Constructor & Destructor Documentation

◆ MoogLadderFilterScalar() [1/3]

MoogLadderFilterScalar::MoogLadderFilterScalar ( float sampleRate)

Construct scalar Moog filter with sample rate configuration.

Initialize scalar filter with Gen~ compatible setup.

Parameters
sampleRateAudio processing sample rate for coefficient calculation

Initializes the filter with sample rate dependent parameters and establishes default state for immediate processing capability.

◆ MoogLadderFilterScalar() [2/3]

MoogLadderFilterScalar::MoogLadderFilterScalar ( float sampleRate)

Construct scalar Moog filter with exact Gen~ parameter mapping.

Parameters
sampleRateAudio processing sample rate for coefficient calculation

Initializes the filter with exact replication of Gen~ initialization sequence, including sample rate dependent coefficient calculation and state variable clearing.

◆ MoogLadderFilterScalar() [3/3]

MoogLadderFilterScalar::MoogLadderFilterScalar ( float sampleRate)

Construct enhanced scalar filter with sample rate configuration.

Parameters
sampleRateAudio processing sample rate for coefficient calculation

Member Function Documentation

◆ process() [1/3]

float MoogLadderFilterScalar::process ( float in1,
float in2,
float in3,
float in4 )

Process audio sample through complete Huovilainen algorithm.

Process sample with complete Gen~ algorithm implementation.

Parameters
in1Primary audio input signal
in2Resonance modulation signal
in3Envelope control signal
in4Thermal noise input signal
Returns
Filtered audio sample with selected mode response

Updated process semantics with corrected input mapping:

  • in1: Audio input (primary signal)
  • in2: Resonance modulation (real-time resonance control)
  • in3: Envelope control (filter frequency modulation)
  • in4: Thermal noise (analog realism enhancement)

This method implements every mathematical operation from the original Gen~ code in exactly the same order with identical coefficients, ensuring bit-exact compatibility with the visual programming version.

SECTION 1: INPUT CONDITIONING (Exact Gen~ sequence) Add thermal noise and process envelope control exactly as in Gen~

SECTION 2: RESONANCE MODULATION (Gen~ envelope shaping) Process resonance control with envelope modulation using exact coefficients

SECTION 3: COEFFICIENT CALCULATION (Exact Gen~ polynomial) Calculate filter coefficients using exact polynomial approximation from original Huovilainen model as implemented in Gen~

SECTION 4: FIRST ITERATION (Gen~ initial processing) Implement first pass through ladder with nonlinear saturation using exact saturation curve and coefficient application

SECTION 5: SECOND ITERATION (Gen~ accuracy refinement) Implement second pass for improved nonlinear accuracy using refined feedback and state calculations

SECTION 6: MODE CALCULATIONS (Complete Gen~ mode set) Calculate all six filter modes using exact Gen~ coefficients and signal combination methods

SECTION 7: MODE SELECTION (Gen~ switch implementation) Select appropriate output based on mode parameter using exact Gen~ mode indexing and default behavior

SECTION 8: STATE UPDATES (Exact Gen~ state management) Update all state variables in exact order as performed by Gen~ history operator updates

◆ process() [2/3]

float MoogLadderFilterScalar::process ( float in1,
float in2,
float in3,
float in4 )

Process audio sample with exact Gen~ algorithm implementation.

Parameters
in1Primary audio input (Gen~ inlet 1)
in2Envelope control signal (Gen~ inlet 2)
in3Resonance modulation (Gen~ inlet 3)
in4Thermal noise input (Gen~ inlet 4)
Returns
Filtered audio sample with exact Gen~ processing

Implements the complete dual-iteration Huovilainen algorithm exactly as coded in the original Gen~ patch, preserving every mathematical operation and coefficient application.

@algorithm_fidelity

  • Exact coefficient application in original order
  • Preserved intermediate variable calculations
  • Identical nonlinear saturation processing
  • Complete mode calculation implementation
  • Exact state variable update sequence

@processing_stages

  1. Input Conditioning: Thermal noise addition and envelope processing
  2. First Iteration: Initial ladder processing with saturation
  3. Second Iteration: Refined processing for improved accuracy
  4. Mode Selection: Complete calculation of all six filter modes
  5. State Updates: Exact replication of Gen~ state management

◆ process() [3/3]

float MoogLadderFilterScalar::process ( float in1,
float in2,
float in3,
float in4 )

Process audio with corrected input mapping and enhanced stability.

Parameters
in1Primary audio input with improved conditioning
in2Resonance modulation with corrected processing
in3Envelope control with enhanced scaling
in4Thermal noise with improved integration
Returns
Filtered audio sample with enhanced precision

◆ reset() [1/3]

void MoogLadderFilterScalar::reset ( )

Reset all filter state variables to zero.

Reset all state variables to exact Gen~ defaults.

Clears all internal state to eliminate residual signal content and prepare for clean processing of new audio material.

Implements exact state clearing as performed by Gen~ reset, ensuring identical initialization behavior across implementations.

◆ reset() [2/3]

void MoogLadderFilterScalar::reset ( )

Reset all filter state to match Gen~ reset behavior.

Clears all state variables to exact zero values as performed by Gen~ reset functionality, ensuring identical startup behavior.

◆ reset() [3/3]

void MoogLadderFilterScalar::reset ( )

Reset all filter state with enhanced clearing.

Improved state clearing that ensures complete elimination of residual content while preparing filter for optimal startup behavior.

◆ setParams() [1/3]

void MoogLadderFilterScalar::setParams ( float cutoffHz,
float resonanceVal,
int modeSel )

Configure filter parameters with unified interface.

Set parameters with exact Gen~ parameter interpretation.

Parameters
cutoffHzCutoff frequency in Hz
resonanceResonance amount [0.0-1.0]
modeFilter mode selection [0-5]

Updated interface with corrected parameter semantics:

  • Direct resonance control (rc parameter directly from resonance input)
  • Simplified parameter mapping for consistent behavior
  • Unified mode selection across all implementations

Maintains exact parameter processing including range validation and internal format conversion as performed in original Gen~ code.

◆ setParams() [2/3]

void MoogLadderFilterScalar::setParams ( float cutoffHz,
float resonance,
int mode )

Set parameters with corrected semantics and improved validation.

Parameters
cutoffHzCutoff frequency in Hz with enhanced range validation
resonanceResonance amount [0.0-1.0] with improved scaling
modeFilter mode selection [0-5] with consistent indexing

◆ setParams() [3/3]

void MoogLadderFilterScalar::setParams ( float cutoffHz,
float resonanceVal,
int modeSel )

Set filter parameters with exact Gen~ parameter mapping.

Parameters
cutoffHzCutoff frequency in Hz (exact Gen~ scaling)
resonanceValResonance amount [0.0-1.0] (Gen~ range)
modeSelFilter mode selection [0-5] (Gen~ mode indices)

Implements exact parameter processing as performed in Gen~ including range validation and internal format conversion.

◆ setSampleRate() [1/3]

void MoogLadderFilterScalar::setSampleRate ( float sr_)

Update sample rate and recalculate dependent coefficients.

Update sample rate with exact Gen~ coefficient calculation.

Parameters
srNew sample rate for coefficient recalculation

Updates all sample rate dependent parameters and coefficients to maintain accurate filter behavior at new processing rate.

Implements the exact mathematical operations performed in Gen~ for sample rate dependent coefficient generation.

◆ setSampleRate() [2/3]

void MoogLadderFilterScalar::setSampleRate ( float sr)

Update sample rate with enhanced coefficient recalculation.

Parameters
srNew sample rate for improved coefficient computation

◆ setSampleRate() [3/3]

void MoogLadderFilterScalar::setSampleRate ( float sr_)

Update sample rate and recalculate derived coefficients.

Parameters
sr_New sample rate for coefficient recalculation

Implements exact Gen~ sample rate update logic including frequency scaling factor calculation and warping compensation.

Member Data Documentation

◆ expr1

float MoogLadderFilterScalar::expr1
private

◆ expr2

float MoogLadderFilterScalar::expr2
private

Sample rate dependent coefficients with improved calculation.

◆ fc

float MoogLadderFilterScalar::fc
private

Filter parameter storage.

Resonance and frequency parameters with corrected scaling.

Current parameter values and derived coefficients:

  • fc: Normalized cutoff frequency
  • rc: Resonance coefficient (directly from input)
  • expr1, expr2: Sample rate dependent coefficients

◆ mode

int MoogLadderFilterScalar::mode
private

Filter mode selection state.

Filter mode selection with consistent indexing.

Integer mode selector matching Gen~ mode parameter for six-mode filter response selection.

◆ previn

float MoogLadderFilterScalar::previn
private

Previous input sample for feedback calculations.

Saturation and delay states with enhanced stability.

Maps to Gen~ previn history operator providing temporal delay element essential for feedback topology.

◆ rc

float MoogLadderFilterScalar::rc
private

Resonance and frequency control parameters.

Direct correspondence with Gen~ param objects maintaining exact parameter interpretation and scaling behavior.

◆ s1

float MoogLadderFilterScalar::s1
private

Comprehensive filter state variable set.

Filter stage state variables [s1-s8].

Complete state preservation matching Gen~ history operators:

  • s1-s8: Filter stage states and intermediate calculations
  • slim: Saturation limiter state for nonlinear modeling
  • previn: Previous input for feedback calculations

Direct mapping from Gen~ history operators maintaining exact correspondence with visual programming state storage.

◆ s2

float MoogLadderFilterScalar::s2
private

◆ s3

float MoogLadderFilterScalar::s3
private

◆ s4

float MoogLadderFilterScalar::s4
private

◆ s5

float MoogLadderFilterScalar::s5
private

◆ s6

float MoogLadderFilterScalar::s6
private

◆ s7

float MoogLadderFilterScalar::s7
private

◆ s8

float MoogLadderFilterScalar::s8
private

Filter stage states with improved precision.

◆ slim

float MoogLadderFilterScalar::slim
private

Saturation limiter state for nonlinear feedback modeling.

Corresponds to Gen~ slim history operator maintaining saturation memory across processing iterations.

◆ sr

float MoogLadderFilterScalar::sr
private

System configuration parameters.

System and filter parameters with enhanced organization.

Sample rate and derived coefficients.

  • sr: Sample rate for coefficient calculations
  • mode: Current filter mode selection [0-5]

System parameters matching Gen~ internal calculations for sample rate dependent coefficient generation.

Sample rate for coefficient calculation


The documentation for this class was generated from the following files: