Skip to content

05_16_04_precision_variants

Multi-Precision Audio Processing Variants

Status: ⏸️ NOT STARTED Priority: MEDIUM Dependencies: TAREA 0 (Variant Framework) Estimated Effort: 2 weeks


🎯 Purpose

Precision variants provide multiple floating-point precision options (float16, float32, float64, fixed-point) to optimize for different use cases: - float16 (half): Mobile GPUs, ML inference (2x memory savings) - float32 (single): Standard audio processing (current default) - float64 (double): High-precision scientific audio (e.g., synthesis) - Fixed-point: Embedded systems, DSPs


πŸ“‹ Planned Variants

Float16 Variants (GPU/Mobile)

class Float16GainVariant : public IVariant {
public:
    bool process(const float* input, float* output, size_t numSamples) override;
    // Converts to fp16 internally, uses GPU fp16 ops

private:
    __half gain_;  // 16-bit
};

Use Cases: - Mobile devices (iOS/Android) - GPU processing (Tensor Cores) - ML audio models (inference)

Trade-offs: - 2x memory savings - 2x bandwidth savings - Lower precision (10-bit mantissa vs 23-bit)

Float64 Variants (High Precision)

class Float64OscillatorVariant : public IVariant {
public:
    bool process(const float* input, float* output, size_t numSamples) override;
    // Uses double internally, converts back to float

private:
    double phase_;
    double phaseIncrement_;
};

Use Cases: - Scientific audio analysis - Long-running synthesis (phase accumulation) - Cascaded filters (error accumulation prevention)

Trade-offs: - Higher precision - 2x memory usage - Slower (no SIMD double on some CPUs)

Fixed-Point Variants (Embedded)

class FixedPoint16GainVariant : public IVariant {
public:
    bool process(const float* input, float* output, size_t numSamples) override;
    // Fixed Q15 format internally

private:
    int16_t gain_;  // Q15: 1 sign bit, 0 integer bits, 15 fractional bits
};

Use Cases: - Embedded systems without FPU - DSP chips - Low-power devices


πŸ“Š Performance Targets

Variant Memory Usage Bandwidth Speed Precision
float16 0.5x 0.5x 1.5-2x (GPU) Medium
float32 1x 1x 1x (baseline) High
float64 2x 2x 0.5-0.8x Very High
fixed16 0.5x 0.5x 1.2-1.5x (embedded) Medium

πŸ› οΈ Implementation Plan

Week 1: - Float16 variants for GPU - Conversion helpers (float32 ↔ float16) - Benchmarking on mobile GPUs

Week 2: - Float64 variants for high precision - Fixed-point variants (Q15, Q31) - Validation and documentation


⚠️ Challenges

  1. Precision Loss: float16 has limited range and precision
  2. Saturation: Fixed-point requires careful overflow handling
  3. Platform Support: Not all CPUs support fp16 efficiently
  4. Mixed Precision: Converting between precisions has overhead

Status: ⏸️ Planned for future development Priority: MEDIUM - Useful for specialized use cases