Skip to content

refactor(processor): consolidate spectral averaging and extract region pair construction#61

Merged
flexiondotorg merged 3 commits intomainfrom
simple
Mar 16, 2026
Merged

refactor(processor): consolidate spectral averaging and extract region pair construction#61
flexiondotorg merged 3 commits intomainfrom
simple

Conversation

@flexiondotorg
Copy link
Contributor

@flexiondotorg flexiondotorg commented Mar 16, 2026

Summary

Refactors the processor package to improve code reuse and clarity. These changes consolidate spectral-averaging logic into dedicated methods and extract repeated region pair construction into a single reusable function, reducing duplication and making the intent of the code more apparent.

Changes

  • Consolidate spectral-averaging block into two methods (finalizeSpectral + writeSpectralTo)
  • Extract region pair construction into reusable function
  • Eliminate redundant interval accumulator reset call and collapse reset body

Testing

  • All existing tests pass
  • New test cases added for extracted functions in analyzer_metrics_test.go and analyzer_output_test.go

…tral and writeSpectralTo methods

- Add finalizeSpectral() method to calculate and return averaged
  spectral metrics
- Add writeSpectralTo() method to map spectral metrics to
  BaseMeasurements fields
- Replace two 16-line spectral averaging blocks with single method calls
  in AnalyzeAudio and finalizeOutputMeasurements
- Add comprehensive test coverage for spectral finalization

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

- Add extractRegionPair function in analyzer_output.go to build optional
  SilenceRegion and SpeechRegion pointers from AudioMeasurements
  profiles
- Replace duplicate 17-line region construction blocks in processor.go
  and  normalise.go with single-line extractRegionPair calls
- Add comprehensive test coverage for region pair extraction logic

Signed-off-by: Martin Wimpress <code@wimpress.io>
- Remove post-declaration reset() call from AnalyzeAudio; struct zero
  values suffice for all fields except truePeakMax and samplePeakMax
- Collapse reset() body from 28 lines to 3 lines using struct literal
  initialization

This reduces unnecessary initialization overhead and improves code
clarity by relying on Go's zero-value semantics.

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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: This is a code refactor that moves and reorganizes logic across multiple files in the processor package, which is explicitly classified as high-impact and requires human review.

@flexiondotorg flexiondotorg merged commit 42d5eda into main Mar 16, 2026
7 checks passed
@flexiondotorg flexiondotorg deleted the simple branch March 16, 2026 13:31
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