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, bufferSize : Int32, 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.
- .minBufferSize(sampleRate : Int) : Int32
Instance Method Summary
-
#atEnd? : Bool
When
true
, then the player has reached the end of the VGM file. -
#bufferSize : Int32
The size of the buffers used for rendering.
-
#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 : Nil
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(Int32) | Slice(Int32), right : Array(Int32) | Slice(Int32)) : Nil
Renders new PCM data to the left and right buffers, and advances the playback state.
-
#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.
-
#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.
-
#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.
-
#render(dest : Array(Int32) | Slice(Int32)) : Nil
Renders new interleaved PCM data to
dest
as interleaved audio, and advances the playback state. -
#render(dest : Array(Int16) | Slice(Int16)) : Nil
Renders new PCM interleaved data to
dest
as interleaved audio, and advances the playback state. -
#render(dest : Array(Float64) | Slice(Float64)) : Nil
Renders new interleaved PCM data to
dest
as interleaved audio, and advances the playback state. -
#render(dest : Array(Float32) | Slice(Float32)) : Nil
Renders new PCM interleaved data to
dest
as interleaved audio, and advances the playback state. -
#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.
-
#renderLQ(dest : Array(Int16) | Slice(Int16)) : Nil
Renders new PCM interleaved data to
dest
as interleaved audio, 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
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
.
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
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.
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. 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.