ResampleAudio

From Avisynth wiki
Revision as of 02:12, 27 February 2016 by Raffriff42 (Talk | contribs)

Jump to: navigation, search

High-quality change of audio sample rate.

  • Accepts any number of channels.
  • The conversion is skipped if the sample rate is already at the given rate.
  • Supports fractional resampling (where new_rate_denominator ≠ 1).
  • Note, internal rounding may affect AudioDuration slighly – see example below.


Syntax and Parameters

ResampleAudio(clip clip, int new_rate_numerator [, int new_rate_denominator ] )

int  new_rate_numerator =
Set the numerator for the new sample rate.
int  new_rate_denominator = 1
Set the denominator for the new sample rate. Default 1.


Examples

  • Resample audio to 48 kHz:
source = WavSource("c:\audio.wav")
return ResampleAudio(source, 48000)
  • Exact 4% speed up for PAL telecine:
Nfr_num = 25
Nfr_den = 1
AviSource("C:\Film.avi") # 23.976 fps, 44100Hz
Ar = AudioRate
# intermediate sample rate:
ResampleAudio(Ar*FramerateNumerator*Nfr_den, FramerateDenominator*Nfr_num)
# final sample rate:
AssumeSampleRate(Ar)
AssumeFPS(Nfr_num, Nfr_den, false)

In the example above, the intermediate sample rate needs to be

(AudioRate*FramerateNumerator*Nfr_den=1)/(FramerateDenominator*Nfr_num=25)
or (44100 * 24000 * 1) / (1001 * 25) = 42293.706294...

but because audio sample rates are always integers, 42293.706294 must be rounded to 42294,
which results in a time slippage of about 30ms per hour.


Changes

v2.56 Added new_sample_rate=float.
Personal tools