vgm

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package vgm plays VGM and VGZ files, register logs of arcade, console and computer sound chips, by emulating the chips with cores from libvgm and emu2413. The command interpreter, DAC stream engine, data block handling, resampling and mixing are our own. A Decoder is a beep StreamSeekCloser; it is not safe for concurrent use.

Index

Constants

View Source
const (

	// MaxFileBytes caps a VGM file, and a VGZ file after decompression.
	MaxFileBytes = 64 << 20
)

Variables

View Source
var (
	// ErrClosed is returned by Seek on a closed Decoder.
	ErrClosed = errors.New("vgm: decoder closed")
)

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder renders a VGM file as a stereo stream. It is not safe for concurrent use.

func Open

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

Open reads a .vgm or gzip-compressed .vgz file.

func OpenBytes

func OpenBytes(data []byte, opts Options) (*Decoder, error)

OpenBytes decodes a VGM or VGZ file held in memory. The Decoder keeps its own copy of uncompressed data.

func (*Decoder) Close

func (d *Decoder) Close() error

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

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 is the file's GD3 tag.

func (*Decoder) Len

func (d *Decoder) Len() int

Len is the stream length in frames, including loops and the fade.

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. Seeking backwards restarts the chips; either way the chips are emulated up to p without producing output.

func (*Decoder) Stream

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

Stream fills samples with the next frames of audio.

type Info

type Info struct {
	Title      string // track title
	Game       string
	System     string
	Author     string
	Date       string // release date as written in the tag
	Year       string // first four-digit year in Date, if any
	Notes      string
	TrackTitle string // same as Title
}

Info is the GD3 tag of a VGM file. English fields are preferred and the Japanese ones fill in when the English one is empty.

func ReadInfo

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

ReadInfo reads only the GD3 tag of a file, without starting any chips. maxBytes caps the bytes read, and decompressed for a VGZ file; 0 or less means MaxFileBytes.

type Options

type Options struct {
	// SampleRate is the output rate in Hz; 0 means 48000.
	SampleRate int
	// Loops is how many times a looping file plays its loop; 0 means 2.
	// The header's loop modifier and loop base adjust it.
	Loops int
	// FadeSeconds is the fade-out after the last loop; 0 means 8.
	FadeSeconds float64
	// AccurateYM2612 uses the Nuked OPN2 core for the YM2612 and YM3438.
	// It is closer to the hardware and several times slower.
	AccurateYM2612 bool
}

Options configures a Decoder. Zero values select the defaults.

Jump to

Keyboard shortcuts

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