abstract class RemiAudio::Formats::AudioFile

Overview

Base class for all PCM- and IEEE Float-based audio file formats.

Direct Known Subclasses

Defined in:

remiaudio/formats/audiofile.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.open(io : IO) : AudioFile #

[View source]
def self.open(filename : Path | String) : AudioFile #

[View source]

Class Method Detail

def self.open(io : IO, &) : Nil #

[View source]
def self.open(filename : Path | String, &) : Nil #

[View source]
def self.test(filename : Path | String) : Type | Nil #

[View source]

Instance Method Detail

def <<(sample : Float64) : self #

Same as #write.


[View source]
def bitDepth : UInt8 #

The bit depth of this instance.


[View source]
def channels : UInt32 #

The number of channels this instance has.


[View source]
def close : Nil #

Flushes the underlying IO then closes it.


[View source]
abstract def copyTo(dest : IO) : Nil #

Writes the current state of this file to dest. This will automatically call #flush before writing.


[View source]
def each(& : Float64 -> ) : Nil #

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.


[View source]
def eachSample(& : Sample -> ) : Nil #

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.


[View source]
abstract def flush : Nil #

Flushes the underlying IO and updates any header fields.


[View source]
def io : IO #

The underlying IO.


[View source]
def mono? : Bool #

Returns true if this is a monaural audio file, or false otherwise.


[View source]
def numSamples : UInt64 #

The current number of samples.


[View source]
def pos : UInt64 #

Returns the current sample position. This is different than calling io.pos in that this is based on samples, not necessarily bytes.


[View source]
def pos=(value : Int) : Nil #

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.


[View source]
def read(pos : Int) : Float64 #

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.


[View source]
abstract def read(dest : Array(Float64)) : Int32 #

Reads up to dest.size samples as ::Float64 sample values into dest. The actual number of samples read is then returned.


[View source]
def read : Float64 #

Reads a single sample and returns it as a ::Float64 sample value. If no more samples are available, this raises an ::IO::EOFError.


[View source]
def read? : Float64 | Nil #

Attempts to read a single sample, returning it as a ::Float64 sample value on success, or nil if no more samples can be read.


[View source]
def readSample(pos : Int) : Sample #

Reads a single sample from an arbitrary point in the file. This does not change the current read position, thus allowing random access reading.


[View source]
def readSample : Sample #

Reads a single sample and returns it as a RemiAudio::Sample sample value. If no more samples are available, this raises an ::IO::EOFError.


[View source]
def readSample? : Sample | Nil #

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.


[View source]
def readSamples(dest : SampleData) : Int32 #

Reads up to dest.size samples as RemiAudio::Sample values into dest. The actual number of samples read is then returned.


[View source]
abstract def readSamplesToEnd : SampleData #

Reads all remaining samples, returning them as RemiAudio::SampleData.


[View source]
def readToEnd : Array(Float64) #

Reads all remaining samples, returning them as ::Float64 sample values.


[View source]
def rewind : Nil #

Rewinds the internal read cursor to the beginning of the sample data.


[View source]
abstract def sampleFormat : SampleFormat #

Returns a RemiAudio::SampleFormat appropriate for this file.


[View source]
def sampleRate : UInt32 #

The sample rate of this instance.


[View source]
def stereo? : Bool #

Returns true if this is a stereo audio file, or false otherwise.


[View source]
def toEnd : Nil #

Seeks to the end of the samples. Writing a sample after this will add a new sample into this instance.


[View source]
def withExcursion(newSamplePos : Int32, &) #

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.


[View source]
def write(value : Float64) : self #

Writes a single sample, then returns self.


[View source]
def write(samples : Array(Float64)) : self #

Writes samples, then returns self.


[View source]
def writeSample(value : Sample) : self #

Writes a single sample, then returns self.


[View source]
def writeSamples(samples : SampleData) : self #

Writes samples, then returns self.


[View source]