Piano-Roll (libsoni.core.pianoroll)

libsoni.core.pianoroll.sonify_pianoroll_additive_synthesis(pianoroll_df: DataFrame, partials: ndarray = array([1]), partials_amplitudes: ndarray | None = None, partials_phase_offsets: ndarray | None = None, tuning_frequency: float = 440.0, signal_fading_duration: float = 0.05, note_fading_duration: float = 0.01, sonification_duration: float | None = None, normalize: bool = True, fs: int = 22050) ndarray[source]

Sonifies a piano-roll with additive synthesis.

The DataFrame representation is assumed to contain row-wise pitch events described by start, duration or end and the corresponding pitch. The sonification is based on additive synthesis, where parameters partials, partials_amplitudes and partials_phase_offsets can be used to shape the sound.

Parameters:
  • pianoroll_df (pd.DataFrame) – Dataframe containing pitch-event information with columns [‘start’, ‘duration’, ‘pitch’, ‘velocity’, ‘label’].

  • partials (np.ndarray (np.float32 / np.float64) [shape=(N, )], default = [1]) – Array containing the desired partials of the fundamental frequencies for sonification. An array [1] leads to sonification with only the fundamental frequency, while an array [1,2] leads to sonification with the fundamental frequency and twice the fundamental frequency.

  • partials_amplitudes (np.ndarray (np.float32 / np.float64) [shape=(N, )], default = None) – Array containing the amplitudes for partials. An array [1,0.5] causes the first partial to have amplitude 1, while the second partial has amplitude 0.5. When not defined, the amplitudes for all partials are set to 1.

  • partials_phase_offsets (np.ndarray (np.float32 / np.float64) [shape=(N, )], default = None) – Array containing the phase offsets for partials. When not defined, the phase offsets for all partials are set to 0.

  • tuning_frequency (float, default = 440.0) – Tuning frequency, in Hertz.

  • sonification_duration (float, default = None) – Determines duration of sonification, in seconds.

  • signal_fading_duration (float, default = 0.05) – Determines duration of fade-in and fade-out at beginning and end of the final sonification, in seconds.

  • note_fading_duration (float, default = 0.01) – Determines duration of fade-in and fade-out at beginning and end of each note event, in seconds.

  • normalize (bool, default = True) – Determines if output signal is normalized to [-1,1].

  • fs (int, default = 22050) – Sampling rate, in samples per seconds.

Returns:

pianoroll_sonification (np.ndarray (np.float32 / np.float64) [shape=(M, )]) – Sonified piano-roll.

libsoni.core.pianoroll.sonify_pianoroll_clicks(pianoroll_df: DataFrame, tuning_frequency: float = 440.0, sonification_duration: float | None = None, signal_fading_duration: float = 0.05, normalize: bool = True, fs: int = 22050) ndarray[source]

Sonifies a piano-roll with clicks.

The DataFrame representation is assumed to contain row-wise pitch events described by start, duration or end and the corresponding pitch. For sonification, coloured clicks are used.

Parameters:
  • pianoroll_df (pd.DataFrame) – Dataframe containing pitch-event information with columns [‘start’, ‘duration’, ‘pitch’, ‘velocity’, ‘label’].

  • tuning_frequency (float, default = 440.0) – Tuning Frequency, in Hertz

  • sonification_duration (float, default = None) – Determines duration of sonification, in seconds.

  • signal_fading_duration (float, default = 0.05) – Determines duration of fade-in and fade-out at beginning and end of the final sonification, in seconds.

  • normalize (bool, default = True) – Determines if output signal is normalized to [-1,1].

  • fs (int, default = 22050) – Sampling rate, in samples per seconds.

Returns:

pianoroll_sonification (np.ndarray (np.float32 / np.float64) [shape=(M, )]) – Sonified waveform in form of a 1D Numpy array.

libsoni.core.pianoroll.sonify_pianoroll_fm_synthesis(pianoroll_df: DataFrame, mod_rate_relative: float = 0.0, mod_amp: float = 0.0, tuning_frequency: float = 440.0, sonification_duration: int | None = None, signal_fading_duration: float = 0.05, note_fading_duration: float = 0.01, normalize: bool = True, fs: int = 22050) ndarray[source]

Sonifies a piano-roll with frequency modulation (FM) synthesis.

The DataFrame representation is assumed to contain row-wise pitch events described by start, duration or end and the corresponding pitch. The sonification is based on FM synthesis, where parameters mod_rate_relative and mod_amp can be used to shape the sound.

Parameters:
  • pianoroll_df (pd.DataFrame) – Dataframe containing pitch-event information with columns [‘start’, ‘duration’, ‘pitch’, ‘velocity’, ‘label’].

  • mod_rate_relative (float, default = 0.0) – Determines the modulation frequency as multiple or fraction of the frequency for the given pitch.

  • mod_amp (float, default = 0.0) – Determines the amount of modulation in the generated signal.

  • tuning_frequency (float, default = 440.0) – Tuning frequency in Hertz.

  • sonification_duration (int, default = None) – Determines duration of sonification, in samples.

  • signal_fading_duration (float, default = 0.05) – Determines duration of fade-in and fade-out at beginning and end of the final sonification, in seconds.

  • note_fading_duration (float, default = 0.01) – Determines duration of fade-in and fade-out at beginning and end of each note event, in seconds.

  • normalize (bool, default = True) – Determines if output signal is normalized to [-1,1].

  • fs (int, default = 22050) – Sampling rate, in samples per seconds.

Returns:

pianoroll_sonification (np.ndarray (np.float32 / np.float64) [shape=(M, )]) – Sonified piano-roll.

libsoni.core.pianoroll.sonify_pianoroll_sample(pianoroll_df: DataFrame, sample: ndarray | None = None, reference_pitch: int = 69, sonification_duration: int | None = None, signal_fading_duration: float = 0.05, note_fading_duration: float = 0.01, normalize: bool = True, fs: int = 22050) ndarray[source]

Sonifies a piano-roll based on custom audio samples.

The DataFrame representation is assumed to contain row-wise pitch events described by start, duration or end and the corresponding pitch. For sonification, warped versions of the given sample are used.

Parameters:
  • pianoroll_df (pd.DataFrame) – Dataframe containing pitch-event information with columns [‘start’, ‘duration’, ‘pitch’, ‘velocity’, ‘label’].

  • sample (np.ndarray (np.float32 / np.float64) [shape=(K, )]) – Sample to use for sonification.

  • reference_pitch (int, default = 69) – Original pitch of the sample.

  • sonification_duration (int, default = None) – Determines duration of sonification, in samples.

  • signal_fading_duration (float, default = 0.05) – Determines duration of fade-in and fade-out at beginning and end of the final sonification, in seconds.

  • note_fading_duration (float, default = 0.01) – Determines duration of fade-in and fade-out at beginning and end of each note event, in seconds.

  • normalize (bool, default = True) – Determines if output signal is normalized to [-1,1].

  • fs (int, default = 22050) – Sampling rate, in samples per seconds.

Returns:

pianoroll_sonification (np.ndarray (np.float32 / np.float64) [shape=(M, )]) – Sonified piano-roll.