Exemplo n.º 1
0
def process(args):
    # options
    mu = 1
    G = 0
    doConvolution = True
    fileName = args[0]
    combmode = 13

    # Compute HF0 (SIMM with source-filter model)
    if combmode > 0:
        timesHF0, HF0, options = SourceFilterModelSF.main(args)

    # In order to have the same structure as the Harmonic Summation Salience Function
    HF0 = HF0[1:, :]


    # -------------------------

    if options.extractionMethod == "BG1":
        # Options MIREX 2016:  BG1
        options.pitchContinuity = 27.56
        options.peakDistributionThreshold = 1.3
        options.peakFrameThreshold = 0.7
        options.timeContinuity = 100
        options.minDuration = 100
        options.voicingTolerance = 1
        options.useVibrato = False

    if options.extractionMethod == "BG2":
        # Options MIREX 2016:  BG2
        options.pitchContinuity = 27.56
        options.peakDistributionThreshold = 0.9
        options.peakFrameThreshold = 0.9
        options.timeContinuity = 100
        options.minDuration = 100
        options.voicingTolerance = 0.2
        options.useVibrato = False

    if combmode != 4 and combmode != 5:
        # Computing Harmonic Summation salience function
        hopSizeinSamplesHSSF = int(min(options.hopsizeInSamples, 0.01 * options.Fs))
        spectogram, fftgram = calculateSpectrum(fileName, hopSizeinSamplesHSSF)
        timesHSSF, HSSF = calculateSF(spectogram,  hopSizeinSamplesHSSF)
    else:
        print "Harmonic Summation Salience function not used"

    # Combination mode used in MIREX, ISMIR2016, SMC2016
    if combmode == 13:
        times, combSal = combineSaliences.combine3MIREX(timesHF0, HF0, timesHSSF, HSSF, G, mu, doConvolution)

    combSal = combSal / max(combSal)

    print("Extracting melody from salience function")
    times, pitch, dummy, dummy = melodyExtractionFromSalienceFunction.MEFromSF(times, combSal, options)

    # Save output file
    savetxt(options.pitch_output_file, column_stack((times.T, pitch.T)), fmt='%-7.5f', delimiter="\t")
    print("Output file written")
Exemplo n.º 2
0
def compare_to_matlab_features(track, options):
    '''
    test computing of harmonic amplitudes with essentia
    load the salience bins, saved as pandas dataframes. extract complex fft spectrum and compute harmonic amplitudes  
    If they have already the timbre features, they are recomputed here.  
    '''
    
    contour_data_frame, adat = get_data_files(track, meltype=1)
    contour_output_path = '/home/georgid/Documents/iKala/Conv_mu-1_G-0_LHSF-0_pC-27.56_pDTh-0.9_pFTh-0.9_tC-100_mD-200_vxTol-0.2_LEH_300_100_300_5_1_5/'
    
    
    
    
    wav_URI = os.path.join(os.path.dirname(__file__), track + '.wav')
    print wav_URI
    _, fftgram = calculateSpectrum(wav_URI , options.hopsizeInSamples)
    timestamps_recording = np.arange(len(fftgram)) * float(options.hopsizeInSamples) / options.Fs
        
    c_times, c_freqs, _ = contours_from_contour_data(contour_data_frame)
    

    
    for i, (times, freqs) in zip(c_times.iterrows(), c_freqs.iterrows()): # for each contour
        row_idx = times[0]
        times = times[1].values
        freqs = freqs[1].values

        # remove trailing NaNs
        times = times[~np.isnan(times)]
        freqs = freqs[~np.isnan(freqs)]
        

        # compute harm magns

        times_contour, idx_start = get_ts_contour(freqs, times[0], timestamps_recording, options)
        print 'contour len: {}'.format(times[-1] - times[0])
        
        vv_array, audio = extract_vocal_var(fftgram, idx_start, freqs, Parameters.dim_vv,    options)  
#         contourTimbre = compute_timbre_features(contours_bins_SAL, contours_start_times_SAL, fftgram, timestamps_recording, options)


        # plot spectrogram per contour
        pyplot.imshow(vv_array, interpolation='none')
        pyplot.show()
        

        ########################### matlab 
        
        # save  audio as file. 
        # extract  feature with matlab
        # visualize in matlab.      
        print 'len : {}'.format(len(audio)/44100.0)
Exemplo n.º 3
0
def add_timbre_features_and_save(track, contours_output_path, options):
    '''
    load extracted ctrs,  
    add timbre features and save contours in 
    same format .pitch.ctr
    '''

    contour_data_frame, contours_bins_SAL, contours_saliences_SAL, contours_start_times_SAL = load_contour(
        track, options)

    wavfile_ = os.path.join(Parameters.iKala_URI, 'Wavfile', track + '.wav')
    _, fftgram = calculateSpectrum(wavfile_, options.hopsizeInSamples)
    timestamps_recording = np.arange(len(fftgram)) * float(
        options.hopsizeInSamples) / options.Fs

    options.saveContours = True
    options.track = track

    options.pitch_output_file = os.path.join(contours_output_path, track)

    options.contours_output_path = contours_output_path
    contourTimbre = compute_timbre_features(contours_bins_SAL,
                                            contours_start_times_SAL, fftgram,
                                            timestamps_recording, options)

    if Parameters.read_features_from_MATLAB:
        path_ = options.contours_output_path + Parameters.features_MATLAB_URI
        contours_vvs_matlab = load_timbre_features(contour_data_frame, path_,
                                                   track)

        #  take median  and put in  numpoy array
        contourTimbre_matlab_vv = np.zeros(
            [len(contours_vvs_matlab),
             Parameters.dim_vv])  # compute timbral features
        for i, contour_vvs in enumerate(contours_vvs_matlab):
            median_timbre_features = np.median(contour_vvs, axis=0)
            contourTimbre[i, :] = median_timbre_features

        contourTimbre[:, 0:contourTimbre_matlab_vv.
                      shape[1]] = contourTimbre_matlab_vv

    if isnan(contourTimbre).any():
        print 'contour for file {} has nans'.format(options.pitch_output_file)


    saveContours(options, options.stepNotes, contours_bins_SAL, contours_saliences_SAL, contours_start_times_SAL, \
                 contourTimbre, old_contour_data=contour_data_frame)
Exemplo n.º 4
0
def compute_and_plot_harmoncis(times, freqs, track ):
        '''
        visualize harm magnitudes
        skip timeframes with any hfreq = 0
        '''
        
        args, options = parsing.parseOptions([])
        _, fftgram = calculateSpectrum(track + '.wav', 128)
        timestamps_recording = np.arange(len(fftgram)) * float(128) / 44100
        times_contour, idx_start = get_ts_contour(freqs, times[0], timestamps_recording, options)
        hfreqs, magns, _ =  compute_harmonic_magnitudes(freqs,  fftgram, idx_start, options )
        # how many harmonics
        until_Harm = 10
        for i in range(len(hfreqs)):
            curr_hFreqs = hfreqs[i]
            indices_zeros = np.where(curr_hFreqs[:until_Harm] == 0)[0] # sskip timeframes with any hfreq = 0
            if len(indices_zeros) != 0:
                continue
            plt.plot(curr_hFreqs[:until_Harm], magns[i][:until_Harm])
            plt.show()
Exemplo n.º 5
0
def contours_to_audio(track, contours_output_path, options):
    '''
    sonify only the harmonic partials from the contour
    take spectral part with f0 at contour 
    '''

    contour_data_frame, contours_bins_SAL, contours_saliences_SAL, contours_start_times_SAL = load_contour(
        track, options)

    wavfile_ = os.path.join(Parameters.iKala_URI, 'Wavfile', track + '.wav')
    _, fftgram = calculateSpectrum(wavfile_, options.hopsizeInSamples)
    timestamps_recording = np.arange(len(fftgram)) * float(
        options.hopsizeInSamples) / options.Fs

    options.contours_output_path = contours_output_path
    options.track = track
    spectogram_contours = contour_to_audio(contours_bins_SAL,
                                           contours_start_times_SAL, fftgram,
                                           timestamps_recording, options)
    return spectogram_contours
Exemplo n.º 6
0
def create_contours_and_store(tracks, contours_output_path):
    '''
    extract contours with essentia with SAL features
    
    output .pitch.ctr in folder contours_output_path
    '''
    import parsing

    (args, options) = parsing.parseOptions(sys.argv)

    options.pitchContinuity = 27.56
    options.peakDistributionThreshold = 1.3
    #     options.peakDistributionThreshold = 0.9
    options.peakFrameThreshold = 0.7
    #     options.peakFrameThreshold = 0.9
    options.timeContinuity = 100

    #     options.timeContinuity = 50     # medley DB
    options.minDuration = 300
    options.voicingTolerance = 1
    options.useVibrato = False

    options.Fs = 44100
    options.extractionMethod = 'PCC'
    options.plotting = False

    for fileName in tracks:

        options.pitch_output_file = contours_output_path + fileName
        wavfile_ = os.path.join(Parameters.iKala_URI, 'Wavfile',
                                fileName + '.wav')
        spectogram, fftgram = calculateSpectrum(wavfile_,
                                                options.hopsizeInSamples)
        timesHSSF, HSSF = calculateSF(spectogram, options.hopsizeInSamples)
        HSSF = HSSF.T
        print("Extracting melody from salience function ")
        times, pitch = MEFromSF(timesHSSF, HSSF, fftgram, options)
Exemplo n.º 7
0
def test_vocal_variance(track, options):
    '''
    test computing of harmonic amplitudes with essentia
    load the salience bins, saved as pandas dataframes. extract complex fft spectrum and compute harmonic amplitudes  
    If they have already the timbre features, they are recomputed here.  
    '''
    
    
        
    _, fftgram = calculateSpectrum(track + '.wav', options.hopsizeInSamples)
    timestamps_recording = np.arange(len(fftgram)) * float(options.hopsizeInSamples) / options.Fs
        
    contour_data_frame, adat = get_data_files(track, meltype=1)
    c_times, c_freqs, _ = contours_from_contour_data(contour_data_frame)
    
    for (times, freqs) in zip(c_times.iterrows(), c_freqs.iterrows()): # for each contour
        row_idx = times[0]
        times = times[1].values
        freqs = freqs[1].values

        # remove trailing NaNs
        times = times[~np.isnan(times)]
        freqs = freqs[~np.isnan(freqs)]
        

        # compute harm magns

        times_contour, idx_start = get_ts_contour(freqs, times[0], timestamps_recording, options)
        print 'contour len: {}'.format(times[-1] - times[0])
        vv_array = extract_vocal_var(fftgram, idx_start, freqs, Parameters.dim_timbre,    options)                
        
#         save_harmonics(times, hfreqs, test_track)
        # plot spectrogram per contour
#         pyplot.imshow(vv_array)
#         pyplot.show()
        return contour_data_frame, vv_array