Skip to content

feat(processor): implement adaptive crest factor compression for quiet recordings#56

Merged
flexiondotorg merged 6 commits intomainfrom
adaptive-crest
Mar 15, 2026
Merged

feat(processor): implement adaptive crest factor compression for quiet recordings#56
flexiondotorg merged 6 commits intomainfrom
adaptive-crest

Conversation

@flexiondotorg
Copy link
Contributor

Summary

Implement Strategy 2: Adaptive Crest Factor Compression - LUFS High-Crest Override. Detects very quiet recordings with high peak-to-average energy ratios and applies specialised LA-2A compression parameters to prevent distortion and improve clarity.

Changes

  • Add high-crest override diagnostic fields (HighCrestDetected, HighCrestAttackMs, HighCrestReleaseMs) to LA-2A tuning reports
  • Implement applyHighCrestOverrides() detection logic: identifies recordings where LUFS < -10 dB and crest factor > 8, triggering adaptive parameter adjustment
  • Wire high-crest system into tuneLA2ACompressor() and sub-tuners (fixed, gentle, moderate, aggressive) with phase-specific parameter scaling
  • Add 449 lines of unit and integration tests covering all crest factor scenarios
  • Fix LUFS truncation bug by removing math.Round() call, preserving precision for very quiet recordings
  • Update design documentation and README with high-crest strategy explanation and diagnostic reporting

Testing

  • Unit tests: 100% coverage of crest factor detection thresholds and parameter calculations across all sub-tuner configurations
  • Integration tests: verify wiring in full tuning pipeline, confirm diagnostic reporting in output
  • All tests pass; golangci-lint clean

- Add high-crest override constants (maxDeficit, safetyMargin,
  minLimiterCeiling)
- Add la2aOverrides struct to carry override floor values for sub-tuners
- Add lerp() helper for linear interpolation (0.0-1.0)
- Add diagnostic fields to FilterChainConfig: LA2AHighCrestActive,
  LA2AHighCrestDeficit, LA2AHighCrestSeverity, LA2AHighCrestProjectedTP

Signed-off-by: Martin Wimpress <code@wimpress.io>
…r calculation

Implement `applyHighCrestOverrides()` to predict when Pass 4 limiter
ceiling will clamp and compute override floors that increase LA-2A
compressor aggression.

Changes:
- Add deficit-based detection mirroring calculateLimiterCeiling() logic
- Calculate severity from 0 to 1 based on deficit magnitude (0–8 dB
  range)
- Return interpolated override floors for threshold, ratio, release, and
  knee
- Populate diagnostic fields (deficit, severity, projectedTP) for all
  recordings
- Add comprehensive unit tests with seven scenarios covering boundary
  cases

Signed-off-by: Martin Wimpress <code@wimpress.io>
- Integrate applyHighCrestOverrides into tuneLA2ACompressor execution
  flow
- Pass override parameters to all four sub-tuners (Release, Ratio,
  Threshold, Knee)
- Add enforcement logic in each sub-tuner to respect override floors
  while preserving clamps
- Add TestTuneLA2ACompressorHighCrest integration tests with four
  acceptance cases
  - high-crest overrides push ratio and threshold
  - no deficit leaves sub-tuners unmodified
  - Hot-input invariant: hot peaks and high-crest deficit cannot
    co-occur
  - Maximum severity: aggressive but bounded parameters at severity 1.0

Signed-off-by: Martin Wimpress <code@wimpress.io>
…ncation

- Extend formatLA2ACompressorFilter() with active/inactive high-crest
  override diagnostic blocks, including deficit, severity, projected TP,
  and ceiling info
- Fix LUFS value truncation in output filename generation by removing
  math.Round() (e.g., -26.8 LUFS now produces LUFS-26, not LUFS-27)
- Update AGENTS.md documentation to clarify truncation behaviour

Signed-off-by: Martin Wimpress <code@wimpress.io>
…ing fixes

- Extend README.md filter comparison and example output with high-crest
  override diagnostics (active state, ceiling deficit, severity,
  projected TP)
- Enhance FilterCompressor-Teletronix LA-2A.md with comprehensive
  high-crest override design documentation including detection
  algorithm, override floor tables, enforcement rules, and integration
  with existing tuning subsystems
- Add high-crest override fields to FilterChainConfig documentation
  table
- Clarify threshold range and release/knee interaction notes for
  override mode

Signed-off-by: Martin Wimpress <code@wimpress.io>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 8 files

Confidence score: 4/5

  • Overall risk looks low because the issues are confined to diagnostics, tests, and documentation rather than core processing logic.
  • Most significant functional concern is in internal/logging/report.go, where hardcoded NormTargetLUFS could make high-crest diagnostics diverge from configured loudnorm settings.
  • Test and docs mismatches reduce confidence in validation and guidance but are not likely to affect runtime behavior directly (internal/processor/adaptive_test.go, README.md, docs/FilterCompressor-Teletronix LA-2A.md).
  • Pay close attention to internal/logging/report.go, internal/processor/adaptive_test.go, README.md, docs/FilterCompressor-Teletronix LA-2A.md - diagnostics accuracy, test coverage, and documentation consistency.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/logging/report.go">

<violation number="1" location="internal/logging/report.go:856">
P2: Use `cfg.LoudnormTargetI` instead of hardcoding `NormTargetLUFS` in the high-crest diagnostics, otherwise the reported gain and projected TP drift from the actual loudnorm settings.</violation>
</file>

<file name="README.md">

<violation number="1" location="README.md:171">
P2: These added diagnostics don't match the surrounding example values, so the README now documents an impossible high-crest result for this sample.</violation>
</file>

<file name="internal/processor/adaptive_test.go">

<violation number="1" location="internal/processor/adaptive_test.go:2478">
P2: This test re-runs the same code path twice, so it cannot prove inactive recordings still match the pre-override tuner behaviour.</violation>
</file>

<file name="docs/FilterCompressor-Teletronix LA-2A.md">

<violation number="1" location="docs/FilterCompressor-Teletronix LA-2A.md:70">
P3: This adds 350 ms / 6.0 high-crest values, but the config table below still says `LA2ARelease` tops out at 300 ms and `LA2AKnee` at 5.0.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Remove impossible high-crest example values from README.md
  (deficit 2.6 dB, projected TP 18.2 dBTP values were unrealistic)
- Correct LA2ARelease range from 150–300 ms to 150–350 ms
- Correct LA2AKnee range from 3.5–5.0 to 3.5–6.0

Signed-off-by: Martin Wimpress <code@wimpress.io>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

@flexiondotorg flexiondotorg merged commit e5bacc1 into main Mar 15, 2026
7 checks passed
@flexiondotorg flexiondotorg deleted the adaptive-crest branch March 15, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant