GetChannel
Raffriff42 (Talk | contribs) m (one more touch-up) |
Raffriff42 (Talk | contribs) m (add example + one more touch-up) |
||
Line 19: | Line 19: | ||
! colspan="2" style="text-align:left" | WAV, 2 channels (stereo) | ! colspan="2" style="text-align:left" | WAV, 2 channels (stereo) | ||
|- | |- | ||
− | | 1 || left | + | | 1 || left |
|- | |- | ||
− | | 2 || right | + | | 2 || right |
|} | |} | ||
Line 27: | Line 27: | ||
|- | |- | ||
! colspan="2" style="text-align:left" | WAV, 5.1 channels | ! colspan="2" style="text-align:left" | WAV, 5.1 channels | ||
− | |-| 1 || front left | + | |-| 1 || front left |
|- | |- | ||
− | | 2 || front right | + | | 2 || front right |
|- | |- | ||
− | | 3 || front center | + | | 3 || front center |
|- | |- | ||
| 4 || LFE (Low Frequency Enhancement; Subwoofer) | | 4 || LFE (Low Frequency Enhancement; Subwoofer) | ||
|- | |- | ||
− | | 5 || rear left | + | | 5 || rear left |
|- | |- | ||
− | | 6 || rear right | + | | 6 || rear right |
|} | |} | ||
</div> | </div> | ||
+ | |||
+ | |||
+ | ==== Remarks ==== | ||
+ | <div style="max-width:68em" > | ||
+ | Every file format has a different internal channel ordering. The following table gives this internal ordering for some formats (useful for plugin writers), but it is the decoder's task to return the expected channel order. If you use decoders like [[NicAudio]]/[[BassAudio]] or [[Ffdshow|ffdshow]]/[http://www.ac3filter.net/ AC3Filter] you don't need to worry about this. | ||
+ | </div> | ||
+ | |||
+ | :{|class="wikitable" | ||
+ | ! Format !! Channel 1 !! Channel 2 !! Channel 3 !! Channel 4 !! Channel 5 !! Channel 6 | ||
+ | |- | ||
+ | | [http://www.cs.bath.ac.uk/~jpff/NOS-DREAM/researchdev/wave-ex/wave_ex.html 5.1 WAV] | ||
+ | | front left | ||
+ | | front right | ||
+ | | front center | ||
+ | | LFE | ||
+ | | rear left | ||
+ | | rear right | ||
+ | |- | ||
+ | | [https://web.archive.org/web/20051108165008/http://www.atsc.org/standards/a_52a.pdf 5.1 AC3] | ||
+ | | front left | ||
+ | | front center | ||
+ | | front right | ||
+ | | rear left | ||
+ | | rear right | ||
+ | | LFE | ||
+ | |- | ||
+ | | [http://www.etsi.org/deliver/etsi_ts/102100_102199/102114/01.01.01_60/ts_102114v010101p.pdf 5.1 DTS] {{BoldColor|blue|100|¹}} | ||
+ | | front center | ||
+ | | front left | ||
+ | | front right | ||
+ | | rear left | ||
+ | | rear right | ||
+ | | LFE | ||
+ | |- | ||
+ | | [http://web.archive.org/web/20070830151620/http://www.hydrogenaudio.org/forums/index.php?showtopic=10986 5.1 AAC] {{BoldColor|blue|100|²}} | ||
+ | | front center | ||
+ | | front left | ||
+ | | front right | ||
+ | | rear left | ||
+ | | rear right | ||
+ | | LFE | ||
+ | |- | ||
+ | | [http://web.archive.org/web/20030817071619/http://preserve.harvard.edu/standards/Audio%20IFF%20Specification%201%203.pdf 5.1 AIFF] | ||
+ | | front left | ||
+ | | rear left | ||
+ | | front center | ||
+ | | front right | ||
+ | | rear right | ||
+ | | LFE | ||
+ | |- | ||
+ | | [http://flac.sourceforge.net/format.html 5.1 FLAC] | ||
+ | | front left | ||
+ | | front right | ||
+ | | front center | ||
+ | | LFE | ||
+ | | rear left | ||
+ | | rear right | ||
+ | |- | ||
+ | | [http://lists.mplayerhq.hu/pipermail/mplayer-users/2006-October/063511.html 5.1 WMA] | ||
+ | | front left | ||
+ | | front right | ||
+ | | front center | ||
+ | | LFE | ||
+ | | rear left | ||
+ | | rear right | ||
+ | |- | ||
+ | |colspan="7"| | ||
+ | {{BoldColor|blue|100|¹}} 5.1 DTS: the LFE is on a separate stream (much like on multichannel MPEG2).<br> | ||
+ | {{BoldColor|blue|100|²}} There is no free version of the AAC specification available online. | ||
+ | |} | ||
+ | |||
==== Examples ==== | ==== Examples ==== | ||
− | * | + | * Remove right channel information, and return as mono clip with only left channel: |
<div {{BoxWidthIndent|36|2}} > | <div {{BoxWidthIndent|36|2}} > | ||
video = [[AviSource]]("c:\filename.avi") | video = [[AviSource]]("c:\filename.avi") | ||
Line 64: | Line 135: | ||
</div> | </div> | ||
− | * | + | * Convert AVI with 5.1 audio to a stereo signal |
<div {{ListItemContinue}} > | <div {{ListItemContinue}} > | ||
(But see below for channel ordering, and [http://forum.doom9.org/showthread.php?p=1243880#post1243880 here] for more complex downmix functions.) | (But see below for channel ordering, and [http://forum.doom9.org/showthread.php?p=1243880#post1243880 here] for more complex downmix functions.) | ||
Line 74: | Line 145: | ||
</div> | </div> | ||
− | * | + | * Convert AVI with "uncompressed 5.1 wav" audio to a stereo signal: |
<div {{BoxWidthIndent|36|2}} > | <div {{BoxWidthIndent|36|2}} > | ||
video = AviSource("c:\divx_wav.avi") | video = AviSource("c:\divx_wav.avi") | ||
Line 82: | Line 153: | ||
</div> | </div> | ||
− | = | + | * Mix 5.1 AC3 to stereo - see discussion [http://forum.doom9.org/showthread.php?p=1735072#post1735072 here]. |
− | <div | + | <div {{ListItemContinue}} > |
− | + | Note returned audio is [[Float]] type. [[Normalize]] is recommended before [[ConvertAudio|converting to 16-bit]] to avoid possible overload. | |
+ | </div> | ||
+ | <div {{BoxWidthIndent|36|2}} > | ||
+ | function DownMix(clip a, | ||
+ | \ float "centergain", float "surroundgain") | ||
+ | { | ||
+ | a.ConvertAudioToFloat() | ||
+ | |||
+ | ## channel layouts: (AC3, the most common) | ||
+ | fl = GetChannel(1) | ||
+ | fr = GetChannel(2) | ||
+ | fc = GetChannel(3) | ||
+ | lf = GetChannel(4) | ||
+ | sl = GetChannel(5) | ||
+ | sr = GetChannel(6) | ||
+ | |||
+ | ## add center | ||
+ | gc = Default(centergain, 1.0) * 0.7071 | ||
+ | fl = MixAudio(fl, fc, 1.0, gc) | ||
+ | fr = MixAudio(fr, fc, 1.0, gc) | ||
+ | |||
+ | ## add surround | ||
+ | gs = Default(surroundgain, 1.0) * 0.7071 | ||
+ | fl = MixAudio(fl, sl, 1.0, gs) | ||
+ | fr = MixAudio(fr, sr, 1.0, gs) | ||
+ | |||
+ | return AudioDub(a, MergeChannels(fl, fr)) | ||
+ | } | ||
</div> | </div> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:Internal filters]] | [[Category:Internal filters]] | ||
[[Category:Audio_filters]] | [[Category:Audio_filters]] |
Revision as of 04:09, 15 February 2016
GetChannel(clip clip, int ch1 [, int ch2, ...] )
GetChannels(clip clip, int ch1 [, int ch2, ...] )
GetLeftChannel(clip clip)
GetRightChannel(clip clip)
- GetChannel returns one or more channels of a multichannel signal.
- GetLeftChannel returns the left channel from a stereo signal, and GetRightChannel returns the right.
- GetChannels is an alias for GetChannel and can be used interchangeably.
The ordering of the channels is determined by the ordering of the input file, because AviSynth doesn't assume any ordering (see Remarks).
In case of WAV files, the ordering should be as follows:
WAV, 2 channels (stereo) 1 left 2 right
WAV, 5.1 channels 2 front right 3 front center 4 LFE (Low Frequency Enhancement; Subwoofer) 5 rear left 6 rear right
Remarks
Every file format has a different internal channel ordering. The following table gives this internal ordering for some formats (useful for plugin writers), but it is the decoder's task to return the expected channel order. If you use decoders like NicAudio/BassAudio or ffdshow/AC3Filter you don't need to worry about this.
Format Channel 1 Channel 2 Channel 3 Channel 4 Channel 5 Channel 6 5.1 WAV front left front right front center LFE rear left rear right 5.1 AC3 front left front center front right rear left rear right LFE 5.1 DTS ¹ front center front left front right rear left rear right LFE 5.1 AAC ² front center front left front right rear left rear right LFE 5.1 AIFF front left rear left front center front right rear right LFE 5.1 FLAC front left front right front center LFE rear left rear right 5.1 WMA front left front right front center LFE rear left rear right ¹ 5.1 DTS: the LFE is on a separate stream (much like on multichannel MPEG2).
² There is no free version of the AAC specification available online.
Examples
- Remove right channel information, and return as mono clip with only left channel:
video = AviSource("c:\filename.avi") stereo = WavSource("c:\afx-ab3_t4.wav") mono = GetLeftChannel(stereo) return AudioDub(video, mono)
- Do the same, alternate syntax:
video = AviSource("c:\filename.avi") stereo = WavSource("c:\afx-ab3_t4.wav") mono = GetChannel(stereo, 1) return AudioDub(video, mono)
- You could also obtain the channels from the AVI file itself:
video = AviSource("c:\filename.avi") return GetChannel(video, 1)
- Convert AVI with 5.1 audio to a stereo signal
(But see below for channel ordering, and here for more complex downmix functions.)
video = AviSource("c:\divx_51.avi") stereo = GetChannel(video, 1, 2) return AudioDub(video, stereo)
- Convert AVI with "uncompressed 5.1 wav" audio to a stereo signal:
video = AviSource("c:\divx_wav.avi") audio = WavSource("c:\divx_wav.avi") stereo = GetChannel(audio, 1, 2) return AudioDub(video, stereo)
- Mix 5.1 AC3 to stereo - see discussion here.
Note returned audio is Float type. Normalize is recommended before converting to 16-bit to avoid possible overload.
function DownMix(clip a, \ float "centergain", float "surroundgain") { a.ConvertAudioToFloat() ## channel layouts: (AC3, the most common) fl = GetChannel(1) fr = GetChannel(2) fc = GetChannel(3) lf = GetChannel(4) sl = GetChannel(5) sr = GetChannel(6) ## add center gc = Default(centergain, 1.0) * 0.7071 fl = MixAudio(fl, fc, 1.0, gc) fr = MixAudio(fr, fc, 1.0, gc) ## add surround gs = Default(surroundgain, 1.0) * 0.7071 fl = MixAudio(fl, sl, 1.0, gs) fr = MixAudio(fr, sr, 1.0, gs) return AudioDub(a, MergeChannels(fl, fr)) }