Пример #1
0
def plot_figure_libcrybaby(clr="-",fs=44100):
    from pluginloader import Plugin
    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt['crybaby2.refvolt'] = 0.1
    para = 'crybaby2.hotpotz'
    name = filt.get_var_attr(para)[0]
    rg = log10(linspace(*np.power(10,filt.get_range(para)), num=10))
    filt.init(fs)
    plot_figure(filt, name, para, rg, clr, fs)
Пример #2
0
def plot_figure_libcrybaby():
    from pluginloader import Plugin

    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt["crybaby2.refvolt"] = 0.1
    para = "crybaby2.hotpotz"
    name = filt.get_var_attr(para)[0]
    rg = log10(linspace(*np.power(10, filt.get_range(para)), num=10))
    filt.init(48000)
    plot_figure(filt, name, para, rg)
Пример #3
0
def compare_dynamics(freq, fs):
    global title
    title("Freq = %g" % freq)

    lfo_freq = 5.0
    block_size = 64
    time = 1
    block_cnt = (time * fs + block_size - 1) / block_size
    samples = block_cnt * block_size

    def sine(freq, div=1):
        return array(sin(2 * pi * linspace(0, freq * time, samples / div)),
                     dtype=float32)

    tm = linspace(0, samples / float(fs), samples)
    lfo = 0.5 + sine(lfo_freq, block_size) * 0.5
    signal = sine(freq).reshape(block_cnt, block_size)
    tt = linspace(0, 1, samples / 100)

    def sweep(filt, para, clr):
        filt[para] = 0.0
        filt.compute(zeros(10000, float32))
        out = zeros((block_cnt, block_size))
        for i in range(block_cnt):
            filt[para] = lfo[i]
            out[i] = filt.compute(signal[i])
        t = 0.999
        ampl = lfilter([1 - t], [1, -t], abs(out.reshape(samples)))
        plot(tm[4000:], 20 * log10(ampl[4000:]), clr)

    import dunwah
    filt = dunwah.dsp()
    filt.init(fs)
    para = "wah"

    sweep(filt, para, "r")

    from pluginloader import Plugin
    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt.init(fs)
    filt['crybaby2.refvolt'] = 0.1
    para = 'crybaby2.hotpotz'

    sweep(filt, para, "b")
Пример #4
0
def compare_dynamics(freq, fs):
    global title
    title("Freq = %g" % freq)

    lfo_freq = 5.0
    block_size = 64
    time = 1
    block_cnt = (time*fs+block_size-1)/block_size
    samples = block_cnt * block_size

    def sine(freq, div=1):
        return array(sin(2*pi*linspace(0,freq*time,samples / div)),dtype=float32)

    tm = linspace(0,samples/float(fs),samples)
    lfo = 0.5 + sine(lfo_freq,block_size) * 0.5
    signal = sine(freq).reshape(block_cnt,block_size)
    tt = linspace(0,1,samples / 100)

    def sweep(filt, para, clr):
        filt[para] = 0.0
        filt.compute(zeros(10000,float32))
        out = zeros((block_cnt,block_size))
        for i in range(block_cnt):
            filt[para] = lfo[i]
            out[i] = filt.compute(signal[i])
        t = 0.999
        ampl = lfilter([1-t],[1,-t],abs(out.reshape(samples)))
        plot(tm[4000:], 20*log10(ampl[4000:]), clr)

    import dunwah
    filt = dunwah.dsp()
    filt.init(fs)
    para = "wah"

    sweep(filt, para, "r")

    from pluginloader import Plugin
    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt.init(fs)
    filt['crybaby2.refvolt'] = 0.1
    para = 'crybaby2.hotpotz'

    sweep(filt, para, "b")
Пример #5
0
def plot_figure_libcrybaby():
    from pluginloader import Plugin
    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt['crybaby2.refvolt'] = 0.1
    para = 'crybaby2.hotpotz'
    name = filt.get_var_attr(para)[0]
    rg = log10(linspace(*np.power(10,filt.get_range(para)), num=10))
    filt.init(48000)
    plot_figure(filt, name, para, rg)
Пример #6
0
def output_freqz_libcrybaby():
    from pluginloader import Plugin

    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt["crybaby2.refvolt"] = 0.1
    para = "crybaby2.hotpotz"
    name = filt.get_var_attr(para)[0]
    fs = 44100
    filt.init(fs)
    impulse = zeros(10000, dtype=float32)
    impulse[0] = 1
    # rg = linspace(*filt.get_range(para), num=20)
    rg = log10(linspace(*np.power(10, filt.get_range(para)), num=20))
    if True:
        aa, Q, maxh = estimate(rg, filt, para, impulse, fs)
        pickle.dump((aa, Q, maxh), file("p.out", "w"))
    else:
        aa, Q, maxh = pickle.load(file("p.out"))
    off, a1A, qA = fit_param(rg, aa, Q, fs)
    g_off, gain, gA = make_gain(rg, off, a1A, qA, maxh, fs)
    show_param(rg, off, g_off, aa, a1A, Q, qA, gain, gA)
    rg = log10(linspace(*np.power(10, filt.get_range(para)), num=10))
    for i, freq in enumerate(rg):
        filt[para] = freq
        filt.compute(zeros(10000, dtype=float32))
        w, h = freqz(filt.compute(impulse), worN=15000)
        k1 = int(round(len(h) * 30.0 / fs))
        k2 = int(round(len(h) * 5000.0 / fs))
        B, A = invfreqz(w[k1 : k2 + 1], h[k1 : k2 + 1])

        R = sqrt(A[2])
        theta = math.acos(A[1] / (-2 * R))
        aa[i] = A[1] / (-2 * R)
        frn = theta / (2 * pi)
        Q[i] = (pi * frn) / (1 - R)

        print "Pole frequency = %f Hz" % (frn * fs)
        print "Q = %f" % Q[i]

        if False:
            A = array((1, -2 * R * cos(theta), R * R))
            w1, h1 = freqz(Bconst, A, worN=15000)
            gain[i] = max(abs(h)) / max(abs(h1))
            B *= gain[i]
            h1 *= gain[i]
            print "gain =", gain[i]
            # h = h1

        if True:
            q = polyval(qA, freq)
            a1 = (off - 1 / polyval(a1A, freq)) / fs
            frn = a1 / (2 * pi)
            r = 1 - a1 / (2 * q)
            # print "R =", r
            # print "frn =", frn, "theta =", math.acos(a1)
            g = g_off - 1 / polyval(gA, freq)

            A = array((1, -2 * r * cos(a1), r * r))
            w1, h1 = freqz(Bconst * g, A, worN=15000)

            R = sqrt(A[2])
            theta = math.acos(A[1] / (-2 * R))
            frn = theta / (2 * pi)
            bq = (pi * frn) / (1 - R)
            print "Pole frequency = %f Hz" % (frn * fs)
            print "Q = %f" % q
            print "gain =", g

        w *= fs / (2 * pi)
        semilogx(w[1:], 20 * log10(abs(h[1:])), "b")
        semilogx(w[1:], 20 * log10(abs(h1[1:])), "r")
    show()
Пример #7
0
def output_freqz_libcrybaby():
    from pluginloader import Plugin
    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt['crybaby2.refvolt'] = 0.1
    para = 'crybaby2.hotpotz'
    name = filt.get_var_attr(para)[0]
    fs = 44100
    filt.init(fs)
    impulse = zeros(10000,dtype=float32)
    impulse[0] = 1
    #rg = linspace(*filt.get_range(para), num=20)
    rg = log10(linspace(*np.power(10,filt.get_range(para)), num=20))
    if True:
        aa, Q, maxh = estimate(rg, filt, para, impulse, fs)
        pickle.dump((aa,Q,maxh), file("p.out","w"))
    else:
        aa, Q, maxh = pickle.load(file("p.out"))
    off, a1A, qA = fit_param(rg, aa, Q, fs)
    g_off, gain, gA = make_gain(rg, off, a1A, qA, maxh, fs)
    show_param(rg, off, g_off, aa, a1A, Q, qA, gain, gA)
    rg = log10(linspace(*np.power(10,filt.get_range(para)), num=10))
    for i, freq in enumerate(rg):
        filt[para] = freq
        filt.compute(zeros(10000,dtype=float32))
        w, h = freqz(filt.compute(impulse), worN=15000)
        k1 = int(round(len(h)*30.0/fs))
        k2 = int(round(len(h)*5000.0/fs))
        B, A = invfreqz(w[k1:k2+1], h[k1:k2+1])

        R = sqrt(A[2])
        theta = math.acos(A[1]/(-2*R))
        aa[i] = A[1]/(-2*R)
        frn = theta / (2*pi)
        Q[i] = (pi * frn) / (1 - R)

        print 'Pole frequency = %f Hz' % (frn * fs)
        print 'Q = %f' % Q[i]

        if False:
            A = array((1, -2*R*cos(theta), R*R))
            w1, h1 = freqz(Bconst, A, worN=15000)
            gain[i] = max(abs(h))/max(abs(h1))
            B *= gain[i]
            h1 *= gain[i]
            print "gain =", gain[i]
            #h = h1

        if True:
            q  = polyval(qA, freq)
            a1 = (off - 1 / polyval(a1A, freq)) / fs
            frn = a1/(2*pi)
            r = 1 - a1/(2*q)
            #print "R =", r
            #print "frn =", frn, "theta =", math.acos(a1)
            g = g_off - 1 / polyval(gA, freq)

            A = array((1, -2*r*cos(a1), r*r))
            w1, h1 = freqz(Bconst*g, A, worN=15000)

            R = sqrt(A[2])
            theta = math.acos(A[1]/(-2*R))
            frn = theta / (2*pi)
            bq = (pi * frn) / (1 - R)
            print 'Pole frequency = %f Hz' % (frn * fs)
            print 'Q = %f' % q
            print "gain =", g

        w *= fs / (2*pi)
        semilogx(w[1:], 20*log10(abs(h[1:])), "b")
        semilogx(w[1:], 20*log10(abs(h1[1:])), "r")
    show()
Пример #8
0
def output_freqz_libcrybaby():
    from pluginloader import Plugin
    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt['crybaby2.refvolt'] = 0.1
    para = 'crybaby2.hotpotz'
    name = filt.get_var_attr(para)[0]
    fs = 44100
    filt.init(fs)
    impulse = zeros(10000, dtype=float32)
    impulse[0] = 1
    rg = log10(linspace(*np.power(10, filt.get_range(para)), num=20))
    if False:
        aa, Q, maxh, p1, Bconst, freq_const = estimate(rg, filt, para, impulse,
                                                       fs)
        pickle.dump((aa, Q, maxh, p1, Bconst, freq_const), file("p.out", "w"))
    else:
        aa, Q, maxh, p1, Bconst, freq_const = pickle.load(file("p.out"))
    z1, z2A, z3A, gcA = estimate_SR(filt, para, freq_const, impulse)
    off, a1A, qA = fit_param(rg, aa, Q, fs)
    gain, g_off, gA = make_gain(rg, off, a1A, qA, maxh, p1, Bconst, fs)
    #show_param(rg, off, g_off, aa, a1A, Q, qA, gain, gA)
    rg = log10(linspace(*np.power(10, filt.get_range(para)), num=10))
    filt.init(fs)
    for i, freq in enumerate(rg):
        filt[para] = freq
        filt.compute(zeros(10000, dtype=float32))
        w, h = freqz(filt.compute(impulse), worN=15000)

        q = polyval(qA, freq)
        a1 = (off - 1 / polyval(a1A, freq)) / fs
        g = g_off - 1 / polyval(gA, freq)
        gc = polyval(gcA, fs)

        r = 1 - a1 / (2 * q)
        A = array((1, -2 * r * cos(a1), r * r))
        A = poly(list(roots(A)) + [p1])
        B = poly([polyval(z2A, fs), polyval(z3A, fs), z1])
        w1, h1 = freqz(B * g * gc, A, worN=15000)

        semilogx((w * fs / (2 * pi))[1:], 20 * log10(abs(h[1:])), "b")
        semilogx((w1 * fs / (2 * pi))[1:], 20 * log10(abs(h1[1:])), "r")

    print "theta2pi = (%g - 1000 / (%s)) / SR;" % (
        off, string_polyval(a1A * 1000, "wah"))
    print "Q = %s;" % string_polyval(qA, "wah")
    print "g = %g - 1 / (%s);" % (g_off, string_polyval(gA, "wah"))
    print "gc = %s;" % string_polyval(gcA, "SR")
    print "p1 = exp(-1000/(%g*SR));" % (-1000 / (fs * log(p1)))
    print "z1 = %g;" % z1
    print "z2 = %s;" % string_polyval(z2A, "SR")
    print "z3 = %s;" % string_polyval(z3A, "SR")

    show()
Пример #9
0
def output_freqz_libcrybaby():
    from pluginloader import Plugin
    filt = Plugin("../build/default/src/plugins/libcrybaby.so")
    filt['crybaby2.refvolt'] = 0.1
    para = 'crybaby2.hotpotz'
    name = filt.get_var_attr(para)[0]
    fs = 44100
    filt.init(fs)
    impulse = zeros(10000,dtype=float32)
    impulse[0] = 1
    rg = log10(linspace(*np.power(10,filt.get_range(para)), num=20))
    if False:
        aa, Q, maxh, p1, Bconst, freq_const = estimate(rg, filt, para, impulse, fs)
        pickle.dump((aa,Q,maxh,p1,Bconst,freq_const), file("p.out","w"))
    else:
        aa, Q, maxh, p1, Bconst, freq_const = pickle.load(file("p.out"))
    z1, z2A, z3A, gcA = estimate_SR(filt, para, freq_const, impulse)
    off, a1A, qA = fit_param(rg, aa, Q, fs)
    gain, g_off, gA = make_gain(rg, off, a1A, qA, maxh, p1, Bconst, fs)
    #show_param(rg, off, g_off, aa, a1A, Q, qA, gain, gA)
    rg = log10(linspace(*np.power(10,filt.get_range(para)), num=10))
    filt.init(fs)
    for i, freq in enumerate(rg):
        filt[para] = freq
        filt.compute(zeros(10000,dtype=float32))
        w, h = freqz(filt.compute(impulse), worN=15000)

        q  = polyval(qA, freq)
        a1 = (off - 1 / polyval(a1A, freq)) / fs
        g = g_off - 1 / polyval(gA, freq)
        gc = polyval(gcA, fs)

        r = 1 - a1/(2*q)
        A = array((1, -2*r*cos(a1), r*r))
        A = poly(list(roots(A))+[p1])
        B = poly([polyval(z2A,fs),polyval(z3A,fs),z1])
        w1, h1 = freqz(B*g*gc, A, worN=15000)

        semilogx((w*fs/(2*pi))[1:],  20*log10(abs(h[1:])), "b")
        semilogx((w1*fs/(2*pi))[1:], 20*log10(abs(h1[1:])), "r")

    print "theta2pi = (%g - 1000 / (%s)) / SR;" % (off, string_polyval(a1A*1000, "wah"))
    print "Q = %s;" % string_polyval(qA, "wah")
    print "g = %g - 1 / (%s);" % (g_off, string_polyval(gA, "wah"))
    print "gc = %s;" % string_polyval(gcA, "SR")
    print "p1 = exp(-1000/(%g*SR));" % (-1000/(fs*log(p1)))
    print "z1 = %g;" % z1
    print "z2 = %s;" % string_polyval(z2A, "SR")
    print "z3 = %s;" % string_polyval(z3A, "SR")

    show()