Version: v1.0.7 Latest Latest

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

Go to latest
Published: Jan 27, 2021 License: Unlicense Imports: 9 Imported by: 8



Package meta implements access to FLAC metadata blocks.

A brief introduction of the FLAC metadata format [1] follows. FLAC metadata is stored in blocks; each block contains a header followed by a body. The block header describes the type of the block body, its length in bytes, and specifies if the block was the last metadata block in a FLAC stream. The contents of the block body depends on the type specified in the block header.

At the time of this writing, the FLAC metadata format defines seven different metadata block types, namely:

* StreamInfo [2]
* Padding [3]
* Application [4]
* SeekTable [5]
* VorbisComment [6]
* CueSheet [7]
* Picture [8]

Please refer to their respective documentation for further information.




View Source
const PlaceholderPoint = 0xFFFFFFFFFFFFFFFF

PlaceholderPoint represent the sample number used to specify placeholder seek points.


View Source
var (
	ErrReservedType = errors.New("meta.Block.Parse: reserved block type")
	ErrInvalidType  = errors.New("meta.Block.Parse: invalid block type")

Errors returned by Parse.

View Source
var (
	ErrInvalidPadding = errors.New("invalid padding")

Errors returned by zeros.Read.


This section is empty.


type Application

type Application struct {
	// Registered application ID.
	// ref:
	ID uint32
	// Application data.
	Data []byte

Application contains third party application specific data.


type Block

type Block struct {
	// Metadata block header.
	// Metadata block body of type *StreamInfo, *Application, ... etc. Body is
	// initially nil, and gets populated by a call to Block.Parse.
	Body interface{}
	// contains filtered or unexported fields

A Block contains the header and body of a metadata block.


func New

func New(r io.Reader) (block *Block, err error)

New creates a new Block for accessing the metadata of r. It reads and parses a metadata block header.

Call Block.Parse to parse the metadata block body, and call Block.Skip to ignore it.

func Parse

func Parse(r io.Reader) (block *Block, err error)

Parse reads and parses the header and body of a metadata block. Use New for additional granularity.

func (*Block) Parse

func (block *Block) Parse() error

Parse reads and parses the metadata block body.

func (*Block) Skip

func (block *Block) Skip() error

Skip ignores the contents of the metadata block body.

type CueSheet

type CueSheet struct {
	// Media catalog number.
	MCN string
	// Number of lead-in samples. This field only has meaning for CD-DA cue
	// sheets; for other uses it should be 0. Refer to the spec for additional
	// information.
	NLeadInSamples uint64
	// Specifies if the cue sheet corresponds to a Compact Disc.
	IsCompactDisc bool
	// One or more tracks. The last track of a cue sheet is always the lead-out
	// track.
	Tracks []CueSheetTrack

A CueSheet describes how tracks are laid out within a FLAC stream.


type CueSheetTrack

type CueSheetTrack struct {
	// Track offset in samples, relative to the beginning of the FLAC audio
	// stream.
	Offset uint64
	// Track number; never 0, always unique.
	Num uint8
	// International Standard Recording Code; empty string if not present.
	// ref:
	ISRC string
	// Specifies if the track contains audio or data.
	IsAudio bool
	// Specifies if the track has been recorded with pre-emphasis
	HasPreEmphasis bool
	// Every track has one or more track index points, except for the lead-out
	// track which has zero. Each index point specifies a position within the
	// track.
	Indicies []CueSheetTrackIndex

CueSheetTrack contains the start offset of a track and other track specific metadata.

type CueSheetTrackIndex

type CueSheetTrackIndex struct {
	// Index point offset in samples, relative to the track offset.
	Offset uint64
	// Index point number; subsequently incrementing by 1 and always unique
	// within a track.
	Num uint8

A CueSheetTrackIndex specifies a position within a track.

type Header struct {
	// Metadata block body type.
	Type Type
	// Length of body data in bytes.
	Length int64
	// IsLast specifies if the block is the last metadata block.
	IsLast bool

A Header contains information about the type and length of a metadata block.


type Picture

type Picture struct {
	// Picture type according to the ID3v2 APIC frame:
	//     0: Other
	//     1: 32x32 pixels 'file icon' (PNG only)
	//     2: Other file icon
	//     3: Cover (front)
	//     4: Cover (back)
	//     5: Leaflet page
	//     6: Media (e.g. label side of CD)
	//     7: Lead artist/lead performer/soloist
	//     8: Artist/performer
	//     9: Conductor
	//    10: Band/Orchestra
	//    11: Composer
	//    12: Lyricist/text writer
	//    13: Recording Location
	//    14: During recording
	//    15: During performance
	//    16: Movie/video screen capture
	//    17: A bright coloured fish
	//    18: Illustration
	//    19: Band/artist logotype
	//    20: Publisher/Studio logotype
	// ref:
	Type uint32
	// MIME type string. The MIME type "-->" specifies that the picture data is
	// to be interpreted as an URL instead of image data.
	MIME string
	// Description of the picture.
	Desc string
	// Image dimensions.
	Width, Height uint32
	// Color depth in bits-per-pixel.
	Depth uint32
	// Number of colors in palette; 0 for non-indexed images.
	NPalColors uint32
	// Image data.
	Data []byte

Picture contains the image data of an embedded picture.


type SeekPoint

type SeekPoint struct {
	// Sample number of the first sample in the target frame, or
	// 0xFFFFFFFFFFFFFFFF for a placeholder point.
	SampleNum uint64
	// Offset in bytes from the first byte of the first frame header to the first
	// byte of the target frame's header.
	Offset uint64
	// Number of samples in the target frame.
	NSamples uint16

A SeekPoint specifies the byte offset and initial sample number of a given target frame.


type SeekTable

type SeekTable struct {
	// One or more seek points.
	Points []SeekPoint

SeekTable contains one or more pre-calculated audio frame seek points.


type StreamInfo

type StreamInfo struct {
	// Minimum block size (in samples) used in the stream; between 16 and 65535
	// samples.
	BlockSizeMin uint16
	// Maximum block size (in samples) used in the stream; between 16 and 65535
	// samples.
	BlockSizeMax uint16
	// Minimum frame size in bytes; a 0 value implies unknown.
	FrameSizeMin uint32
	// Maximum frame size in bytes; a 0 value implies unknown.
	FrameSizeMax uint32
	// Sample rate in Hz; between 1 and 655350 Hz.
	SampleRate uint32
	// Number of channels; between 1 and 8 channels.
	NChannels uint8
	// Sample size in bits-per-sample; between 4 and 32 bits.
	BitsPerSample uint8
	// Total number of inter-channel samples in the stream. One second of 44.1
	// KHz audio will have 44100 samples regardless of the number of channels. A
	// 0 value implies unknown.
	NSamples uint64
	// MD5 checksum of the unencoded audio data.
	MD5sum [md5.Size]uint8

StreamInfo contains the basic properties of a FLAC audio stream, such as its sample rate and channel count. It is the only mandatory metadata block and must be present as the first metadata block of a FLAC stream.


type Type

type Type uint8

Type represents the type of a metadata block body.

const (
	TypeStreamInfo    Type = 0
	TypePadding       Type = 1
	TypeApplication   Type = 2
	TypeSeekTable     Type = 3
	TypeVorbisComment Type = 4
	TypeCueSheet      Type = 5
	TypePicture       Type = 6

Metadata block body types.

func (Type) String

func (t Type) String() string

type VorbisComment

type VorbisComment struct {
	// Vendor name.
	Vendor string
	// A list of tags, each represented by a name-value pair.
	Tags [][2]string

VorbisComment contains a list of name-value pairs.


Jump to

Keyboard shortcuts

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