class Yuno::VgmPlayer
- Yuno::VgmPlayer
- Reference
- Object
Overview
The VgmPlayer
class is used to play VGM files by rendering them to PCM data.
Defined in:
yunosynth/vgmplayer.cryunosynth/vgmplayerinst.cr
Constant Summary
-
MIN_SAMPLE_RATE =
8000_u32
-
The minimum supported output sample rate.
Constructors
-
.new(vgm : VgmFile, newSettings : VgmPlayerSettings | Nil = nil)
Creates a new
VgmPlayer
instance that will play the given VGM file.
Class Method Summary
-
.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.
-
.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.
Instance Method Summary
-
#atEnd? : Bool
When
true
, then the player has reached the end of the VGM file. -
#chipNamesUsed(useShort : Bool = false) : Array(String)
Returns the list of all the fancy names for the chips that are used in this VGM.
-
#chipsUsed : Hash(ChipType, Int32)
Returns the
Hash
where the keys areChipType
s for the chips that are used in this VGM, and the values are the number of instances of that chip. -
#loopPcmSamples : UInt32
Returns the total number of PCM samples that the loaded VGM will generate in one loop when it is played back.
-
#mainVolume : Float64
The main output volume.
-
#mainVolume=(val : Float64) : Nil
Sets the main output volume of the rendered PCM data.
-
#minBufferSize : Int32
The minimum size for the buffer to use to pass to
#render
. -
#play(lowQualityResampling : Bool = false)
Starts playback.
-
#playing? : Bool
If this is
true
, then#play
has been called and cannot be called again. -
#playTime : Int32
The total number of samples rendered so far.
-
#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.
-
#reset : Nil
Resets the player to the beginning.
-
#sampleRate : UInt32
The output sample rate.
-
#settings : VgmPlayerSettings
The currently loaded settings for the player.
-
#stop : Nil
Sets "#atEnd?
to
true`. -
#timesPlayed : UInt32
The number of times the VGM file has currently played one full loop.
-
#timesPlayed=(timesPlayed : UInt32)
The number of times the VGM file has currently played one full loop.
-
#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.
-
#vgm : VgmFile
The currently loaded
VgmFile
instance. -
#volumeModifier : Float64
The main volume will be multiplied by this when calculating the final output volume.
Constructor Detail
Class Method Detail
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):
- The multiplier for the PCM sample rate
- The divider for the PCM sample rate
- The multiplier for the VGM sample rate
- The divider for the VGM sample rate
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):
- The multiplier for the PCM sample rate
- The divider for the PCM sample rate
Instance Method Detail
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.
Returns the Hash
where the keys are ChipType
s for the chips that are
used in this VGM, and the values are the number of instances of that chip.
Returns the total number of PCM samples that the loaded VGM will generate in one loop when it is played back.
The main output volume. If you want to change the volume, change this
first. 1.0
is the "normal" output volume.
Sets the main output volume of the rendered PCM data. 1.0
is the
"normal" output volume.
The minimum size for the buffer to use to pass to #render
. This is
per-channel.
Starts playback. This must be called before calling #render
. Calling
this more than once is effectively a non-op.
Renders new PCM data to the left and right buffers, and advances the
playback state. You must call #play
exactly once before calling this.
The number of times the VGM file has currently played one full loop. This starts at 0.
The number of times the VGM file has currently played one full loop. This starts at 0.
Returns the total number of PCM samples that the loaded VGM will generate when the loop is ignored and it is played back.
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.