|
TR123e - EMCT Computing Final Project Version 1.0
Research Project Translation from gen~ to embedded Moog synth
|
High-performance fixed-point implementation of Moog ladder filter. More...
#include <MoogLadderFilterFixedPoint.h>
Public Member Functions | |
| MoogLadderFilterFixedPoint (int sampleRate) | |
| Construct fixed-point Moog filter with sample rate configuration. | |
| void | setCutoff (int frequency) |
| Configure filter cutoff frequency using integer parameter. | |
| void | setResonance (int resonance) |
| Configure filter resonance using integer parameter. | |
| void | reset () |
| Reset all filter state to zero for clean initialization. | |
| int | process (int in) |
| Process single audio sample through fixed-point ladder filter. | |
| MoogLadderFilterFixedPoint (int sampleRate) | |
| Construct fixed-point filter with integer sample rate. | |
| void | setCutoff (int frequency) |
| Set cutoff frequency using integer parameter. | |
| void | setResonance (int resonance) |
| Set resonance using 8-bit integer parameter. | |
| void | reset () |
| Reset all filter state to prevent artifacts. | |
| int | process (int in) |
| Process integer audio sample through fixed-point filter. | |
Private Member Functions | |
| int | tanh_approx (int x) |
| Fast tanh approximation for nonlinear processing. | |
| int | tanh_approx (int x) |
| Fast tanh approximation for fixed-point nonlinear processing. | |
Private Attributes | |
| int | sampleRate |
| Audio system sample rate for frequency calculations. | |
| int | alpha = 0 |
| Filter coefficient alpha in Q16 fixed-point format. | |
| int | feedbackAmount = 0 |
| Feedback amount coefficient in Q16 fixed-point format. | |
| int | fc = 1000 |
| Current cutoff frequency in Hz. | |
| int | rc = 0 |
| Current resonance coefficient in Q8 fixed-point format. | |
| int | prevIn = 0 |
| Previous input sample for delay line implementation. | |
| int | s [4] = {0} |
| Filter stage state variables [4 elements]. | |
High-performance fixed-point implementation of Moog ladder filter.
Professional fixed-point Moog ladder filter for embedded systems.
This class provides a complete Moog ladder filter implementation using fixed-point arithmetic optimized for embedded systems and applications requiring deterministic execution. The implementation maintains the essential characteristics of the analog Moog filter while providing significant computational advantages over floating-point alternatives.
@design_principles
@performance_characteristics
@applications
@usage_example
This class implements a complete Moog ladder filter using fixed-point arithmetic optimized for embedded systems and applications requiring deterministic execution. The implementation maintains the essential characteristics of the analog Moog filter while providing significant computational and power advantages over floating-point alternatives.
@design_principles
@fixed_point_implementation_strategy
@performance_optimization
@usage_example
| MoogLadderFilterFixedPoint::MoogLadderFilterFixedPoint | ( | int | sampleRate | ) |
Construct fixed-point Moog filter with sample rate configuration.
Initialize fixed-point Moog filter with comprehensive setup.
| sampleRate | Audio system sample rate in Hz |
Initializes the filter with integer-based parameters and clears all internal state variables. The constructor sets up the fixed-point arithmetic framework and prepares the filter for immediate use.
@complexity O(1) - Simple initialization @memory 32 bytes object size (8 × 4-byte integers) @precision Fixed-point Q16.16 format throughout
| MoogLadderFilterFixedPoint::MoogLadderFilterFixedPoint | ( | int | sampleRate | ) |
Construct fixed-point filter with integer sample rate.
| sampleRate | Audio system sample rate as integer value |
Initializes the filter with integer-based parameters and establishes the fixed-point arithmetic framework for all subsequent operations.
| int MoogLadderFilterFixedPoint::process | ( | int | in | ) |
Process single audio sample through fixed-point ladder filter.
Process audio sample through fixed-point ladder algorithm.
| in | Input audio sample (integer format) |
Core processing method implementing the complete ladder filter algorithm using fixed-point arithmetic. Includes anti-denormalization, nonlinear feedback, and four-stage ladder processing with overflow protection.
@complexity O(1) - Fixed number of integer operations @precision Q16.16 fixed-point throughout processing chain @overflow_protection Comprehensive bounds checking and saturation
@algorithm_implementation
Implements the complete ladder filter using fixed-point arithmetic with careful attention to overflow prevention and precision management.
Apply anti-denormalization offset to prevent filter stasis Small offset ensures filter continues processing during silence
Calculate nonlinear feedback using tanh approximation Provides the resonance effect through controlled feedback
Process through four ladder stages with fixed-point arithmetic Each stage implements: output = (input * alpha + state * feedback) >> 16 The >> 16 operation maintains Q16 format after multiplication
Update filter state variables for next sample These maintain the temporal memory of each filter pole
| int MoogLadderFilterFixedPoint::process | ( | int | in | ) |
Process integer audio sample through fixed-point filter.
| in | Input audio sample as integer (typically 16-bit range) |
Core processing method implementing complete fixed-point ladder algorithm with overflow protection, saturation limiting, and precision management while maintaining real-time performance guarantees.
| void MoogLadderFilterFixedPoint::reset | ( | ) |
Reset all filter state to zero for clean initialization.
Clear all filter state for clean initialization.
Clears all internal state variables to eliminate residual signal content. Essential for filter initialization and clean transitions between different audio materials.
@complexity O(1) - Fixed loop clearing 4 state variables @memory_safety Accesses only local array elements
Essential for preventing artifacts from previous audio content and ensuring predictable filter behavior from first sample.
| void MoogLadderFilterFixedPoint::reset | ( | ) |
Reset all filter state to prevent artifacts.
Clears all integer state variables to eliminate residual signal content and ensure clean startup behavior without floating-point dependencies.
| void MoogLadderFilterFixedPoint::setCutoff | ( | int | frequency | ) |
Configure filter cutoff frequency using integer parameter.
Configure cutoff frequency with fixed-point coefficient calculation.
| frequency | Cutoff frequency in Hz (integer) |
Sets the filter cutoff frequency with automatic range validation and fixed-point coefficient calculation. The method performs all necessary mathematical operations using integer arithmetic while maintaining adequate precision for musical applications.
@complexity O(1) - Fixed number of integer operations @precision Frequency accuracy limited by Q16 fractional precision @range [20Hz, sampleRate/2] automatically enforced
@algorithm_details
This method implements frequency-to-coefficient conversion using fixed-point arithmetic while maintaining adequate precision for musical applications. The algorithm carefully manages bit precision to prevent overflow while maximizing useful dynamic range.
Validate and clamp frequency to safe operating range
Convert to normalized frequency using Q16 fixed-point arithmetic Formula: normFreq = (fc << 16) / sampleRate This shifts fc left by 16 bits then divides, effectively creating Q16 format
Calculate filter coefficient 'g' using fixed-point multiplication Formula: g = normFreq² (in Q16 format) Q16 * Q16 >> 16 maintains Q16 format while preventing overflow
Calculate alpha coefficient for ladder implementation Formula: alpha = g / (1 + g) This provides the fundamental filter coefficient for each pole
Calculate feedback amount for resonance implementation Formula: feedbackAmount = alpha² Provides the scaling factor for resonance feedback around ladder
| void MoogLadderFilterFixedPoint::setCutoff | ( | int | frequency | ) |
Set cutoff frequency using integer parameter.
| frequency | Cutoff frequency in Hz as integer value |
Configures filter cutoff with automatic range validation and fixed-point coefficient calculation while maintaining adequate precision for musical applications through careful scaling and bit manipulation.
| void MoogLadderFilterFixedPoint::setResonance | ( | int | resonance | ) |
Configure filter resonance using integer parameter.
Configure resonance with 8-bit precision scaling.
| resonance | Resonance intensity [0-255] integer range |
Sets the filter resonance with 8-bit precision, providing 256 discrete resonance levels from no resonance to self-oscillation. The integer parameter is scaled internally for optimal fixed-point processing.
@complexity O(1) - Simple bit shifting and clamping @precision 8-bit resonance control (256 levels) @range [0-255] automatically clamped and scaled to Q8 format
Converts 8-bit resonance control to internal Q8 fixed-point format optimized for feedback calculations in the ladder structure.
Clamp resonance to 8-bit range and scale to Q8 format
2 operation converts from 8-bit to 6-bit range for stability
| void MoogLadderFilterFixedPoint::setResonance | ( | int | resonance | ) |
Set resonance using 8-bit integer parameter.
| resonance | Resonance intensity [0-255] for 8-bit precision |
Controls filter resonance using 8-bit precision providing 256 discrete levels from no resonance to self-oscillation, with automatic scaling to internal fixed-point format for optimal processing efficiency.
|
private |
Fast tanh approximation for nonlinear processing.
Fast tanh approximation using quadratic polynomial.
| x | Input value in fixed-point format |
Provides computationally efficient tanh approximation using quadratic polynomial. Trades some accuracy for significant performance improvement over transcendental function evaluation.
@complexity O(1) - Single multiply and subtract operation @accuracy Within ~5% of true tanh for audio range @range Input clamped to [-32768, 32767] for stability
Provides efficient nonlinear processing suitable for fixed-point systems where transcendental function evaluation would be prohibitively expensive.
Clamp input to prevent overflow in subsequent operations
Quadratic approximation: tanh(x) ≈ x - x²/65536 The >> 16 operation provides the division by 65536 in fixed-point
|
private |
Fast tanh approximation for fixed-point nonlinear processing.
| x | Input value in fixed-point format |
Implements efficient polynomial approximation of tanh function using only integer arithmetic, providing nonlinear saturation characteristics essential for authentic analog filter modeling.
|
private |
Filter coefficient alpha in Q16 fixed-point format.
Filter coefficient in Q16.16 format.
Primary filter coefficient determining cutoff frequency behavior. Calculated from normalized frequency using fixed-point arithmetic.
|
private |
Current cutoff frequency in Hz.
|
private |
Feedback amount coefficient in Q16 fixed-point format.
Feedback gain in Q16.16 format.
Controls the amount of resonance feedback around the ladder structure. Derived from alpha coefficient using fixed-point multiplication.
|
private |
Previous input sample for delay line implementation.
Filter state variables in fixed-point format.
Previous input sample for delay implementation
|
private |
Current resonance coefficient in Q8 fixed-point format.
Current resonance coefficient in Q8 format.
Resonance control parameter scaled to Q8 format for optimal precision in feedback calculations.
|
private |
Filter stage state variables [4 elements].
Filter stage states in Q16.16 format.
Internal state of each ladder stage stored as fixed-point integers. These represent the "memory" of each filter pole.
|
private |
Audio system sample rate for frequency calculations.
System configuration parameters.
Audio sample rate for coefficient calculation