Documentation ¶
Overview ¶
mp3 is a package used to access mp3 information See: http://sea-mist.se/fou/cuppsats.nsf/all/857e49b9bfa2d753c125722700157b97/$file/Thesis%20report-%20MP3%20Decoder.pdf Uses some code from https://github.com/tcolgate/mp3 under MIT license Tristan Colgate-McFarlane and badgerodon
Index ¶
- Variables
- func SeemsValid(r io.Reader) bool
- type Decoder
- type Frame
- type FrameBitRate
- type FrameChannelMode
- type FrameEmphasis
- type FrameHeader
- func (h FrameHeader) BitRate() FrameBitRate
- func (h FrameHeader) ChannelMode() FrameChannelMode
- func (h FrameHeader) CopyRight() bool
- func (h FrameHeader) Emphasis() FrameEmphasis
- func (h FrameHeader) IsValid() bool
- func (h FrameHeader) Layer() FrameLayer
- func (h FrameHeader) Original() bool
- func (h FrameHeader) Pad() bool
- func (h FrameHeader) Private() bool
- func (h FrameHeader) Protection() bool
- func (h FrameHeader) SampleRate() FrameSampleRate
- func (h FrameHeader) Samples() int
- func (h FrameHeader) Size() int64
- func (h FrameHeader) String() string
- func (h FrameHeader) Version() FrameVersion
- type FrameLayer
- type FrameSampleRate
- type FrameSideInfo
- type FrameVersion
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ID31HBytes are the 2 bytes starting the ID3 v1 tag ID31HBytes = []byte{0xFF, 0xFB} // XingTAGID Xing vbr tag XingTAGID = []byte{0x58, 0x69, 0x6E, 0x67} // InfoTAGID Info cbr tag InfoTAGID = []byte{0x49, 0x6E, 0x66, 0x6F} )
var ( // ErrNoSyncBits implies we could not find a valid frame header sync bit before EOF ErrNoSyncBits = errors.New("EOF before sync bits found") // ErrPrematureEOF indicates that the filed ended before a complete frame could be read ErrPrematureEOF = errors.New("EOF mid stream") ErrInvalidHeader = errors.New("invalid header") // ErrInvalidBitrate indicates that the header information did not contain a recognized bitrate ErrInvalidBitrate FrameBitRate = -1 // ErrInvalidSampleRate indicates that no samplerate could be found for the frame header provided ErrInvalidSampleRate = FrameSampleRate(-1) )
Functions ¶
func SeemsValid ¶
SeemsValid checks if the mp3 file looks like a valid mp3 file by looking at the first few bytes. The data can be corrupt but at least the header seems alright. It is the caller's responsibility to rewind/close the reader when done.
Types ¶
type Decoder ¶
Decoder operates on a reader and extracts important information See http://www.mp3-converter.com/mp3codec/mp3_anatomy.htm
func NewDecoder ¶
NewDecoder creates a new reader reading the given reader and parsing its data. It is the caller's responsibility to call Close on the reader when done.
func (*Decoder) Duration ¶
Duration returns the time duration for the current mp3 file The entire reader will be consumed, the consumer might want to rewind the reader if they want to read more from the feed. Note that this is an estimated duration based on how the frames look. An invalid file might have a duration.
Example ¶
package main import ( "fmt" "os" "github.com/mattetti/audio/mp3" ) func main() { f, err := os.Open("fixtures/HousyStab.mp3") if err != nil { panic(err) } d := mp3.New(f) dur, err := d.Duration() if err != nil { panic(err) } fmt.Println(dur) }
Output: 16.483264688s
type Frame ¶
type Frame struct { // SkippedBytes is the amount of bytes we had to skip before getting to the frame SkippedBytes int // Counter gets incremented if the same frame is reused to parse a file Counter int Header FrameHeader // contains filtered or unexported fields }
func (*Frame) Duration ¶
Duration calculates the time duration of this frame based on the samplerate and number of samples
func (*Frame) SideInfo ¶
func (f *Frame) SideInfo() FrameSideInfo
SideInfo returns the side info for this frame
type FrameChannelMode ¶
type FrameChannelMode byte
FrameChannelMode is the Channel mode from the frame header
const ( Stereo FrameChannelMode = iota JointStereo DualChannel SingleChannel )
type FrameEmphasis ¶
type FrameEmphasis byte
FrameEmphasis is the Emphasis value from the frame header
const ( EmphNone FrameEmphasis = iota Emph5015 EmphReserved EmphCCITJ17 )
type FrameHeader ¶
type FrameHeader []byte
FrameHeader represents the entire header of a frame
func (FrameHeader) BitRate ¶
func (h FrameHeader) BitRate() FrameBitRate
BitRate returns the calculated bit rate from the header
func (FrameHeader) ChannelMode ¶
func (h FrameHeader) ChannelMode() FrameChannelMode
ChannelMode returns the channel mode from the header
func (FrameHeader) CopyRight ¶
func (h FrameHeader) CopyRight() bool
CopyRight returns the CopyRight bit from the header
func (FrameHeader) Emphasis ¶
func (h FrameHeader) Emphasis() FrameEmphasis
Emphasis returns the Emphasis from the header
func (FrameHeader) IsValid ¶
func (h FrameHeader) IsValid() bool
IsValid tests the basic validity of the frame header by checking the sync word
func (FrameHeader) Layer ¶
func (h FrameHeader) Layer() FrameLayer
Layer returns the MPEG layer from the header
func (FrameHeader) Original ¶
func (h FrameHeader) Original() bool
Original returns the "original content" bit from the header
func (FrameHeader) Pad ¶
func (h FrameHeader) Pad() bool
Pad returns the pad bit, indicating if there are extra samples in this frame to make up the correct bitrate
func (FrameHeader) Private ¶
func (h FrameHeader) Private() bool
Private retrusn the Private bit from the header
func (FrameHeader) Protection ¶
func (h FrameHeader) Protection() bool
Protection indicates if there is a CRC present after the header (before the side data)
func (FrameHeader) SampleRate ¶
func (h FrameHeader) SampleRate() FrameSampleRate
SampleRate returns the samplerate from the header
func (FrameHeader) Samples ¶
func (h FrameHeader) Samples() int
Samples is the number of samples contained in this frame
func (FrameHeader) Size ¶
func (h FrameHeader) Size() int64
func (FrameHeader) String ¶
func (h FrameHeader) String() string
String dumps the frame header as a string for display purposes
func (FrameHeader) Version ¶
func (h FrameHeader) Version() FrameVersion
Version returns the MPEG version from the header
type FrameLayer ¶
type FrameLayer byte
FrameLayer is the MPEG layer given in the frame header
const ( LayerReserved FrameLayer = iota Layer3 Layer2 Layer1 )
type FrameSampleRate ¶
type FrameSampleRate int
FrameSampleRate is the sample rate from teh frame header
type FrameSideInfo ¶
type FrameSideInfo []byte
FrameSideInfo holds the SideInfo bytes from the frame
func (FrameSideInfo) NDataBegin ¶
func (i FrameSideInfo) NDataBegin() uint16
NDataBegin is the number of bytes before the frame header at which the sample data begins 0 indicates that the data begins after the side channel information. This data is the data from the "bit resevoir" and can be up to 511 bytes
type FrameVersion ¶
type FrameVersion byte
FrameVersion is the MPEG version given in the frame header
const ( MPEG25 FrameVersion = iota MPEGReserved MPEG2 MPEG1 )