TimeStretch

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (UNDO *** TODO "an updated SoundTouch library is used" ***)
(note AVS+ differences)
(34 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Change the audio speed and/or [[Wikipedia:Pitch_(music)|pitch]]:
+
TimeStretch allows changing the sound tempo, [[Wikipedia:Pitch_(music)|pitch]] and playback rate parameters independently from each other, i.e.:
 
{| border="0"
 
{| border="0"
|style="line-height:1.2em"|{{BoldColor|blue|100|•}} {{FuncArg|tempo}}
+
|style="line-height:1.2em"|{{BoldColor|#669999|85|}} {{FuncArg|tempo}}
|style="line-height:1.2em"|adjusts speed while maintaining pitch.
+
|style="line-height:1.2em"|adjusts speed while maintaining the original pitch.
 
|-
 
|-
|style="line-height:1.2em"|{{BoldColor|blue|100|•}} {{FuncArg|rate}}
+
|style="line-height:1.2em"|{{BoldColor|#669999|85|}} {{FuncArg|pitch}}
|style="line-height:1.2em"|adjusts speed while allowing pitch to rise or fall.
+
|style="line-height:1.2em"|adjusts speed while maintaining the original tempo.
 
|-
 
|-
|style="line-height:1.2em"|{{BoldColor|blue|100|•}} {{FuncArg|pitch}}
+
|style="line-height:1.2em"|{{BoldColor|#669999|85|}} {{FuncArg|rate}}
|style="line-height:1.2em"|adjusts pitch while maintaining speed.
+
|style="line-height:1.2em"|adjusts playback rate that affects both tempo and pitch at the same time.
 
|}
 
|}
 
You can use these parameters in any combination – for example, 104% {{FuncArg|tempo}} with 95% {{FuncArg|pitch}}.
 
You can use these parameters in any combination – for example, 104% {{FuncArg|tempo}} with 95% {{FuncArg|pitch}}.
 
  
 
__TOC__
 
__TOC__
 
 
==== Syntax and Parameters ====
 
==== Syntax and Parameters ====
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
{{FuncDef
+
{{Func2Def
 
|TimeStretch(clip ''clip'' [, float ''tempo'', float ''rate'', float ''pitch'', <br>
 
|TimeStretch(clip ''clip'' [, float ''tempo'', float ''rate'', float ''pitch'', <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''sequence'', int ''seekwindow'', int ''overlap'', bool ''quickseek'', int ''aa'' ] )
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''sequence'', int ''seekwindow'', int ''overlap'', bool ''quickseek'', int ''aa'' ])
 +
|TimeStretch(clip ''clip'' [, int ''tempo_n'', int ''tempo_d'', int ''rate_n'', int ''rate_d'', int ''pitch_n'', int ''pitch_d'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''sequence'', int ''seekwindow'', int ''overlap'', bool ''quickseek'', int ''aa'' ])
 
}}
 
}}
  
:{{FuncArg|clip|clip|}}
+
:{{Par2|clip|clip|}}
::Audio sample type is automatically converted to [[Float]].
+
::Source clip. Audio is always converted to [[Float]].
::If {{FuncArg|clip}}.[[Clip_properties|AudioChannels]]=2, special processing is used to preserve [[Wikipedia:Stereo_imaging|stereo imaging]]. Otherwise, channels are processed independently. Independent processing works well for unrelated audio tracks, for not very well for [[Wikipedia:5.1_surround_sound|surround sound]]; for that, try [[TimeStretchPlugin]] instead. * [[TODO]] ''(this information may not be up to date)''
+
::{{AvsPluscon}} no conversion is performed. Accepts [[Float]] audio only.
 +
::Starting from v2.61 multichannel audio is supported.
 +
::Prior to v2.61: If {{FuncArg|clip}}.[[Clip_properties|AudioChannels]]=2, special processing is used to preserve [[Wikipedia:Stereo_imaging|stereo imaging]]. Otherwise, channels are processed independently. Independent processing works well for unrelated audio tracks, but not very well for [[Wikipedia:5.1_surround_sound|surround sound]]; pending the release of AviSynth v2.61, try [[TimeStretchPlugin]] instead. <sup>[http://forum.doom9.org/showthread.php?t=71632] [http://forum.doom9.org/showthread.php?t=172054#post1718302]</sup>
  
<div style="margin:0 0 0 0.5em" >
+
<div style="margin:0 0 0 2em" >
===== &nbsp;''Tempo, Rate and Pitch'' =====
+
===== ''Tempo, Rate and Pitch'' =====
 
</div>
 
</div>
 
:{{Par2|tempo|float|100.0}}
 
:{{Par2|tempo|float|100.0}}
::Changes speed and {{FuncArg|clip}}.[[Clip_properties|AudioLength]] while maintaining the original [[Wikipedia:Pitch_(music)|pitch]].
+
::Changes speed while maintaining the original [[Wikipedia:Pitch_(music)|pitch]].  
 
::If {{FuncArg|tempo}}=200, the audio will play twice (200%) as fast; if {{FuncArg|tempo}}=50, the audio will play half (50%) as fast.
 
::If {{FuncArg|tempo}}=200, the audio will play twice (200%) as fast; if {{FuncArg|tempo}}=50, the audio will play half (50%) as fast.
 +
::The effect is also known as [[Wikipedia:Audio_time-scale/pitch_modification|time-stretching]].
  
 
:{{Par2|rate|float|100.0}}
 
:{{Par2|rate|float|100.0}}
::Changes speed and {{FuncArg|clip}}.[[Clip_properties|AudioLength]] while allowing [[Wikipedia:Pitch_(music)|pitch]] to rise or fall.
+
::Changes speed while allowing [[Wikipedia:Pitch_(music)|pitch]] to rise or fall, like the traditional analog [[Wikipedia:Pitch_control|vari-speed]] effect.  
::Adjusting {{FuncArg|rate}} is equivalent to adjusting the speed of a [[Wikipedia:Phonograph|record player]] or [[Wikipedia:Tape_recorder|tape recorder]].  
+
 
::If {{FuncArg|rate}}=200, the audio will play twice (200%) as fast; if {{FuncArg|rate}}=50, the audio will play half (50%) as fast.
 
::If {{FuncArg|rate}}=200, the audio will play twice (200%) as fast; if {{FuncArg|rate}}=50, the audio will play half (50%) as fast.
  
::By the way, the following script:
+
::Rate control is implemented purely by sample rate transposing.<sup>[http://www.surina.net/soundtouch/README.html]</sup>  
<div {{BoxWidthIndent|24|6}} >
+
::If {{FuncArg|rate}} is adjusted by itself, no [[Wikipedia:Audio_time-scale/pitch_modification|time-stretching or pitch-shifting]] is performed, and the [[#Advanced_Parameters|'''''Advanced Parameters''''']] will have no effect.
TimeStretch(rate=105)
+
</div>
+
::is equivalent to
+
<div {{BoxWidthIndent|24|6}} >
+
ar=[[Clip_properties|AudioRate]]  
+
[[AssumeSampleRate]](Round(ar*1.05))
+
[[ResampleAudio]](ar)
+
</div>
+
  
 
:{{Par2|pitch|float|100.0}}
 
:{{Par2|pitch|float|100.0}}
::Changes [[Wikipedia:Pitch_(music)|pitch]] while maintaining the length of the original sample: ''{{FuncArg|clip}}.[[Clip_properties|AudioLength]]'' is not changed.  
+
::Changes [[Wikipedia:Pitch_(music)|pitch]] while maintaining the original speed (within a small tolerance&ndash;see [[#Notes|Notes]] below).
::(within a small tolerance &ndash; see [[#Notes|Notes]] below)
+
::If {{FuncArg|pitch}}=200, the audio will sound an [[Wikipedia:Octave|octave]] higher; if {{FuncArg|pitch}}=50, the audio will sound an octave lower.
 +
::The effect is also known as [[Wikipedia:Audio_time-scale/pitch_modification|pitch-shifting]].
 +
 
 +
:{{FuncArg|tempo}}, {{FuncArg|rate}} and {{FuncArg|pitch}} can all be adjusted independently, in which case their effects are added together.
 +
 
 +
<div style="margin:0 0 0 2em" >
 +
 
 +
===== ''Tempo_n, Tempo_d, Rate_n, Rate_d, Pitch_n and Pitch_d'' =====
 +
</div>
 +
:When needing more accuracy you can use the rational pair parameters {{FuncArg|tempo_n}}, {{FuncArg|tempo_d}}, {{FuncArg|rate_n}}, {{FuncArg|rate_d}}, {{FuncArg|pitch_n}} and {{FuncArg|pitch_d}} instead. All parameters are integers and have default value 1. Internally {{FuncArg|tempo}} is calculated as double({{FuncArg|tempo_n}}/{{FuncArg|tempo_d}}) ({{FuncArg|rate}} and {{FuncArg|pitch}} likewise), before further processing. Seeking should be sample exact.
  
:{{FuncArg|Tempo}}, {{FuncArg|rate}} and {{FuncArg|pitch}} can all be adjusted independently, in which case their effects are added together.
+
<div style="margin:0 0 0 2em" >
  
<div style="margin:0 0 0 0.5em" >
+
===== ''Advanced Parameters'' =====
===== &nbsp;''Advanced Parameters'' =====
+
 
</div>
 
</div>
 
:The time-stretch algorithm has a few parameters that can be tuned to optimize sound quality for certain applications. The current default parameters have been chosen by iterative if-then analysis (read: "trial and error") to obtain the best subjective sound quality in pop/rock music processing, but in applications processing different kind of sound the default parameter set may return a sub-optimal result.
 
:The time-stretch algorithm has a few parameters that can be tuned to optimize sound quality for certain applications. The current default parameters have been chosen by iterative if-then analysis (read: "trial and error") to obtain the best subjective sound quality in pop/rock music processing, but in applications processing different kind of sound the default parameter set may return a sub-optimal result.
  
:{{Par2|sequence|int|82 *}}
+
:These parameters affect the time-stretch algorithm as follows:
 +
 
 +
:{{Par2|sequence|int|100 *}}
 
::This is the length of a single ''processing sequence'' in milliseconds, which determines how the original sound is chopped in the time-stretch algorithm. Larger values mean fewer, and longer, sequences are used. In general,  
 
::This is the length of a single ''processing sequence'' in milliseconds, which determines how the original sound is chopped in the time-stretch algorithm. Larger values mean fewer, and longer, sequences are used. In general,  
 
::* a larger {{FuncArg|sequence}} value sounds better with a lower {{FuncArg|tempo}} and/or {{FuncArg|pitch}};  
 
::* a larger {{FuncArg|sequence}} value sounds better with a lower {{FuncArg|tempo}} and/or {{FuncArg|pitch}};  
 
::* a smaller {{FuncArg|sequence}} value sounds better with a higher {{FuncArg|tempo}} and/or {{FuncArg|pitch}}.
 
::* a smaller {{FuncArg|sequence}} value sounds better with a higher {{FuncArg|tempo}} and/or {{FuncArg|pitch}}.
  
:{{Par2|seekwindow|int|28 *}}
+
:{{Par2|seekwindow|int|22 *}}
::The length in milliseconds for the algorithm that searches for the best possible overlap location. For larger {{FuncArg|seekwindow}} values, the possibility of finding a better mixing position increases, but too-large {{FuncArg|seekwindow}} values may cause a "drifting" sound (a disturbing artifact where what ''should'' be steady frequencies &ndash; such as piano notes &ndash; seem to drifting around) because neighboring sequences may be chosen at more uneven intervals.
+
::The length in milliseconds for the algorithm that searches for the best possible overlap location. For larger {{FuncArg|seekwindow}} values, the possibility of finding a better mixing position increases, but an overly large {{FuncArg|seekwindow}} may cause '''''drifting''''' (a disturbing artifact where audio pitch seems unsteady) because neighboring sequences may be chosen at more uneven intervals.
  
:{{Par2|overlap|int|12 *}}
+
:{{Par2|overlap|int|8 *}}
 
::The overlap length in milliseconds. When the sound sequences are mixed back together to form a continuous sound stream again, {{FuncArg|overlap}} defines how much of the ends of the consecutive sequences will be overlapped. This shouldn't be a critical parameter. If you reduce the {{FuncArg|sequence}} by a large amount, you might wish to try a smaller {{FuncArg|overlap}}.
 
::The overlap length in milliseconds. When the sound sequences are mixed back together to form a continuous sound stream again, {{FuncArg|overlap}} defines how much of the ends of the consecutive sequences will be overlapped. This shouldn't be a critical parameter. If you reduce the {{FuncArg|sequence}} by a large amount, you might wish to try a smaller {{FuncArg|overlap}}.
  
:{{Par2|quickseek|bool|true? *}}
+
:{{Par2|quickseek|bool|false *}}
::The time-stretch routine has a 'quick' mode that substantially speeds up the algorithm but may degrade the sound quality.  
+
::The time-stretch routine has a 'quick' mode that substantially speeds up the algorithm but may degrade the sound quality when {{FuncArg|quickseek}} is set to true.
 +
::*'''Try {{Template:FuncArg|quickseek}}=false''' if you hear artifacts like warbling, clicking etc.
  
:{{Par2|aa|int|? *}}  
+
:{{Par2|aa|int|64 *}}  
 
::Controls the number of ''taps'' the [[Wikipedia:Finite_impulse_response|anti-alias filter]] uses. Set to 0 to disable the filter. Must be a multiple of 4.
 
::Controls the number of ''taps'' the [[Wikipedia:Finite_impulse_response|anti-alias filter]] uses. Set to 0 to disable the filter. Must be a multiple of 4.
 
:'''*''' [[TODO]] ''( default values are under investigation at the time of updating this documentation )''
 
 
  
 
:This table summarizes how these parameters can be adjusted for different applications:
 
:This table summarizes how these parameters can be adjusted for different applications:
Line 115: Line 117:
 
|style="vertical-align:top"| Larger value increases CPU burden.
 
|style="vertical-align:top"| Larger value increases CPU burden.
 
|}
 
|}
 +
:'''*''' {{FuncArg|sequence}} and {{FuncArg|seekwindow}} have default values 100 and 22. However they are updated if the calculated tempo is different from the default value (100). The calculated tempo depends on the specified tempo or pitch in your script. It will be different from 100 if tempo or pitch in your script is different from 100. The update of the default values happens in TDStretch::calcSeqParameters().
 
</div>
 
</div>
 
  
 
==== Notes ====
 
==== Notes ====
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
* Slight audio duration inaccuracies might occur. Since we are dealing with float values for {{FuncArg|Tempo}}, {{FuncArg|rate}} and {{FuncArg|pitch}}, but [[Clip_properties|audio sample rates]] are always integers, rounding errors might occur, especially on long duration audio tracks. In general however, inaccuracies should not exceed a few 10's of milliseconds for movie-length samples.
+
* Since {{FuncArg|tempo}}, {{FuncArg|rate}} and {{FuncArg|pitch}} are floating-point values, but [[Clip_properties|sample rates]] are integers, rounding effects in calculations are unavoidable; the resulting audio track duration may be off by up to several 10's of milliseconds (less than one video frame) per hour.
 +
<div {{ListItemContinue}} >
 +
Pitch is also rounded for the same reason, but the amount is so small that the effect is inaudible: according to Wikipedia, the [[Wikipedia:Pitch_(music)#Just-noticeable_difference|just-noticeable pitch difference]] is 0.1%&ndash;0.6%, while the rounding error is about 0.002%.
 +
</div>
  
* In '''TimeStretch''' 2.61 an updated [http://www.surina.net/soundtouch/ SoundTouch] library is used which supports multichannel audio. Prior versions supported stereo only. See this thread for details :- [http://forum.doom9.org/showthread.php?t=71632 ''TimeStretch in AVISynth 2.5.5 Alpha - Strange stereo effects?'']  
+
* In upcoming AviSynth v2.61<sup>[http://forum.doom9.org/showthread.php?t=172054#post1718302]</sup> an updated [http://www.surina.net/soundtouch/ SoundTouch] library is used which supports multichannel audio. AviSynth v2.60 and below support stereo only. See the thread [http://forum.doom9.org/showthread.php?t=71632 ''TimeStretch in AVISynth 2.5.5 Alpha - Strange stereo effects?''] for details.
 
</div>
 
</div>
  
 
==== Examples ====
 
==== Examples ====
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
* Raise pitch one octave, while preserving the length of the original sample.
+
* Raise pitch one octave, without changing speed:
 
<div {{BoxWidthIndent|36|3}} >
 
<div {{BoxWidthIndent|36|3}} >
  TimeStretch(pitch=200)  
+
  TimeStretch(pitch=200.0)
 +
# TimeStretch(pitch_n=2, pitch_d=1) # more accurate processing
 
</div>
 
</div>
  
* Raise [[Wikipedia:Pitch_(music)|pitch]] one semi-tone, while preserving the length of the original sample.
+
* Raise pitch one [[Wikipedia:Semitone|semi-tone]], without changing speed:
 
<div {{BoxWidthIndent|36|3}} >
 
<div {{BoxWidthIndent|36|3}} >
  ## (pitch changes
+
  delta_pitch=1.0 ## (semitones)
  TimeStretch(pitch=100.0*pow(2.0, 1.0/12.0))  
+
  TimeStretch(pitch=100.0*pow(2.0, delta_pitch/12.0))  
 
</div>
 
</div>
  
* Change playback tempo from NTSC Film speed ([[ShowFrameNumber#Drop-Frame_versus_Non-Drop-Frame_Time_Code|23.97 fps]]) to PAL speed (25 fps) without changing pitch.
+
* Raise playback tempo from NTSC Film speed ([[ShowFrameNumber#Drop-Frame_versus_Non-Drop-Frame_Time_Code|23.97 fps]]) to PAL speed (25 fps) without changing pitch:
 
<div {{BoxWidthIndent|36|3}} >
 
<div {{BoxWidthIndent|36|3}} >
 
  TimeStretch(tempo=100.0*25.0/(24000.0/1001.0))
 
  TimeStretch(tempo=100.0*25.0/(24000.0/1001.0))
 +
</div>
 +
 +
* Increase speed to 105%, allowing pitch to rise.
 +
<div {{BoxWidthIndent|36|3}} >
 +
TimeStretch({{FuncArg|rate}}=105)
 +
</div>
 +
<div {{ListItemContinue}} >
 +
...which is equivalent to:
 +
</div>
 +
<div {{BoxWidthIndent|36|3}} >
 +
ar=[[Clip_properties|AudioRate]]
 +
[[AssumeSampleRate]](Round(ar*1.05))
 +
[[ResampleAudio]](ar)
 
</div>
 
</div>
 
</div>
 
</div>
Line 146: Line 165:
 
==== Credits ====
 
==== Credits ====
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
This function uses '''SoundTouch Audio Processing Library''' <br>
+
'''TimeStretch''' uses the ''SoundTouch Audio Processing Library'' <br>
Copyright © Olli Parviainen <br>
+
:Copyright © Olli Parviainen <br>
[http://www.surina.net/soundtouch surina.net/soundtouch]
+
:SoundTouch home page: [http://www.surina.net/soundtouch surina.net/soundtouch]
 
</div>
 
</div>
  
Line 156: Line 175:
 
|-
 
|-
 
| v2.61
 
| v2.61
| Updated SoundTouch library to 1.9.0. Fixes multichannel issues.
+
| Updated SoundTouch library to 1.9.2. Fixes multichannel issues.
 +
|-
 +
|
 +
| Add TimeStretch overload with rational pair arguments.
 
|-
 
|-
 
| v2.57
 
| v2.57

Revision as of 01:07, 5 July 2017

TimeStretch allows changing the sound tempo, pitch and playback rate parameters independently from each other, i.e.:

tempo adjusts speed while maintaining the original pitch.
pitch adjusts speed while maintaining the original tempo.
rate adjusts playback rate that affects both tempo and pitch at the same time.

You can use these parameters in any combination – for example, 104% tempo with 95% pitch.

Contents

Syntax and Parameters

TimeStretch(clip clip [, float tempo, float rate, float pitch,
      int sequence, int seekwindow, int overlap, bool quickseek, int aa ])

TimeStretch(clip clip [, int tempo_n, int tempo_d, int rate_n, int rate_d, int pitch_n, int pitch_d,
      int sequence, int seekwindow, int overlap, bool quickseek, int aa ])

clip  clip =
Source clip. Audio is always converted to Float.
AVS+ no conversion is performed. Accepts Float audio only.
Starting from v2.61 multichannel audio is supported.
Prior to v2.61: If clip.AudioChannels=2, special processing is used to preserve stereo imaging. Otherwise, channels are processed independently. Independent processing works well for unrelated audio tracks, but not very well for surround sound; pending the release of AviSynth v2.61, try TimeStretchPlugin instead. [1] [2]
Tempo, Rate and Pitch
float  tempo = 100.0
Changes speed while maintaining the original pitch.
If tempo=200, the audio will play twice (200%) as fast; if tempo=50, the audio will play half (50%) as fast.
The effect is also known as time-stretching.
float  rate = 100.0
Changes speed while allowing pitch to rise or fall, like the traditional analog vari-speed effect.
If rate=200, the audio will play twice (200%) as fast; if rate=50, the audio will play half (50%) as fast.
Rate control is implemented purely by sample rate transposing.[3]
If rate is adjusted by itself, no time-stretching or pitch-shifting is performed, and the Advanced Parameters will have no effect.
float  pitch = 100.0
Changes pitch while maintaining the original speed (within a small tolerance–see Notes below).
If pitch=200, the audio will sound an octave higher; if pitch=50, the audio will sound an octave lower.
The effect is also known as pitch-shifting.
tempo, rate and pitch can all be adjusted independently, in which case their effects are added together.
Tempo_n, Tempo_d, Rate_n, Rate_d, Pitch_n and Pitch_d
When needing more accuracy you can use the rational pair parameters tempo_n, tempo_d, rate_n, rate_d, pitch_n and pitch_d instead. All parameters are integers and have default value 1. Internally tempo is calculated as double(tempo_n/tempo_d) (rate and pitch likewise), before further processing. Seeking should be sample exact.
Advanced Parameters
The time-stretch algorithm has a few parameters that can be tuned to optimize sound quality for certain applications. The current default parameters have been chosen by iterative if-then analysis (read: "trial and error") to obtain the best subjective sound quality in pop/rock music processing, but in applications processing different kind of sound the default parameter set may return a sub-optimal result.
These parameters affect the time-stretch algorithm as follows:
int  sequence = 100 *
This is the length of a single processing sequence in milliseconds, which determines how the original sound is chopped in the time-stretch algorithm. Larger values mean fewer, and longer, sequences are used. In general,
  • a larger sequence value sounds better with a lower tempo and/or pitch;
  • a smaller sequence value sounds better with a higher tempo and/or pitch.
int  seekwindow = 22 *
The length in milliseconds for the algorithm that searches for the best possible overlap location. For larger seekwindow values, the possibility of finding a better mixing position increases, but an overly large seekwindow may cause drifting (a disturbing artifact where audio pitch seems unsteady) because neighboring sequences may be chosen at more uneven intervals.
int  overlap = 8 *
The overlap length in milliseconds. When the sound sequences are mixed back together to form a continuous sound stream again, overlap defines how much of the ends of the consecutive sequences will be overlapped. This shouldn't be a critical parameter. If you reduce the sequence by a large amount, you might wish to try a smaller overlap.
bool  quickseek = false *
The time-stretch routine has a 'quick' mode that substantially speeds up the algorithm but may degrade the sound quality when quickseek is set to true.
  • Try quickseek=false if you hear artifacts like warbling, clicking etc.
int  aa = 64 *
Controls the number of taps the anti-alias filter uses. Set to 0 to disable the filter. Must be a multiple of 4.
This table summarizes how these parameters can be adjusted for different applications:
Parameter Default value If larger... If smaller... Music Speech CPU burden
sequence Relatively large, chosen for slowing music tempo. Usually better for slowing tempo. You might need less overlap. Accelerates "echoing" artifact when slowing down the tempo. Default value usually good. A smaller value might be better. Smaller value increases CPU burden.
seekwindow  Relatively large, chosen for slowing music tempo. Eases finding a good mixing position, but may cause "drifting" artifact. Makes finding a good mixing position more difficult. Default usually good, unless "drifting" is a problem. Default usually good. Larger value increases CPU burden.
overlap Relatively large, chosen to suit above parameters. Larger value increases CPU burden.
* sequence and seekwindow have default values 100 and 22. However they are updated if the calculated tempo is different from the default value (100). The calculated tempo depends on the specified tempo or pitch in your script. It will be different from 100 if tempo or pitch in your script is different from 100. The update of the default values happens in TDStretch::calcSeqParameters().

Notes

  • Since tempo, rate and pitch are floating-point values, but sample rates are integers, rounding effects in calculations are unavoidable; the resulting audio track duration may be off by up to several 10's of milliseconds (less than one video frame) per hour.

Pitch is also rounded for the same reason, but the amount is so small that the effect is inaudible: according to Wikipedia, the just-noticeable pitch difference is 0.1%–0.6%, while the rounding error is about 0.002%.

Examples

  • Raise pitch one octave, without changing speed:
TimeStretch(pitch=200.0)
# TimeStretch(pitch_n=2, pitch_d=1) # more accurate processing
  • Raise pitch one semi-tone, without changing speed:
delta_pitch=1.0 ## (semitones)
TimeStretch(pitch=100.0*pow(2.0, delta_pitch/12.0)) 
  • Raise playback tempo from NTSC Film speed (23.97 fps) to PAL speed (25 fps) without changing pitch:
TimeStretch(tempo=100.0*25.0/(24000.0/1001.0))
  • Increase speed to 105%, allowing pitch to rise.
TimeStretch(rate=105)

...which is equivalent to:

ar=AudioRate 
AssumeSampleRate(Round(ar*1.05))
ResampleAudio(ar)

Credits

TimeStretch uses the SoundTouch Audio Processing Library

Copyright © Olli Parviainen
SoundTouch home page: surina.net/soundtouch

Changelog

v2.61 Updated SoundTouch library to 1.9.2. Fixes multichannel issues.
Add TimeStretch overload with rational pair arguments.
v2.57 Expose soundtouch parameters
v2.55 Initial Release (based on SoundTouch library 1.4.0?)
Personal tools