[][src]Crate tdpsola

Tdpsola: an implementation of the tdpsola algorithm

TDPSOLA (Time-Domain Pitch-Synchronous Overlap and Add) is an algorithm that allows to modify the pitch and the speed of a sound independently of each other.

Example of reconstructing audio

use tdpsola::{TdpsolaSynthesis, Speed, AlternatingHann, TdpsolaAnalysis};
let input = vec![1.0, 2.0, 3.0, -3.0, -2.0, -1.0, 1.0, 0.0, 1.0];
let source_wavelength = 4.0; // Source wavelength
let mut alternating_hann = AlternatingHann::new(source_wavelength);
let mut analysis = TdpsolaAnalysis::new(&alternating_hann);

// Pre-padding, this is used to avoid artifacts at the beginning of the reconstructed audio.
// If you do not apply pre-padding and discarding of the first samples, the audio will
// in general "fade in" (depending on the window being used) during the first `x` samples
// where `x` is the source wavelength.
let padding_length = source_wavelength as usize + 1;
for _ in 0..padding_length {
    analysis.push_sample(0.0, &mut alternating_hann);
}

// The analysis
for sample in input.iter() {
    analysis.push_sample(*sample, &mut alternating_hann);
}

let target_wavelength = source_wavelength;
let mut synthesis = TdpsolaSynthesis::new(Speed::from_f32(1.0), target_wavelength);


// Re-synthesis and check that it matches with the input.

for (input_sample, output_sample) in input.iter().zip(synthesis.iter(&analysis).skip(padding_length)) {
    assert!((output_sample - input_sample).abs() < 1e-6);
}

Structs

AlternatingHann

Two alternating Hann windows.

AlternatingHat

Two alternating hat windows. This should be more performant than the AlternatingHann.

Speed

The playback speed.

SynthesisIter
TdpsolaAnalysis
TdpsolaSynthesis

Struct used to re-synthesize a TdpsolaSynthesis into audio again.

Enums

SamplingError

Traits

AlternatingWindow

Describes two alternating windows.