struct RemiAudio::DSP::Ditherer

Overview

A record that is used to hold dithering state for TPDF dithering. This structure can be used to convert samples from one type to another.

The Ditherer struct also contains methods for converting sample formats without dithering.

Defined in:

remiaudio/dsp/ditherer.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

Creates a new Ditherer instance.


[View source]

Class Method Detail

def self.withConvertedSamples(from : SampleData, srcFormat : SampleFormat, destFormat : SampleFormat, *, useNoiseShaping : Bool = false, & : Sample, Int32 -> ) #

For each sample in from, this converts the sample using a Ditherer to the destination format, then yields the converted sample and its index. Unlike Ditherer.withDitheredSamples, this uses the #ditherOrConvert method internally.


[View source]
def self.withDitheredSamples(from : RemiAudio::SampleData, srcFormat : SampleFormat, targetBitDepth : Int, *, useNoiseShaping : Bool = false, & : RemiAudio::Sample, Int32 -> ) #

For each sample in from, this converts the sample using a Ditherer to the destination format, then yields the converted sample and its index.


[View source]

Instance Method Detail

def dither(sample : RemiAudio::Sample, srcFormat : SampleFormat, targetBitDepth : Int, *, useNoiseShaping = false) : Sample #

Converts sample to a signed integer sample of targetBitDepth bits while applying TPDF dithering when needed. The format of sample must be supplied via srcFormat. The returned value is guaranteed to fit in targetBitDepth bits.

If the sample is already an integer sample, and targetBitDepth is already greater than or equal to the current bit depth, then the sample is simply coerced to the appropriate integer type without dithering.

Unsupported bit depths will cause this to raise an InvalidBitDepthError.


[View source]
def ditherOrConvert(sample : RemiAudio::Sample, srcFormat : SampleFormat, destFormat : SampleFormat, *, useNoiseShaping : Bool = false) : RemiAudio::Sample #

Converts sample from srcFormat to destFormat, applying dithering using #dither as-needed.

Unlike the #dither method, this knows how to convert between float formats.


[View source]