pytimbre.spectral.timbral_model.timbral_util.calculate_onsets

pytimbre.spectral.timbral_model.timbral_util.calculate_onsets(audio_samples, envelope_samples, fs, look_back_time=20, hysteresis_time=300, hysteresis_percent=10, onset_in_noise_threshold=10, minimum_onset_time_separation=100, nperseg=512)
Calculates the onset times using a look backwards recursive function to identify actual note onsets, and weights

the outputs based on the onset strength to avoid misidentifying onsets.

Required inputs :param audio_samples: the audio file in the time domain. :param envelope_samples: the envelope of the audio file, suggested to be calculated with

sample_and_hold_envelope_calculation.

Parameters:

fs – samplerate of the audio file. Function assumes the same sample rate for both audio_samples and envelop_samples

Optional inputs :param look_back_time: time in ms to recursively lookbackwards to identify start of onset,

defaults to 20ms.

Parameters:
  • hysteresis_time – time in ms to look backwards in time for a hysteresis check, set to 300ms bedefault.

  • hysteresis_percent – set the percentage of dynamic range that must be checked when looking backwards via hysteresis, default to 10%.

  • onset_in_noise_threshold – set a threshold of dynamic range for determining if an onset was variation in noise or an actual onset, default to 10%.

  • minimum_onset_time_separation – set the minimum time in ms that two offsets can be separated by.

  • method – set the method for calculating the onsets. Default to ‘librosa’, but can be ‘essentia_hfc’, or ‘essentia_complex’.

  • nperseg – value used in return loop.

Returns:

thresholded onsets, returns [0] if no onsets are identified. Note that a value of [0] is also possible during normal opperation.