Skip to content

Commit c2476ec

Browse files
committed
refactor: remove legacy helpers and unify numeric helpers
- Remove legacy/unused helpers and diagnostic placeholders: - delete formatNormalisationResult, writeDiagnosticAdaptive, joinWithComma - remove calculateLUFSGap, lerp, clampFloat, and SilenceAnalysis type - drop legacy Entropy fields used only for backwards compatibility - Standardise numeric helper usage in analyzer: - replace ad-hoc 20*log10(...) conversions with linearRatioToDB - replace clampFloat calls with shared clamp(...) helper - Trim obsolete diagnostics from internal/logging/report.go and remove placeholder adaptive diagnostics in adaptive.go Signed-off-by: Martin Wimpress <martin@wimpress.org>
1 parent 33d67de commit c2476ec

3 files changed

Lines changed: 17 additions & 209 deletions

File tree

internal/logging/report.go

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -356,88 +356,6 @@ func GenerateReport(data ReportData) error {
356356
return nil
357357
}
358358

359-
// formatNormalisationResult outputs the loudnorm normalisation pass details
360-
func formatNormalisationResult(f *os.File, result *processor.NormalisationResult, config *processor.FilterChainConfig) {
361-
writeSection(f, "Pass 3: Loudnorm Measurement")
362-
363-
if result == nil || !config.LoudnormEnabled {
364-
fmt.Fprintln(f, "Status: DISABLED")
365-
return
366-
}
367-
368-
if result.Skipped {
369-
fmt.Fprintln(f, "Status: SKIPPED")
370-
return
371-
}
372-
373-
fmt.Fprintln(f, "Status: APPLIED")
374-
fmt.Fprintln(f, "")
375-
fmt.Fprintln(f, "Pre-normalisation (Pass 2 output):")
376-
fmt.Fprintf(f, " Integrated loudness: %.1f LUFS\n", result.InputLUFS)
377-
fmt.Fprintf(f, " True peak: %.1f dBTP\n", result.InputTP)
378-
fmt.Fprintln(f, "")
379-
380-
writeSection(f, "Pass 4: Loudnorm Normalisation")
381-
fmt.Fprintln(f, "")
382-
fmt.Fprintln(f, "Loudnorm configuration:")
383-
if result.LinearModeForced {
384-
fmt.Fprintf(f, " Target I: %.1f LUFS (adjusted from %.1f to preserve linear mode)\n",
385-
result.EffectiveTargetI, result.RequestedTargetI)
386-
} else {
387-
fmt.Fprintf(f, " Target I: %.1f LUFS\n", config.LoudnormTargetI)
388-
}
389-
fmt.Fprintf(f, " Target TP: %.1f dBTP\n", config.LoudnormTargetTP)
390-
fmt.Fprintf(f, " Target LRA: %.1f LU\n", config.LoudnormTargetLRA)
391-
fmt.Fprintf(f, " Mode: %s\n", loudnormModeString(config.LoudnormLinear))
392-
fmt.Fprintf(f, " Dual mono: %v\n", config.LoudnormDualMono)
393-
fmt.Fprintf(f, " Offset: %+.2f dB\n", result.GainApplied)
394-
395-
// Display loudnorm measurement (from Pass 3, used for Pass 4 parameters)
396-
fmt.Fprintln(f, "")
397-
fmt.Fprintln(f, "Loudnorm measurement (from Pass 3):")
398-
fmt.Fprintf(f, " Input I: %.2f LUFS\n", result.InputLUFS)
399-
fmt.Fprintf(f, " Input TP: %.2f dBTP\n", result.InputTP)
400-
fmt.Fprintf(f, " Target Offset: %.2f dB (from loudnorm, used in Pass 4)\n", result.GainApplied)
401-
402-
// Display loudnorm filter's second pass stats (parsed from JSON output)
403-
if result.LoudnormStats != nil {
404-
stats := result.LoudnormStats
405-
fmt.Fprintln(f, "")
406-
fmt.Fprintln(f, "Loudnorm second pass diagnostics:")
407-
fmt.Fprintf(f, " Input I: %s LUFS\n", stats.InputI)
408-
fmt.Fprintf(f, " Input TP: %s dBTP\n", stats.InputTP)
409-
fmt.Fprintf(f, " Input LRA: %s LU\n", stats.InputLRA)
410-
fmt.Fprintf(f, " Input Thresh: %s LUFS\n", stats.InputThresh)
411-
fmt.Fprintf(f, " Output I: %s LUFS\n", stats.OutputI)
412-
fmt.Fprintf(f, " Output TP: %s dBTP\n", stats.OutputTP)
413-
fmt.Fprintf(f, " Output LRA: %s LU\n", stats.OutputLRA)
414-
fmt.Fprintf(f, " Output Thresh: %s LUFS\n", stats.OutputThresh)
415-
fmt.Fprintf(f, " Norm Type: %s\n", stats.NormalizationType)
416-
fmt.Fprintf(f, " Target Offset: %s dB\n", stats.TargetOffset)
417-
}
418-
419-
fmt.Fprintln(f, "")
420-
fmt.Fprintln(f, "Post-normalisation:")
421-
fmt.Fprintf(f, " Integrated loudness: %.1f LUFS\n", result.OutputLUFS)
422-
fmt.Fprintf(f, " True peak: %.1f dBTP\n", result.OutputTP)
423-
424-
fmt.Fprintln(f, "")
425-
// Calculate deviation from effective target (what loudnorm was actually targeting)
426-
effectiveDeviation := math.Abs(result.OutputLUFS - result.EffectiveTargetI)
427-
if result.WithinTarget {
428-
if result.LinearModeForced {
429-
// Target was adjusted to preserve linear mode
430-
requestedDeviation := math.Abs(result.OutputLUFS - result.RequestedTargetI)
431-
fmt.Fprintf(f, "Result: ✓ Linear mode preserved (%.2f LU from effective target, %.2f LU from requested)\n",
432-
effectiveDeviation, requestedDeviation)
433-
} else {
434-
fmt.Fprintf(f, "Result: ✓ Within target (deviation: %.2f LU)\n", effectiveDeviation)
435-
}
436-
} else {
437-
fmt.Fprintf(f, "Result: ⚠ Outside tolerance (deviation: %.2f LU)\n", effectiveDeviation)
438-
}
439-
}
440-
441359
// loudnormModeString converts linear bool to readable mode string
442360
func loudnormModeString(linear bool) string {
443361
if linear {
@@ -682,18 +600,6 @@ func formatNoiseRemoveFilter(f *os.File, cfg *processor.FilterChainConfig, m *pr
682600
cfg.NoiseRemoveCompandKnee)
683601
}
684602

685-
// joinWithComma joins string slice with comma separator
686-
func joinWithComma(items []string) string {
687-
result := ""
688-
for i, item := range items {
689-
if i > 0 {
690-
result += ", "
691-
}
692-
result += item
693-
}
694-
return result
695-
}
696-
697603
// formatDS201GateFilter outputs DS201-inspired gate filter details
698604
func formatDS201GateFilter(f *os.File, cfg *processor.FilterChainConfig, m *processor.AudioMeasurements, prefix string) {
699605
if !cfg.DS201GateEnabled {
@@ -2443,35 +2349,10 @@ func writeDiagnosticLoudnorm(f *os.File, result *processor.NormalisationResult,
24432349
fmt.Fprintln(f, "")
24442350
}
24452351

2446-
// writeDiagnosticAdaptive outputs detailed adaptive parameter diagnostics.
2447-
// This section is filled by the existing formatFilterChain function.
2448-
// For now, we just write a header - the actual content comes from writeFilterChainApplied.
2449-
func writeDiagnosticAdaptive(f *os.File, config *processor.FilterChainConfig, measurements *processor.AudioMeasurements) {
2450-
// The filter chain section already contains adaptive rationale for each filter.
2451-
// This function is a placeholder for additional adaptive debugging if needed.
2452-
// Currently, all adaptive info is in writeFilterChainApplied.
2453-
}
2454-
24552352
// getFinalMeasurements safely extracts final measurements from the result.
24562353
func getFinalMeasurements(result *processor.ProcessingResult) *processor.OutputMeasurements {
24572354
if result == nil || result.NormResult == nil {
24582355
return nil
24592356
}
24602357
return result.NormResult.FinalMeasurements
24612358
}
2462-
2463-
// getFilteredNoise safely extracts filtered noise profile from the result.
2464-
func getFilteredNoise(result *processor.ProcessingResult) *processor.SilenceCandidateMetrics {
2465-
if result == nil || result.FilteredMeasurements == nil {
2466-
return nil
2467-
}
2468-
return result.FilteredMeasurements.SilenceSample
2469-
}
2470-
2471-
// getFinalNoise safely extracts final noise profile from the result.
2472-
func getFinalNoise(result *processor.ProcessingResult) *processor.SilenceCandidateMetrics {
2473-
if result == nil || result.NormResult == nil || result.NormResult.FinalMeasurements == nil {
2474-
return nil
2475-
}
2476-
return result.NormResult.FinalMeasurements.SilenceSample
2477-
}

internal/processor/adaptive.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,6 @@ func AdaptConfig(config *FilterChainConfig, measurements *AudioMeasurements) {
408408
sanitizeConfig(config)
409409
}
410410

411-
// calculateLUFSGap returns the dB difference between target and input LUFS.
412-
// Returns 0.0 if input is not measured.
413-
func calculateLUFSGap(targetI, inputI float64) float64 {
414-
if inputI != 0.0 {
415-
return targetI - inputI
416-
}
417-
return 0.0
418-
}
419-
420411
// tuneDS201HighPass adapts DS201-inspired highpass composite filter based on:
421412
// - Spectral centroid (voice brightness/warmth)
422413
// - Spectral decrease (LF voice content - protects warm voices)
@@ -1551,9 +1542,3 @@ func clamp(val, min, max float64) float64 {
15511542
}
15521543
return val
15531544
}
1554-
1555-
// lerp performs linear interpolation between a and b based on t (0-1).
1556-
// When t=0, returns a. When t=1, returns b.
1557-
func lerp(a, b, t float64) float64 {
1558-
return a + (b-a)*t
1559-
}

0 commit comments

Comments
 (0)