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

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.

Detailed Description

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

  • Simplicity: Linear interpolation for predictable behavior and minimal CPU overhead
  • Reliability: Automatic completion detection prevents infinite ramping
  • Responsiveness: Configurable ramp time balances smoothness with control latency
  • Universality: Generic parameter smoother suitable for various control applications

@applications

  • Filter resonance smoothing (primary use case)
  • Oscillator frequency gliding (alternative to portamento)
  • Amplitude level transitions
  • LFO rate smoothing
  • Any continuous parameter requiring smooth transitions

@usage_example

ResonanceRamp resonanceSmooth(44100.0f, 50.0f); // 50ms ramp time
// User changes resonance control:
resonanceSmooth.setTarget(0.8f);
// In audio processing loop:
for (int i = 0; i < bufferSize; ++i) {
float smoothResonance = resonanceSmooth.process();
filter.setResonance(smoothResonance);
// Continue with audio processing...
}
ResonanceRamp(float sampleRate, float rampTimeMs=50.0f)
Construct parameter ramp with timing configuration.
Definition ResonanceRamp.cpp:31
int bufferSize
Definition render_with_MOOGFILTER.cpp:116

Constructor & Destructor Documentation

◆ ResonanceRamp()

ResonanceRamp::ResonanceRamp ( float rate,
float rampTimeMs = 50.0f )

Construct parameter ramp with timing configuration.

Initialize parameter ramp with timing configuration.

Parameters
sampleRateAudio processing sample rate in Hz Used for accurate timing calculations Typical values: 44100, 48000, 96000 Hz
rampTimeMsInterpolation 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

  • currentValue: 0.5 (middle resonance value, safe default)
  • targetValue: 0.5 (no initial ramping required)
  • incrementPerSample: Calculated for specified ramp time

@ramp_time_considerations

  • Short times (1-20ms): Minimal smoothing, preserves control responsiveness
  • Medium times (20-100ms): Optimal balance for most musical applications
  • Long times (100ms+): Heavy smoothing, may feel sluggish but very smooth
Parameters
rateAudio sample rate for timing calculations
rampTimeMsInterpolation 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

Member Function Documentation

◆ process()

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.

Returns
Current interpolated parameter value Smoothly progressing between previous and target values Equals target value when interpolation complete

@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

  1. Direction Detection: Determines upward or downward interpolation
  2. Increment Application: Applies calculated step size toward target
  3. Completion Detection: Stops interpolation when target reached
  4. Value Return: Provides current parameter value for immediate use

@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:

for (int sample = 0; sample < bufferSize; ++sample) {
float resonance = ramp.process();
// Use resonance value immediately...
}
Returns
Current interpolated parameter value

@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

  • Two floating-point comparisons (direction and completion)
  • One floating-point addition or subtraction (increment application)
  • Branch prediction friendly (consistent direction during ramps)
  • Total execution: ~3-5 CPU cycles per sample

@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)

◆ setTarget()

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.

Parameters
targetResNew 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

  • Real-time control: Responds to continuous controller movements
  • Preset changes: Smooth transitions between stored parameter sets
  • Automation: Gradual parameter changes for musical expression
  • Safety ramping: Gentle parameter initialization to prevent artifacts
Parameters
targetResNew 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().

Member Data Documentation

◆ currentValue

float ResonanceRamp::currentValue
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.

◆ incrementPerSample

float ResonanceRamp::incrementPerSample
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

◆ sampleRate

float ResonanceRamp::sampleRate
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.

◆ targetValue

float ResonanceRamp::targetValue
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.


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