mp3

package
v0.0.0-...-c5379f9 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 9 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

View Source
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}
)
View Source
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

func SeemsValid(r io.Reader) bool

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

type Decoder struct {
	NbrFrames int

	ID3v2tag *id3v2.Tag
	// contains filtered or unexported fields
}

Decoder operates on a reader and extracts important information See http://www.mp3-converter.com/mp3codec/mp3_anatomy.htm

func New

func New(r io.Reader) *Decoder

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

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

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

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

func (*Decoder) Next

func (d *Decoder) Next(f *Frame) error

Next decodes the next frame into the provided frame structure.

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) CRC

func (f *Frame) CRC() uint16

CRC returns the CRC word stored in this frame

func (*Frame) Duration

func (f *Frame) Duration() time.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

func (*Frame) String

func (f *Frame) String() string

Frame returns a string describing this frame, header and side info

type FrameBitRate

type FrameBitRate int

FrameBitRate is the bit rate from the frame header

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
)

Directories

Path Synopsis
cmd
validator
this is a simple tool to validate the mp3 files in a folder
this is a simple tool to validate the mp3 files in a folder
id3v1 is a package allowing the extraction of id3v1 tags.
id3v1 is a package allowing the extraction of id3v1 tags.

Jump to

Keyboard shortcuts

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