wav

package module
v0.0.0-...-ea4f266 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: BSD-2-Clause Imports: 8 Imported by: 0

README

wav

A simple Go library for reading PCM WAV audio files.

Usage

import "github.com/djfritz/wav"

w, err := wav.LoadFromFile("audio.wav")
if err != nil {
    // handle error
}

fmt.Println(w.Channels)      // number of channels
fmt.Println(w.Frequency)     // sample rate (e.g., 44100)
fmt.Println(w.BitsPerSample) // e.g., 16
fmt.Println(w.Length())      // duration
Loading from bytes
w, err := wav.Load(data)

Data

The PCM data is arranged as N many channels in the wav.Data field. Each channel has the same number of samples, and is stored as an int regardless of the bits per sample. You will have to scale the data using the BitsPerSample field.

License

BSD 2-Clause

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShort                 = errors.New("short buffer")
	ErrRIFF                  = errors.New("invalid RIFF header")
	ErrNotWav                = errors.New("not a wav file")
	ErrMissingFmt            = errors.New("missing format block")
	ErrInvalidFmtSize        = errors.New("invalid format size")
	ErrAudioFmt              = errors.New("invalid audio format, only PCM integer supported")
	ErrUnsupportedSampleSize = errors.New("unsupported sample size")
)

Functions

This section is empty.

Types

type WAV

type WAV struct {
	Size           int
	Channels       int
	Frequency      int
	BytesPerSecond int
	BytesPerBlock  int
	BitsPerSample  int
	Data           [][]int32
}

func Load

func Load(b []byte) (*WAV, error)

func LoadFromFile

func LoadFromFile(filename string) (*WAV, error)

func (*WAV) FloatData

func (w *WAV) FloatData() [][]float64

func (*WAV) Length

func (w *WAV) Length() time.Duration

func (*WAV) NumSamples

func (w *WAV) NumSamples() int

Jump to

Keyboard shortcuts

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