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, bufferSize : Int32, newSettings : VgmPlayerSettings | Nil = nil) #

Creates a new VgmPlayer instance that will play the given VGM file. #bufferSize is the size of buffers that you will use for rendering audio. See #render for more details and important notes. #bufferSize must be even, and must be greater than or equal to the minimum buffer size for the requested sample rate.

If the VgmFile uses any chips that are not currently supported by YunoSynth, then this will raise an UnsupportedChipError.


[View source]

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

[View source]
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

[View source]
def self.minBufferSize(sampleRate : Int) : Int32 #

[View source]

Instance Method Detail

def atEnd? : Bool #

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


[View source]
def bufferSize : Int32 #

The size of the buffers used for rendering. This is provided when creating a new instance of the class. See #render for details and important notes.


[View source]
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.


[View source]
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.


[View source]
def loopPcmSamples : UInt32 #

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


[View source]
def mainVolume : Float64 #

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


[View source]
def mainVolume=(val : Float64) : Nil #

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


[View source]
def minBufferSize : Int32 #

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


[View source]
def play : Nil #

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


[View source]
def playing? : Bool #

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


[View source]
def playTime : Int32 #

The total number of samples rendered so far.


[View source]
def render(left : Array(Int32) | Slice(Int32), right : Array(Int32) | Slice(Int32)) : Nil #

Renders new PCM data to the left and right buffers, and advances the playback state. The audio is rendered in signed 32-bit PCM format (the native format internally).

You must call #play once before calling this.

The size of left and right MUST be even and MUST be equal to the #bufferSize provided when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
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. The audio is rendered in signed 32-bit PCM format (the native format internally), then automatically dithered to signed 16-bit PCM using high quality dithering.

You must call #play once before calling this.

The size of left and right MUST be even and MUST be equal to the #bufferSize provided when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def render(left : Array(Float64) | Slice(Float64), right : Array(Float64) | Slice(Float64)) : Nil #

Renders new PCM data to the left and right buffers, and advances the playback state. The audio is rendered in signed 32-bit PCM format (the native format internally), then automatically converted to 64-bit IEEE floating point audio.

You must call #play once before calling this.

The size of left and right MUST be even and MUST be equal to the #bufferSize provided when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def render(left : Array(Float32) | Slice(Float32), right : Array(Float32) | Slice(Float32)) : Nil #

Renders new PCM data to the left and right buffers, and advances the playback state. The audio is rendered in signed 32-bit PCM format (the native format internally), then automatically converted to 32-bit IEEE floating point audio.

You must call #play once before calling this.

The size of left and right MUST be even and MUST be equal to the #bufferSize provided when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def render(dest : Array(Int32) | Slice(Int32)) : Nil #

Renders new interleaved PCM data to dest as interleaved audio, and advances the playback state. The audio is rendered in signed 32-bit integer format (the native format internally).

You must call #play once before calling this.

The size of `` MUST be exactly twice the #bufferSize that was requested when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def render(dest : Array(Int16) | Slice(Int16)) : Nil #

Renders new PCM interleaved data to dest as interleaved audio, and advances the playback state. The audio is rendered in signed 32-bit integer format (the native format internally), then automatically dithered to signed 16-bit PCM using high quality dithering.

You must call #play once before calling this.

The size of `` MUST be exactly twice the #bufferSize that was requested when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def render(dest : Array(Float64) | Slice(Float64)) : Nil #

Renders new interleaved PCM data to dest as interleaved audio, and advances the playback state. The audio is rendered in signed 32-bit PCM format (the native format internally), then automatically converted to 64-bit IEEE floating point audio.

You must call #play once before calling this.

The size of `` MUST be exactly twice the #bufferSize that was requested when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def render(dest : Array(Float32) | Slice(Float32)) : Nil #

Renders new PCM interleaved data to dest as interleaved audio, and advances the playback state. The audio is rendered in signed 32-bit PCM format (the native format internally), then automatically converted to 32-bit IEEE floating point audio.

You must call #play once before calling this.

The size of `` MUST be exactly twice the #bufferSize that was requested when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def renderLQ(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. The audio is rendered in signed 32-bit PCM format (the native format internally), then automatically converted to signed 16-bit PCM using a slightly lower quality (but slightly faster) sample conversion.

You must call #play once before calling this.

The size of left and right MUST be even and MUST be equal to the #bufferSize provided when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def renderLQ(dest : Array(Int16) | Slice(Int16)) : Nil #

Renders new PCM interleaved data to dest as interleaved audio, and advances the playback state. The audio is rendered in signed 32-bit integer format (the native format internally), then automatically converted to signed 16-bit PCM using a slightly lower quality (but slightly faster) sample conversion.

You must call #play once before calling this.

The size of `` MUST be exactly twice the #bufferSize that was requested when you created this instance. If your program is compiled without the -Dyunosynth_wd40, this will be checked, otherwise this check is left out at compile time.


[View source]
def reset : Nil #

Resets the player to the beginning.


[View source]
def sampleRate : UInt32 #

The output sample rate.


[View source]
def settings : VgmPlayerSettings #

The currently loaded settings for the player.


[View source]
def stop : Nil #

Sets "#atEnd?totrue`.


[View source]
def timesPlayed : UInt32 #

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


[View source]
def timesPlayed=(timesPlayed : UInt32) #

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


[View source]
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.


[View source]
def vgm : VgmFile #

The currently loaded VgmFile instance.


[View source]
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.


[View source]