Exemplo n.º 1
0
def plots(track):
    f, axarr = plt.subplots(2, sharex=True)
    path = "../../msd_dense_subset/dense/"+track[2]+"/"+track[3]+"/"+track[4]+"/"+track+".h5"
    h5 = GETTERS.open_h5_file_read(path)
    segments = (GETTERS.get_segments_start(h5))
    sections = (GETTERS.get_sections_start(h5))
    max_loudness = (GETTERS.get_segments_loudness_max(h5))
    loudness = (GETTERS.get_segments_loudness_start(h5))
    average_loudness = (max_loudness + loudness) / 2
    average_loudness_song = GETTERS.get_loudness(h5)
    start_fade_out = GETTERS.get_start_of_fade_out(h5)
    end_fade_in = GETTERS.get_end_of_fade_in(h5)
    pitches = GETTERS.get_segments_pitches(h5)
    h5.close()
    
    
    axarr[0].set_title('loudness curve for ' + ut.get_track_info(track))
    axarr[0].plot(segments, average_loudness, label='Filtered')
    axarr[0].axhline(average_loudness_song, color='green')
    for section in enumerate(sections):
        axarr[0].axvline(section[1], color='red')
    axarr[0].axvline(start_fade_out, color='green')
    axarr[0].axvline(end_fade_in, color='green')
    
    
    idx = list()
    for section in sections:
        dif = segments - section
        posdif = np.where(dif >=0)
        idx.append(posdif[0][0])
    axarr[1].set_title('Chroma values for ' + ut.get_track_info(track))
    #axarr[1].set_xticks(idx,sections.astype(int))
    extent =[0,segments.shape[0],0,12]
    axarr[1].imshow(pitches.transpose(),extent = extent,aspect = 'auto',interpolation='nearest',origin='lower')
    plt.show()
Exemplo n.º 2
0
def parse_file(file, targetfile):
    print "print parsing %s" %file
    with open(file, 'r') as f:
        global tracks, labels, features
        tracks = list()
        labels = list()
        for line in f:
            track, label = line.strip().split(' ')
            tracks.append(track)
            labels.append(int(label))
        labels = np.array(labels)
        features = np.empty((len(tracks),NUM_FEATURES),dtype='float')#hardcode number of features otherwise problem with scaling
        track_info = np.empty((len(tracks)),dtype='object')
        for i,track in enumerate(tracks):
            #print track +' - ' +ut.get_track_info(track)
            if(i%100 ==0):
                print "processing track:%s\t%s" %(str(i),str(track))
            if(file == SOURCE_DATA_FILE): #fetch h5 file from small dataset
                h5 = GETTERS.open_h5_file_read("../../msd_dense_subset/dense/"+track[2]+"/"+track[3]+"/"+track[4]+"/"+track+".h5")    #fetch h5 file to allow faster preprocessing
            else:
                h5 = GETTERS.open_h5_file_read("../../msd_dense_subset/mood/"+track[2]+"/"+track[3]+"/"+track[4]+"/"+track+".h5")    #fetch h5 file to allow faster preprocessing
            track_info[i] = ut.get_track_info(track,h5)
            timbre = ut.get_timbre(track,h5) #returns a tuple with 5 elements (12*5 = 60)
            tempo = ut.get_tempo_feature(track,h5) #(1)
            loudness = ut.get_loudness(track,h5)#returns a tuple with 3 elements (3)
            energy = ut.get_energy_feature(track) #(1)
            pitches = ut.get_pitches(track, h5) #(12)
            features[i] =  np.concatenate((timbre[0], timbre[1], timbre[2], timbre[3], timbre[4],pitches[0], pitches[1],pitches[2], pitches[3],pitches[4],np.array([tempo]),np.array(loudness),np.array([energy])))
            h5.close()
        print "done parsing"
        print "saving data"
        
    data = {
        'features': features,
        'labels': labels,
        'tracks': tracks, #(songindex, songid)
        'track_titles': track_info
    }
    
    with open(targetfile, 'w') as f:
        pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
        
    print "data saved to %s" % targetfile

#SCRIPT
#parse_file(SOURCE_DATA_FILE_2,E_TARGET_DATA_FILE_2)
#parse_file(SOURCE_DATA_FILE,E_TARGET_DATA_FILE)
Exemplo n.º 3
0
def plot_chroma(track):   
    path = "../../msd_dense_subset/mood/"+track[2]+"/"+track[3]+"/"+track[4]+"/"+track+".h5"
    h5 = GETTERS.open_h5_file_read(path)
    pitches = GETTERS.get_segments_pitches(h5)
    segments = GETTERS.get_segments_start(h5)
    sections = GETTERS.get_sections_start(h5)
    idx = list()
    for section in sections:
        dif = segments - section
        posdif = np.where(dif >=0)
        idx.append(posdif[0][0])
    plt.figure(num=None, figsize=(20, 12), dpi=80, facecolor='w', edgecolor='k')
    plt.title('Chroma values for ' + ut.get_track_info(track))
    plt.ylabel('Chroma values')
    plt.xlabel('Time')
    plt.xticks(idx,sections.astype(int))
    extent =[0,segments.shape[0],0,12]
    plt.imshow(pitches.transpose(), extent = extent,aspect = 'auto',interpolation='nearest',origin='lower')
    plt.colorbar()
    plt.autoscale(enable=True, axis='x')
    #plt.pcolor(pitches.transpose())
    h5.close()
    plt.show()
Exemplo n.º 4
0
def plot_loudness_curve(track):
    path = "../../msd_dense_subset/mood/"+track[2]+"/"+track[3]+"/"+track[4]+"/"+track+".h5"
    h5 = GETTERS.open_h5_file_read(path)
    segments = (GETTERS.get_segments_start(h5))
    sections = (GETTERS.get_sections_start(h5))
    max_loudness = (GETTERS.get_segments_loudness_max(h5))
    loudness = (GETTERS.get_segments_loudness_start(h5))
    average_loudness = (max_loudness + loudness) / 2
    average_loudness_song = GETTERS.get_loudness(h5)
    start_fade_out = GETTERS.get_start_of_fade_out(h5)
    end_fade_in = GETTERS.get_end_of_fade_in(h5)
    plt.title('loudness curve for ' + ut.get_track_info(track))
    plt.ylabel('Loudness(dB)')
    plt.xlabel('Time(s)')
    plt.plot(segments, average_loudness, label='Filtered')
    plt.axhline(average_loudness_song, color='green',label='average')
    for section in enumerate(sections):
        plt.axvline(section[1], color='red')
    plt.axvline(start_fade_out, color='green')
    plt.axvline(end_fade_in, color='green')
    #plt.legend(('average'))
    h5.close()
    plt.show()