mp3

package module
Version: v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 5 Imported by: 60

README

go-mp3

GoDoc

An MP3 decoder in pure Go based on PDMP3.

Slide at golang.tokyo #11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

A Decoder is a MP3-decoded stream.

Decoder decodes its underlying source on the fly.

func NewDecoder

func NewDecoder(r io.Reader) (*Decoder, error)

NewDecoder decodes the given io.Reader and returns a decoded stream.

The stream is always formatted as 16bit (little endian) 2 channels even if the source is single channel MP3. Thus, a sample always consists of 4 bytes.

func (*Decoder) Length

func (d *Decoder) Length() int64

Length returns the total size in bytes.

Length returns -1 when the total size is not available e.g. when the given source is not io.Seeker.

func (*Decoder) Read

func (d *Decoder) Read(buf []byte) (int, error)

Read is io.Reader's Read.

func (*Decoder) SampleRate

func (d *Decoder) SampleRate() int

SampleRate returns the sample rate like 44100.

Note that the sample rate is retrieved from the first frame.

func (*Decoder) Seek

func (d *Decoder) Seek(offset int64, whence int) (int64, error)

Seek is io.Seeker's Seek.

Seek returns an error when the underlying source is not io.Seeker.

Note that seek uses a byte offset but samples are aligned to 4 bytes (2 channels, 2 bytes each). Be careful to seek to an offset that is divisible by 4 if you want to read at full sample boundaries.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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