class RemiAudio::Formats::WavFile

Overview

A virtual representation of a RIFF WAVE file (.wav).

RIFF WAVE (usually just called "wave") is, as the name suggests, based on the RIFF file format. It is an extremely common format that originated with IBM and Microsoft.

The official specification supports more encodings, as well as "extensible WAVEs". This library does not support these. See WavEncoding for a list of supported encodings, and WAV_SUPPORTED_INT_BIT_DEPTHS and WAV_SUPPORTED_FLOAT_BIT_DEPTHS for supported bit depths.

Defined in:

remiaudio/formats/wav.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class RemiAudio::Formats::AudioFile

<<(sample : Float64) : self <<, bitDepth : UInt8 bitDepth, channels : UInt32 channels, close : Nil close, copyTo(dest : IO) : Nil copyTo, each(& : Float64 -> ) : Nil each, eachSample(& : Sample -> ) : Nil eachSample, flush : Nil flush, io : IO io, mono? : Bool mono?, numSamples : UInt64 numSamples, pos : UInt64 pos, pos=(value : Int) : Nil pos=, read(pos : Int) : Float64
read(dest : Array(Float64)) : Int32
read : Float64
read
, read? : Float64 | Nil read?, readSample(pos : Int) : Sample
readSample : Sample
readSample
, readSample? : Sample | Nil readSample?, readSamples(dest : SampleData) : Int32 readSamples, readSamplesToEnd : SampleData readSamplesToEnd, readToEnd : Array(Float64) readToEnd, rewind : Nil rewind, sampleFormat : SampleFormat sampleFormat, sampleRate : UInt32 sampleRate, stereo? : Bool stereo?, toEnd : Nil toEnd, withExcursion(newSamplePos : Int32, &) withExcursion, write(value : Float64) : self
write(samples : Array(Float64)) : self
write
, writeSample(value : Sample) : self writeSample, writeSamples(samples : SampleData) : self writeSamples

Constructor methods inherited from class RemiAudio::Formats::AudioFile

open(io : IO) : AudioFile
open(filename : Path | String) : AudioFile
open

Class methods inherited from class RemiAudio::Formats::AudioFile

open(io : IO, &) : Nil
open(filename : Path | String, &) : Nil
open
, test(filename : Path | String) : Type | Nil test

Constructor Detail

def self.create(io : IO, *, sampleRate : Int = 44100, bitDepth : Int = 16, channels : Int32 = 2, encoding : WavEncoding = WavEncoding::Lpcm) : WavFile #

Creates a new WavFile that that is backed by io and returns the new instance. Skeleton RIFF file data is immediately written into io.


[View source]
def self.create(filename : Path | String, *, sampleRate : Int = 44100, bitDepth : Int = 16, channels : Int = 2, encoding : WavEncoding = WavEncoding::Lpcm) : WavFile #

Creates a new WavFile that is backed by a new file on disk.

This always opens the file with the mode "w+b" (i.e. existing files are overwritten/truncated). Skeleton RIFF file data is immediately written into the file.


[View source]
def self.new(io : IO, *, sampleRate : UInt32 = 44100_u32, bitDepth : UInt8 = 16_u8, channels : UInt32 = 2_u32, encoding : WavEncoding = WavEncoding::Lpcm) #

Creates a new WavFile that is backed by the given ::IO.


[View source]
def self.new(*, sampleRate : UInt32 = 44100_u32, bitDepth : UInt8 = 16_u8, channels : UInt32 = 2_u32, encoding : WavEncoding = WavEncoding::Lpcm) #

Creates a new WavFile that is backed by a fresh ::IO::Memory.


[View source]
def self.open(io : IO) : WavFile #

Creates a new WavFile by reading the existing RIFF WAVE data from io. Samples will be streamed from io as needed.


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

Creates a new WavFile by reading the existing RIFF WAVE data from the given file. The file is always opened with the mode "r+b". Samples will be streamed from the file as needed.


[View source]

Class Method Detail

def self.create(io : IO, *, sampleRate : Int = 44100, bitDepth : Int = 16, channels : Int32 = 2, encoding : WavEncoding = WavEncoding::Lpcm, &) #

Creates a new WavFile that that is backed by io and yields the new instance to the block. Skeleton RIFF file data is immediately written into io. The WavFile instance will be flushed and closed once the block exits.


[View source]
def self.create(filename : Path | String, *, sampleRate : Int = 44100, bitDepth : Int = 16, channels : Int = 2, encoding : WavEncoding = WavEncoding::Lpcm, &) #

Creates a new WavFile that is backed by a new file on disk, then yields it to the block. This automatically closes the AuFile and the underlying file before the block returns.

This always opens the file with the mode "w+b" (i.e. existing files are overwritten/truncated). Skeleton RIFF file data is immediately written into the file.


[View source]
def self.open(io : IO, &) #

Creates a new WavFile by reading the existing RIFF WAVE data from io, then yields it to the block. Samples will be streamed from io as needed. This will NOT automatically close the WavFile before returning in case you have passed an io that cannot does not support writing.


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

Creates a new WavFile by reading the existing RIFF WAVE data from the file, then yields it to the block. The file is always opened with the mode "r+b". Samples will be streamed from io as needed. This will automatically close the WavFile and underlying ::IO before returning.


[View source]

Instance Method Detail

def copyTo(dest : IO) : Nil #
Description copied from class RemiAudio::Formats::AudioFile

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


[View source]
def encoding : WavEncoding #

The WavEncoding that the samples in this instance uses.


[View source]
def flush : Nil #

:inherited:


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

:inherited:


[View source]
def readSamplesToEnd : SampleData #

:inherited:


[View source]
def sampleFormat : SampleFormat #

:inherited:


[View source]