Ejemplo n.º 1
0
def get_f0(audio, sampling_rate=22050, frame_length=1024,
           hop_length=256, f0_min=100, f0_max=300, harm_thresh=0.1):
    f0, harmonic_rates, argmins, times = compute_yin(
        audio, sampling_rate, frame_length, hop_length, f0_min, f0_max,
        harm_thresh)
    pad = int((frame_length / hop_length) / 2)
    f0 = [0.0] * pad + f0 + [0.0] * pad

    f0 = np.array(f0, dtype=np.float32)
    return f0
Ejemplo n.º 2
0
Archivo: toy.py Proyecto: Maugeais/dde
def toyModel(TMax, h):

    omega1 = 2764.

    t0 = np.arange(-5, 0, h)
    X0 = np.zeros((len(t0), 4))

    X0[:, 0] = 1e-1 + 0 * np.cos(100 * np.pi * t0)
    X0[:, 1] = 0 * np.cos(3 * np.pi / 2 * t0)

    T = TMax * omega1

    t, X = dde.rk4Delay(t0, X0, T, 'toy.c', [30, T])

    p = X[:, 0] + X[:, 2]

    #plt.plot(t, p)

    # Calcul les fréquences
    w_len = 1024 * 4
    w_step = 256 * 4
    f0_min = 0.05
    f0_max = 3
    harmo_thresh = 0.85

    sr = int(1 / (t[1] - t[0]))
    pitches, harmonic_rates, argmins, times = yin.compute_yin(
        p[len(t0):], sr, None, w_len, w_step, f0_min, f0_max, harmo_thresh)
    pitches = np.array(pitches)
    times = np.array(times)

    # Changements de signes
    """ Calcul bourrin
    I = np.where(p[1:]*p[:-1] < 0)[0]
    F = t[I]
    
    treal = 0.1+(T/2-abs(t[I[2:]]-T/2))*30/T
    Freal = omega1/(F[2:]-F[:-2])
    plt.plot(treal[:len(treal)//2], Freal[:len(treal)//2])
    plt.plot(treal[len(treal)//2:], Freal[len(Freal)//2:])"""

    tau = 0.1 + (T / 2 - abs(times - T / 2)) * 30 / T
    #print(times[-1], t[-1])
    plt.plot(tau[:len(tau) // 2], omega1 * np.array(pitches[:len(tau) // 2]))
    #plt.plot(tau[len(tau)//2:], omega1*np.array(pitches[len(tau)//2:]))

    from scipy.io.wavfile import write
    scaled = np.int16(p / np.max(np.abs(p)) * 32767)
    write('test.wav', int(sr * omega1), scaled)
Ejemplo n.º 3
0
def transform_f0(wav, hparams):
    sampling_rate = hparams.sampling_rate
    frame_length = hparams.filter_length
    hop_length = hparams.hop_length
    f0_min = hparams.f0_min
    f0_max = hparams.f0_max
    harm_thresh = hparams.harm_thresh

    f0, harmonic_rates, argmins, times = compute_yin(wav, sampling_rate,
                                                     frame_length, hop_length,
                                                     f0_min, f0_max,
                                                     harm_thresh)
    pad = int((frame_length / hop_length) / 2)
    f0 = [0.0] * pad + f0 + [0.0] * pad

    f0 = np.array(f0, dtype=np.float32)
    return f0
Ejemplo n.º 4
0
def runYin(result,
           s,
           sr,
           w_len=1024,
           w_step=512,
           f0_min=70,
           f0_max=450,
           harmo_thresh=0.15):
    print("Charger F0")
    pitches, harmonic_rates, argmins, times = yin.compute_yin(
        s,
        sr,
        None,
        w_len=w_len,
        w_step=w_step,
        f0_min=f0_min,
        f0_max=f0_max,
        harmo_thresh=harmo_thresh)
    pitches = filterPitches(pitches, argmins, 2, 98)
    F0 = np.array(zip(times, pitches, harmonic_rates, argmins))
    f0Time = time()
    result.append(F0)
    result.append(f0Time)
Ejemplo n.º 5
0
def stateArtModel(TMax, h, params, alg='rk4Neutral', interpOrder=2):

    t0 = np.arange(-1e-2, h, h)
    X0 = np.zeros((len(t0), 2 * K + 2))

    label = 'h= ' + str(h) + ', ' + alg  #str(h) + ', ' + str(params) +

    for i in range(2 * K + 2):

        if i % 2 == 0:
            X0[:, i] = 1e-6 * np.cos(2 * np.pi * t0 * omega1 / 3.5)
        else:
            X0[:, i] = -1e-6 * np.sin(2 * np.pi * t0 * omega1 / 3.5)

    t0 *= omega1
    T = TMax * omega1

    t, X = dde.rk4Delay(t0,
                        X0,
                        T,
                        'stateArt.c',
                        params,
                        alg=alg,
                        interpOrder=interpOrder)

    p = np.sum(X[:, ::2], axis=1)

    # plt.figure("Wave")
    # plt.plot(t/omega1, p, label=label)
    # plt.legend()

    # Calcul les fréquences
    w_len = 1024 * 8
    w_step = 256 // 2

    f0_min = 200
    f0_max = 2500
    harmo_thresh = 0.6

    sr = int(omega1 / (t[1] - t[0]))

    pitches, harmonic_rates, argmins, times = yin.compute_yin(
        p[len(t0):], sr, None, w_len, w_step, f0_min, f0_max, harmo_thresh)
    pitches = np.array(pitches)
    times = np.array(times)

    Pm = params[0] + (TMax / 2 - abs(times - TMax / 2)) / TMax * (params[1] -
                                                                  params[0])

    plt.figure("Yin")
    ax = plt.gca()

    color = next(ax._get_lines.prop_cycler)['color']
    plt.plot(Pm[:len(Pm) // 2],
             np.array(pitches[:len(Pm) // 2]),
             '-',
             c=color,
             label=label)
    plt.plot(Pm[len(Pm) // 2:], np.array(pitches[len(Pm) // 2:]), ':', c=color)

    plt.legend()

    from scipy.io.wavfile import write
    scaled = np.int16(p / np.max(np.abs(p)) * 32767)
    write('test' + '.'.join(str(e) for e in params) + '.wav', int(sr), scaled)