Exemplo n.º 1
0
def per_file(f, X, Y):
    wav_filename = dirs.get_wav(f)
    txt_filename = dirs.get_txt(f)
    wav_data, samplerate = ap.get_wav_data(wav_filename)
    framesamp = 1024
    hopsamp = 80
    x = features.get_wav_data_as_feature(wav_data, framesamp, hopsamp, True)
    y = features.get_txt_as_label_for_note(txt_filename, 60, samplerate/8, framesamp, hopsamp, len(x))
#    y = features.get_txt_as_label_for_note(txt_filename, 102, samplerate/8, framesamp, hopsamp, len(x))
    start, end = ut.get_trim_indices(x)
    trunc = 2000
    if end-start > trunc:
        print("\t%d windows, truncated to %d" % (end-start, trunc))
    end = min(end, trunc+start)

    subx = x[start: end]
    suby = y[start: end]

    # get rid of complex complexities    
    subx = abs(subx)

#    ind = random.sample(range(len(subx)), samples_per_file)
#    subx = [subx[i] for i in ind]
#    suby = [suby[i] for i in ind]
    
    X.append(copy.deepcopy(subx))
    Y.append(copy.deepcopy(suby))
Exemplo n.º 2
0
def get_data(f, note, sub = True):
    global framesamp, hopsamp
    wav_filename = dirs.get_wav(f)
    txt_filename = dirs.get_txt(f)
    wav_data, samplerate = ap.get_wav_data(wav_filename)
    x = features.get_wav_data_as_feature(wav_data, framesamp, hopsamp, True)
    y = features.get_txt_as_label_for_note(txt_filename, note, samplerate/8, framesamp, hopsamp, len(x), True)

    start, end = ut.get_trim_indices(x)
    end = min(end, windows_per_file + start)
    x = x[start:end]
    y = y[start:end]

    posx = []
    posy = []
    negx = []
    negy = []

    # balance
    for i in range(len(x)):
        if y[i]:
            posx.append(x[i])
            posy.append(y[i])
        else:
            negx.append(x[i])
            negy.append(y[i])

    return (copy.deepcopy(posx), copy.deepcopy(posy), copy.deepcopy(negx), copy.deepcopy(negy))
Exemplo n.º 3
0
def test():
    filename = '/home/charles/maps-data/maps/MAPS_AkPnCGdD_1/AkPnCGdD/ISOL/NO/MAPS_ISOL_NO_M_S0_M60_AkPnCGdD.wav'
    midi_file = dirs.get_midi(filename)
    wav_file = dirs.get_wav(filename)
    txt_file = dirs.get_txt(filename)
    wav_data = get_wav_data(wav_file)
    wf = get_wav_file(filename)
    samplerate = wf.samplerate
    nframes = wf.nframes
    data = get_wav_data(filename)
    txt_data = get_txt_as_label(txt_file, samplerate, nframes)