Пример #1
0
def audio(filename, name_file, hpss, sr):
    """
        Wrapper of get audio for save all results for future same calculations. If parameterization
        have been computed before get audio is not computed.

        Parameters
        ----------
        filename: str
            name of the file that is being computed witout format extension

        name_file: str
        name of the file that is being computed

        hpss: bool optional
        true or false depends is harmonic percussive source separation (hpss) block wants to be computed. Default False.

        sr: number > 0 [scalar]
        target sampling rate

        Returns
        -------
        list
        sample of audio
    """
    name_audio = get_name_audio(name_file, hpss, sr)
    if path.exists(name_audio):
        dic = load_binary(name_audio)
    else:
        y, sr = get_audio(filename, hpss, sr)
        dic = {'y': y, 'sr': sr}
        # dic_save = {'y': y.tolist(), 'sr': sr}
        save_binary(dic, name_audio)
    # save_json(dic_save, name_audio + '.json')
    return dic['y'], dic['sr']
Пример #2
0
def harmonic_change(filename: str, name_file: str, hpss: bool = False, tonal_model: str = 'TIV2', chroma: str = 'cqt',
                    blur: str = 'full', sigma: int = 11, log_compresion: str = 'none', distance: str = 'euclidean'):
	"""
		Wrapper of harmonic change detection function for save all results for future same calculations. If parameterization
		have been computed before HCDF is not computed. 

		Parameters
		----------
		filename: str
				name of the file that is being computed witout format extension

		name_file: str
			name of the file that is being computed
		
		hpss : bool optional
			true or false depends is harmonic percussive source separation (hpss) block wants to be computed. Default False.

		tonal_model: str optional
			Tonal model block type. "TIV2" for Tonal Interval space focus on audio. "TIV2" for audio. "TIV2_Symb" for symbolic data.
			"tonnetz" for harte centroids aproach. Default TIV2
			
		chroma: str optional
		    "chroma-samplerate-framesize-overlap"
			chroma can be "CQT","NNLS", "STFT", "CENS" or "HPCP"
			samplerate as a number scalar
			frame size as a number scalar
			overlap number that a windows is divided

		sigma: number (scalar > 0) optional
			sigma of gaussian smoothing value. Default 11

		distance: str optional
			type of distance measure used. Types can be "euclidean" for euclidean distance and "cosine" for cosine distance. Default "euclidean".

		
		Returns
		-------
		list
			harmonic changes (the peaks) on the song detected
		list
		    HCDF function values
		number
		    windows size
	"""
	centroid_changes = []
	check_parameters(chroma, blur, tonal_model, log_compresion, distance)

	name_harmonic_change = get_name_harmonic_change(name_file, hpss, tonal_model, chroma, blur, sigma, log_compresion,
	                                                distance)
	if path.exists(name_harmonic_change):
		dic = load_binary(name_harmonic_change)
	else:
		changes, harmonic_function, windows_size, centroid_changes = get_harmonic_change(filename, name_file, hpss,
		                                                                                 tonal_model, chroma,
		                                                                                 blur, sigma, log_compresion,
		                                                                                 distance)
		dic = {'changes': changes, 'harmonic_function': harmonic_function, 'windows_size': windows_size}
		
		save_binary(dic, name_harmonic_change)
	return dic['changes'], dic['harmonic_function'], dic['windows_size']
Пример #3
0
def gaussian_blur(hpss, chroma, tonal_model, name_file, centroid_vector,
                  log_compresion, blur, sigma):
    """
        Wrapper of get_gaussian_blur for save all results for future same calculations. If parameterization
        have been computed before get_gaussian_blur is not computed.

        Parameters
        ----------
        name_file: str
            name of the file that is being computed

        hpss: bool optional
            true or false depends is harmonic percussive source separation (hpss) block wants to be computed. Default False.

        sr: number > 0 [scalar]
            target sampling rate

        chroma: str optional
            "chroma-samplerate-framesize-overlap"
            chroma can be "CQT","NNLS", "STFT", "CENS" or "HPCP"
            samplerate as a number scalar
            frame size as a number scalar
            overlap number that a windows is divided

        tonal_model: str optional
            Tonal model block type. "TIV2" for Tonal Interval space focus on audio. "TIV2" for audio. "TIV2_Symb" for symbolic data.
            "tonnetz" for harte centroids aproach. Default TIV2

        centoid_vector: list
            tonal centroids of the tonal model

        sigma: number (scalar > 0) optional
            sigma of gaussian smoothing value. Default 11


        Returns
        -------
        list
            sample of audio
    """
    gaussian_blur = get_name_gaussian_blur(name_file, hpss, chroma,
                                           tonal_model, blur, sigma,
                                           log_compresion)
    if path.exists(gaussian_blur):
        dic = load_binary(gaussian_blur)
    else:
        centroid_vector = get_gaussian_blur(centroid_vector, blur, sigma)
        dic = {'centroid_vector': centroid_vector}
        # dic_save = {'centroid_vector': centroid_vector.tolist()}
        save_binary(dic, gaussian_blur)
    # save_json(dic_save, gaussian_blur + '.json')
    return dic['centroid_vector']
Пример #4
0
def tonal_centroid_transform(hpss, chroma, name_file, y, sr, tonal_model,
                             doce_bins_tuned_chroma):
    """
        wrapper of tonal centroid transform for save all results for future same calculations

        Parameters
        ----------
        hpss : bool
            true or false depends on hpss block

        name_file: str
            name of the file that is being computed

        y : number > 0 [scalar]
            audio

        sr: number > 0 [scalar]
            target sampling rate

        chroma: str
            chroma-samplerate-framesize-overlap

        tonal_model: str optional
            Tonal model block type. "TIV2" for Tonal Interval space focus on audio. "TIV2" for audio. "TIV2_Symb" for symbolic data.
            "tonnetz" for harte centroids aproach. Default TIV2\

        doce_bins_tuned_chroma: list
            list of chroma vectors

        Returns
        -------
        list of tonal centroids vectors
    """
    name_tonal_model = get_name_tonal_model(name_file, hpss, chroma,
                                            tonal_model)
    if tonal_model == 'without_tc':
        dic = {'centroid_vector': doce_bins_tuned_chroma}
    else:
        if path.exists(name_tonal_model):
            dic = load_binary(name_tonal_model)
        else:
            centroid_vector = get_tonal_centroid_transform(
                y, sr, tonal_model, doce_bins_tuned_chroma)
            dic = {'centroid_vector': centroid_vector}
            save_binary(dic, name_tonal_model)
    return dic['centroid_vector']
Пример #5
0
def chromagram(hpss, name_file, y, sr, chroma):
    """
        wrapper of get_chromagram for save all results for future same calculations

        Parameters
        ----------
        hpss : bool
            true or false depends on hpss block

        name_file: str
            name of the file that is being computed

        y : number > 0 [scalar]
            audio

        sr: number > 0 [scalar]
            target sampling rate

        chroma: str
            chroma-samplerate-framesize-overlap


        Returns
        -------
        list of chromagrams
    """
    name_chromagram = get_name_chromagram(name_file, hpss, chroma)
    if path.exists(name_chromagram):
        dic = load_binary(name_chromagram)
    else:
        # if mutex_global.mutex is not None:
        #     mutex_global.mutex.acquire()
        doce_bins_tuned_chroma = get_chromagram(y, sr, chroma)
        # if mutex_global.mutex is not None:
        #     mutex_global.mutex.release()
        dic = {'doce_bins_tuned_chroma': doce_bins_tuned_chroma}
        # dic_save = {'doce_bins_tuned_chroma': doce_bins_tuned_chroma.tolist()}
        save_binary(dic, name_chromagram)
    # save_json(dic_save, name_chromagram + '.json')
    return dic['doce_bins_tuned_chroma']