Sunday, 10 August 2014

Really Simple Reverb' Script

This takes an impulse response wav (in this example I was using one called spring.wav) and and input.wav and it produces output.wav

This patch is part of my latest push to github.

def reverbInner(signal,convol,grainLength):
    def reverbInnerDo():
        mag=sf.Magnitude(+signal)
        if mag>0:
            signal_=sf.Concatenate(signal,sf.Silence(grainLength))
            signal_=sf.FrequencyDomain(signal_)
            signal_=sf.CrossMultiply(convol,signal_)
            signal_=sf.TimeDomain(signal_)
            newMag=sf.Magnitude(+signal_)
            signal_=sf.NumericVolume(signal_,mag/newMag)        
            # tail out clicks due to amplitude at end of signal 
            return signal_
        else:
            -convol
            return signal
            
    return sf_do(reverbInnerDo)

def reverberate(signal,convol):
    grainLength = sf.Length(+convol)
    convol_=sf.FrequencyDomain(sf.Concatenate(convol,sf.Silence(grainLength)))
    signal_=sf.Concatenate(signal,sf.Silence(grainLength))
    out=[]
    for grain in sf.Granulate(signal_,grainLength):
        (signal_i,at)=grain
        out.append((reverbInner(signal_i,+convol_,grainLength),at))
    -convol_
    return sf.Clean(sf.Normalise(sf.MixAt(out)))

    
(left,right)=sf.ReadFile("temp/input.wav")
(convoll,convolr)=sf.ReadFile("temp/spring.wav")

wleft =reverberate(+left,convoll)
wright=reverberate(+right,convolr)

left=sf.Normalise(sf.MixAt(
    (sf.Pcnt30(wleft),0),
    (sf.Pcnt70(left),00)
))

right=sf.Normalise(sf.MixAt(
    (sf.Pcnt30(wright),0),
    (sf.Pcnt70(right),0)
))


sf.WriteFile32((left,right),"temp/output.wav")

No comments:

Post a Comment