wav

package
v1.17.13 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 8 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 wav reads WAV files (SPEC §28.3): RIFF files with linear PCM of 8, 16, 24 or 32 bits (also in the WAVE_FORMAT_EXTENSIBLE form) or IEEE float of 32 or 64 bits, with 1 to 8 channels. The samples come out as float32, ready for audio.Stream.Put. Other codecs (ADPCM, Ogg Vorbis, MP3, Opus) are not in Glutter: an app decodes them itself and puts the samples. Flutter has no audio.

It follows the subset of src/audio/SDL_wave.c of SDL 3 (zlib license, third_party/sdl/LICENSE) that the format list above is, translated to Go and changed: the chunks are read one after another, those that are not "fmt " and "data" are skipped, and a data chunk that is longer than the file (a file written to a pipe has the size 0 or 0xFFFFFFFF) takes what there is.

Flutter: no counterpart

Index

Constants

View Source
const (
	// TagInvalid is the tag of the error of a file that is not a WAV file of the subset this package reads: a message says what is
	// wrong (the magic, a chunk, the format, the rate, the channels, the size of the data).
	//
	// Flutter: no counterpart
	TagInvalid = "WAVInvalid"
	// TagReadFailed is the tag of the error of a reader that failed, or whose context ended, while the file was read.
	//
	// Flutter: no counterpart
	TagReadFailed = "WAVReadFailed"
)

The tags of the errors of this package (SPEC §28.7).

Variables

This section is empty.

Functions

This section is empty.

Types

type Audio

type Audio struct {
	// Format is the sample rate and the number of channels.
	Format audio.Format
	// Samples are the interleaved samples from -1 to 1, a whole number of frames.
	Samples []float32
	// BitsPerSample is the size of the samples in the file, and Float says that they were IEEE float.
	BitsPerSample int
	Float         bool
}

Audio is a decoded WAV file.

Flutter: no counterpart

func Decode

func Decode(ctx context.Context, r io.Reader) (*Audio, error)

Decode reads a WAV file from r. It fails with WAVInvalid when the file is not a WAV file of the subset above (with a message that says what is wrong), with WAVReadFailed when r fails or ctx ends, and the data it did read is dropped.

Flutter: no counterpart

func DecodeBytes

func DecodeBytes(data []byte) (*Audio, error)

DecodeBytes reads a WAV file that is in memory. The errors are those of Decode (it does no I/O, so it never fails with WAVReadFailed).

Flutter: no counterpart

func (*Audio) Duration

func (a *Audio) Duration() time.Duration

Duration is how long the file plays at its own rate.

Flutter: no counterpart

func (*Audio) Frames

func (a *Audio) Frames() int

Frames is the number of frames of the file.

Flutter: no counterpart

Jump to

Keyboard shortcuts

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