Documentation
¶
Index ¶
- func BinFFT(coeffs []complex128, sensitivity float64, baseScale float64, result []float64)
- func FillFFTBuffer(reader *StreamingReader, buf []float64) (int, error)
- func ReadNextFrame(reader *StreamingReader, buf []float64) (int, error)
- func RearrangeFrequenciesCenterOut(barHeights []float64, result []float64)
- type Decoder
- type FFmpegDecoder
- type FrameAnalysis
- type Metadata
- type Processor
- type Profile
- type ProgressCallback
- type StreamingReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinFFT ¶
func BinFFT(coeffs []complex128, sensitivity float64, baseScale float64, result []float64)
BinFFT bins FFT coefficients into bars and returns normalized values (0.0-1.0) CAVA-style approach: work in normalized space, apply maxBarHeight scaling later baseScale is calculated from Pass 1 analysis for optimal visualization result buffer is provided by caller to avoid allocations
func FillFFTBuffer ¶
func FillFFTBuffer(reader *StreamingReader, buf []float64) (int, error)
FillFFTBuffer reads up to len(buf) samples from reader via repeated ReadChunk calls. Returns the number of samples read. Returns (0, nil) on immediate EOF, allowing callers to decide whether that is an error.
func ReadNextFrame ¶
func ReadNextFrame(reader *StreamingReader, buf []float64) (int, error)
ReadNextFrame reads up to len(buf) samples from reader into the provided buffer. Returns the number of samples read. Returns (0, io.EOF) when no samples are available. Returns (n, nil) for partial frames at end of file.
func RearrangeFrequenciesCenterOut ¶
RearrangeFrequenciesCenterOut creates a symmetric mirror pattern with most active frequencies at CENTER result buffer is provided by caller to avoid allocations
Types ¶
type Decoder ¶
type Decoder interface {
// ReadChunk reads the next chunk of samples as float64
// Returns nil when EOF is reached
ReadChunk(numSamples int) ([]float64, error)
// SampleRate returns the audio sample rate in Hz
SampleRate() int
// NumChannels returns the number of audio channels (1=mono, 2=stereo)
NumChannels() int
// Close closes the decoder and releases resources
Close() error
}
Decoder defines the interface for all audio format decoders
type FFmpegDecoder ¶
type FFmpegDecoder struct {
// contains filtered or unexported fields
}
FFmpegDecoder implements Decoder using FFmpeg's libavformat/libavcodec. This provides support for any audio format FFmpeg can decode.
func NewFFmpegDecoder ¶
func NewFFmpegDecoder(filename string) (*FFmpegDecoder, error)
NewFFmpegDecoder creates a new FFmpeg-based audio decoder. Supports any audio format FFmpeg can decode (MP3, FLAC, WAV, OGG, AAC, etc.)
func (*FFmpegDecoder) Close ¶
func (d *FFmpegDecoder) Close() error
Close releases all FFmpeg resources.
func (*FFmpegDecoder) NumChannels ¶
func (d *FFmpegDecoder) NumChannels() int
NumChannels returns the number of audio channels in the source file. Note: ReadChunk always returns mono samples (stereo is downmixed).
func (*FFmpegDecoder) ReadChunk ¶
func (d *FFmpegDecoder) ReadChunk(numSamples int) ([]float64, error)
ReadChunk reads the next chunk of samples as float64. Stereo input is automatically downmixed to mono. Returns io.EOF when no more samples are available.
func (*FFmpegDecoder) SampleRate ¶
func (d *FFmpegDecoder) SampleRate() int
SampleRate returns the audio sample rate in Hz.
func (*FFmpegDecoder) SeekToSample ¶
func (d *FFmpegDecoder) SeekToSample(samplePos int64) error
SeekToSample seeks to the specified sample position. This enables efficient re-reading for Pass 2 without re-opening the file.
type FrameAnalysis ¶
type FrameAnalysis struct {
// Peak FFT magnitude across all bars
PeakMagnitude float64
// RMS level of audio chunk
RMSLevel float64
}
FrameAnalysis holds statistics for a single frame
type Metadata ¶
type Metadata struct {
SampleRate int
Channels int
NumSamples int64
Duration float64 // in seconds
}
Metadata holds information about an audio file
func GetMetadata ¶
GetMetadata uses ffmpeg to extract accurate audio file metadata
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor handles FFT analysis for visualization
func NewProcessor ¶
func NewProcessor() *Processor
NewProcessor creates a new audio processor with pre-computed Hanning window
func (*Processor) ProcessChunk ¶
func (p *Processor) ProcessChunk(samples []float64) []complex128
ProcessChunk performs FFT on a chunk of audio samples. Uses pre-computed Hanning window coefficients for better performance.
type Profile ¶
type Profile struct {
// Total number of frames in audio
NumFrames int
// Global statistics
GlobalPeak float64 // Highest peak magnitude across all frames
GlobalRMS float64 // Average RMS across all frames
DynamicRange float64 // Ratio of GlobalPeak to GlobalRMS
// Calculated optimal parameters
OptimalBaseScale float64 // Replaces hardcoded 0.0075
// Audio metadata
SampleRate int
Duration float64 // Seconds
}
Profile holds complete audio analysis results.
func AnalyzeAudio ¶
func AnalyzeAudio(filename string, progressCb ProgressCallback) (*Profile, error)
AnalyzeAudio performs Pass 1: stream through audio and collect statistics
type ProgressCallback ¶
type ProgressCallback func(frame, totalFrames int, currentRMS, currentPeak float64, barHeights []float64, duration time.Duration)
ProgressCallback is called with progress updates during analysis
type StreamingReader ¶
type StreamingReader struct {
// contains filtered or unexported fields
}
StreamingReader provides chunk-based audio reading for multiple formats
func NewStreamingReader ¶
func NewStreamingReader(filename string) (*StreamingReader, error)
NewStreamingReader creates a streaming audio reader for the given file. Uses FFmpeg decoder for broad format support (MP3, FLAC, WAV, OGG, AAC, etc.)
func (*StreamingReader) Close ¶
func (r *StreamingReader) Close() error
Close closes the underlying file
func (*StreamingReader) ReadChunk ¶
func (r *StreamingReader) ReadChunk(numSamples int) ([]float64, error)
ReadChunk reads next chunk of samples, returns nil when EOF
func (*StreamingReader) SampleRate ¶
func (r *StreamingReader) SampleRate() int
SampleRate returns the sample rate