Skip to content

refactor(processor): simplify analyzer and normaliser implementation#60

Merged
flexiondotorg merged 8 commits intomainfrom
tinkering
Mar 16, 2026
Merged

refactor(processor): simplify analyzer and normaliser implementation#60
flexiondotorg merged 8 commits intomainfrom
tinkering

Conversation

@flexiondotorg
Copy link
Contributor

Summary

This pull request consolidates duplicated logic, removes unused code, and eliminates hidden mutations throughout the processor package. The changes reduce cognitive load and make the codebase easier to maintain.

Changes

  • Consolidate test-only helper functions and inline wrapper function for clarity
  • Remove unused silence detection code from analyzer metrics
  • Replace string comparison with sentinel error value for cancellation in main
  • Eliminate variable shadowing and dead code patterns in analyzer
  • Remove unused public function exports in analyzer
  • Hide internal mutation in buildLoudnormFilterSpec from public API
  • Consolidate safety margin and limiter ceiling constants

Testing

  • All existing tests pass (7 commits touching test files)
  • New test cases added for analyzer output handling
  • New test cases added for normaliser output handling

Related Issues

N/A

…nstants

Remove duplicate constant definitions from adaptive.go and use the
canonical constants from normalise.go. Both la2aHighCrestSafetyMargin
and la2aHighCrestMinLimiterCeiling were duplicates of safetyMarginDB and
minLimiterCeilingDB respectively, requiring manual synchronisation
across two files. Consolidating to a single source eliminates the
Shotgun Surgery smell and ensures any future adjustments need only
happen once.

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

Replace set/call/restore pattern that mutated config.ResampleEnabled
with direct filter construction. The function now builds the resample
filter spec directly using fmt.Sprintf instead of calling
buildResampleFilter(), which is gated on ResampleEnabled.

Add TestBuildLoudnormFilterSpec_DoesNotMutateConfig to prevent
regression of this Inappropriate Intimacy smell.

Signed-off-by: Martin Wimpress <code@wimpress.io>
Remove exported MeasureOutputSilenceRegion and
MeasureOutputSpeechRegion; rename to unexported
measureOutputSilenceRegion and measureOutputSpeechRegion. These
functions are only used in tests and should not be part of the public
API. Update test call sites and test function names accordingly.

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

- Rename shadowing `frameCount` to `spectralFrameCountF` in spectral
  averaging block
- Remove unused `lastFrameTime` variable that silenced a compiler
  warning

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

Replace error message string comparison with idiomatic sentinel error
pattern. This eliminates Primitive Obsession by introducing
errCancelledByUser sentinel and using errors.Is for comparison instead
of Error() string matching.

- Add errors import
- Define errCancelledByUser sentinel error
- Update creation site to use sentinel value
- Use errors.Is for idiomatic comparison

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

Remove unreachable silence detection block from extractFrameMetadata
(lines 832-880), silence metadata keys, and unused accumulators:
- silenceRegions, pendingSilenceStart, hasPendingSilence fields
- peakMax field and accumulation/reset sites in intervalAccumulator
- six metaKeySilence* variable declarations

All changes are pure deletions identified in Phase 1 dead code analysis.

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

- Move measureOutputSilenceRegion and measureOutputSpeechRegion to
  analyzer_output_test.go
- Inline createLoudnormFilterGraph wrapper and delete function from
  normalise.go
- Eliminate public functions with no external callers

All changes are pure deletions and relocations; build and tests pass.

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.

1 issue found across 9 files

Confidence score: 5/5

  • This PR looks low risk to merge: the only reported issue is low severity (2/10) and appears documentation/comment accuracy related rather than behavioral.
  • In internal/processor/analyzer_output.go, the comment above MeasureOutputRegions references test-only/removed function names, which could mislead future maintainers about the production measurement path.
  • Pay close attention to internal/processor/analyzer_output.go - update the MeasureOutputRegions comment so it reflects the current production flow.
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/processor/analyzer_output.go">

<violation number="1" location="internal/processor/analyzer_output.go:187">
P3: This comment now references test-only/removed function names instead of the production measurement path, so it will mislead readers of `MeasureOutputRegions`.</violation>
</file>

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

Reword to explain outcome (measured in separate passes) rather than
function names, maintaining clarity for future maintainers.

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 1 file (changes from recent commits).

Requires human review: This is a significant refactor of core audio processing logic, including changes to public APIs, constant consolidation, and removal of silence detection code across multiple files.

@flexiondotorg flexiondotorg merged commit 55abb9c into main Mar 16, 2026
7 checks passed
@flexiondotorg flexiondotorg deleted the tinkering branch March 16, 2026 02:51
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