Documentation
¶
Overview ¶
Package gme plays chiptune rips (NES .nsf/.nsfe, Game Boy .gbs, PC Engine .hes, MSX .kss and SNES .spc) by emulating the original sound hardware with Game_Music_Emu. A Decoder is a beep StreamSeekCloser that plays one track, or every track of a file back to back as one stream.
Index ¶
- Constants
- Variables
- func Supported(ext string) bool
- func TrackCount(path string) (int, error)
- type Decoder
- func (d *Decoder) Close() error
- func (d *Decoder) CurrentTrack() int
- func (d *Decoder) Err() error
- func (d *Decoder) Info() Info
- func (d *Decoder) Len() int
- func (d *Decoder) Position() int
- func (d *Decoder) SampleRate() int
- func (d *Decoder) Seek(p int) error
- func (d *Decoder) Stream(samples [][2]float64) (n int, ok bool)
- func (d *Decoder) TrackStarts() []int
- type Info
- type Options
- type TrackInfo
Constants ¶
const ( // DefaultSampleRate is the output rate used when Options.SampleRate is 0. DefaultSampleRate = 48000 // DefaultTrackSeconds is how long a track without a length tag plays. DefaultTrackSeconds = 150 // DefaultFadeSeconds is the fade-out at the end of every track. DefaultFadeSeconds = 8 // MaxFileBytes is the largest file Open reads. MaxFileBytes = 16 << 20 )
Variables ¶
var ( // ErrUnsupported is returned for data that is not one of the formats // Supported lists. ErrUnsupported = errors.New("gme: unsupported or unrecognized file") // ErrTooLarge is returned for a file above the size cap. ErrTooLarge = errors.New("gme: file too large") // ErrClosed is returned by a Decoder used after Close. ErrClosed = errors.New("gme: decoder closed") // ErrNoTrack is returned for a track index the file does not have. ErrNoTrack = errors.New("gme: no such track") )
Functions ¶
func Supported ¶
Supported reports whether files with extension ext, which includes the dot and is matched case-insensitively, are played by this package.
func TrackCount ¶
TrackCount reports how many tracks the file at path holds. HES and KSS files do not record a count; Game_Music_Emu reports 256 for them.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder streams one track or a run of tracks. It is not safe for concurrent use.
func Open ¶
Open plays the file at path. track is a 0-based track index, or -1 to play every track in order as one stream. HES and KSS files do not record how many tracks they hold, so -1 plays only their first.
func OpenBytes ¶
OpenBytes plays a file held in memory. The format is identified from the data; ext, when not "", must also be one Supported lists.
func (*Decoder) CurrentTrack ¶
CurrentTrack is the index into TrackStarts of the track at Position.
func (*Decoder) Len ¶
Len is the stream length in frames: the sum of the tracks' play times and fades.
func (*Decoder) SampleRate ¶
SampleRate is the output rate in Hz.
func (*Decoder) Seek ¶
Seek moves playback to frame p. The emulator has no random access, so a seek restarts the track and emulates forward to the offset; that takes time in proportion to the offset.
func (*Decoder) TrackStarts ¶
TrackStarts is the first frame of each track in the stream; it has one element, 0, for a Decoder playing a single track.
type Info ¶
Info describes a file. Title is the title of the track a Decoder plays; it is "" for a Decoder playing every track and from ReadInfo.
type Options ¶
type Options struct {
// SampleRate is the output rate in Hz; 0 means DefaultSampleRate.
SampleRate int
// DefaultTrackSeconds is the play time of a track whose file gives no
// length; 0 means DefaultTrackSeconds.
DefaultTrackSeconds float64
// FadeSeconds is the fade-out after each track's play time when the
// file does not give its own; 0 means DefaultFadeSeconds.
FadeSeconds float64
}
Options configures a Decoder.