Skip to content

Playback Warp Processor

David Braun edited this page Jun 30, 2022 · 2 revisions

Pitch-stretching and Time-stretching with Warp Markers

(For a companion project related to warp markers, see AbletonParsing. )

Time-stretching and pitch-stretching are currently available thanks to Rubber Band Library.

engine = daw.RenderEngine(SAMPLE_RATE, BUFFER_SIZE)

playback_processor = engine.make_playbackwarp_processor("drums", load_audio_file("drums.wav"))
playback_processor.time_ratio = 2.  # Play back in twice the amount of time (i.e., slowed down).
playback_processor.transpose = -5.  # Down 5 semitones.

# Optionally set more options:
# https://breakfastquay.com/rubberband/code-doc/classRubberBand_1_1RubberBandStretcher.html
playback_processor.set_options(
  daw.PlaybackWarpProcessor.option.OptionTransientsSmooth |
  daw.PlaybackWarpProcessor.option.OptionPitchHighQuality |
  daw.PlaybackWarpProcessor.option.OptionChannelsTogether
)

graph = [
  (playback_processor, []),
]

engine.load_graph(graph)

You can set an Ableton Live .asd file containing warp markers to do beat-matching:

engine = daw.RenderEngine(SAMPLE_RATE, BUFFER_SIZE)

# Suppose that the Ableton clip info thinks the input audio is 120 BPM,
# but we want to play it back at 130 BPM.
engine.set_bpm(130.)
playback_processor = engine.make_playbackwarp_processor("drums", load_audio_file("drum_loop.wav"))
playback_processor.set_clip_file("drum_loop.wav.asd")

graph = [
  (playback_processor, []),
]

engine.load_graph(graph)

The set_clip_file method will set several properties:

  • .warp_markers (np.array [N, 2]) : List of pairs of (time in seconds, time in beats)
  • .start_marker (float) : Start marker position in beats relative to 1.1.1
  • .end_marker (float) : End marker position in beats relative to 1.1.1
  • .loop_start (float) : Loop start position in beats relative to 1.1.1
  • .loop_end (float) : Loop end position in beats relative to 1.1.1
  • .warp_on (bool) : Whether warping is enabled
  • .loop_on (bool) : Whether looping is enabled

Any of these properties can be changed after an .asd file is loaded.

If .warp_on is True, then any value set by .time_ratio will be ignored.

With set_clip_positions, you can use the same audio clip at multiple places along the timeline.

playback_processor.set_clip_positions([[0., 4., 0.], [5., 9., 1.]])

Each tuple of three numbers is the (global timeline clip start, global timeline clip end, local clip offset). Imagine dragging a clip onto an arrangement view. The clip start and clip end are the bounds of the clip on the global timeline. The local clip offset is an offset to the start marker set by the ASD file. In the example above, the first clip starts at 0 beats, ends at 4 beats, and has no offset. The second clip starts at 5 beats, ends at 9 beats, and has a 1 beat clip offset.

Clone this wiki locally