analysis

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 11 Imported by: ? modules, 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 analysis computes information about a file that playback does not need, starting with the waveform a seek bar draws.

It never touches the playback ring: the ring is forward-only and feeding the device, so reading it would steal audio. Waveform opens its own decoder and runs synchronously on the caller's goroutine, which is why every entry point takes a context a scrubbing UI can cancel.

Index

Constants

This section is empty.

Variables

View Source
var ErrBuckets = errors.New("analysis: Buckets must be positive")

ErrBuckets means Options.Buckets was not positive. It is a caller bug rather than a decode failure, so it is returned before any file is touched.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Min, Max, RMS float32
}

Bucket is one column of a waveform: the extremes and the RMS of the mono downmix over a slice of frames.

type Options

type Options struct {
	// Buckets is the requested column count. It must be positive.
	Buckets int

	// OnProgress reports how far the decode has come, in frames. It is called
	// once with zero before the first read and after every chunk. It runs on
	// the calling goroutine, so a UI must keep it cheap.
	OnProgress func(done, total int64)

	// CacheDir overrides the on-disk cache directory. Empty selects
	// <user cache dir>/molo/waveform. Tests set it so they never touch the
	// real cache.
	CacheDir string

	// NoCache skips both reading and writing the cache.
	NoCache bool
}

Options controls one waveform pass. Buckets is required; the rest have sensible zero values.

type Result

type Result struct {
	Buckets []Bucket
	Format  core.FrameFormat
	Frames  int64
}

Result is a decoded waveform. It is named Result rather than Waveform because a type and the function that builds it cannot share one identifier.

func Waveform

func Waveform(ctx context.Context, path string, opts Options) (*Result, error)

Waveform decodes path and reduces it to a fixed number of buckets.

The total frame count is read from the decoder. A decoder that does not know its length (-1) is streamed once to count and once to reduce, so memory stays bounded instead of trusting a total that is not there.

Jump to

Keyboard shortcuts

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