Documentation ¶
Overview ¶
DEPRECATED PACKAGE, see github.com/mattetti/audio/wav
Index ¶
- type Clip
- type Decoder
- func (d *Decoder) DecodeRawPCM(chunk *riff.Chunk) ([][]int, error)
- func (d *Decoder) Duration() (time.Duration, error)
- func (d *Decoder) Frames() (info *Info, frames audio.Frames, err error)
- func (d *Decoder) Info() (*Info, error)
- func (d *Decoder) Parse(ch chan *riff.Chunk) error
- func (d *Decoder) ReadFrames() (info *Info, sndDataFrames [][]int, err error)
- type Encoder
- type Info
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) Read ¶
Read reads frames into the passed buffer and returns the number of full frames read.
func (*Clip) ReadPCM ¶
ReadPCM reads up to n frames from the clip. The frames as well as the number of frames/items read are returned.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder handles the decoding of wav files.
func NewDecoder ¶
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 ¶
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 ¶
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) Info ¶
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 ¶
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
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.
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