Function timeStretch

  • OFFLINE independent time-stretch of a single channel.

    Parameters

    • input: Float32Array

      Mono signal.

    • factor: number

      Stretch factor α = a_s/a_a (Průša 2022, Eq.7). >1 lengthens (slower tempo), <1 shortens (faster tempo); pitch unchanged.

    • opts: TimeStretchOptions = {}

    Returns Float32Array

    A new Float32Array of length ≈ round(input.length·factor) at the SAME pitch as the input.

    Pipeline (Průša 2022, the STFT analysis-modify-synthesis loop, p.2-3):

    1. Whole-signal STFT (Hann window, analysis hop a_a) → magnitude s + phase φ_a.
    2. Phase gradients: CENTERED time derivative Δt φ_a (Eqs 13-15, heterodyned) and the directional forward/backward frequency difference Δf φ_a (Eqs 16-17). See the gradient block below for why the directional (rather than the centered+trapezoidal) frequency integration is used.
    3. Per frame: PGHI heap integration (Algorithm 1) → synthesis phase φ_s, using synthesis hop a_s for the trapezoidal TIME update (Eq.8) and synthesis freq step b_s = α·b_a for the directional FREQUENCY update.
    4. ISTFT each synthesis frame (s·e^{iφ_s}) + Hann window, overlap-add at synthesis hop a_s, normalized by the COLA window-energy envelope.