2015-10-17 23 views
4

我試圖通過在SoX中使用脈衝響應進行卷積來應用混響。下面的腳本不正是我想要的:SoX FIR單線程

#!/usr/bin/env bash 
# 
# Convolve audio file with and impulse response (IR) 
# 
# Usage: 
# 
#  applyReverb.sh <ir.wav> <audio.wav> <output.wav> 

# IR duration (needed for zero-padding to prevent SoX from cutting 
# the resulting audio after applying the FIR filter 
IR_DUR=`soxi -D $1` 

# read IR from wav, resample it if necessary, make sure is mono 
# and save it as plain text (.dat format in SoX). Also reduces gain 
# to prevent clipping later 
sox --norm=-10 -c 1 $1 -r 44100 filter.dat 

# extract the coeffients (second column, skipping the first 2 lines) 
awk 'NR<3{next}{print $2}' filter.dat > filter.txt 

# apply reverb using SoX's fir effect (need front zero-padding to for 
# the extra samples due to the convolution 
sox "|sox $2 -p pad $IR_DUR 0" --norm $3 fir filter.txt 

問題

我怎樣才能做到這一點沒有臨時文件(*過濾器)?我知道答案在於管道內,但我無法讓它工作。

+2

小心解釋爲什麼它downvoted? – jorgeh

+1

對我來說這看起來是一個合理的問題。 – lCapp

+2

@ICapp感謝您的支持和恢復平衡,假設您提高了它;)。無論如何,如果你有興趣,我找到了解決方案(見下面的答案) – jorgeh

回答

2

經過一些試驗和錯誤,我發現我在找什麼。如果有人有興趣,這是我的解決方案:

sox --norm=-10 -c 1 $1 -r 44100 -t dat - | awk 'NR<3{next}{print $2;}' | sox "|sox $2 -p pad $d $d" --norm $3 fir -