Skip to content
forked from echo66/OLA-TS.js

Audio time stretching implementation of a modified Overlap and Add (OLA) algorithm

License

Notifications You must be signed in to change notification settings

combs/OLA-TS.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OLA-TS.js

OLA-TS.js is an audio time stretching implementation of a modified Overlap and Add (OLA) algorithm.

This fork

This fork is an outside attempt to clean up and update the abandoned OLA-TS.js.

Quick start


import { OLATSPlayer } from "ola-ts"

// Set up your audioContext after a user interaction, retrieve & decode audio data, pass it in

var player = new OLATSPlayer(audioContext, decodedAudioData, 4096, 4096);
player.connect(gain);
var gain = audioContext.createGain();
gain.connect(audioContext.destination);
player.speed = 2; // Speeds are reversed from playbackRate. Big num = slow play
player.play();

Constructor

OLATS(Number frameSize): frameSize must be an integer. The default window type is the Lanczos.

API

process(Array inputFrame, CBuffer outputFrame): given a (mono) frame, performs a time stretching iteration and pushes H s samples in the output CBuffer.

clear_buffers(): clears all internal buffers, like the overlapping buffer. This can be useful for audio players that need to create a noticeable stop in the transition to the next file in a playlist, in order to avoid using the phase of the previous song to adjust the phase of the next song.

set_alpha(Number alpha, Number overlap, Number beta): given the new stretching factor, it computes the new values for Hs , Ha (both integers) and invokes the function pointed by overlap_fn.

set_window_type(String windowType): changes the type of the window used within OLA. Available types are Lanczos, Triangular, Bartlett, BartlettHann, Blackman, Cosine, Gauss, Hamming, Hann, Rectangular, SinBeta.

beta_fn(Number alpha): public field pointing to a function that, given a stretching factor α, will return a new window exponent.

overlap_fn(Number alpha): public field pointing to a function that, given a stretching factor α, will return a new overlapping factor.

get_alpha(): returns the last specified stretching factor.

get_ha(): returns the current analysis hop size. This function calculates the increment to the “read head” of the input signal, when playing an audio file.

get_hs(): returns the current synthesis hop size. This function calculates the increment to the output signal position which an be used to guide the cursor in the UI of an audio player using OLA-TS.js as time stretcher.

get_overlap_factor(): returns the current overlapping factor.

get_beta(): returns the current window exponent.

Helpers

BufferedTS: it manages the intermediary frame buffering for two OLATS instances. This class offers two public writable fields, alpha and position to manipulate the stretching factor and the 'read head' of the input audio buffer, as well as two public methods:

  • process(AudioBuffer outputAudioBuffer): writes the next output frame in the provided output audio buffer.
  • set_audio_buffer(AudioBuffer newBuffer): defines the input audio buffer.

WAAPlayer: integrates a BufferedTS instance in a ScriptProcessor node, providing the usual functions connect(AudioNode) and disconnect(AudioNode), two extra public methods, play and stop, as well as four public writable fields: position, speed, audioContext and audioBuffer.

Notes

  • Audio quality, in OLA-TS.js, is strongly dependent on (1) frame size and (2) the overlapping factor. For small frame sizes (=< 2048) and songs with harmonic structures like voices, there will be modulation in the output, which can be minimized with careful management of the overlapping factor (overlap_fn) and window exponent (beta_fn). For large frame sizes (>= 4096), the modulation becomes less perceivable.

  • This time stretcher is recommended for applications that need a cheap solution for time stretching while maintaining good quality for harmonic structures and do not require very fast manipulation of the time stretch factor.

About

Audio time stretching implementation of a modified Overlap and Add (OLA) algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%