Documentation
¶
Index ¶
- Constants
- Variables
- func IsImageName(name string) bool
- func MayBeRaw(name string) bool
- func SheetFiles(path string) (files []string, image bool)
- type Disc
- func (d *Disc) AudioTracks() []*Track
- func (d *Disc) Close() error
- func (d *Disc) DurationSec() float64
- func (d *Disc) NewStream(tracks []int, loops int, deemphasis bool) (Stream, error)
- func (d *Disc) ReadGraphics(from, sectors int) ([]byte, error)
- func (d *Disc) TOC() TOC
- func (d *Disc) TotalBytes() int64
- func (d *Disc) Track(n int) *Track
- type DiscEngine
- type Index
- type Stream
- type TOC
- type Text
- type Track
- type WAV
- type Warning
Constants ¶
const ( // SectorBytes is one sector of CD audio: 1/75 of a second. SectorBytes = 2352 // SectorSamples is the stereo samples in a sector. SectorSamples = 588 // SampleBytes is one stereo sample: two 16-bit values. SampleBytes = 4 // SampleRate is what every audio CD plays at. SampleRate = 44100 // FramesPerSecond is sectors per second, the F of MM:SS:FF. FramesPerSecond = 75 // LeadIn is the 2 seconds before LBA 0, in sectors: MM:SS:FF counts them on a // real disc, and disc IDs add them to every offset. LeadIn = 150 // MaxSectors is the longest disc there can be: 99:59:74. MaxSectors = 450000 // MaxTracks is the most a disc's table of contents can hold. MaxTracks = 99 )
Variables ¶
var ( // ErrNotCD: not a CD image at all, such as a DVD or a data disc's ISO. ErrNotCD = errors.New("this isn't an image of an audio CD") // ErrNoAudio: a CD image with only data tracks. ErrNoAudio = errors.New("this CD image holds only data tracks, so there is nothing to play") // ErrUnsupported: a CD image in a form this version can't read. ErrUnsupported = errors.New("this CD image is stored in a form WittyCD can't read") )
Errors a caller may want to tell apart. Each reads as a sentence.
var ErrNoEngine = errors.New("WittyCD isn't on this server")
ErrNoEngine: nothing has been set to open an image with.
var ForeignAudio func(path string) (flac string, err error)
ForeignAudio, when set, makes a FLAC file of CD audio for a sound file WittyCD doesn't read itself, so that a cue sheet can split it. It's here since the server has FFmpeg, and WittyCD asks for it.
var Open = func(string) (*Disc, error) { return nil, ErrNoEngine }
Open opens a CD image through the WittyCD version in use. The server sets it as it starts.
Functions ¶
func IsImageName ¶
IsImageName says whether a file's name marks it as a CD image's sheet or container. .iso, .img and .bin may be one too, which only opening them tells.
func SheetFiles ¶
SheetFiles lists the files a sheet plays, resolved beside it, without opening any of them, and says whether the sheet is really a disc image. It is cheap enough for a scan to ask about every sheet it finds.
A sheet is not treated as an image when its audio is already a set of separately compressed files, one to a track: those are tagged songs, and the sheet is just a rip's notes. The same goes for a sheet naming compressed audio WittyCD can't read. A .ccd, .nrg or .chd holds its own audio, and is always an image.
Types ¶
type Disc ¶
type Disc struct {
// Format is the image's form: cue, toc, ccd, nrg, chd or raw.
Format string `json:"format"`
Tracks []Track `json:"tracks"`
Text Text `json:"text"`
Catalog string `json:"catalog,omitempty"`
Genre string `json:"genre,omitempty"`
Date string `json:"date,omitempty"`
// DiscNumber is from the sheet (REM DISCNUMBER), 0 when it doesn't say.
DiscNumber int `json:"discNumber,omitempty"`
// Sessions is 2 for a CD-Extra.
Sessions int `json:"sessions"`
// HiddenTrack: track 1's pregap holds audio that is not silence.
HiddenTrack bool `json:"hiddenTrack,omitempty"`
// Problem is why this disc would not sound like music: "dts" or "noise" with
// a plain Warning alongside it, "" for a normal disc.
Problem string `json:"problem,omitempty"`
Warnings []Warning `json:"warnings,omitempty"`
// HasGraphics: the image holds CD+G subcode (a karaoke disc).
HasGraphics bool `json:"hasGraphics,omitempty"`
// What the helper works out, so nothing here does.
TotalSize int64 `json:"totalBytes"`
Duration float64 `json:"durationSec"`
Table TOC `json:"toc"`
// Engine is the helper's half of this disc.
Engine DiscEngine `json:"-"`
}
Disc is an opened CD image, in a helper. It is safe for concurrent reads.
func (*Disc) AudioTracks ¶
AudioTracks lists the tracks that can be played, in order.
func (*Disc) DurationSec ¶
DurationSec is how long the whole disc plays.
func (*Disc) ReadGraphics ¶
ReadGraphics reads a run of a karaoke disc's subcode.
func (*Disc) TotalBytes ¶
TotalBytes is how long the whole disc is as samples.
type DiscEngine ¶
type DiscEngine interface {
NewStream(tracks []int, loops int, deemphasis bool) (Stream, error)
ReadGraphics(from, sectors int) ([]byte, error)
Close() error
}
DiscEngine is what a disc asks of its helper.
type Stream ¶
type Stream interface {
io.ReaderAt
Samples() int64
Size() int64
// WAV is the program from a sample on, as a WAV file.
WAV(startSample int64) WAV
// WriteFLAC writes the program from a sample on, as FLAC.
WriteFLAC(w io.Writer, startSample int64) error
}
Stream reads samples of a program: the whole disc as it is laid out, or chosen tracks in a chosen order, any number of times.
type TOC ¶
TOC is a table of contents as disc ID services take it: audio tracks only, with the 2-second lead-in added to every offset.
func (TOC) CDDBID ¶
CDDBID is the older eight-digit disc ID. It is only shown, for matching a disc against other tools' logs; nothing here looks it up.
func (TOC) LookupString ¶
LookupString is the toc= value of a MusicBrainz lookup, which also finds a disc nobody has attached that exact ID to. A release is looked up by its track count from 1, so a first track above 1 (a data track first) is told as it is.
func (TOC) MusicBrainzID ¶
MusicBrainzID is the disc's ID in MusicBrainz: 28 characters, from the SHA-1 of the table of contents written in hexadecimal.
type Text ¶
type Text struct {
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
Songwriter string `json:"songwriter,omitempty"`
Composer string `json:"composer,omitempty"`
Arranger string `json:"arranger,omitempty"`
Message string `json:"message,omitempty"`
}
Text is what a disc says about itself or about one track.
type Track ¶
type Track struct {
Number int `json:"number"`
// Audio is false for a data track, which is listed and never played.
Audio bool `json:"audio"`
Mode string `json:"mode"` // AUDIO, MODE1/2352 and so on
// Pregap is where index 0 starts, Start where index 1 starts and End where
// the next track's pregap starts, all in sectors from LBA 0.
Pregap int `json:"pregap"`
Start int `json:"start"`
End int `json:"end"`
// Indexes above 1.
Indexes []Index `json:"indexes,omitempty"`
PreEmphasis bool `json:"preEmphasis,omitempty"`
CopyAllowed bool `json:"copyAllowed,omitempty"`
FourChannel bool `json:"fourChannel,omitempty"`
ISRC string `json:"isrc,omitempty"`
Session int `json:"session,omitempty"`
Text Text `json:"text"`
}
Track is one track of the table of contents, data tracks included.