Skip to content

refactor(audio): migrate from gofft to FFmpeg av_tx RDFT#50

Merged
flexiondotorg merged 4 commits into
mainfrom
ffmpeg-statigo
Jun 8, 2026
Merged

refactor(audio): migrate from gofft to FFmpeg av_tx RDFT#50
flexiondotorg merged 4 commits into
mainfrom
ffmpeg-statigo

Conversation

@flexiondotorg

Copy link
Copy Markdown
Contributor

Replace hand-rolled pure-Go FFT (gofft) with FFmpeg's av_tx real-input RDFT, unifying the audio pipeline on FFmpeg. Output remains bit-identical through log scale + noise gate + pixel quantisation.

  • Migrate ProcessChunk to av_tx with proper C-resource lifecycle (init/uninit)
  • Add Processor.Close() for av_tx teardown; wire deferred cleanup in both passes
  • Update NewProcessor signature to return (*Processor, error) for init validation
  • Remove gofft dependency and transitive imports
  • Update Pass 2 consumer to float32 Spectrum type

Performance: 20789 ns/op → 3108 ns/op (0 allocs retained). No functional change; all downstream consumers unaffected.

Replace hand-rolled pure-Go FFT (gofft) with FFmpeg's av_tx real-input
RDFT, unifying the audio pipeline on FFmpeg. Output remains
bit-identical through log scale + noise gate + pixel quantisation.

- Migrate ProcessChunk to av_tx with proper C-resource lifecycle
  (init/uninit)
- Add Processor.Close() for av_tx teardown; wire deferred cleanup in
  both passes
- Update NewProcessor signature to return (*Processor, error) for init
  validation
- Remove gofft dependency and transitive imports
- Update Pass 2 consumer to float32 Spectrum type

Performance: 20789 ns/op → 3108 ns/op (0 allocs retained). No functional
change; all downstream consumers unaffected.

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 8 files

Confidence score: 5/5

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

Requires human review: This PR replaces the core FFT library and restructures audio processing logic, which carries significant risk of breaking downstream analysis and visualization even if the AI review found no issues.

Re-trigger cubic

- Replace pure-Go AudioFIFO (struct + 6 methods) with avAudioFIFO
  wrapper backed by FFmpeg's AVAudioFifo library.
- Reorganise encode hot path: WriteAudioSamples and FlushAudioEncoder
  now route through AVAudioFifoWrite/Read with planar split at drain via
  existing writeStereoFloats/writeMonoFloats.
- Zero-pad partial final frame; free FIFO handle on Encoder.Close.
- Update AGENTS.md to reflect AVAudioFifo location in encoder.go.

Signed-off-by: Martin Wimpress <code@wimpress.io>
The two BenchmarkAVAudioFIFO_* benchmarks served only the one-time
merge gate, now signed off. The TestAVAudioFIFO_* functional tests cover
correctness; the FIFO is off the critical path, so the micro-benchmarks
add no ongoing value.

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Requires human review: This PR replaces a core FFT library with a C-based FFmpeg av_tx RDFT and swaps a Go FIFO for an FFmpeg AVAudioFifo, introducing new C memory management and unsafe code paths in the audio pipeline and encoder, which have high risk of silent correctness bugs or crashes despite no detected issues...

Re-trigger cubic

@flexiondotorg flexiondotorg merged commit c095a71 into main Jun 8, 2026
16 checks passed
@flexiondotorg flexiondotorg deleted the ffmpeg-statigo branch June 8, 2026 17:04
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