Skip to content

Commit 42d5eda

Browse files
committed
refactor(processor): eliminate redundant interval accumulator reset call
- 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>
1 parent c706579 commit 42d5eda

2 files changed

Lines changed: 4 additions & 28 deletions

File tree

internal/processor/analyzer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ func AnalyzeAudio(filename string, config *FilterChainConfig, progressCallback f
326326
const intervalDuration = 250 * time.Millisecond
327327
var intervals []IntervalSample
328328
var intervalAcc intervalAccumulator
329-
intervalAcc.reset() // Initialize with proper defaults
330329
var intervalStartTime time.Duration
331330

332331
// Track input frame time (before filter graph, which upsamples to 192kHz)

internal/processor/analyzer_metrics.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -301,33 +301,10 @@ func (a *intervalAccumulator) finalize(timestamp time.Duration) IntervalSample {
301301

302302
// reset clears the accumulator for the next interval.
303303
func (a *intervalAccumulator) reset() {
304-
a.frameCount = 0
305-
306-
// Raw sample RMS and peak
307-
a.rawSumSquares = 0
308-
a.rawSampleCount = 0
309-
a.rawPeakAbs = 0
310-
311-
// aspectralstats
312-
a.spectralMeanSum = 0
313-
a.spectralVarianceSum = 0
314-
a.spectralCentroidSum = 0
315-
a.spectralSpreadSum = 0
316-
a.spectralSkewnessSum = 0
317-
a.spectralKurtosisSum = 0
318-
a.spectralEntropySum = 0
319-
a.spectralFlatnessSum = 0
320-
a.spectralCrestSum = 0
321-
a.spectralFluxSum = 0
322-
a.spectralSlopeSum = 0
323-
a.spectralDecreaseSum = 0
324-
a.spectralRolloffSum = 0
325-
326-
// ebur128
327-
a.momentaryLUFSSum = 0
328-
a.shortTermLUFSSum = 0
329-
a.truePeakMax = -120.0
330-
a.samplePeakMax = -120.0
304+
*a = intervalAccumulator{
305+
truePeakMax: -120.0,
306+
samplePeakMax: -120.0,
307+
}
331308
}
332309

333310
// Cached metadata keys for frame extraction - avoids per-frame C string allocations

0 commit comments

Comments
 (0)