|
TR123e - EMCT Computing Final Project Version 1.0
Research Project Translation from gen~ to embedded Moog synth
|
Linear parameter interpolation engine for smooth resonance control. More...
#include <ResonanceRamp.h>
Public Member Functions | |
| ResonanceRamp (float sampleRate, float rampTimeMs=50.0f) | |
| Construct parameter ramp with timing configuration. | |
| void | setTarget (float targetRes) |
| Set new target value for parameter interpolation. | |
| float | process () |
| Process interpolation and return current parameter value. | |
Private Attributes | |
| float | sampleRate |
| Audio system sample rate for timing calculations. | |
| float | currentValue |
| Current parameter value during interpolation. | |
| float | targetValue |
| Target parameter value for interpolation destination. | |
| float | incrementPerSample |
| Parameter increment applied per audio sample. | |
Linear parameter interpolation engine for smooth resonance control.
The ResonanceRamp class provides professional-grade parameter smoothing specifically designed for filter resonance control in real-time audio applications. It implements efficient linear interpolation with automatic completion detection and configurable ramping time to prevent audio artifacts while maintaining responsive control.
@design_philosophy
@applications
@usage_example
| ResonanceRamp::ResonanceRamp | ( | float | rate, |
| float | rampTimeMs = 50.0f ) |
Construct parameter ramp with timing configuration.
Initialize parameter ramp with timing configuration.
| sampleRate | Audio processing sample rate in Hz Used for accurate timing calculations Typical values: 44100, 48000, 96000 Hz |
| rampTimeMs | Interpolation duration in milliseconds Time required for complete parameter transition Default: 50ms (good balance of smoothness and responsiveness) Range: [1.0-1000.0]ms practical limits |
@complexity O(1) - Constant time initialization @memory 16 bytes object size (4 float members) @thread_safety Safe for concurrent construction
@initialization_behavior
@ramp_time_considerations
| rate | Audio sample rate for timing calculations |
| rampTimeMs | Interpolation duration in milliseconds |
@implementation_details Calculates increment per sample based on ramp time and sample rate. The increment represents the reciprocal of total samples in ramp period, providing normalized step size for linear interpolation algorithms.
@mathematical_derivation Total samples in ramp = rampTimeMs × 0.001 × sampleRate Increment per sample = 1.0 / total_samples
This gives a normalized increment that, when applied over the ramp duration, will complete exactly one full parameter transition from 0.0 to 1.0.
Calculate increment per sample for linear interpolation Formula: 1.0 / (rampTimeMs * 0.001 * sampleRate)
The 0.001 factor converts milliseconds to seconds for sample rate multiplication The reciprocal provides step size for normalized [0.0-1.0] parameter range
| float ResonanceRamp::process | ( | ) |
Process interpolation and return current parameter value.
Execute linear parameter interpolation with completion detection.
Core processing method that advances the parameter interpolation and returns the current smoothed value. Must be called once per audio sample to maintain proper timing and smooth parameter progression.
@complexity O(1) - Constant time processing per sample @determinism Bounded execution time regardless of parameter values @realtime_safety Real-time safe (no allocation or blocking)
@algorithm_behavior
@completion_logic Interpolation completes when the remaining distance to target becomes smaller than the increment step size. This ensures completion within one additional sample period regardless of floating-point precision.
@numerical_stability Uses separate handling for positive and negative interpolation directions to ensure symmetric behavior and proper completion detection in both directions without floating-point precision issues.
@call_pattern Must be called exactly once per audio sample:
@algorithm_implementation The method uses bidirectional interpolation logic with automatic completion detection. Separate handling for upward and downward transitions ensures symmetric behavior and numerical stability across parameter ranges.
@performance_analysis
@numerical_precision Completion detection uses direct comparison rather than threshold-based detection, relying on overshoot correction for exact target achievement. This approach ensures precise completion regardless of increment size or floating-point precision limitations.
Handle upward interpolation (current < target)
Apply positive increment toward target
Check for overshoot and correct to exact target Ensures precise completion without oscillation
Handle downward interpolation (current > target)
Apply negative increment toward target
Check for undershoot and correct to exact target Maintains symmetrical completion behavior
Return current parameter value (No action needed when currentValue == targetValue)
| void ResonanceRamp::setTarget | ( | float | targetRes | ) |
Set new target value for parameter interpolation.
Update interpolation target value.
Establishes new target parameter value, triggering smooth interpolation from current value to target over the configured ramp time. Multiple calls to setTarget() before completion will redirect interpolation to the new target, providing responsive control behavior.
| targetRes | New target resonance value Typical range: [0.0-1.0] for normalized resonance No bounds checking performed for maximum performance |
@complexity O(1) - Simple parameter assignment @realtime_safety Real-time safe (no allocation or blocking) @response_behavior Immediate redirection of interpolation target
@interpolation_redirection If called during active interpolation, the system smoothly redirects toward the new target without discontinuities. The interpolation recalculates timing based on remaining distance and original ramp time.
@musical_usage_patterns
| targetRes | New target parameter value |
Simple parameter assignment that immediately redirects interpolation toward new target. No recalculation of increment required since the system uses normalized step sizes with directional logic in process().
|
private |
Current parameter value during interpolation.
Real-time parameter value updated each sample during interpolation. Represents the instantaneous parameter value for immediate use by audio processing components. Progresses linearly toward target value.
|
private |
Parameter increment applied per audio sample.
Calculated step size for linear interpolation, determined by the distance between current and target values divided by the total number of samples in the ramp time. Provides precise timing control over parameter transitions.
@calculation increment = 1.0 / (rampTimeMs * 0.001 * sampleRate) @units Parameter_units_per_sample (dimensionless ratio) @direction Positive for upward ramps, negative for downward ramps
|
private |
Audio system sample rate for timing calculations.
Cached sample rate used for converting millisecond ramp times to sample counts and calculating per-sample increment values. Essential for sample-accurate parameter timing.
|
private |
Target parameter value for interpolation destination.
Destination value for current interpolation process. Set by setTarget() method and remains constant during interpolation unless updated by subsequent setTarget() calls for responsive control behavior.