cava

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Silent added in v0.2.0

func Silent(samples []float64) bool

Silent reports whether every sample is zero; no samples are silent.

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

func NewFifoInput(path string, channels, capacity int) (*FifoInput, error)

NewFifoInput reads path; channels is 1 or 2, capacity the analyzer's input size in interleaved samples.

func (*FifoInput) Drained

func (f *FifoInput) Drained(dst []float64) []float64

Drained hands over every sample read since the last call, in place of dst's contents.

func (*FifoInput) NotifySound added in v0.2.0

func (f *FifoInput) NotifySound(fn func())

NotifySound implements Input.

func (*FifoInput) Start

func (f *FifoInput) Start() error

Start begins reading on a goroutine (libcava's input thread).

func (*FifoInput) Stop

func (f *FifoInput) Stop()

Stop ends the reader.

type Input

type Input interface {
	Start() error
	Drained(dst []float64) []float64
	NotifySound(fn func())
	Stop()
}

Input is what the analyzer reads from: a capture started and stopped, its samples drained each frame into the caller's buffer. NotifySound calls fn once, off the loop, when a non-zero sample next arrives; until then silence is dropped, so a parked analyzer wakes for sound and nothing else.

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) Channels

func (p *Plan) Channels() int

Channels is the plan's channel count, 1 or 2.

func (*Plan) Execute

func (p *Plan) Execute(dst, samples []float64) []float64

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 writes the bar heights, one per bar per channel (the left bars, then the right), into dst, grown when it is short, and returns it: a caller passing the previous frame's slice back analyzes without allocating.

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.

func (*Plan) InputSize

func (p *Plan) InputSize() int

InputSize is the sample ring's length, interleaved samples: the most one Execute can use, and so the capture backlog cava keeps before discarding.

func (*Plan) Peaks

func (p *Plan) Peaks() []float64

Peaks reports the current per-bar peak values in Execute's order, the markers the peaks draw style renders.

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(dst []float64) []float64

Drained hands over every sample read since the last call, in place of dst's contents.

func (*ShmemInput) NotifySound added in v0.2.0

func (s *ShmemInput) NotifySound(fn func())

NotifySound implements Input.

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).

func (*ShmemInput) Stop

func (s *ShmemInput) Stop()

Stop ends the reader and unmaps the area.

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

func NewSource(capturer Capturer, source string, channels, capacity int) (*Source, error)

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.

func (*Source) Drained

func (s *Source) Drained(dst []float64) []float64

Drained hands over every sample captured since the last call, in place of dst's contents.

func (*Source) NotifySound added in v0.2.0

func (s *Source) NotifySound(fn func())

NotifySound implements Input.

func (*Source) Start

func (s *Source) Start() error

Start opens the record stream.

func (*Source) Stop

func (s *Source) Stop()

Stop closes the record stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL