SynthBase Class

Synth Abstract Base Class

class spiegelib.synth.SynthBase(sample_rate=44100, buffer_size=512, midi_note=48, midi_velocity=127, note_length_secs=1.0, render_length_secs=2.0, overridden_params=None, clamp_params=True)
Parameters
  • sample_rate (int, optional) – sampling rate for rendering audio, defaults to 44100

  • buffer_size (int, optional) – buffer size for rendering audio, defaults to 512

  • midi_note (int, optional) – midi note number used for rendering, 0-127, defaults to 40

  • midi_velocity (int, optional) – midi velocity used for rendering. 0-127, defaults to 127

  • note_length_secs (float, optional) – length of midi note in seconds, defaults to 1.0

  • render_length_secs (float, optional) – length that audio is rendered for in total, defaults to 2.5

  • overridden_params (list, optional) – a list of tuples containing the parameter index to override and the value to lock that parameter to, defaults to []

  • clamp_params (bool, optional) – If true, parameter values will be forced to the acceptable range of values. Defaults to True.

Variables
  • rendered_patch (boolean) – indicates whether a patch has been rendered yet, defaults to False

  • parameters (dict) – parameter indices and names

  • patch (list) – current patch values

  • param_range (tuple) – Range of acceptable parameter values, defaults to (0.0, 1.0)

set_patch(parameters)

Set a new patch with updated parameter values with a list of flaots or a list of tuples referring to parameter indices and values.

Parameters

parameters (list) – A list of floats or tuples. If passing in a list of numbers, the length must be either the number of non-overridden parameters of the number of total parameters for this synth. Parameter values will then be mapped to corresponding parameter in order. If a list of tuples is provided, the tuples must have the shape (int, float) where the int is the parameter number and the float is the parameter value.

abstract load_patch()

Must be overridden. Load current patch into synth engine

abstract render_patch()

Must be overridden. Should render audio for the currently loaded patch

abstract get_audio()

This method must be overridden and should return an audio buffer rendered during the last call to render_patch.

Returns

An audio buffer of float audio samples with a value between -1 & 1

Return type

spiegelib.core.audio_buffer.AudioBuffer

abstract randomize_patch()

This method must be overridden and should have the effect of randomizing parameters of the synthesizer. Overridden methods should be uneffected by this randomization

get_random_example()

Returns audio from a new random patch

Returns

An audio buffer

Return type

np.array

get_parameters()

Returns parameters for the synth

Returns

A dictionary of parameters with the parameter index (int) as the key and the parameter name short description as the value

Return type

Dictionary

get_patch(skip_overridden=True)

Get current patch

Parameters

skip_overridden (bool, optional) – Indicates whether to remove overridden parameters from results, defaults to True

set_overridden_parameters(parameters)

Override parameters with specific values

Parameters

parameters – List of parameter tuples with parameter index and parameter value that will be patched and then the parameter frozen.

save_state(path)

Save parameters and current state to a JSON file. Includes whether or not a parameter has been overridden so this can be used to save synth configuration

Parameters

path (str) – Location to save JSON file to

load_state(path)

Load parameter state from JSON file. Will set a new patch and overridden parameters.

Parameters

path (str) – Location to load JSON file from

static load_synth_config(path)

Loads and extracts patch setting and overridden parameters from a saved synth JSON file

Parameters

path (str) – location to load JSON file from

Returns

patch list and overridden parameter list

Return type

list, list

static expand_sub_patch(patch, param_indices, overridden)

Convert an ordered list of parameter values into a list of tuples containing the parameter indices linked to the parameter values. Does so by comparing the overridden parameters to the full list of paramater indices and using the differences to label the patch values.

Parameters
  • patch (list) – An ordered list of parameter values

  • param_indices (list) – A full list of all parameter indices

  • overridden (list of tuples) – A list of tuples which contain the parameter indices and values of the overridden parameters

Returns

a list of tuples representing a full patch setting

Return type

list