Skip to content

Commit

Permalink
flac: Add preliminary encoding support.
Browse files Browse the repository at this point in the history
Support for encoding metadata has been added.

Proper support for encoding audio samples is yet to be
implemented. For now, simply copy the original encoded
audio data from the source FLAC file.

The API mirrors that of image.Encode.

Updates #14.
  • Loading branch information
mewmew committed Jul 20, 2016
1 parent 7164e11 commit 306014a
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 14 deletions.
425 changes: 425 additions & 0 deletions enc.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/bits/reader.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package bits provides bit reading operations and binary decoding algorithms.
// Package bits provides bit access operations and binary decoding algorithms.
package bits

import (
Expand All @@ -20,7 +20,7 @@ type Reader struct {
}

// NewReader returns a new Reader that reads bits from r.
func NewReader(r io.Reader) (br *Reader) {
func NewReader(r io.Reader) *Reader {
return &Reader{r: r}
}

Expand Down
2 changes: 1 addition & 1 deletion meta/cuesheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type CueSheet struct {
Tracks []CueSheetTrack
}

// parseCueSheet reads and parses the body of an CueSheet metadata block.
// parseCueSheet reads and parses the body of a CueSheet metadata block.
func (block *Block) parseCueSheet() error {
// Parse cue sheet.
// 128 bytes: MCN.
Expand Down
14 changes: 7 additions & 7 deletions meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ type Type uint8

// Metadata block body types.
const (
TypeStreamInfo Type = iota
TypePadding
TypeApplication
TypeSeekTable
TypeVorbisComment
TypeCueSheet
TypePicture
TypeStreamInfo Type = 0

This comment has been minimized.

Copy link
@karlek

karlek Jul 20, 2016

Contributor

Why change to explicitly typed values?

This comment has been minimized.

Copy link
@mewmew

mewmew Jul 20, 2016

Author Member

Why change to explicitly typed values?

iota may be used when the value doesn't matter, just to enumerate. The motivation behind using explicit values is to ensure that they always map to their corresponding value in the FLAC spec.

BLOCK_TYPE

    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

This comment has been minimized.

Copy link
@karlek

karlek Jul 21, 2016

Contributor

Good point!

TypePadding Type = 1
TypeApplication Type = 2
TypeSeekTable Type = 3
TypeVorbisComment Type = 4
TypeCueSheet Type = 5
TypePicture Type = 6
)

func (t Type) String() string {
Expand Down
2 changes: 1 addition & 1 deletion meta/picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Picture struct {
Data []byte
}

// parsePicture reads and parses the body of an Picture metadata block.
// parsePicture reads and parses the body of a Picture metadata block.
func (block *Block) parsePicture() error {
// 32 bits: Type.
pic := new(Picture)
Expand Down
2 changes: 1 addition & 1 deletion meta/seektable.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type SeekTable struct {
Points []SeekPoint
}

// parseSeekTable reads and parses the body of an SeekTable metadata block.
// parseSeekTable reads and parses the body of a SeekTable metadata block.
func (block *Block) parseSeekTable() error {
// The number of seek points is derived from the header length, divided by
// the size of a SeekPoint; which is 18 bytes.
Expand Down
2 changes: 1 addition & 1 deletion meta/streaminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type StreamInfo struct {
MD5sum [md5.Size]uint8
}

// parseStreamInfo reads and parses the body of an StreamInfo metadata block.
// parseStreamInfo reads and parses the body of a StreamInfo metadata block.
func (block *Block) parseStreamInfo() error {
// 16 bits: BlockSizeMin.
br := bits.NewReader(block.lr)
Expand Down
2 changes: 1 addition & 1 deletion meta/vorbiscomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type VorbisComment struct {
Tags [][2]string
}

// parseVorbisComment reads and parses the body of an VorbisComment metadata
// parseVorbisComment reads and parses the body of a VorbisComment metadata
// block.
func (block *Block) parseVorbisComment() error {
// 32 bits: vendor length.
Expand Down

0 comments on commit 306014a

Please sign in to comment.