ResampleAudio: Difference between revisions

From Avisynth wiki
Jump to navigationJump to search
Raffriff42 (talk | contribs)
m added category
add link to avs+ documentation
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Template:FuncDef|ResampleAudio(clip, int new_rate_numerator [, int new_rate_denominator])}}
<div style="max-width:62em" >
<div {{BlueBox2|40|0|3px solid purple}} >
{{AvsPlusFullname}}<br>
Up-to-date documentation: [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/resampleaudio.html https://avisynthplus.readthedocs.io]
</div>


ResampleAudio performs a high-quality change of audio sample rate.
The conversion is skipped if the samplerate is already at the given rate.


When using fractional resampling the output audio samplerate is given by :
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 {{FuncArg|new_rate_denominator}} ≠ 1).
* Note, internal rounding may affect [[Clip_properties|AudioDuration]] slightly &ndash; see [[#Examples|example]] below.
</div>


int(new_rate_numerator / new_rate_denominator + 0.5)


However the internally the resampling factor used is :
== Syntax and Parameters ==
<div style="max-width:62em" >
{{FuncDef
|ResampleAudio(clip ''clip'', ''int new_rate_numerator'' [, int ''new_rate_denominator'' ] )
}}


new_rate_numerator / (new_rate_denominator * old_sample_rate)
:{{Par2|clip |clip|}}
::Source clip. Supported [[ConvertAudio|audio sample types]]: 16-bit integer and [[Float|32-bit floating-point]].
::Other sample types (8-, 24- and 32-bit integer) are automatically converted to floating-point. 


This causes the audio duration to vary slightly (which is generally what is desired).
:{{Par2|new_rate_numerator|int|}}
::Set the numerator for the new sample rate.


Starting from v2.53 ResampleAudio accepts any number of channels.
:{{Par2|new_rate_denominator|int|1}}
Starting from v2.56 ResampleAudio process float samples directly. Support fractional resampling.
::Set the denominator for the new sample rate. Default 1.
</div>


# Resamples audio to 48 kHz:
 
  source = AviSource("c:\audio.wav")
== Examples ==
* Resample audio to 48 kHz:
<div {{BoxWidthIndent|26|2}} >
  source = [[WavSource]]("c:\audio.wav")
  return ResampleAudio(source, 48000)
  return ResampleAudio(source, 48000)
</div>


 
* Exact 4% speed up for PAL telecine:
# Exact 4% speed up for PAL telecine:
<div {{BoxWidthIndent|56|2}} >
  Nfr_num = 25
  Nfr_num = 25
  Nfr_den = 1
  Nfr_den = 1
  AviSource("C:\Film.avi") # 23.976 fps, 44100Hz
  [[AviSource]]("C:\Film.avi") # 23.976 fps, 44100Hz
  Ar = Audiorate()
  Ar = [[Clip_properties|AudioRate]]
  ResampleAudio(Ar*FramerateNumerator()*Nfr_den, FramerateDenominator()*Nfr_num)
''# intermediate sample rate:''
  AssumeSampleRate(Ar)
  ResampleAudio(Ar*[[Clip_properties|FramerateNumerator]]*Nfr_den, [[Clip_properties|FramerateDenominator]]*Nfr_num)
  AssumeFPS(Nfr_num, Nfr_den, False)
  ''# final sample rate:''
[[AssumeSampleRate]](Ar)
  [[AssumeFPS]](Nfr_num, Nfr_den, false)
</div>
<div style="max-width:62em" >
In the example above, the intermediate sample rate needs to be
:<tt>([[Clip_properties|AudioRate]]*[[Clip_properties|FramerateNumerator]]*Nfr_den=1)/([[Clip_properties|FramerateDenominator]]*Nfr_num=25)</tt>
:or <tt>(44100 * 24000 * 1) / (1001 * 25)</tt> = 42293.706294...
but because audio sample rates are always integers, 42293.706294 must be rounded to 42294, <br>
which results in a time slippage of about 30ms per hour.
</div>


For exact resampling the intermediate samplerate needs to be 42293.706293 which if rounded to 42294 would causes about 30ms per hour variation.


'''Changes:'''
== Changes ==
{| border="1"
{| border="1"
|-  
|-  

Latest revision as of 06:39, 18 September 2022

AviSynth+
Up-to-date documentation: https://avisynthplus.readthedocs.io


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 slightly – see example below.


Syntax and Parameters

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

clip  clip =
Source clip. Supported audio sample types: 16-bit integer and 32-bit floating-point.
Other sample types (8-, 24- and 32-bit integer) are automatically converted to floating-point.
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.