meta

package
v0.0.0-...-6217932 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2016 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package meta contains functions for parsing FLAC metadata.

Index

Constants

View Source
const PlaceholderPoint = 0xFFFFFFFFFFFFFFFF

PlaceholderPoint is the sample number used for placeholder points. For placeholder points, the second and third field values in the SeekPoint structure are undefined.

Variables

View Source
var RegisteredApplications = map[string]string{
	"ATCH": "FlacFile",
	"BSOL": "beSolo",
	"BUGS": "Bugs Player",
	"Cues": "GoldWave cue points (specification)",
	"Fica": "CUE Splitter",
	"Ftol": "flac-tools",
	"MOTB": "MOTB MetaCzar",
	"MPSE": "MP3 Stream Editor",
	"MuML": "MusicML: Music Metadata Language",
	"RIFF": "Sound Devices RIFF chunk storage",
	"SFFL": "Sound Font FLAC",
	"SONY": "Sony Creative Software",
	"SQEZ": "flacsqueeze",
	"TtWv": "TwistedWave",
	"UITS": "UITS Embedding tools",
	"aiff": "FLAC AIFF chunk storage",
	"imag": "flac-image application for storing arbitrary files in APPLICATION metadata blocks",
	"peem": "Parseable Embedded Extensible Metadata (specification)",
	"qfst": "QFLAC Studio",
	"riff": "FLAC RIFF chunk storage",
	"tune": "TagTuner",
	"xbat": "XBAT",
	"xmcd": "xmcd",
}

RegisteredApplications maps from a registered application ID to a description.

ref: http://flac.sourceforge.net/id.html

Functions

func VerifyPadding

func VerifyPadding(r io.Reader) (err error)

VerifyPadding verifies that the padding metadata block only contains 0 bits. The provided io.Reader should limit the amount of data that can be read to header.Length bytes.

Types

type Application

type Application struct {
	// Registered application ID.
	ID string
	// Application data.
	Data []byte
}

An Application metadata block is for use by third-party applications. The only mandatory field is a 32-bit identifier. This ID is granted upon request to an application by the FLAC maintainers. The remainder of the block is defined by the registered application.

func NewApplication

func NewApplication(r io.Reader) (app *Application, err error)

NewApplication parses and returns a new Application metadata block. The provided io.Reader should limit the amount of data that can be read to header.Length bytes.

Application format (pseudo code):

// ref: http://flac.sourceforge.net/format.html#metadata_block_application

type METADATA_BLOCK_APPLICATION struct {
   ID   uint32
   Data [header.Length-4]byte
}

type Block

type Block struct {
	// Metadata block header.
	Header *BlockHeader
	// Metadata block body: StreamInfo, Application, SeekTable, etc.
	Body interface{}
}

A Block is a metadata block, consisting of a block header and a body.

func NewBlock

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

NewBlock parses and returns a new metadata block, which consists of a header and body.

type BlockHeader

type BlockHeader struct {
	// IsLast is true if this block is the last metadata block before the audio
	// blocks, and false otherwise.
	IsLast bool
	// Block types:
	//    0: Streaminfo
	//    1: Padding
	//    2: Application
	//    3: Seektable
	//    4: Vorbis_comment
	//    5: Cuesheet
	//    6: Picture
	//    7-126: reserved
	//    127: invalid, to avoid confusion with a frame sync code
	BlockType BlockType
	// Length (in bytes) of metadata to follow (does not include the size of the
	// BlockHeader).
	Length int
}

A BlockHeader contains type and length about a metadata block.

func NewBlockHeader

func NewBlockHeader(r io.Reader) (h *BlockHeader, err error)

NewBlockHeader parses and returns a new metadata block header.

Block header format (pseudo code):

// ref: http://flac.sourceforge.net/format.html#metadata_block_header

type METADATA_BLOCK_HEADER struct {
   is_last    bool
   block_type uint7
   length     uint24
}

type BlockType

type BlockType uint8

BlockType is used to identify the metadata block type.

const (
	TypeStreamInfo BlockType = iota
	TypePadding
	TypeApplication
	TypeSeekTable
	TypeVorbisComment
	TypeCueSheet
	TypePicture
)

Metadata block types.

func (BlockType) String

func (t BlockType) String() string

type CueSheet

type CueSheet struct {
	// Media catalog number, in ASCII printable characters 0x20-0x7e. In general,
	// the media catalog number may be 0 to 128 bytes long; any unused characters
	// should be right-padded with NUL characters. For CD-DA, this is a thirteen
	// digit number, followed by 115 NUL bytes.
	MCN string
	// The number of lead-in samples. This field has meaning only for CD-DA
	// cuesheets; for other uses it should be 0. For CD-DA, the lead-in is the
	// TRACK 00 area where the table of contents is stored; more precisely, it is
	// the number of samples from the first sample of the media to the first
	// sample of the first index point of the first track. According to the Red
	// Book, the lead-in must be silence and CD grabbing software does not
	// usually store it; additionally, the lead-in must be at least two seconds
	// but may be longer. For these reasons the lead-in length is stored here so
	// that the absolute position of the first track can be computed. Note that
	// the lead-in stored here is the number of samples up to the first index
	// point of the first track, not necessarily to INDEX 01 of the first track;
	// even the first track may have INDEX 00 data.
	LeadInSampleCount uint64
	// true if the CUESHEET corresponds to a Compact Disc, else false.
	IsCompactDisc bool
	// The number of tracks. Must be at least 1 (because of the requisite
	// lead-out track). For CD-DA, this number must be no more than 100 (99
	// regular tracks and one lead-out track).
	TrackCount uint8
	// One or more tracks. A CUESHEET block is required to have a lead-out track;
	// it is always the last track in the CUESHEET. For CD-DA, the lead-out track
	// number must be 170 as specified by the Red Book, otherwise is must be 255.
	Tracks []CueSheetTrack
}

A CueSheet metadata block is for storing various information that can be used in a cue sheet. It supports track and index points, compatible with Red Book CD digital audio discs, as well as other CD-DA metadata such as media catalog number and track ISRCs. The CUESHEET block is especially useful for backing up CD-DA discs, but it can be used as a general purpose cueing mechanism for playback.

func NewCueSheet

func NewCueSheet(r io.Reader) (cs *CueSheet, err error)

NewCueSheet parses and returns a new CueSheet metadata block. The provided io.Reader should limit the amount of data that can be read to header.Length bytes.

Cue sheet format (pseudo code):

// ref: http://flac.sourceforge.net/format.html#metadata_block_cuesheet

type METADATA_BLOCK_CUESHEET struct {
   mcn                  [128]byte
   lead_in_sample_count uint64
   is_compact_disc      bool
   _                    uint7
   _                    [258]byte
   track_count          uint8
   tracks               [track_count]track
}

type track struct {
   offset            uint64
   track_num         uint8
   isrc              [12]byte
   is_audio          bool
   has_pre_emphasis  bool
   _                 uint6
   _                 [13]byte
   track_index_count uint8
   track_indexes     [track_index_count]track_index
}

type track_index {
   offset          uint64
   index_point_num uint8
   _               [3]byte
}

type CueSheetTrack

type CueSheetTrack struct {
	// Track offset in samples, relative to the beginning of the FLAC audio
	// stream. It is the offset to the first index point of the track. (Note how
	// this differs from CD-DA, where the track's offset in the TOC is that of
	// the track's INDEX 01 even if there is an INDEX 00.) For CD-DA, the offset
	// must be evenly divisible by 588 samples (588 samples = 44100 samples/sec *
	// 1/75th of a sec).
	Offset uint64
	// Track number. A track number of 0 is not allowed to avoid conflicting with
	// the CD-DA spec, which reserves this for the lead-in. For CD-DA the number
	// must be 1-99, or 170 for the lead-out; for non-CD-DA, the track number
	// must for 255 for the lead-out. It is not required but encouraged to start
	// with track 1 and increase sequentially. Track numbers must be unique
	// within a CUESHEET.
	TrackNum uint8
	// Track ISRC. This is a 12-digit alphanumeric code. A value of 12 ASCII NUL
	// characters may be used to denote absence of an ISRC.
	ISRC string
	// The track type: true for audio, false for non-audio.
	IsAudio bool
	// The pre-emphasis flag: false for no pre-emphasis, true for pre-emphasis.
	// This corresponds to the CD-DA Q-channel control bit 5.
	HasPreEmphasis bool
	// The number of track index points. There must be at least one index in
	// every track in a CUESHEET except for the lead-out track, which must have
	// zero. For CD-DA, this number may be no more than 100.
	TrackIndexCount uint8
	// For all tracks except the lead-out track, one or more track index points.
	TrackIndexes []CueSheetTrackIndex
}

A CueSheetTrack contains information about a track within a CueSheet.

type CueSheetTrackIndex

type CueSheetTrackIndex struct {
	// Offset in samples, relative to the track offset, of the index point. For
	// CD-DA, the offset must be evenly divisible by 588 samples (588 samples =
	// 44100 samples/sec * 1/75th of a sec). Note that the offset is from the
	// beginning of the track, not the beginning of the audio data.
	Offset uint64
	// The index point number. For CD-DA, an index number of 0 corresponds to the
	// track pre-gap. The first index in a track must have a number of 0 or 1,
	// and subsequently, index numbers must increase by 1. Index numbers must be
	// unique within a track.
	IndexPointNum uint8
}

A CueSheetTrackIndex contains information about an index point in a track.

type Picture

type Picture struct {
	// The 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
	//
	// Others are reserved and should not be used. There may only be one each of
	// picture type 1 and 2 in a file.
	Type uint32
	// The MIME type string, in printable ASCII characters 0x20-0x7e. The MIME
	// type may also be --> to signify that the data part is a URL of the picture
	// instead of the picture data itself.
	MIME string
	// The description of the picture, in UTF-8.
	Desc string
	// The width of the picture in pixels.
	Width uint32
	// The height of the picture in pixels.
	Height uint32
	// The color depth of the picture in bits-per-pixel.
	ColorDepth uint32
	// For indexed-color pictures (e.g. GIF), the number of colors used, or 0 for
	// non-indexed pictures.
	ColorCount uint32
	// The binary picture data.
	Data []byte
}

A Picture metadata block is for storing pictures associated with the file, most commonly cover art from CDs. There may be more than one PICTURE block in a file.

func NewPicture

func NewPicture(r io.Reader) (pic *Picture, err error)

NewPicture parses and returns a new Picture metadata block. The provided io.Reader should limit the amount of data that can be read to header.Length bytes.

Picture format (pseudo code):

// ref: http://flac.sourceforge.net/format.html#metadata_block_picture

type METADATA_BLOCK_PICTURE struct {
   type        uint32
   mime_length uint32
   mime_string [mime_length]byte
   desc_length uint32
   desc_string [desc_length]byte
   width       uint32
   height      uint32
   color_depth uint32
   color_count uint32
   data_length uint32
   data        [data_length]byte
}

type SeekPoint

type SeekPoint struct {
	// Sample number of 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.
	SampleCount uint16
}

A SeekPoint specifies the offset of a sample.

type SeekTable

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

A SeekTable metadata block is an optional block for storing seek points. It is possible to seek to any given sample in a FLAC stream without a seek table, but the delay can be unpredictable since the bitrate may vary widely within a stream. By adding seek points to a stream, this delay can be significantly reduced. Each seek point takes 18 bytes, so 1% resolution within a stream adds less than 2k.

There can be only one SEEKTABLE in a stream, but the table can have any number of seek points. There is also a special 'placeholder' seekpoint which will be ignored by decoders but which can be used to reserve space for future seek point insertion.

func NewSeekTable

func NewSeekTable(r io.Reader) (st *SeekTable, err error)

NewSeekTable parses and returns a new SeekTable metadata block. The provided io.Reader should limit the amount of data that can be read to header.Length bytes.

Seek table format (pseudo code):

// ref: http://flac.sourceforge.net/format.html#metadata_block_seektable

type METADATA_BLOCK_SEEKTABLE struct {
   // The number of seek points is implied by the metadata header 'length'
   // field, i.e. equal to length / 18.
   points []point
}

type point struct {
   sample_num   uint64
   offset       uint64
   sample_count uint16
}

type StreamInfo

type StreamInfo struct {
	// The minimum block size (in samples) used in the stream.
	MinBlockSize uint16
	// The maximum block size (in samples) used in the stream.
	// (MinBlockSize == MaxBlockSize) implies a fixed-blocksize stream.
	MaxBlockSize uint16
	// The minimum frame size (in bytes) used in the stream. May be 0 to imply
	// the value is not known.
	MinFrameSize uint32
	// The maximum frame size (in bytes) used in the stream. May be 0 to imply
	// the value is not known.
	MaxFrameSize uint32
	// Sample rate in Hz. Though 20 bits are available, the maximum sample rate
	// is limited by the structure of frame headers to 655350Hz. Also, a value of
	// 0 is invalid.
	SampleRate uint32
	// Number of channels. FLAC supports from 1 to 8 channels.
	ChannelCount uint8
	// Bits per sample. FLAC supports from 4 to 32 bits per sample. Currently the
	// reference encoder and decoders only support up to 24 bits per sample.
	BitsPerSample uint8
	// Total samples in stream. 'Samples' means inter-channel sample, i.e. one
	// second of 44.1Khz audio will have 44100 samples regardless of the number
	// of channels. A value of zero here means the number of total samples is
	// unknown.
	SampleCount uint64
	// MD5 signature of the unencoded audio data. This allows the decoder to
	// determine if an error exists in the audio data even when the error does
	// not result in an invalid bitstream.
	MD5sum [16]byte
}

A StreamInfo metadata block has information about the entire stream. It must be present as the first metadata block in the stream.

func NewStreamInfo

func NewStreamInfo(r io.Reader) (si *StreamInfo, err error)

NewStreamInfo parses and returns a new StreamInfo metadata block. The provided io.Reader should limit the amount of data that can be read to header.Length bytes.

Stream info format (pseudo code):

// ref: http://flac.sourceforge.net/format.html#metadata_block_streaminfo

type METADATA_BLOCK_STREAMINFO struct {
   min_block_size  uint16
   max_block_size  uint16
   min_frame_size  uint24
   max_frame_size  uint24
   sample_rate     uint20
   channel_count   uint3 // (number of channels)-1.
   bits_per_sample uint5 // (bits per sample)-1.
   sample_count    uint36
   md5sum          [16]byte
}

type VorbisComment

type VorbisComment struct {
	Vendor  string
	Entries []VorbisEntry
}

A VorbisComment metadata block is for storing a list of human-readable name/value pairs. Values are encoded using UTF-8. It is an implementation of the Vorbis comment specification (without the framing bit). This is the only officially supported tagging mechanism in FLAC. There may be only one VORBIS_COMMENT block in a stream. In some external documentation, Vorbis comments are called FLAC tags to lessen confusion.

func NewVorbisComment

func NewVorbisComment(r io.Reader) (vc *VorbisComment, err error)

NewVorbisComment parses and returns a new VorbisComment metadata block. The provided io.Reader should limit the amount of data that can be read to header.Length bytes.

Vorbis comment format (pseudo code):

// ref: http://flac.sourceforge.net/format.html#metadata_block_vorbis_comment

type METADATA_BLOCK_VORBIS_COMMENT struct {
   vendor_length uint32
   vendor_string [vendor_length]byte
   comment_count uint32
   comments      [comment_count]comment
}

type comment struct {
   vector_length uint32
   // vector_string is a name/value pair. Example: "NAME=value".
   vector_string [length]byte
}

type VorbisEntry

type VorbisEntry struct {
	Name  string
	Value string
}

A VorbisEntry is a name/value pair.

Jump to

Keyboard shortcuts

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