Documentation
¶
Overview ¶
Package cava is the Go port of the audio spectrum analyzer behind lys-shell's cava bar module: crates/wayle-cava's vendored cavacore.c translated algorithm-for-algorithm. The plan distributes bars across the frequency range on a log scale (with the bass split onto a double-size FFT), Execute turns PCM frames into 0..1 bar heights with cava's gravity falloff and integral smoothing, and the autosens feedback keeps the output normalized. Capture is a record stream on the shell's PulseAudio native client (source.go).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capturer ¶
type Capturer interface {
Capture(target pulse.CaptureTarget, spec pulse.CaptureSpec, onData func([]byte)) (*pulse.Capture, error)
}
Capturer is the record-stream seam; *pulse.Service implements it.
type FifoInput ¶
type FifoInput struct {
// contains filtered or unexported fields
}
FifoInput reads s16le PCM from a named pipe (libcava's input_fifo): whole blocks of 512 frames, interleaved when stereo, at the rate the analyzer was planned for. /dev/zero is the test source, paced at a block a millisecond.
func NewFifoInput ¶
NewFifoInput reads path; channels is 1 or 2, capacity the analyzer's input size in interleaved samples.
type Input ¶
Input is what the analyzer reads from: a capture started and stopped, its samples drained each frame.
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
Plan holds the analyzer state for one bar layout: one cava_init call. It is not safe for concurrent use; Execute owns it from the loop goroutine.
func NewPlan ¶
func NewPlan(bars, rate, channels int, noiseReduction float64, autosens bool, lowCutoff, highCutoff int) (*Plan, error)
NewPlan initializes the analyzer: bars per channel over [lowCutoff, highCutoff] Hz at the given sample rate, for one channel or two (stereo, the samples interleaved). noiseReduction is cava's 0..1 filter strength and autosens enables the feedback that keeps bars in 0..1. The validations mirror cava_init's; each failure is an error naming the bad value.
func (*Plan) Execute ¶
Execute is cava_execute: fold new samples into the ring, FFT the windowed bass and main buffers per channel, sum each bar's bins through the eq, and run cava's two-stage smoothing (gravity falloff plus integral) with the autosens feedback clamping bars into 0..1. Stereo samples come interleaved, left first. It returns the bar heights, one per bar per channel: the left bars, then the right.
The ring is the C one, newest sample first, so the main FFT reads the newest stretch of it as cava's does; its reversed time order only conjugates the spectrum, whose magnitudes are all that is read.
type ShmemInput ¶
type ShmemInput struct {
// contains filtered or unexported fields
}
ShmemInput reads squeezelite's visualization area (libcava's input_shmem): it maps the POSIX shared memory object the source names and, paced to the stream rate, hands the analyzer the area's first fftw_frames*2 samples while squeezelite runs, silence while it does not.
func NewShmemInput ¶
func NewShmemInput(name string, channels, capacity int) (*ShmemInput, error)
NewShmemInput reads the shared memory object name ("/squeezelite-…"); channels is 1 or 2, capacity the analyzer's input size.
func (*ShmemInput) Drained ¶
func (s *ShmemInput) Drained() []float64
Drained hands over every sample read since the last call.
func (*ShmemInput) Start ¶
func (s *ShmemInput) Start() error
Start maps the area and begins reading. A missing object or a failed map is an error (libcava exits the process over them).
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source records the configured PulseAudio source as 16-bit PCM, mono or interleaved stereo, on the shell's native client, the counterpart of libcava's pulse input: samples are handed over as raw int16 values, and a pending buffer that would overflow is discarded whole, as cava's input buffering does.
func NewSource ¶
NewSource records source ("auto" or empty: the default sink's monitor, following default changes; otherwise a device by name, a sink recording its monitor). channels is 1 or 2, capacity the analyzer's input size in interleaved samples.