abstract class RemiAudio::Formats::AudioFile
- RemiAudio::Formats::AudioFile
- Reference
- Object
Overview
Base class for all PCM- and IEEE Float-based audio file formats.
Direct Known Subclasses
Defined in:
remiaudio/formats/audiofile.crConstructors
Class Method Summary
- .open(io : IO, &) : Nil
- .open(filename : Path | String, &) : Nil
- .test(filename : Path | String) : Type | Nil
Instance Method Summary
-
#<<(sample : Float64) : self
Same as
#write
. -
#bitDepth : UInt8
The bit depth of this instance.
-
#channels : UInt32
The number of channels this instance has.
-
#close : Nil
Flushes the underlying
IO
then closes it. -
#copyTo(dest : IO) : Nil
Writes the current state of this file to dest.
-
#each(& : Float64 -> ) : Nil
Loops over all of the samples within this instance, yielding each one to the block as a
::Float64
sample value. -
#eachSample(& : Sample -> ) : Nil
Loops over all of the samples within this instance, yielding each one to the block as a
RemiAudio::Sample
value. -
#flush : Nil
Flushes the underlying
IO
and updates any header fields. -
#io : IO
The underlying IO.
-
#mono? : Bool
Returns
true
if this is a monaural audio file, orfalse
otherwise. -
#numSamples : UInt64
The current number of samples.
-
#pos : UInt64
Returns the current sample position.
-
#pos=(value : Int) : Nil
Sets the current sample position.
-
#read(pos : Int) : Float64
Reads a single sample from an arbitrary point in the file and returns it as a
::Float64
sample value. -
#read(dest : Array(Float64)) : Int32
Reads up to
dest.size
samples as::Float64
sample values into dest. -
#read : Float64
Reads a single sample and returns it as a
::Float64
sample value. -
#read? : Float64 | Nil
Attempts to read a single sample, returning it as a
::Float64
sample value on success, ornil
if no more samples can be read. -
#readSample(pos : Int) : Sample
Reads a single sample from an arbitrary point in the file.
-
#readSample : Sample
Reads a single sample and returns it as a
RemiAudio::Sample
sample value. -
#readSample? : Sample | Nil
Attempts to read a single sample, returning it as a
RemiAudio::Sample
sample value on success, ornil
if no more samples can be read. -
#readSamples(dest : SampleData) : Int32
Reads up to
dest.size
samples asRemiAudio::Sample
values into dest. -
#readSamplesToEnd : SampleData
Reads all remaining samples, returning them as
RemiAudio::SampleData
. -
#readToEnd : Array(Float64)
Reads all remaining samples, returning them as
::Float64
sample values. -
#rewind : Nil
Rewinds the internal read cursor to the beginning of the sample data.
-
#sampleFormat : SampleFormat
Returns a
RemiAudio::SampleFormat
appropriate for this file. -
#sampleRate : UInt32
The sample rate of this instance.
-
#stereo? : Bool
Returns
true
if this is a stereo audio file, orfalse
otherwise. -
#toEnd : Nil
Seeks to the end of the samples.
-
#withExcursion(newSamplePos : Int32, &)
Temporary seeks to the given sample number, yields the block, then returns to the previous sample number.
-
#write(value : Float64) : self
Writes a single sample, then returns
self
. -
#write(samples : Array(Float64)) : self
Writes samples, then returns
self
. -
#writeSample(value : Sample) : self
Writes a single sample, then returns
self
. -
#writeSamples(samples : SampleData) : self
Writes samples, then returns
self
.
Constructor Detail
Class Method Detail
Instance Method Detail
Writes the current state of this file to dest. This will automatically
call #flush
before writing.
Loops over all of the samples within this instance, yielding each one to
the block as a ::Float64
sample value.
This will call #withExcursion
to set the position to the first sample,
so once the block finishes, the internal read cursor will be back at its
original position.
Loops over all of the samples within this instance, yielding each one to
the block as a RemiAudio::Sample
value.
This will call #withExcursion
to set the position to the first sample,
so once the block finishes, the internal read cursor will be back at its
original position.
Returns the current sample position. This is different than calling
io.pos
in that this is based on samples, not necessarily bytes.
Sets the current sample position. This is different than calling io.pos = value
in that this is based on samples, not necessarily bytes.
This will raise an ::ArgumentError
if value is less than zero.
Reads a single sample from an arbitrary point in the file and returns it
as a ::Float64
sample value. This does not change the current read
position, thus allowing random access reading.
Reads up to dest.size
samples as ::Float64
sample values into dest.
The actual number of samples read is then returned.
Reads a single sample and returns it as a ::Float64
sample value. If no
more samples are available, this raises an ::IO::EOFError
.
Attempts to read a single sample, returning it as a ::Float64
sample
value on success, or nil
if no more samples can be read.
Reads a single sample from an arbitrary point in the file. This does not change the current read position, thus allowing random access reading.
Reads a single sample and returns it as a RemiAudio::Sample
sample
value. If no more samples are available, this raises an ::IO::EOFError
.
Attempts to read a single sample, returning it as a RemiAudio::Sample
sample value on success, or nil
if no more samples can be read.
Reads up to dest.size
samples as RemiAudio::Sample
values into dest.
The actual number of samples read is then returned.
Reads all remaining samples, returning them as RemiAudio::SampleData
.
Reads all remaining samples, returning them as ::Float64
sample values.
Returns a RemiAudio::SampleFormat
appropriate for this file.
Seeks to the end of the samples. Writing a sample after this will add a new sample into this instance.
Temporary seeks to the given sample number, yields the block, then returns to the previous sample number. This returns the final value in the block.