codec

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2015 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const IdSep = "\n"

Variables

View Source
var ErrFormat = errors.New("codec: unknown format")

ErrFormat indicates that decoding encountered an unknown format.

Functions

func RegisterCodec

func RegisterCodec(name string, magic, extensions []string, decode func(Reader) (Songs, error), get func(Reader, ID) (Song, error))

RegisterCodec registers an audio codec for use by Decode. Name is the name of the format, like "nsf" or "wav". Magic is the magic prefix that identifies the codec's encoding. The magic string can contain "?" wildcards that each match any one byte. Decode is the function that decodes the encoded codec.

Types

type ID added in v0.0.7

type ID string
const None ID = ""

func Int added in v0.0.7

func Int(i int) ID

func Int64 added in v0.0.7

func Int64(i int64) ID

func NewID added in v0.0.7

func NewID(s ...string) ID

func (ID) Pop added in v0.0.7

func (i ID) Pop() (string, ID)

func (ID) Push added in v0.0.7

func (i ID) Push(s string) ID

func (ID) Top added in v0.0.7

func (i ID) Top() string

type Reader

type Reader func() (io.ReadCloser, int64, error)

Reader returns a file reader and the file size in bytes (or 0 if streamed or unknown).

func (Reader) Metadata added in v0.0.8

func (rf Reader) Metadata(ft tag.FileType) (*SongInfo, tag.Metadata, []byte, error)

type Song

type Song interface {
	// Info returns information about a song.
	Info() (SongInfo, error)
	// Init is called before the first call to Play(). It should prepare resources
	// needed for Play().
	Init() (sampleRate, channels int, err error)
	// Play returns the next n samples. Return < n to indicate end of song or 0
	// to indicate EOF, neither of which should return an error. If < n samples
	// are returned, Play will not be invoked again.
	Play(n int) ([]float32, error)
	// Close releases resources used by the current file.
	Close()
}

func ByExtensionID added in v0.0.7

func ByExtensionID(path string, id ID, rf Reader) (Song, error)

type SongInfo

type SongInfo struct {
	Time     time.Duration
	Artist   string
	Title    string
	Album    string
	Track    float64
	ImageURL string `json:",omitempty"`
}

type Songs added in v0.0.7

type Songs map[ID]Song

func ByExtension

func ByExtension(path string, rf Reader) (Songs, string, error)

func Decode

func Decode(rf Reader) (Songs, string, error)

Decode decodes audio that has been encoded in a registered codec. The string returned is the format name used during format registration. Format registration is typically done by the init method of the codec- specific package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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