示例#1
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)
示例#2
0
文件: dunwah2.py 项目: dafx/guitarix
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)
示例#3
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)
示例#4
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()
示例#5
0
文件: dunwah2.py 项目: dafx/guitarix
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()
示例#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()