Documentation
¶
Overview ¶
Package wittycd reads images of audio CDs and plays them the way a CD player does: one continuous program area, with tracks, indexes and pregaps as places in it rather than as separate files. That is what makes it gapless, and what lets a position be a sample rather than an estimate.
Everything in an image is untrusted: sizes are checked before use, a sheet can only name files beside itself, and a damaged image gives a smaller disc or a clear error, never a crash.
Index ¶
- Constants
- Variables
- func IsImageName(name string) bool
- func MayBeRaw(name string) bool
- func SheetFiles(path string) (files []string, image bool)
- func UI() *sdui.Module
- type Disc
- func (d *Disc) AudioEnd() int
- func (d *Disc) AudioTracks() []*Track
- func (d *Disc) Check(progress func(done float64) bool) *Report
- func (d *Disc) Close() error
- func (d *Disc) DurationSec() float64
- func (d *Disc) Facts() Facts
- func (d *Disc) IsSilentRange(from, to int) bool
- func (d *Disc) NewStream(tracks []int, loops int, deemphasis bool) (*Stream, error)
- func (d *Disc) RangeStream(from, to int) (*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
- func (d *Disc) TrackStream(n int) (*Stream, error)
- type Facts
- type Finding
- type Index
- type Report
- type Severity
- 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 )
const HiddenTrackNumber = 0
HiddenTrackNumber asks a Stream for what is in track 1's pregap.
const MaxLoops = 64
MaxLoops bounds how many times a program can be repeated in one stream.
const ModuleID = "wittycd"
ModuleID is this module's ID, the same as module.json's.
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 ForeignAudio func(path string) (flac string, err error)
ForeignAudio, when set, gives a FLAC file of CD audio for a sound file in a format this package doesn't read itself, so that a cue sheet can split it into tracks. It may take a while the first time. The server sets it, since it has FFmpeg and a cache.
var ManifestJSON []byte
ManifestJSON is this module's manifest (docs/MODULES.md, "The manifest").
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.
func UI ¶ added in v0.2.1
UI is WittyCD's part of every app (module API 4, WittyMediaServer docs/SDUI-MODULES.md), written to sdui.json beside module.json. It is only the theme scope, on purpose:
- An audio CD's page and its tracks are the server's music pages, drawn from what this module's helper reads, so a page or menu entry here would only show them twice.
- The helper reads no settings of its own, and answers no data source: a CD image is an item of the server's music libraries already.
The scope still names the module for the theme editor.
Types ¶
type Disc ¶
type Disc struct {
Path string `json:"-"`
// 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"` // the disc's barcode, if it says
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"`
// contains filtered or unexported fields
}
Disc is an opened CD image.
func Open ¶
Open reads a CD image by what its name says it is. An .img opens through the .ccd or .cue beside it when there is one.
func (*Disc) AudioTracks ¶
AudioTracks lists the tracks that can be played, in order.
func (*Disc) Check ¶
Check reads every audio sector of the disc and reports what it finds. progress, if given, is called now and then with the fraction done and can stop the check by returning false. It is the hook for the Disk Diagnoser and for `cd check`.
func (*Disc) DurationSec ¶
DurationSec is the disc's playing time, from track 1's index 1 to the last track's end. A hidden track is left out, as a player would.
func (*Disc) IsSilentRange ¶
IsSilentRange reports whether a run of sectors is digital silence. The player uses it to tell a real pause from an empty pregap.
func (*Disc) NewStream ¶
NewStream makes a program. tracks is nil for the whole disc as laid out, with every pregap in place (the disc starts at sample 0, which is track 1's pregap when it has one). Pre-emphasised tracks are corrected when deemphasis is on, so they sound as they were meant to.
func (*Disc) RangeStream ¶
RangeStream is any run of audio sectors exactly as it is on the disc, for a rip that keeps pregaps its own way. Sectors of a data track, or that the image doesn't supply, read as silence.
func (*Disc) ReadGraphics ¶
ReadGraphics returns the CD+G packets of a run of sectors, each packet's bytes masked to the 6 bits that carry graphics. Sectors with no graphics read as zeroes, which a decoder ignores.
func (*Disc) TOC ¶
TOC works out the table of contents an audio player would read. Data tracks aren't counted. On a CD-Extra the lead-out is where the audio session ended, 11400 sectors before the data session if the image kept that gap.
func (*Disc) TotalBytes ¶
TotalBytes is the size of the files the image is made of.
type Facts ¶
type Facts struct {
Format string `json:"format"`
DiscID string `json:"discId"`
CDDBID string `json:"cddbId"`
TOC string `json:"toc"`
Tracks []Track `json:"tracks"`
Sessions int `json:"sessions"`
DurationSec float64 `json:"durationSec"`
HiddenTrack bool `json:"hiddenTrack"`
HasGraphics bool `json:"hasGraphics"`
Problem string `json:"problem,omitempty"`
Warnings []Warning `json:"warnings"`
}
Facts is a disc's structure in plain data.
type Finding ¶
type Finding struct {
Severity Severity `json:"severity"`
Code string `json:"code"`
Text string `json:"text"`
// Track is the track concerned, 0 for the whole disc.
Track int `json:"track,omitempty"`
}
Finding is one thing a check found.
type Report ¶
type Report struct {
Facts Facts `json:"facts"`
AudioTracks int `json:"audioTracks"`
Sectors int `json:"sectors"`
Unreadable int `json:"unreadable"`
Findings []Finding `json:"findings"`
Worst Severity `json:"worst"`
Summary string `json:"summary"`
}
Report is the outcome of reading a whole disc.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream reads samples of a program. It is safe for concurrent reads and holds no position, so one Disc can serve any number of listeners.
func (*Stream) ReadAt ¶
ReadAt reads little-endian PCM. It returns io.EOF only at the end of the program, and any range is allowed, as HTTP range requests are.
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.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cli is the command line of the standalone wittycd tool.
|
Package cli is the command line of the standalone wittycd tool. |
|
cmd
|
|
|
wittycd
command
Command wittycd inspects audio CD images with the WittyCD engine: tracks, indexes, CD-TEXT, disc IDs, and a read of the whole image to find damage.
|
Command wittycd inspects audio CD images with the WittyCD engine: tracks, indexes, CD-TEXT, disc IDs, and a read of the whole image to find damage. |
|
wittycd-module
command
Command wittycd-module is WittyCD as a helper process: the only way a server reaches it.
|
Command wittycd-module is WittyCD as a helper process: the only way a server reaches it. |
|
Package lookup finds out what an audio CD is, from MusicBrainz and the Cover Art Archive, using nothing but its table of contents: no names, no audio, and nothing about the person or their files.
|
Package lookup finds out what an audio CD is, from MusicBrainz and the Cover Art Archive, using nothing but its table of contents: no names, no audio, and nothing about the person or their files. |
