gme

package
v2.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: GPL-3.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

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

func Supported(ext string) bool

Supported reports whether files with extension ext, which includes the dot and is matched case-insensitively, are played by this package.

func TrackCount

func TrackCount(path string) (int, error)

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

func Open(path string, track int, opts Options) (*Decoder, error)

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

func OpenBytes(data []byte, ext string, track int, opts Options) (*Decoder, error)

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) Close

func (d *Decoder) Close() error

Close frees the emulator. It is safe to call more than once.

func (*Decoder) CurrentTrack

func (d *Decoder) CurrentTrack() int

CurrentTrack is the index into TrackStarts of the track at Position.

func (*Decoder) Err

func (d *Decoder) Err() error

Err returns the error that stopped the stream, if any.

func (*Decoder) Info

func (d *Decoder) Info() Info

Info describes the file and the track playing.

func (*Decoder) Len

func (d *Decoder) Len() int

Len is the stream length in frames: the sum of the tracks' play times and fades.

func (*Decoder) Position

func (d *Decoder) Position() int

Position is the current frame.

func (*Decoder) SampleRate

func (d *Decoder) SampleRate() int

SampleRate is the output rate in Hz.

func (*Decoder) Seek

func (d *Decoder) Seek(p int) error

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) Stream

func (d *Decoder) Stream(samples [][2]float64) (n int, ok bool)

Stream fills samples with the next frames of audio.

func (*Decoder) TrackStarts

func (d *Decoder) TrackStarts() []int

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

type Info struct {
	Title, Game, System, Author, Copyright string
	Tracks                                 []TrackInfo
}

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.

func ReadInfo

func ReadInfo(path string, maxBytes int64) (Info, error)

ReadInfo reads a file's tags without starting playback. Files larger than maxBytes (MaxFileBytes when maxBytes <= 0 or above it) are refused, as the formats keep tags at both ends of the file.

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.

type TrackInfo

type TrackInfo struct {
	Title, Game, System, Author, Copyright, Comment string
	// LengthFrames is the track's play time including its fade, at the
	// decoder's sample rate (at DefaultSampleRate from ReadInfo).
	LengthFrames int
}

TrackInfo describes one track of a file.

Jump to

Keyboard shortcuts

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