wav

package
v0.0.0-...-cabcf74 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

DEPRECATED PACKAGE, see github.com/mattetti/audio/wav

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clip

type Clip struct {
	// contains filtered or unexported fields
}

Clip represents the PCM data contained in the aiff stream.

func Decode

func Decode(r io.ReadSeeker) (*Clip, error)

Decode reads from a Read Seeker and converts the input to a PCM clip output.

func (*Clip) FrameInfo

func (c *Clip) FrameInfo() audio.FrameInfo

func (*Clip) Read

func (c *Clip) Read(buf []byte) (n int, err error)

Read reads frames into the passed buffer and returns the number of full frames read.

func (*Clip) ReadPCM

func (c *Clip) ReadPCM(nFrames int) (frames audio.Frames, n int, err error)

ReadPCM reads up to n frames from the clip. The frames as well as the number of frames/items read are returned.

func (*Clip) Seek

func (c *Clip) Seek(offset int64, whence int) (int64, error)

Seek seeks into the clip TODO(mattetti): Seek offset should be in frames, not bytes

func (*Clip) Size

func (c *Clip) Size() int64

Size returns the total number of frames available in this clip.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder handles the decoding of wav files.

func NewDecoder

func NewDecoder(r io.Reader, c chan *audio.Chunk) *Decoder

New creates a decoder for the passed wav reader. Note that the reader doesn't get rewinded as the container is processed.

func (*Decoder) DecodeRawPCM

func (d *Decoder) DecodeRawPCM(chunk *riff.Chunk) ([][]int, error)

DecodeRawPCM converts a 'data' wav RAW PCM chunk into frames of samples. Each frame can contain one or more channels with their own value.

func (*Decoder) Duration

func (d *Decoder) Duration() (time.Duration, error)

Duration returns the time duration of the decoded wav file.

Example
f, err := os.Open("fixtures/kick.wav")
if err != nil {
	log.Fatal(err)
}
defer f.Close()
dur, err := NewDecoder(f, nil).Duration()
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%s duration: %s\n", f.Name(), dur)
Output:

fixtures/kick.wav duration: 204.172335ms

func (*Decoder) Frames

func (d *Decoder) Frames() (info *Info, frames audio.Frames, err error)

func (*Decoder) Info

func (d *Decoder) Info() (*Info, error)

Info returns the generic file information. Note that the information is cached can be called multiple times safely.

Example
f, err := os.Open("fixtures/kick.wav")
if err != nil {
	log.Fatal(err)
}
info, err := NewDecoder(f, nil).Info()
if err != nil {
	log.Fatal(err)
}
f.Close()
fmt.Println(info)
Output:

22050 Hz @ 16 bits, 1 channel(s), 44100 avg bytes/sec, duration: 204.172335ms

func (*Decoder) Parse

func (d *Decoder) Parse(ch chan *riff.Chunk) error

Parse reads the content of the file, populates the decoder fields and pass the chunks to the provided channel. Note that the channel consumer needs to call Done() on the chunk to release the wait group and deain the chunk if needed.

Example
f, err := os.Open("fixtures/bass.wav")
if err != nil {
	log.Fatal(err)
}
d := NewDecoder(f, nil)
if err != nil {
	log.Fatal(err)
}
defer f.Close()

ch := make(chan *riff.Chunk)

go func() {
	if err := d.Parse(ch); err != nil {
		log.Fatal(err)
	}
}()

for chunk := range ch {
	fmt.Println(string(chunk.ID[:]))
	// without this, the goroutines will deadlock
	chunk.Done()
}
Output:

data

func (*Decoder) ReadFrames

func (d *Decoder) ReadFrames() (info *Info, sndDataFrames [][]int, err error)

ReadFrames decodes the file and returns its info and the audio frames

type Encoder

type Encoder struct {
	SampleRate     int
	BitsPerSample  int
	NumChannels    int
	Frames         [][]int
	WavAudioFormat int

	WrittenBytes int
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(w io.WriteSeeker, nfo *Info) *Encoder

NewEncoder creates a new encoder to create a new aiff file. Don't forget to add Frames to the encoder before writing.

func (*Encoder) Add

func (e *Encoder) Add(src interface{}) error

Add serializes and adds the passed value using little endian

func (*Encoder) AddBE

func (e *Encoder) AddBE(src interface{}) error

AddBE serializes and adds the passed value using big endian

func (*Encoder) Write

func (e *Encoder) Write() error

type Info

type Info struct {
	// NumChannels is the number of channels represented in the waveform data:
	// 1 for mono or 2 for stereo.
	// Audio: Mono = 1, Stereo = 2, etc.
	// The EBU has defined the Multi-channel Broadcast Wave
	// Format [4] where more than two channels of audio are required.
	NumChannels uint16
	// SampleRate The sampling rate (in sample per second) at which each channel should be played.
	// 8000, 44100, etc.
	SampleRate uint32
	// AvgBytesPerSec The average number of bytes per second at which the waveform data should be
	// transferred. Playback software can estimate the buffer size using this value.
	// SampleRate * NumChannels * BitsPerSample/8
	AvgBytesPerSec uint32
	// BitsPerSample 8, 16, 24...
	// Only available for PCM
	// The <nBitsPerSample> field specifies the number of bits of data used to represent each sample of
	// each channel. If there are multiple channels, the sample size is the same for each channel.
	BitsPerSample uint16
	// Duration of the audio content
	Duration time.Duration
	// A number indicating the WAVE format category of the file. The content of the
	// <format-specific-fields> portion of the ‘fmt’ chunk, and the interpretation of
	// the waveform data, depend on this value.
	// PCM = 1 (i.e. Linear quantization) Values other than 1 indicate some form of compression.
	WavAudioFormat uint16
}

Info represents the metadata of the wav file

func (*Info) String

func (i *Info) String() string

String implements the Stringer interface

Directories

Path Synopsis
wavinfo is a command line tool extracting metadata information from a wav file.
wavinfo is a command line tool extracting metadata information from a wav file.

Jump to

Keyboard shortcuts

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