Music Synchronization (libfmp.c3)¶
The FMP notebooks provide detailed textbook-like explanations of central techniques and algorithms implemented in the libfmp. The part of FMP related to this module is available at the following URL:
https://www.audiolabs-erlangen.de/resources/MIR/FMP/C3/C3.html
- libfmp.c3.c3s1_audio_feature.compute_chromagram(Y_LF)[source]¶
Computes a chromagram
Notebook: C3/C3S1_SpecLogFreq-Chromagram.ipynb
- Parameters
Y_LF (np.ndarray) – Log-frequency spectrogram
- Returns
C (np.ndarray) – Chromagram
- libfmp.c3.c3s1_audio_feature.compute_spec_log_freq(Y, Fs, N)[source]¶
Computes a log-frequency spectrogram
Notebook: C3/C3S1_SpecLogFreq-Chromagram.ipynb
- Parameters
Y (np.ndarray) – Magnitude or power spectrogram
Fs (scalar) – Sampling rate
N (int) – Window size of Fourier fransform
- Returns
Y_LF (np.ndarray) – Log-frequency spectrogram
F_coef_pitch (np.ndarray) – Pitch values
- libfmp.c3.c3s1_audio_feature.f_pitch(p, pitch_ref=69, freq_ref=440.0)[source]¶
Computes the center frequency/ies of a MIDI pitch
Notebook: C3/C3S1_SpecLogFreq-Chromagram.ipynb
- Parameters
p (float) – MIDI pitch value(s)
pitch_ref (float) – Reference pitch (default: 69)
freq_ref (float) – Frequency of reference pitch (default: 440.0)
- Returns
freqs (float) – Frequency value(s)
- libfmp.c3.c3s1_audio_feature.note_name(p)[source]¶
Returns note name of pitch
Notebook: C3/C3S1_SpecLogFreq-Chromagram.ipynb
- Parameters
p (int) – Pitch value
- Returns
name (str) – Note name
- libfmp.c3.c3s1_audio_feature.pool_pitch(p, Fs, N, pitch_ref=69, freq_ref=440.0)[source]¶
Computes the set of frequency indices that are assigned to a given pitch
Notebook: C3/C3S1_SpecLogFreq-Chromagram.ipynb
- Parameters
p (float) – MIDI pitch value
Fs (scalar) – Sampling rate
N (int) – Window size of Fourier fransform
pitch_ref (float) – Reference pitch (default: 69)
freq_ref (float) – Frequency of reference pitch (default: 440.0)
- Returns
k (np.ndarray) – Set of frequency indices
- libfmp.c3.c3s1_post_processing.log_compression(v, gamma=1.0)[source]¶
Logarithmically compresses a value or array
Notebook: C3/C3S1_LogCompression.ipynb
- Parameters
v (float or np.ndarray) – Value or array
gamma (float) – Compression factor (Default value = 1.0)
- Returns
v_compressed (float or np.ndarray) – Compressed value or array
- libfmp.c3.c3s1_post_processing.median_downsample_feature_sequence(X, Fs, filt_len=41, down_sampling=10)[source]¶
Smoothes and downsamples a feature sequence. Smoothing is achieved by median filtering
Notebook: C3/C3S1_FeatureSmoothing.ipynb
- Parameters
X (np.ndarray) – Feature sequence
Fs (scalar) – Frame rate of
X
filt_len (int) – Length of smoothing filter (Default value = 41)
down_sampling (int) – Downsampling factor (Default value = 10)
- Returns
X_smooth (np.ndarray) – Smoothed and downsampled feature sequence
Fs_feature (scalar) – Frame rate of
X_smooth
- libfmp.c3.c3s1_post_processing.normalize_feature_sequence(X, norm='2', threshold=0.0001, v=None)[source]¶
Normalizes the columns of a feature sequence
Notebook: C3/C3S1_FeatureNormalization.ipynb
- Parameters
X (np.ndarray) – Feature sequence
norm (str) – The norm to be applied. ‘1’, ‘2’, ‘max’ or ‘z’ (Default value = ‘2’)
threshold (float) – An threshold below which the vector
v
used instead of normalization (Default value = 0.0001)v (float) – Used instead of normalization below
threshold
. If None, uses unit vector for given norm (Default value = None)
- Returns
X_norm (np.ndarray) – Normalized feature sequence
- libfmp.c3.c3s1_post_processing.smooth_downsample_feature_sequence(X, Fs, filt_len=41, down_sampling=10, w_type='boxcar')[source]¶
Smoothes and downsamples a feature sequence. Smoothing is achieved by convolution with a filter kernel
Notebook: C3/C3S1_FeatureSmoothing.ipynb
- Parameters
X (np.ndarray) – Feature sequence
Fs (scalar) – Frame rate of
X
filt_len (int) – Length of smoothing filter (Default value = 41)
down_sampling (int) – Downsampling factor (Default value = 10)
w_type (str) – Window type of smoothing filter (Default value = ‘boxcar’)
- Returns
X_smooth (np.ndarray) – Smoothed and downsampled feature sequence
Fs_feature (scalar) – Frame rate of
X_smooth
- libfmp.c3.c3s1_transposition_tuning.compute_freq_distribution(x, Fs, N=16384, gamma=100.0, local=True, filt=True, filt_len=101)[source]¶
Compute an overall frequency distribution
Notebook: C3/C3S1_TranspositionTuning.ipynb
- Parameters
x (np.ndarray) – Signal
Fs (scalar) – Sampling rate
N (int) – Window size (Default value = 16384)
gamma (float) – Constant for logarithmic compression (Default value = 100.0)
local (bool) – Computes STFT and averages; otherwise computes global DFT (Default value = True)
filt (bool) – Applies local frequency averaging and by rectification (Default value = True)
filt_len (int) – Filter length for local frequency averaging (length given in cents) (Default value = 101)
- Returns
v (np.ndarray) – Vector representing an overall frequency distribution
F_coef_cents (np.ndarray) – Frequency axis (given in cents)
- libfmp.c3.c3s1_transposition_tuning.cyclic_shift(C, shift=1)[source]¶
Cyclically shift a chromagram
Notebook: C3/C3S1_TranspositionTuning.ipynb
- Parameters
C (np.ndarray) – Chromagram
shift (int) – Tranposition shift (Default value = 1)
- Returns
C_shift (np.ndarray) – Cyclically shifted chromagram
- libfmp.c3.c3s1_transposition_tuning.plot_freq_vector_template(v, F_coef_cents, template_max, theta_max, ax=None, title=None, figsize=(8, 3))[source]¶
Plots frequency distribution and similarity-maximizing template
Notebook: C3/C3S1_TranspositionTuning.ipynb
- Parameters
v – Vector representing an overall frequency distribution
F_coef_cents – Frequency axis
template_max – Similarity-maximizing template
theta_max – Maximizing tuning parameter
ax – Axis (in case of ax=None, figure is generated) (Default value = None)
title – Title of figure (or subplot) (Default value = None)
figsize – Size of figure (only used when ax=None) (Default value = (8, 3))
- Returns
fig – Handle for figure
ax – Handle for axes
line – handle for line plot
- libfmp.c3.c3s1_transposition_tuning.plot_tuning_similarity(sim, theta_axis, theta_max, ax=None, title=None, figsize=(4, 3))[source]¶
Plots tuning similarity
Notebook: C3/C3S1_TranspositionTuning.ipynb
- Parameters
sim – Similarity values
theta_axis – Axis consisting of cent values [-50:49]
theta_max – Maximizing tuning parameter
ax – Axis (in case of ax=None, figure is generated) (Default value = None)
title – Title of figure (or subplot) (Default value = None)
figsize – Size of figure (only used when ax=None) (Default value = (4, 3))
- Returns
fig – Handle for figure
ax – Handle for axes
line – handle for line plot
- libfmp.c3.c3s1_transposition_tuning.template_comb(M, theta=0)[source]¶
Compute a comb template on a pitch axis
Notebook: C3/C3S1_TranspositionTuning.ipynb
- Parameters
M (int) – Length template (given in cents)
theta (int) – Shift parameter (given in cents); -50 <= theta < 50 (Default value = 0)
- Returns
template (np.ndarray) – Comb template shifted by theta
- libfmp.c3.c3s1_transposition_tuning.tuning_similarity(v)[source]¶
Compute tuning similarity
Notebook: C3/C3S1_TranspositionTuning.ipynb
- Parameters
v (np.ndarray) – Vector representing an overall frequency distribution
- Returns
theta_axis (np.ndarray) – Axis consisting of all tuning parameters -50 <= theta < 50
sim (np.ndarray) – Similarity values for all tuning parameters
ind_max (int) – Maximizing index
theta_max (int) – Maximizing tuning parameter
template_max (np.ndarray) – Similiarty-maximizing comb template
- libfmp.c3.c3s2_dtw.compute_accumulated_cost_matrix(C)[source]¶
Compute the accumulated cost matrix given the cost matrix
Notebook: C3/C3S2_DTWbasic.ipynb
- Parameters
C (np.ndarray) – Cost matrix
- Returns
D (np.ndarray) – Accumulated cost matrix
- libfmp.c3.c3s2_dtw.compute_accumulated_cost_matrix_21(C)[source]¶
Compute the accumulated cost matrix given the cost matrix
Notebook: C3/C3S2_DTWvariants.ipynb
- Parameters
C (np.ndarray) – Cost matrix
- Returns
D (np.ndarray) – Accumulated cost matrix
- libfmp.c3.c3s2_dtw.compute_cost_matrix(X, Y, metric='euclidean')[source]¶
Compute the cost matrix of two feature sequences
Notebook: C3/C3S2_DTWbasic.ipynb
- Parameters
X (np.ndarray) – Sequence 1
Y (np.ndarray) – Sequence 2
metric (str) – Cost metric, a valid strings for scipy.spatial.distance.cdist (Default value = ‘euclidean’)
- Returns
C (np.ndarray) – Cost matrix
- libfmp.c3.c3s2_dtw.compute_optimal_warping_path(D)[source]¶
Compute the warping path given an accumulated cost matrix
Notebook: C3/C3S2_DTWbasic.ipynb
- Parameters
D (np.ndarray) – Accumulated cost matrix
- Returns
P (np.ndarray) – Optimal warping path
- libfmp.c3.c3s2_dtw.compute_optimal_warping_path_21(D)[source]¶
Compute the warping path given an accumulated cost matrix
Notebook: C3/C3S2_DTWvariants.ipynb
- Parameters
D (np.ndarray) – Accumulated cost matrix
- Returns
P (np.ndarray) – Optimal warping path
- libfmp.c3.c3s2_dtw_plot.plot_matrix_with_points(C, P=np.empty((0, 2)), color='r', marker='o', linestyle='', **kwargs)[source]¶
Compute the cost matrix of two feature sequences
- Parameters
C – Matrix to be plotted
P – List of index pairs, to be visualized on the matrix (Default value = np.empty((0, 2)))
color – The color of the line plot (Default value = ‘r’). See https://matplotlib.org/users/colors.html
marker – The marker of the line plot (Default value = ‘o’). See https://matplotlib.org/3.1.0/api/markers_api.html
linestyle – The line-style of the line plot (Default value = ‘’). See https://matplotlib.org/gallery/lines_bars_and_markers/line_styles_reference.html
**kwargs – keyword arguments for
libfmp.b.b_plot.plot_matrix()
- Returns
fig – Handle for figure
im – Handle for imshow
line – handle for line plot
- libfmp.c3.c3s3_tempo_curve.compute_score_chromagram(score, Fs_beat)[source]¶
Compute chromagram from score representation
Notebook: C3/C3S3_MusicAppTempoCurve.ipynb
- Parameters
score (list) – Score representation
Fs_beat (scalar) – Sampling rate for beat axis
- Returns
X_score (np.ndarray) – Chromagram representation X_score
t_beat (np.ndarray) – Time axis t_beat (given in beats)
- libfmp.c3.c3s3_tempo_curve.compute_strict_alignment_path(P)[source]¶
Compute strict alignment path from a warping path
Notebook: C3/C3S3_MusicAppTempoCurve.ipynb
- Parameters
P (list or np.ndarray) – Warping path
- Returns
P_mod (list or np.ndarray) – Strict alignment path
- libfmp.c3.c3s3_tempo_curve.compute_strict_alignment_path_mask(P)[source]¶
Compute strict alignment path from a warping path
Notebook: C3/C3S3_MusicAppTempoCurve.ipynb
- Parameters
P (list or np.ndarray) – Wapring path
- Returns
P_mod (list or np.ndarray) – Strict alignment path
- libfmp.c3.c3s3_tempo_curve.compute_tempo_curve(score, x, Fs=22050, Fs_beat=10, N=4410, H=2205, shift=0, sigma=np.array([[1, 0], [0, 1], [2, 1], [1, 2], [1, 1]]), win_len_beat=4)[source]¶
Compute a tempo curve
Notebook: C3/C3S3_MusicAppTempoCurve.ipynb
- Parameters
score (list) – Score representation
x (np.ndarray) – Audio signal
Fs (scalar) – Samping rate of audio signal (Default value = 22050)
Fs_beat (scalar) – Sampling rate for beat axis (Default value = 10)
N (int) – Window size for computing audio chromagram (Default value = 4410)
H (int) – Hop size for computing audio chromagram (Default value = 2205)
shift (int) – Cyclic chroma shift applied to audio chromagram (Default value = 0)
sigma (np.ndarray) – Step size set used for DTW (Default value = np.array([[1, 0], [0, 1], [2, 1], [1, 2], [1, 1]]))
win_len_beat (float) – Window length (given in beats) used for smoothing tempo curve (Default value = 4)
- Returns
f_tempo (np.ndarray) – Tempo curve
t_beat (np.ndarray) – Time axis (given in beats)
- libfmp.c3.c3s3_tempo_curve.plot_measure(ax, measure_pos)[source]¶
Plot measure positions
Notebook: C3/C3S3_MusicAppTempoCurve.ipynb
- Parameters
ax (mpl.axes.Axes) – Figure axis
measure_pos (list or np.ndarray) – Array containing measure positions
- libfmp.c3.c3s3_tempo_curve.plot_tempo_curve(f_tempo, t_beat, ax=None, figsize=(8, 2), color='k', logscale=False, xlabel='Time (beats)', ylabel='Temp (BPM)', xlim=None, ylim=None, label='', measure_pos=[])[source]¶
Plot a tempo curve
Notebook: C3/C3S3_MusicAppTempoCurve.ipynb
- Parameters
f_tempo – Tempo curve
t_beat – Time axis of tempo curve (given as sampled beat axis)
ax – Plot either as figure (ax==None) or into axis (ax==True) (Default value = None)
figsize – Size of figure (Default value = (8, 2))
color – Color of tempo curve (Default value = ‘k’)
logscale – Use linear (logscale==False) or logartihmic (logscale==True) tempo axis (Default value = False)
xlabel – Label for x-axis (Default value = ‘Time (beats)’)
ylabel – Label for y-axis (Default value = ‘Temp (BPM)’)
xlim – Limits for x-axis (Default value = None)
ylim – Limits for x-axis (Default value = None)
label – Figure labels when plotting into axis (ax==True) (Default value = ‘’)
measure_pos – Plot measure positions as spefified (Default value = [])
- Returns
fig – figure handle
ax – axes handle