# Music Representations (libfmp.c1)¶

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/C1/C1.html

libfmp.c1.c1s1_sheet_music.generate_chirp_exp_octave(freq_start=440, dur=8, Fs=44100, amp=1)[source]

Generate one octave of a chirp with exponential frequency increase

Notebook: C1/C1S1_ChromaShepard.ipynb

Parameters
• freq_start (float) – Start frequency of chirp (Default value = 440)

• dur (float) – Duration (in seconds) (Default value = 8)

• Fs (scalar) – Sampling rate (Default value = 44100)

• amp (float) – Amplitude of generated signal (Default value = 1)

Returns
• x (np.ndarray) – Chirp signal

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s1_sheet_music.generate_shepard_glissando(num_octaves=3, dur_octave=8, Fs=44100)[source]

Generate several ocatves of a Shepared glissando

Notebook: C1/C1S1_ChromaShepard.ipynb

Parameters
• num_octaves (int) – Number of octaves (Default value = 3)

• dur_octave (int) – Duration (in seconds) per octave (Default value = 8)

• Fs (scalar) – Sampling rate (Default value = 44100)

Returns
• x (np.ndarray) – Shepared glissando

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s1_sheet_music.generate_shepard_tone(freq=440, dur=0.5, Fs=44100, amp=1)[source]

Generate Shepard tone

Notebook: C1/C1S1_ChromaShepard.ipynb

Parameters
• freq (float) – Frequency of Shepard tone (Default value = 440)

• dur (float) – Duration (in seconds) (Default value = 0.5)

• Fs (scalar) – Sampling rate (Default value = 44100)

• amp (float) – Amplitude of generated signal (Default value = 1)

Returns
• x (np.ndarray) – Shepard tone

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s1_sheet_music.generate_sinusoid_pitches(pitches=, dur=0.5, Fs=4000, amp=1)[source]

Generation of sinusoids for a given list of MIDI pitches

Notebook: C1/C1S1_MusicalNotesPitches.ipynb

Parameters
• pitches (list) – List of MIDI pitches (Default value = )

• dur (float) – Duration (in seconds) of each sinusoid (Default value = 0.5)

• Fs (scalar) – Sampling rate (Default value = 4000)

• amp (float) – Amplitude of generated signal (Default value = 1)

Returns
• x (np.ndarray) – Signal

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s2_symbolic_rep.csv_to_list(csv)[source]

Convert a csv score file to a list of note events

Notebook: C1/C1S2_CSV.ipynb

Parameters

csv (str or pd.DataFrame) – Either a path to a csv file or a data frame

Returns

score (list) – A list of note events where each note is specified as `[start, duration, pitch, velocity, label]`

libfmp.c1.c1s2_symbolic_rep.list_to_csv(score, fn_out)[source]

Write a list of note events (comprising a start time, duration, pitch, velocity, and label for each note event) to a CSV file

Parameters
• score (list) – List of note events

• fn_out (str) – The path of the csv file to be created

libfmp.c1.c1s2_symbolic_rep.midi_to_list(midi)[source]

Convert a midi file to a list of note events

Notebook: C1/C1S2_MIDI.ipynb

Parameters

midi (str or pretty_midi.pretty_midi.PrettyMIDI) – Either a path to a midi file or PrettyMIDI object

Returns

score (list) – A list of note events where each note is specified as `[start, duration, pitch, velocity, label]`

libfmp.c1.c1s2_symbolic_rep.visualize_piano_roll(score, xlabel='Time (seconds)', ylabel='Pitch', colors='FMP_1', velocity_alpha=False, figsize=(12, 4), ax=None, dpi=72)[source]

Plot a pianoroll visualization

Notebook: C1/C1S2_CSV.ipynb

Parameters
• score – List of note events

• xlabel – Label for x axis (Default value = ‘Time (seconds)’)

• ylabel – Label for y axis (Default value = ‘Pitch’)

• colors – Several options: 1. string of FMP_COLORMAPS, 2. string of matplotlib colormap, 3. list or np.ndarray of matplotlib color specifications, 4. dict that assigns labels to colors (Default value = ‘FMP_1’)

• velocity_alpha – Use the velocity value for the alpha value of the corresponding rectangle (Default value = False)

• figsize – Width, height in inches (Default value = (12)

• ax – The Axes instance to plot on (Default value = None)

• dpi – Dots per inch (Default value = 72)

Returns
• fig – The created matplotlib figure or None if ax was given.

• ax – The used axes

libfmp.c1.c1s2_symbolic_rep.xml_to_list(xml)[source]

Convert a music xml file to a list of note events

Notebook: C1/C1S2_MusicXML.ipynb

Parameters

xml (str or music21.stream.Score) – Either a path to a music xml file or a music21.stream.Score

Returns

score (list) – A list of note events where each note is specified as `[start, duration, pitch, velocity, label]`

libfmp.c1.c1s3_audio_rep.compute_adsr(len_A=10, len_D=10, len_S=60, len_R=10, height_A=1.0, height_S=0.5)[source]

Notebook: C1/C1S3_Timbre.ipynb

Parameters
• len_A (int) – Length (samples) of A phase (Default value = 10)

• len_D (int) – Length (samples) of D phase (Default value = 10)

• len_S (int) – Length (samples) of S phase (Default value = 60)

• len_R (int) – Length (samples) of R phase (Default value = 10)

• height_A (float) – Height of A phase (Default value = 1.0)

• height_S (float) – Height of S phase (Default value = 0.5)

Returns

libfmp.c1.c1s3_audio_rep.compute_envelope(x, win_len_sec=0.01, Fs=4000)[source]

Computation of a signal’s envelopes

Notebook: C1/C1S3_Timbre.ipynb

Parameters
• x (np.ndarray) – Signal (waveform) to be analyzed

• win_len_sec (float) – Length (seconds) of the window (Default value = 0.01)

• Fs (scalar) – Sampling rate (Default value = 4000)

Returns
• env (np.ndarray) – Magnitude envelope

• env_upper (np.ndarray) – Upper envelope

• env_lower (np.ndarray) – Lower envelope

libfmp.c1.c1s3_audio_rep.compute_equal_loudness_contour(freq_min=30, freq_max=15000, num_points=100)[source]

Computation of the equal loudness contour

Notebook: C1/C1S3_Dynamics.ipynb

Parameters
• freq_min (float) – Lowest frequency to be evaluated (Default value = 30)

• freq_max (float) – Highest frequency to be evaluated (Default value = 15000)

• num_points (int) – Number of evaluation points (Default value = 100)

Returns
• equal_loudness_contour (np.ndarray) – Equal loudness contour (in dB)

• freq_range (np.ndarray) – Evaluated frequency points

libfmp.c1.c1s3_audio_rep.compute_plot_envelope(x, win_len_sec, Fs, figsize=(6, 3), title='')[source]

Computation and subsequent plotting of a signal’s envelope

Notebook: C1/C1S3_Timbre.ipynb

Parameters
• x (np.ndarray) – Signal (waveform) to be analyzed

• win_len_sec (float) – Length (seconds) of the window

• Fs (scalar) – Sampling rate

• figsize (tuple) – Size of the figure (Default value = (6, 3))

• title (str) – Title of the figure (Default value = ‘’)

Returns

fig (mpl.figure.Figure) – Generated figure

libfmp.c1.c1s3_audio_rep.compute_power_db(x, Fs, win_len_sec=0.1, power_ref=10 ** - 12)[source]

Computation of the signal power in dB

Notebook: C1/C1S3_Dynamics.ipynb

Parameters
• x (np.ndarray) – Signal (waveform) to be analyzed

• Fs (scalar) – Sampling rate

• win_len_sec (float) – Length (seconds) of the window (Default value = 0.1)

• power_ref (float) – Reference power level (0 dB) (Default value = 10**(-12))

Returns

power_db (np.ndarray) – Signal power in dB

libfmp.c1.c1s3_audio_rep.difference_cents(freq_1, freq_2)[source]

Difference between two frequency values specified in cents

Notebook: C1/C1S3_FrequencyPitch.ipynb

Parameters
• freq_1 (float) – First frequency

• freq_2 (float) – Second frequency

Returns

delta (float) – Difference in cents

libfmp.c1.c1s3_audio_rep.f_pitch(p)[source]

Compute center frequency for (single or array of) MIDI note numbers

Notebook: C1/C1S3_FrequencyPitch.ipynb

Parameters

p (float or np.ndarray) – MIDI note numbers

Returns

freq_center (float or np.ndarray) – Center frequency

libfmp.c1.c1s3_audio_rep.generate_chirp_exp(dur, freq_start, freq_end, Fs=22050)[source]

Generation chirp with exponential frequency increase

Notebook: C1/C1S3_Dynamics.ipynb

Parameters
• dur (float) – Length (seconds) of the signal

• freq_start (float) – Start frequency of the chirp

• freq_end (float) – End frequency of the chirp

• Fs (scalar) – Sampling rate (Default value = 22050)

Returns
• x (np.ndarray) – Generated chirp signal

• t (np.ndarray) – Time axis (in seconds)

• freq (np.ndarray) – Instant frequency (in Hz)

libfmp.c1.c1s3_audio_rep.generate_chirp_exp_equal_loudness(dur, freq_start, freq_end, Fs=22050)[source]

Generation chirp with exponential frequency increase and equal loudness

Notebook: C1/C1S3_Dynamics.ipynb

Parameters
• dur (float) – Length (seconds) of the signal

• freq_start (float) – Starting frequency of the chirp

• freq_end (float) – End frequency of the chirp

• Fs (scalar) – Sampling rate (Default value = 22050)

Returns
• x (np.ndarray) – Generated chirp signal

• t (np.ndarray) – Time axis (in seconds)

• freq (np.ndarray) – Instant frequency (in Hz)

• intensity (np.ndarray) – Instant intensity of the signal

libfmp.c1.c1s3_audio_rep.generate_sinusoid(dur=5, Fs=1000, amp=1, freq=1, phase=0)[source]

Generation of sinusoid

Notebook: C1/C1S3_FrequencyPitch.ipynb

Parameters
• dur (float) – Duration (in seconds) (Default value = 5)

• Fs (scalar) – Sampling rate (Default value = 1000)

• amp (float) – Amplitude of sinusoid (Default value = 1)

• freq (float) – Frequency of sinusoid (Default value = 1)

• phase (float) – Phase of sinusoid (Default value = 0)

Returns
• x (np.ndarray) – Signal

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s3_audio_rep.generate_sinusoid_tremolo(dur=5, Fs=1000, amp=0.5, freq=440, trem_amp=0.1, trem_rate=5)[source]

Generation of a sinusoid signal with tremolo

Notebook: C1/C1S3_Timbre.ipynb

Parameters
• dur (float) – Duration (in seconds) (Default value = 5)

• Fs (scalar) – Sampling rate (Default value = 1000)

• amp (float) – Amplitude of sinusoid (Default value = 0.5)

• freq (float) – Frequency (Hz) of sinusoid (Default value = 440)

• trem_amp (float) – Amplitude of the amplitude oscillation (Default value = 0.1)

• trem_rate (float) – Rate (Hz) of the amplitude oscillation (Default value = 5)

Returns
• x (np.ndarray) – Generated signal

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s3_audio_rep.generate_sinusoid_vibrato(dur=5, Fs=1000, amp=0.5, freq=440, vib_amp=1, vib_rate=5)[source]

Generation of a sinusoid signal with vibrato

Notebook: C1/C1S3_Timbre.ipynb

Parameters
• dur (float) – Duration (in seconds) (Default value = 5)

• Fs (scalar) – Sampling rate (Default value = 1000)

• amp (float) – Amplitude of sinusoid (Default value = 0.5)

• freq (float) – Frequency (Hz) of sinusoid (Default value = 440)

• vib_amp (float) – Amplitude (Hz) of the frequency oscillation (Default value = 1)

• vib_rate (float) – Rate (Hz) of the frequency oscillation (Default value = 5)

Returns
• x (np.ndarray) – Generated signal

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s3_audio_rep.generate_tone(p=60, weight_harmonic=np.ones([16, 1]), Fs=11025, dur=2)[source]

Generation of a tone with harmonics

Notebook: C1/C1S3_Timbre.ipynb

Parameters
• p (float) – MIDI pitch of the tone (Default value = 60)

• weight_harmonic (np.ndarray) – Weights for the different harmonics (Default value = np.ones([16, 1])

• Fs (scalar) – Sampling frequency (Default value = 11025)

• dur (float) – Duration (seconds) of the signal (Default value = 2)

Returns
• x (np.ndarray) – Generated signal

• t (np.ndarray) – Time axis (in seconds)

libfmp.c1.c1s3_audio_rep.plot_spectrogram(x, Fs=11025, N=4096, H=2048, figsize=(4, 2))[source]

Computation and subsequent plotting of the spectrogram of a signal

Notebook: C1/C1S3_Timbre.ipynb

Parameters
• x – Signal (waveform) to be analyzed

• Fs – Sampling rate (Default value = 11025)

• N – FFT length (Default value = 4096)

• H – Hopsize (Default value = 2048)

• figsize – Size of the figure (Default value = (4, 2))