ResampleAudio: Difference between revisions
From Avisynth wiki
Jump to navigationJump to search
Raffriff42 (talk | contribs) m added category |
Raffriff42 (talk | contribs) formatting, links, phrasing |
||
| Line 1: | Line 1: | ||
{{ | <div style="max-width:62em" > | ||
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). | |||
</div> | |||
== Syntax and Parameters == | |||
<div style="max-width:62em" > | |||
{{FuncDef | |||
|ResampleAudio(clip ''clip'', ''int new_rate_numerator'' [, int ''new_rate_denominator'' ] ) | |||
}} | |||
:{{Par2|new_rate_numerator|int|}} | |||
::Set new sample rate, or if {{FuncArg|new_rate_denominator}} != 1, set the numerator. | |||
:{{Par2|new_rate_denominator|int|1}} | |||
::Set the denominator for the new sample rate. Default 1. | |||
When using fractional resampling (where {{FuncArg|new_rate_denominator}} != 1) the output audio sample rate is given by : | |||
:int({{FuncArg|new_rate_numerator}} / {{FuncArg|new_rate_denominator}} + 0.5) | |||
However internally the resampling factor used is : | |||
:{{FuncArg|new_rate_numerator}} / ({{FuncArg|new_rate_denominator}} * [[Clip_properties|AudioRate]]) | |||
This causes the audio duration to vary slightly (which is generally what is desired).{{Clarify}} | |||
source = | </div> | ||
== 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: | |||
<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 = | Ar = [[Clip_properties|AudioRate]] | ||
ResampleAudio(Ar*FramerateNumerator | ''# 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 | |||
:(44100 * 24000 / 1001) / (25 * 1) = 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> | |||
== Changes == | |||
{| border="1" | {| border="1" | ||
|- | |- | ||
Revision as of 08:21, 15 February 2016
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).
Syntax and Parameters
ResampleAudio(clip clip, int new_rate_numerator [, int new_rate_denominator ] )
- int new_rate_numerator =
- Set new sample rate, or if new_rate_denominator != 1, set the numerator.
- int new_rate_denominator = 1
- Set the denominator for the new sample rate. Default 1.
When using fractional resampling (where new_rate_denominator != 1) the output audio sample rate is given by :
- int(new_rate_numerator / new_rate_denominator + 0.5)
However internally the resampling factor used is :
- new_rate_numerator / (new_rate_denominator * AudioRate)
This causes the audio duration to vary slightly (which is generally what is desired).[clarification needed]
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
- (44100 * 24000 / 1001) / (25 * 1) = 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. |