class Yuno::VgmFile

Overview

A virtual representation of a VGM file.

Defined in:

yunosynth/vgmfile.cr

Constant Summary

VGM_MAGIC = "Vgm "

The magic four bytes at the start of a VGM file.

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.fromIO(io : IO) : VgmFile #

Loads a VGM file from io, returning a new VgmFile instance. The data in IO may be compressed. The IO must be able to seek.


def self.load(path : Path | String) : VgmFile #

Loads a VGM file from path, returning a new VgmFile instance. If the VGM is compressed using a supported compression scheme, it will first be decompressed into RAM.


def self.new(io : IO) #

Creates a new VgmFile instance by reading data from io. The data in io cannot be compressed. If you need to read possibly compressed data from an ::IO, then use VgmFile.fromIO instead. The IO must be able to seek.


Class Method Detail

def self.pcmSampleToVgmSample(sampleNum : Int64, sampleRateDiv : Int64, sampleRateMul : Int64) : UInt32 #

Converts a playback sample index number into a VGM sample index number. That is, this converts a PCM sample position into a VGM sample position.


def self.validVgmFile?(io : IO) : Bool #

Reads the first four bytes from io to check for the magic bytes that indicate a VGM file. If they're found, this returns true, otherwise it returns false. The IO must be seekable.


def self.validVgmFile?(path : Path | String) : Bool #

Reads the first four bytes from the given file to check for the magic bytes that indicate a VGM file. If they're found, this returns true, otherwise it returns false.


def self.vgmSampleToPcmSample(sampleNum : Int64, sampleRateDiv : Int64, sampleRateMul : Int64) : UInt32 #

Converts a VGM sample index number into a playback sample index number. That is, this converts a VGM sample position into a PCM sample position.


Instance Method Detail

def chipsUsed : Hash(ChipType, Int32) #

Returns the list of all chips that are used in this VGM. The keys of the Hash that is returned are the types of chips, while the values dictate whether the chip is solo (1) or paired (2).

Note that VgmPlayer#chipNamesUsed and VgmPlayer#chipsUsed is the preferred way to get a list of chips that are used since these return more information, such as the number of each chip. This can still be used as a quick way to get a list of ChipTypes, however.


def chipUsed?(chip : ChipType) : Bool #

Returns true if chip is used at least once in this VGM, or false otherwise.


def data : Bytes #

Returns the data (that is, the stream of instructions and data bytes) associated with this VGM.


def extraHeader? : ExtraHeader | Nil #

The extra header, if any, in this VGM file.


def gd3Tag : Gd3Tag #

Returns the GD3 tag associated with this VGM.


def getChipClock(chip : ChipType) : UInt32 #

Returns the current clock rate for a given ChipType.


def getChipVolume(chip : AbstractChip, chipType : ChipType, chipCount : Int32, paired : ChipType | Nil = nil) : UInt16 #

Retrieves a volume for chip given a chipType and the number of chips of chipType. If paired is nonNil, then the volume is retrieved for chip's internal paired chip of type paired.


def hasLoopInfo? : Bool #

Returns true if this VGM file contains loop information, or false otherwise.


def header : Header #

Returns the header associated with this VGM.