Documentation
¶
Overview ¶
Package flac encapsulated the operations that extract and split FLAC metadata blocks from a FLAC stream file and assembles them back after modifications provided by other packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // 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") // ErrorAlreadyWritten indicates that the frames have already been written to the file ErrorAlreadyWritten = errors.New("frames already written") )
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 BufIOWithInner ¶ added in v2.0.2
func NewBufIOWithInner ¶ added in v2.0.2
func NewBufIOWithInner(inner io.Reader) *BufIOWithInner
func (*BufIOWithInner) Close ¶ added in v2.0.3
func (b *BufIOWithInner) Close() error
type ErrorReader ¶
type ErrorReader struct {
// contains filtered or unexported fields
}
type File ¶
type File struct { Meta []*MetaDataBlock Frames io.Reader }
File represents a handler of FLAC file
func ParseBytes ¶
ParseBytes accepts a reader to a FLAC stream and returns the final file FLAC audio frames are stored as a reader You should call Close() on the returned File to free resources
func ParseFile ¶
ParseFile parses a FLAC file FLAC audio frames are stored as a reader You should call Close() on the returned File to free resources
func ParseMetadata ¶
ParseMetadata accepts a reader to a FLAC stream and consumes only FLAC metadata Frames are not read Further calls to WriteTo will only write the metadata
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) Save ¶
Save encapsulates WriteTo by writing the edited metadata to the given path and then piping the audio stream to the output file. The output must not feed back into the input as the data will be corrupted when piping the audio stream. This is commonly caused by attempting to save the file to the same location as the input file. The only information this library have is an io.Reader so it is impossible to reliably detect such cases. Thus caller should implement logic to prevent such cases.
type MetaDataBlock ¶
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 PrefixReader ¶
type PrefixReader struct {
// contains filtered or unexported fields
}
func (*PrefixReader) Close ¶
func (c *PrefixReader) Close() error
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