Utility functions
Audio and spectrogram utilities
- ctfr.load(path, *, sr=None, mono=True, offset=0.0, duration=None, dtype=<class 'numpy.float64'>, res_type='soxr_hq')
Loads an audio file as a floating point time series.
This function is a wrapper for
librosa.load(). The default values forsranddtypeare changed.
- ctfr.stft(signal, *, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, dtype=None, pad_mode='constant', out=None)
Computes the short-time Fourier transform (STFT) of a signal.
This function is a wrapper for
librosa.stft(). The default value forn_fftis changed to matchctfr.ctfr()for a signal with a sampling rate of 22050 Hz.See also
- ctfr.cqt(signal, *, sr=22050, hop_length=512, fmin=None, n_bins=288, bins_per_octave=36, tuning=0.0, filter_scale=1, norm=1, sparsity=0.01, window='hann', scale=True, pad_mode='constant', res_type='soxr_hq', dtype=None)
Computes the constant-Q transform (CQT) of a signal.
This function is a wrapper for
librosa.cqt(). The default values forn_binsandbins_per_octaveare changed to matchctfr.ctfr().See also
- ctfr.stft_spec(signal, *, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant', dtype=<class 'numpy.float64'>, stft_dtype=None)
Computes the squared magnitude of the short-time Fourier transform (STFT) of a signal.
This function is equivalent to:
>>> np.square(np.abs(ctfr.stft(signal, ...), dtype=dtype))
Notes
The dtype parameter refers to the data type of the output array. In order to pass a data type to
stft(), use the stft_dtype parameter.Unlike
stft(), this function does not include an out parameter and always returns a new array.See also
- ctfr.cqt_spec(signal, *, sr=22050, hop_length=512, fmin=None, n_bins=288, bins_per_octave=36, tuning=0.0, filter_scale=1, norm=1, sparsity=0.01, window='hann', scale=True, pad_mode='constant', res_type='soxr_hq', dtype=<class 'numpy.float64'>, cqt_dtype=None)
Computes the squared magnitude of the constant-Q transform (CQT) of a signal.
This function is equivalent to:
>>> np.square(np.abs(ctfr.cqt(signal, ...), dtype=dtype))
Notes
The dtype parameter refers to the data type of the output array. In order to pass a data type to
cqt(), use the cqt_dtype parameter.See also
- ctfr.specshow(data, *, x_coords=None, y_coords=None, x_axis=None, y_axis=None, sr=22050, hop_length=512, n_fft=None, win_length=None, fmin=None, fmax=None, tempo_min=16, tempo_max=480, tuning=0.0, bins_per_octave=12, key='C:maj', Sa=None, mela=None, thaat=None, auto_aspect=True, htk=False, unicode=True, intervals=None, unison=None, ax=None, **kwargs)
Displays a spectrogram, chromagram or similar plot.
This function is a wrapper for
librosa.display.specshow().Notes
This function is not installed with ctfr by default. To use it, you must install
ctfrwith the[display]extra. See Installation for more information.
- ctfr.power_to_db(S, ref=1.0, amin=1e-10, top_db=80.0)
Converts a power spectrogram (amplitude squared) to decibel (dB) units.
This function is a wrapper for
librosa.power_to_db().
Combination method utilities
- ctfr.show_methods()
Prints information for all installed combination methods.
See also
- ctfr.get_methods_list()
Returns a list of all installed combination methods’ keys.
This function can be employed to iterate over installed methods.
- Returns:
A list of all installed combination methods’ keys.
- Return type:
list of str
See also
- ctfr.get_method_name(key)
Returns the name for a given combination method key.
This function can be useful for displaying and plotting purposes.
- Parameters:
key (str) – The key of the combination method.
- Returns:
The name of the combination method.
- Return type:
str
- Raises:
ctfr.exception.InvalidCombinationMethodError – If the given key is not a valid combination method.
- ctfr.cite_method(method: str)
Prints the citation information for a combination method.
- Parameters:
method (str) – The combination method to get the citation information.
- Raises:
ctfr.exception.InvalidCombinationMethodError – If the combination method is invalid.
See also
- ctfr.show_method_params(method: str)
Prints parameters’ information for a combination method.
- Parameters:
method (str) – The combination method to get the parameter information.
- Raises:
ctfr.exception.InvalidCombinationMethodError – If the combination method is invalid.
Sample fetching utilities
- ctfr.list_samples()
List the available sample files included in this package, along with their brief descriptions.
See also
- ctfr.fetch_sample(sample_key)
Fetch the filename for a data sample included in this package.
- Parameters:
sample_key (str) – The key of the sample dataset to fetch. The available keys can be listed using
list_samples().- Returns:
The path to the fetched sample dataset.
- Return type:
str
- Raises:
ctfr.exception.InvalidSampleError – If the sample key does not match any sample file included in this package.
See also