cd

package
v0.8.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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.

View Source
var ErrNoEngine = errors.New("WittyCD isn't on this server")

ErrNoEngine: nothing has been set to open an image with.

View Source
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.

View Source
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

func IsImageName(name string) bool

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 MayBeRaw

func MayBeRaw(name string) bool

MayBeRaw says whether a file with this name might be bare CD audio.

func SheetFiles

func SheetFiles(path string) (files []string, image bool)

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

func (d *Disc) AudioTracks() []*Track

AudioTracks lists the tracks that can be played, in order.

func (*Disc) Close

func (d *Disc) Close() error

Close lets go of the image.

func (*Disc) DurationSec

func (d *Disc) DurationSec() float64

DurationSec is how long the whole disc plays.

func (*Disc) NewStream

func (d *Disc) NewStream(tracks []int, loops int, deemphasis bool) (Stream, error)

NewStream makes a program. tracks is nil for the whole disc as laid out.

func (*Disc) ReadGraphics

func (d *Disc) ReadGraphics(from, sectors int) ([]byte, error)

ReadGraphics reads a run of a karaoke disc's subcode.

func (*Disc) TOC

func (d *Disc) TOC() TOC

TOC is the table of contents an audio player would read.

func (*Disc) TotalBytes

func (d *Disc) TotalBytes() int64

TotalBytes is how long the whole disc is as samples.

func (*Disc) Track

func (d *Disc) Track(n int) *Track

Track finds a track by number.

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 Index

type Index struct {
	Number int `json:"number"`
	LBA    int `json:"lba"`
}

Index is an index point inside a track.

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

type TOC struct {
	First, Last int
	LeadOut     int
	Offsets     []int // of tracks First to Last
}

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

func (t TOC) CDDBID() string

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

func (t TOC) LookupString() string

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

func (t TOC) MusicBrainzID() string

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.

type WAV

type WAV interface {
	io.ReaderAt
	Size() int64
}

WAV is a stream as a file.

type Warning

type Warning struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Warning is something worth telling the owner about an image that still plays.

Jump to

Keyboard shortcuts

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