flac

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FIELD_TITLE Track/Work name
	FIELD_TITLE = "TITLE"
	// FIELD_VERSION The version field may be used to differentiate multiple versions of the same track title in a single collection. (e.g. remix info)
	FIELD_VERSION = "VERSION"
	// FIELD_ALBUM The collection name to which this track belongs
	FIELD_ALBUM = "ALBUM"
	// FIELD_TRACKNUMBER The track number of this piece if part of a specific larger collection or album
	FIELD_TRACKNUMBER = "TRACKNUMBER"
	// FIELD_ARTIST The artist generally considered responsible for the work. In popular music this is usually the performing band or singer. For classical music it would be the composer. For an audio book it would be the author of the original text.
	FIELD_ARTIST = "ARTIST"
	// FIELD_PERFORMER The artist(s) who performed the work. In classical music this would be the conductor, orchestra, soloists. In an audio book it would be the actor who did the reading. In popular music this is typically the same as the ARTIST and is omitted.
	FIELD_PERFORMER = "PERFORMER"
	// FIELD_COPYRIGHT Copyright attribution, e.g., '2001 Nobody's Band' or '1999 Jack Moffitt'
	FIELD_COPYRIGHT = "COPYRIGHT"
	// FIELD_LICENSE License information, eg, 'All Rights Reserved', 'Any Use Permitted', a URL to a license such as a Creative Commons license ("www.creativecommons.org/blahblah/license.html") or the EFF Open Audio License ('distributed under the terms of the Open Audio License. see http://www.eff.org/IP/Open_licenses/eff_oal.html for details'), etc.
	FIELD_LICENSE = "LICENSE"
	// FIELD_ORGANIZATION Name of the organization producing the track (i.e. the 'record label')
	FIELD_ORGANIZATION = "ORGANIZATION"
	// FIELD_DESCRIPTION A short text description of the contents
	FIELD_DESCRIPTION = "DESCRIPTION"
	// FIELD_GENRE A short text indication of music genre
	FIELD_GENRE = "GENRE"
	// FIELD_DATE Date the track was recorded
	FIELD_DATE = "DATE"
	// FIELD_LOCATION Location where track was recorded
	FIELD_LOCATION = "LOCATION"
	// FIELD_CONTACT Contact information for the creators or distributors of the track. This could be a URL, an email address, the physical address of the producing label.
	FIELD_CONTACT = "CONTACT"
	// FIELD_ISRC ISRC number for the track; see the ISRC intro page for more information on ISRC numbers.
	FIELD_ISRC = "ISRC"
)
View Source
const (
	// MIMEURL is the MIME string indicating that imgData is a URL pointing to the image
	MIMEURL = "-->"
)

Variables

View Source
var (
	ErrorNotVorbisComment = errors.New("not a vorbis comment metadata block")
	ErrorUnexpEof         = errors.New("unexpected end of stream")
	ErrorMalformedComment = errors.New("malformed comment")
	ErrorInvalidFieldName = errors.New("malformed field Name")
	// ErrorNotPictureMetadataBlock is returned if the metadata provided is not a picture block.
	ErrorNotPictureMetadataBlock = errors.New("not a picture metadata block")
	// ErrorUnsupportedMIME is returned if the provided image MIME type is unsupported.
	ErrorUnsupportedMIME = errors.New("unsupported MIME")
	// ErrorNoFLACHeader indicates that "fLaC" marker not found at the beginning of the file
	ErrorNoFLACHeader = errors.New("fLaC head incorrect")
	// ErrorNoStreamInfo indicates that StreamInfo Metablock not present or is not the first Metablock
	ErrorNoStreamInfo = errors.New("stream info not present")
	// ErrorStreamInfoEarlyEOF indicates that an unexpected EOF is hit while reading StreamInfo Metablock
	ErrorStreamInfoEarlyEOF = errors.New("unexpected end of stream while reading stream info")
	// ErrorNoSyncCode indicates that the frames are malformed as the sync code is not present after the last Metablock
	ErrorNoSyncCode = errors.New("frames do not begin with sync code")
)

Functions

This section is empty.

Types

type BlockData

type BlockData []byte

BlockData data in a FLAC Metadata Block. Custom Metadata decoders and modifiers should accept/modify whole MetaDataBlock instead.

type BlockType

type BlockType int

BlockType representation of types of FLAC Metadata Block

const (
	// StreamInfo METADATA_BLOCK_STREAMINFO
	// This block has information about the whole stream, like sample rate, number of channels, total number of samples, etc. It must be present as the first metadata block in the stream. Other metadata blocks may follow, and ones that the decoder doesn't understand, it will skip.
	StreamInfo BlockType = iota
	// Padding METADATA_BLOCK_PADDING
	// This block allows for an arbitrary amount of padding. The contents of a PADDING block have no meaning. This block is useful when it is known that metadata will be edited after encoding; the user can instruct the encoder to reserve a PADDING block of sufficient size so that when metadata is added, it will simply overwrite the padding (which is relatively quick) instead of having to insert it into the right place in the existing file (which would normally require rewriting the entire file).
	Padding
	// Application METADATA_BLOCK_APPLICATION
	// This 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 is of the block is defined by the registered application. Visit the registration page if you would like to register an ID for your application with FLAC.
	Application
	// SeekTable METADATA_BLOCK_SEEKTABLE
	// This 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.
	SeekTable
	// VorbisComment METADATA_BLOCK_VORBIS_COMMENT
	// This 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.
	VorbisComment
	// CueSheet METADATA_BLOCK_CUESHEET
	// This 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.
	CueSheet
	// Picture METADATA_BLOCK_PICTURE
	// This 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. The picture format is similar to the APIC frame in ID3v2. The PICTURE block has a type, MIME type, and UTF-8 description like ID3v2, and supports external linking via URL (though this is discouraged). The differences are that there is no uniqueness constraint on the description field, and the MIME type is mandatory. The FLAC PICTURE block also includes the resolution, color depth, and palette size so that the client can search for a suitable picture without having to scan them all.
	Picture
	// Reserved Reserved Metadata Block Types
	Reserved
	// Invalid Invalid Metadata Block Type
	Invalid BlockType = 127
)

type File

type File struct {
	Meta   []*MetaDataBlock
	Frames FrameData
}

File represents a handler of FLAC file

func ParseBytes

func ParseBytes(f io.Reader) (*File, error)

ParseBytes accepts a reader to a FLAC stream and returns the final file

func ParseFile

func ParseFile(filename string) (*File, error)

ParseFile parses a FLAC file

func ParseMetadata

func ParseMetadata(f io.Reader) (*File, error)

ParseMetadata accepts a reader to a FLAC stream and consumes only FLAC metadata Frames is always nil

func (*File) GetStreamInfo

func (c *File) GetStreamInfo() (*StreamInfoBlock, error)

GetStreamInfo parses the first metadata block of the File which should always be StreamInfo and returns a StreamInfoBlock containing the decoded StreamInfo data.

func (*File) Marshal

func (c *File) Marshal() []byte

Marshal encodes all meta tags and returns the content of the resulting whole FLAC file

func (*File) Save

func (c *File) Save(fn string) error

Save encapsulates Marshal and save the file to the file system

type FrameData

type FrameData []byte

type MetaDataBlock

type MetaDataBlock struct {
	Type BlockType
	Data BlockData
}

MetaDataBlock is the struct representation of a FLAC Metadata Block

func (*MetaDataBlock) Marshal

func (c *MetaDataBlock) Marshal(isfinal bool) []byte

Marshal encodes this MetaDataBlock without touching block data isfinal defines whether this is the last metadata block of the FLAC file

type MetaDataBlockVorbisComment

type MetaDataBlockVorbisComment struct {
	Vendor   string
	Comments []string
}

func New

New creates a new MetaDataBlockVorbisComment vendor is set to flacvorbis <version> by default

func ParseFromMetaDataBlock

func ParseFromMetaDataBlock(meta MetaDataBlock) (*MetaDataBlockVorbisComment, error)

ParseFromMetaDataBlock parses an existing picture MetaDataBlock

func (*MetaDataBlockVorbisComment) Add

func (c *MetaDataBlockVorbisComment) Add(key string, val string) error

Add adds a key-val pair to the comments

func (*MetaDataBlockVorbisComment) Get

func (c *MetaDataBlockVorbisComment) Get(key string) ([]string, error)

Get get all comments with field name specified by the key parameter If there is no match, error would still be nil

func (MetaDataBlockVorbisComment) Marshal

Marshal marshals this block back into a flac.MetaDataBlock

type MetadataBlockPicture

type MetadataBlockPicture struct {
	PictureType       PictureType
	MIME              string
	Description       string
	Width             uint32
	Height            uint32
	ColorDepth        uint32
	IndexedColorCount uint32
	ImageData         []byte
}

MetadataBlockPicture represents a picture metadata block

func NewFromImageData

func NewFromImageData(pictype PictureType, description string, imgdata []byte, mime string) (*MetadataBlockPicture, error)

NewFromImageData generates a MetadataBlockPicture from image data, returns an error if the picture data connot be parsed

func ParsePicFromMetaDataBlock

func ParsePicFromMetaDataBlock(meta MetaDataBlock) (*MetadataBlockPicture, error)

ParseFromMetaDataBlock parses an existing picture MetaDataBlock

func (*MetadataBlockPicture) Marshal

func (c *MetadataBlockPicture) Marshal() MetaDataBlock

Marshal encodes the PictureBlock to a standard FLAC MetaDataBloc to be accepted by go-flac

func (*MetadataBlockPicture) ParsePicture

func (c *MetadataBlockPicture) ParsePicture() error

ParsePicture decodes the image and inflated the Width, Height, ColorDepth, IndexedColorCount fields. This is called automatically by NewFromImageData

type PictureType

type PictureType uint32

PictureType defines the type of this image

const (
	PictureTypeOther PictureType = iota
	PictureTypeFileIcon
	PictureTypeOtherIcon
	PictureTypeFrontCover
	PictureTypeBackCover
	PictureTypeLeaflet
	PictureTypeMedia
	PictureTypeLeadArtist
	PictureTypeArtist
	PictureTypeConductor
	PictureTypeBand
	PictureTypeComposer
	PictureTypeLyricist
	PictureTypeRecordingLocation
	PictureTypeDuringRecording
	PictureTypeDuringPerformance
	PictureTypeScreenCapture
	PictureTypeBrightColouredFish
	PictureTypeIllustration
	PictureTypeBandArtistLogotype
	PictureTypePublisherStudioLogotype
)

type StreamInfoBlock

type StreamInfoBlock struct {
	// BlockSizeMin The minimum block size (in samples) used in the stream.
	BlockSizeMin int
	// BlockSizeMax The maximum block size (in samples) used in the stream. (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
	BlockSizeMax int
	// FrameSizeMin The minimum frame size (in bytes) used in the stream. May be 0 to imply the value is not known.
	FrameSizeMin int
	// FrameSizeMax The maximum frame size (in bytes) used in the stream. May be 0 to imply the value is not known.
	FrameSizeMax int
	// SampleRate Sample rate in Hz
	SampleRate int
	// ChannelCount Number of channels
	ChannelCount int
	// BitDepth  Bits per sample
	BitDepth int
	// SampleCount 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 int64
	// AudioMD5 MD5 signature of the unencoded audio data
	AudioMD5 []byte
}

StreamInfoBlock represents the undecoded data of StreamInfo block

Jump to

Keyboard shortcuts

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