class Yuno::VgmPlayer

Overview

The VgmPlayer class is used to play VGM files by rendering them to PCM data.

Defined in:

yunosynth/vgmplayer.cr
yunosynth/vgmplayerinst.cr

Constant Summary

MIN_SAMPLE_RATE = 8000_u32

The minimum supported output sample rate.

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(vgm : VgmFile, newSettings : VgmPlayerSettings | Nil = nil) #

Creates a new VgmPlayer instance that will play the given VGM file.


Class Method Detail

def self.calcResampling(sampleRate : UInt32, vgm : VgmFile, playbackRate : UInt32 = 0, vgmSampleRate : UInt32 = VGM_SAMPLE_RATE.to_u32) : Tuple(UInt32, UInt32, UInt32, UInt32) #

Given a VGM file, an output sample rate, and some other information, this calculates multiplier and divider values that can be used for resampling. The playbackRate parameter is a multiplier of how fast you intend to play back the VGM file. A value of 0 means to use the default playback rate. The vgmSampleRate parameter is the rate of VGM sampling rate.

In nearly all cases, you want to instead use VgmPlayer.calcResampling(UInt32, VgmFile).

The returned Tuple contains (in order):

  1. The multiplier for the PCM sample rate
  2. The divider for the PCM sample rate
  3. The multiplier for the VGM sample rate
  4. The divider for the VGM sample rate

def self.calcResampling(sampleRate, vgm : VgmFile) : Tuple(UInt32, UInt32) #

Given a VGM file and an output PCM sample rate, this calculates multiplier and divider values that can be used for resampling.

The returned Tuple contains (in order):

  1. The multiplier for the PCM sample rate
  2. The divider for the PCM sample rate

Instance Method Detail

def atEnd? : Bool #

When true, then the player has reached the end of the VGM file.


def chipNamesUsed(useShort : Bool = false) : Array(String) #

Returns the list of all the fancy names for the chips that are used in this VGM. This only returns a valid set after the #play method has been run.

If useShort is true, then the short names are returned for each chip instead of the full name.


def chipsUsed : Hash(ChipType, Int32) #

Returns the Hash where the keys are ChipTypes for the chips that are used in this VGM, and the values are the number of instances of that chip.


def loopPcmSamples : UInt32 #

Returns the total number of PCM samples that the loaded VGM will generate in one loop when it is played back.


def mainVolume : Float64 #

The main output volume. If you want to change the volume, change this first. 1.0 is the "normal" output volume.


def mainVolume=(val : Float64) : Nil #

Sets the main output volume of the rendered PCM data. 1.0 is the "normal" output volume.


def minBufferSize : Int32 #

The minimum size for the buffer to use to pass to #render. This is per-channel.


def play(lowQualityResampling : Bool = false) #

Starts playback. This must be called before calling #render. Calling this more than once is effectively a non-op.


def playing? : Bool #

If this is true, then #play has been called and cannot be called again.


def playTime : Int32 #

The total number of samples rendered so far.


def render(left : Array(Int16) | Slice(Int16), right : Array(Int16) | Slice(Int16)) : Nil #

Renders new PCM data to the left and right buffers, and advances the playback state. You must call #play exactly once before calling this.


def reset : Nil #

Resets the player to the beginning.


def sampleRate : UInt32 #

The output sample rate.


def settings : VgmPlayerSettings #

The currently loaded settings for the player.


def stop : Nil #

Sets "#atEnd?totrue`.


def timesPlayed : UInt32 #

The number of times the VGM file has currently played one full loop. This starts at 0.


def timesPlayed=(timesPlayed : UInt32) #

The number of times the VGM file has currently played one full loop. This starts at 0.


def totalPcmSamples : UInt32 #

Returns the total number of PCM samples that the loaded VGM will generate when the loop is ignored and it is played back.


def vgm : VgmFile #

The currently loaded VgmFile instance.


def volumeModifier : Float64 #

The main volume will be multiplied by this when calculating the final output volume. When this is needed, the VGM file's header usually sets the appropriate value. This is automatically calculated and is provided for informational purposes.