Utils (synctoolbox.feature.utils)

synctoolbox.feature.utils.estimate_tuning(x: ndarray, Fs: float, N: int = 16384, gamma: float = 100, local: bool = True, filt: bool = True, filt_len: int = 101) int[source]

Compute tuning deviation in cents for an audio signal. Convenience wrapper around ‘compute_freq_distribution’ and ‘tuning_similarity’ from libfmp.

Parameters
  • x (np.ndarray) – Input signal

  • Fs (float) – Sampling rate

  • N (int) – Window size

  • gamma (float) – Constant for logarithmic compression

  • local (bool) – If True, computes STFT and averages; otherwise computes global DFT

  • filt (bool) – If True, applies local frequency averaging and by rectification

  • filt_len (int) – Filter length for local frequency averaging (length given in cents)

Returns

tuning (int) – Estimated tuning deviation for x (in cents)

synctoolbox.feature.utils.normalize_feature(feature: ndarray, norm_ord: int, threshold: float) ndarray[source]

Normalizes a feature sequence according to the l^norm_ord norm.

Parameters
  • feature (np.ndarray) –

    Input feature sequence of size d x N

    d: dimensionality of feature vectors N: number of feature vectors (time in frames)

  • norm_ord (int) – Norm degree

  • threshold (float) – If the norm falls below threshold for a feature vector, then the normalized feature vector is set to be the normalized unit vector.

Returns

f_normalized (np.ndarray) – Normalized feature sequence

synctoolbox.feature.utils.shift_chroma_vectors(chroma: ndarray, chroma_shift: int) ndarray[source]

Shift chroma representation by the given number of semitones. Format is assumed to be 12xN

Parameters
  • chroma (np.ndarray [shape=(12, N)]) – Chroma representation

  • chroma_shift (int) – Chroma shift

Returns

shifted_chroma (np.ndarray) – Shifted chroma representation

synctoolbox.feature.utils.smooth_downsample_feature(f_feature: ndarray, input_feature_rate: float, win_len_smooth: int = 0, downsamp_smooth: int = 1) Tuple[ndarray, float][source]

Temporal smoothing and downsampling of a feature sequence

Parameters
  • f_feature (np.ndarray) – Input feature sequence, size dxN

  • input_feature_rate (float) – Input feature rate in Hz

  • win_len_smooth (int) – Smoothing window length. For 0, no smoothing is applied.

  • downsamp_smooth (int) – Downsampling factor. For 1, no downsampling is applied.

Returns
  • f_feature_stat (np.ndarray) – Downsampled & smoothed feature.

  • new_feature_rate (float) – New feature rate after downsampling