Ejemplo 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))
Ejemplo 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))
Ejemplo n.º 3
0
def get_wav_file_as_feature(filename, framesamp, hopsamp, downsample=False):
    data, samplerate = ap.get_wav_data(filename)
    return get_wav_data_as_feature(data, framesamp, hopsamp, downsample)