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

Implements keyboard tracking for filter frequency modulation. More...

#include <KeyFollow.h>

Public Member Functions

 KeyFollow (float keyFollowAmount=0.01f)
 Construct KeyFollow processor with specified tracking intensity.
void setKeyFollowAmount (float amount)
 Update keyboard tracking intensity in real-time.
float process (int midiNote)
 Process MIDI note number and generate frequency offset.

Private Attributes

float keyFollowAmount
 Keyboard tracking intensity coefficient.

Detailed Description

Implements keyboard tracking for filter frequency modulation.

The KeyFollow class provides real-time keyboard tracking functionality, generating frequency offset values based on MIDI note numbers. The implementation uses a linear mapping with configurable intensity to maintain musical relationships while allowing artistic control over tracking behavior.

@design_pattern

  • Strategy Pattern: Encapsulates keyboard tracking algorithm
  • Value Object: Immutable processing with configurable parameters
  • Real-time Safe: No dynamic allocation in processing path

@usage_example

KeyFollow keyTracker(0.05f); // 5% tracking intensity
float offset = keyTracker.process(60); // Process middle C (C4)
float cutoff = baseCutoff + offset; // Apply to filter cutoff
KeyFollow(float keyFollowAmount=0.01f)
Construct KeyFollow processor with specified tracking intensity.
Definition KeyFollow.cpp:24

Constructor & Destructor Documentation

◆ KeyFollow()

KeyFollow::KeyFollow ( float amount = 0.01f)

Construct KeyFollow processor with specified tracking intensity.

Initialize KeyFollow processor with tracking intensity.

Parameters
keyFollowAmountTracking intensity coefficient [0.0-1.0] 0.0 = no tracking (constant filter frequency) 1.0 = full tracking (maximum frequency scaling) Default: 0.01f (subtle tracking, typical for bass/lead sounds)

@complexity O(1) - Constant time initialization @memory Single float storage for tracking coefficient

Note
Default value of 0.01f provides subtle tracking suitable for most musical applications without excessive filter opening in high registers
Parameters
amountInitial tracking intensity coefficient Stored directly without validation for performance

@implementation_notes

  • No parameter validation for real-time performance
  • Direct assignment avoids conditional branching
  • Minimal constructor overhead for audio thread instantiation

Member Function Documentation

◆ process()

float KeyFollow::process ( int midiNote)

Process MIDI note number and generate frequency offset.

Generate frequency offset from MIDI note number.

Converts MIDI note number to proportional frequency offset using linear scaling with configurable intensity. The algorithm provides musically appropriate tracking behavior consistent with classic analog synthesizer implementations.

Parameters
midiNoteMIDI note number [0-127] Note 36 (C2) serves as reference point (0 offset) Values below 36 are clamped to 0 for stability
Returns
Frequency offset in implementation-defined units Positive values indicate filter opening Range: [0, ∞) depending on tracking amount and note number

@complexity O(1) - Constant time processing @precision Maintains full floating-point precision for smooth tracking @realtime_safety Real-time safe (deterministic execution time)

@algorithm_details

  1. Offset calculation: note_offset = max(0, note - 36)
  2. Frequency scaling: scaled_note = note_offset * 0.33 + 36
  3. Intensity application: output = scaled_note * tracking_amount
Note
The 0.33 scaling factor provides approximately 1/3 octave tracking per octave played, which matches typical analog synthesizer behavior
Parameters
midiNoteInput MIDI note number for tracking calculation
Returns
Frequency offset scaled by tracking intensity

@algorithm_analysis The algorithm implements a three-stage transformation:

  1. Reference Point Offset: (midiNote - 36)
    • Note 36 (C2, ~65.4 Hz) serves as tracking reference
    • Notes below C2 are clamped to prevent negative offsets
    • Provides stable behavior across full MIDI note range
  2. Frequency Scaling: noteScaled * 0.33 + 36
    • 0.33 factor provides 1/3 proportional tracking
    • Addition of 36 restores absolute note reference
    • Results in musically appropriate tracking slope
  3. Intensity Application: result * keyFollowAmount
    • Scales final output by user-configurable intensity
    • Allows artistic control over tracking strength
    • Preserves linear relationship for predictable behavior

@mathematical_justification The 0.33 scaling factor is derived from perceptual studies showing that approximately 1/3 octave filter tracking per octave played provides optimal timbre consistency across keyboard ranges in subtractive synthesis applications.

@performance_characteristics

  • Branch prediction friendly (single conditional)
  • FPU pipeline efficient (sequential operations)
  • Cache friendly (single memory access)
  • Vectorization potential for SIMD implementations

Calculate note offset from reference point (C2 = MIDI note 36) Cast to float for subsequent floating-point arithmetic efficiency

Clamp negative values to prevent filter frequency reduction below reference point, ensuring stable filter behavior in lowest octaves where tracking could cause instability

Apply frequency scaling factor (0.33) for musical tracking response This provides approximately 1/3 octave tracking per octave played, matching traditional analog synthesizer keyboard tracking behavior

Restore absolute note reference by adding back reference point This maintains proper frequency relationships while preserving the scaled tracking response for musical predictability

Apply user-configurable tracking intensity to final result Allows real-time artistic control over tracking strength while maintaining linear scaling relationship

◆ setKeyFollowAmount()

void KeyFollow::setKeyFollowAmount ( float amount)

Update keyboard tracking intensity in real-time.

Update keyboard tracking intensity parameter.

Parameters
amountNew tracking intensity coefficient [0.0-1.0] Values outside this range are not validated but may produce unexpected results

@complexity O(1) - Constant time parameter update @thread_safety Thread-safe for single writer, multiple readers @realtime_safety Real-time safe (no blocking operations)

Note
This method can be called safely from real-time audio threads without risk of priority inversion or blocking
Parameters
amountNew tracking intensity value

@thread_safety Safe for concurrent read/write from different threads @atomic_behavior Float assignment is atomic on most architectures

@implementation_notes

  • No parameter validation for maximum performance
  • Relies on IEEE 754 float assignment atomicity
  • Immediate effect on subsequent process() calls

Member Data Documentation

◆ keyFollowAmount

float KeyFollow::keyFollowAmount
private

Keyboard tracking intensity coefficient.

Controls the proportional amount of filter frequency change relative to note number variation. Higher values create more dramatic filter opening in upper registers, while lower values provide subtle tracking.

@range [0.0-1.0] typical, though implementation accepts any float value @default 0.01f (1% tracking intensity) @units Dimensionless coefficient (ratio)


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