示例#1
0
def command_instrumental(*args):
    if len(args) != 2:
        usage()
        return
    w = wav.Wav(args[0])
    out = music.extract_instrumentals(w.time_series)
    wav.write(args[1], out, w.sample_rate)
示例#2
0
def command_transpose(*args):
    if len(args) != 3:
        usage()
        return
    w = wav.Wav(args[0])
    out = music.transpose_key(float(args[2]), w)
    wav.write(args[1], out, w.sample_rate)
示例#3
0
def main():
    if not os.path.exists("../img"):
        os.mkdir("../img", 0755)
    fs = 44100  # in Hz
    length = 0.01  # in seconds
    t = np.linspace(0, length, num=length * fs)
    h_function = lambda t: b * np.exp(-t / tau)
    h = h_function(t)
    plt.plot(h, t, fs, 3, "h(t)", "Signal h(t)")
    plt.savefig("../img/4.1-transfer_function.png")

    x_function = lambda t: a1 * np.cos(2 * np.pi * f1 * t) + a2 * np.sin(
        2 * np.pi * f2 * t) + a3 * np.cos(2 * np.pi * f3 * t)
    x = x_function(t)
    plt.plot(x, t, fs, 10, "x(t)", "Signal x(t)")
    yx = np.convolve(h, x)
    plt.plot(np.array([x, yx[0:len(t)]]), t, fs, 10, "yx(t)", "Signal yx(t)")
    plt.savefig("../img/4.2-sines.png")

    z_function = lambda t: A * (abs((t - T / 2) / T) < 1.0)
    z = z_function(t)
    yz = np.convolve(h, z)
    plt.plot(np.array([z, yz[0:len(t)]]), t, fs, 10, "yz(t)", "Signal yz(t)")
    plt.savefig("../img/4.3-rect.png")

    w, tw, rate, size, max = wav.readWav("../3-audio/af2.wav")
    h = h_function(tw)  # new sample rate and time vector
    yw = np.convolve(h, w)
    plt.plot(np.array([w, yw[0:len(tw)]]), tw, rate, 10, "yw(t)",
             "Signal yw(t)")
    rel_max = np.amax(yw) if np.amax(yw) > abs(np.amin(yw)) else abs(
        np.amin(yw))
    yw = yw * (max / rel_max)
    wav.write("convoluted.wav", rate, yw.astype(np.dtype('i2')))
    plt.savefig("../img/4.4-audio.png")
示例#4
0
def command_mash(*args):
    wavs = [wav.Wav(w) for w in args[:-1]]
    out = mashup.generate(wavs)
    wav.write(args[-1], out, 44100)