Nikolay-Lysenko/sinethesizer

View on GitHub
docs/examples/instruments.yml

Summary

Maintainability
Test Coverage
# This file illustrates how to create `sinethesizer` instruments.
---

# This is a minimal example. It is a pure sine wave.
- name: sine
  partials:
    - wave:
        waveform: sine
        amplitude_envelope_fn:
          name: trapezoid
      frequency_ratio: 1.0
      amplitude_ratio: 1.0
  amplitude_scaling: 1.0

# It is a less artificial sine wave.
- name: quasiperiodic_sine
  partials:
    - wave:
        waveform: sine
        amplitude_envelope_fn:
          name: trapezoid
        quasiperiodic_bandwidth: 0.5
        quasiperiodic_breakpoints_frequency: 10
      frequency_ratio: 1.0
      amplitude_ratio: 1.0
      random_detuning_range: 0.005
  amplitude_scaling: 1.0

# This is an example of additive synthesis (overtones are added explicitly).
- name: sine_with_three_partials
  partials:
    - wave:
        waveform: sine
        amplitude_envelope_fn:
          name: trapezoid
      frequency_ratio: 1.0
      amplitude_ratio: 1.0
      event_to_amplitude_factor_fn:
        name: power_fn_of_velocity
        power: 1.0
      random_detuning_range: 0.005
    - wave:
        waveform: sine
        amplitude_envelope_fn:
          name: trapezoid
      frequency_ratio: 2.0
      amplitude_ratio: 0.5
      event_to_amplitude_factor_fn:
        name: power_fn_of_velocity
        power: 1.1  # The lower velocity is, the lower ratio of this partial amplitude to amplitude of fundamental is.
      random_detuning_range: 0.005
    - wave:
        waveform: sine
        amplitude_envelope_fn:
          name: trapezoid
      frequency_ratio: 3.0
      amplitude_ratio: 0.25
      event_to_amplitude_factor_fn:
        name: power_fn_of_velocity
        power: 1.15  # This partial depends on velocity even stronger than the previous one.
      random_detuning_range: 0.005
  amplitude_scaling: 0.5714  # Inverse of sum of `amplitude_ratio` over all partials.
  effects:
    # Make sound more natural by imitating frequency response of resonating body.
    - name: equalizer
      breakpoint_frequencies:
        - 3000
        - 8000
        - 20000
      gains:
        - 1.0
        - 0.5
        - 0.0

# This is an example of subtractive synthesis (some frequencies are filtered out).
- name: filtered_sawtooth
  partials:
    - wave:
        waveform: sawtooth
        amplitude_envelope_fn:
          name: trapezoid
      frequency_ratio: 1.0
      amplitude_ratio: 1.0
      random_detuning_range: 0.005
      effects:
        - name: filter
          kind: relative
          min_frequency_ratio: 3.5
          max_frequency_ratio: 7.5
          invert: true
          order: 10
  amplitude_scaling: 1.0

# This is an example of more advanced subtractive synthesis (there is an envelope for filter).
- name: another_filtered_sawtooth
  partials:
    - wave:
        waveform: sawtooth
        amplitude_envelope_fn:
          name: trapezoid
      frequency_ratio: 1.0
      amplitude_ratio: 1.0
      random_detuning_range: 0.005
      effects:
        - name: automation
          automated_effect_name: equalizer
          break_points:
            # Initially, gain starts to decay linearly at 1000 Hz and becomes zero at 10000 Hz.
            - relative_position: 0.0
              breakpoint_frequencies:
                - 1000
                - 10000
              gains:
                - 1.0
                - 0.0
            # In the middle, gain starts to decay linearly at 5000 Hz and becomes zero at 15000 Hz.
            - relative_position: 0.5
              breakpoint_frequencies:
                - 5000
                - 15000
              gains:
                - 1.0
                - 0.0
            # Finally, gain is distributed like at the beginning.
            - relative_position: 1.0
              breakpoint_frequencies:
                - 1000
                - 10000
              gains:
                - 1.0
                - 0.0
  amplitude_scaling: 1.0

# This is an example of FM synthesis (although, to be rigorous, it is PM synthesis).
- name: fm_sine
  partials:
    - wave:
        waveform: sine
        amplitude_envelope_fn:
          name: trapezoid
        phase_modulator:
          waveform: sine
          frequency_ratio_numerator: 3
          frequency_ratio_denominator: 1
          modulation_index_envelope_fn:
            name: generic_ahdsr
            attack_to_ahds_max_ratio: 0.1
            max_attack_duration: 0.05
            attack_degree: 2.0
            hold_to_hds_max_ratio: 0
            max_hold_duration: 0
            decay_to_ds_max_ratio: 1.0
            max_decay_duration: 100
            decay_degree: 0.5
            sustain_level: 0.05
            max_sustain_duration: 0
            max_release_duration: 0.05
            release_duration_on_velocity_order: 0
            release_degree: 1.5
            peak_value: 5.0
            ratio_at_zero_velocity: 0.5
            envelope_values_on_velocity_order: 0.5
      frequency_ratio: 1.0
      amplitude_ratio: 1.0
      random_detuning_range: 0.005
  amplitude_scaling: 1.0
  effects:
    # Make sound more natural by imitating frequency response of resonating body.
    - name: equalizer
      breakpoint_frequencies:
        - 3000
        - 8000
        - 20000
      gains:
        - 1.0
        - 0.5
        - 0.0

# This is an example of non-AHDSR amplitude envelope.
- name: sine_with_user_defined_envelope
  partials:
    - wave:
        waveform: sine
        amplitude_envelope_fn:
          name: user_defined
          parts:
            - values:
                - 0.0
                - 0.1
                - 0.3
                - 1.0
                - 0.5
                - 0.9
                - 0.7
                - 0.5
                - 0.3
                - 0.1
              max_duration: 0.2
            - values:
                - 0.1
                - 0.2
                - 0.5
                - 0.7
                - 1.0
                - 1.0
                - 0.8
                - 0.6
                - 0.4
                - 0.2
                - 0.0
              max_duration: null
      frequency_ratio: 1.0
      amplitude_ratio: 1.0
  amplitude_scaling: 1.0