sample.sample module

Module for using the entire SAMPLE method pipeline

class sample.sample.SAMPLE(sinusoidal: ~sample.sms.sm.SinusoidalModel = None, regressor: ~sample.hinge.HingeRegression = None, regressor_k: str = 'k_', regressor_q: str = 'q_', freq_reduce: ~typing.Callable[[~numpy.ndarray], float] = <function mean>, max_n_modes: ~typing.Optional[int] = None, **kwargs)

Bases: RegressorMixin, BaseEstimator

SAMPLE (Spectral Analysis for Modal Parameter Linear Estimate) model

Parameters:
param_matrix_

3-by-N matrix of modal parameters

Type:

array

property amps_: ndarray

Learned modal amplitudes

property decays_: ndarray

Learned modal decays

property energies_: ndarray

Learned modal energies

fit(x: ndarray, y=None, **kwargs)

Analyze audio data

Parameters:
  • x (array) – audio input

  • y (ignored) – exists for compatibility

  • kwargs – Any parameter, overrides initialization

Returns:

self

Return type:

SAMPLE

property freqs_: ndarray

Learned modal frequencies

mode_argsort_(order: str = 'energies', reverse: bool = True) List[int]

Get the indices for sorting modes

Parameters:
  • order (str) – Feature to use for ordering modes. Default is "energies", so that reducing active modes keeps the modes with most energy. Other options are "freqs", "amps" and "decays"

  • reverse (bool) – Whether the order should be reversed (decreasing). Defaults to True

Returns:

Array of indices for sorting

Return type:

array

predict(x: ndarray, n_modes: Optional[int] = None, order: str = 'energies', reverse: bool = True, **kwargs) ndarray

Resynthesize audio

Parameters:
  • x (array) – Time axis

  • n_modes (int) – Number of modes to synthesize. If None, then use the max_n_modes parameter

  • order (str) – Feature to use for ordering modes. Default is "energies", so that reducing active modes keeps the modes with most energy. Other options are "freqs", "amps" and "decays"

  • reverse (bool) – Whether the order should be reversed (decreasing). Defaults to True

  • **kwargs – Keyword arguments for additive_synth()

Returns:

Array of audio samples

Return type:

array

property regressor

Modal parameters regression model

sdt_params_(order: str = 'energies', reverse: bool = True) dict

SDT parameters as a JSON serializable dictionary

Parameters:
  • order (str) – Feature to use for ordering modes. Default is "energies", so that reducing active modes in SDT keeps the modes with most energy. Other options are "freqs", "amps" and "decays"

  • reverse (bool) – Whether the order should be reversed (decreasing). Defaults to True

Returns:

SDT parameters

Return type:

dict

set_params(**kwargs)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

property sinusoidal

Sinusoidal analysis model

sample.sample.additive_synth(x, freqs: Sequence[float], decays: Sequence[float], amps: Sequence[float], phases: Optional[Union[Sequence[float], str]] = None, analytic: bool = False, **kwargs) array

Additively synthesize audio

Parameters:
  • x (array) – Time axis

  • freqs (array) – Modal frequencies

  • decays (array) – Modal decays

  • amps (array) – Modal amplitudes

  • phases (array) – Starting phase for every mode, optional

  • analytic (bool) – If True, use a complex exponential as an oscillator

  • **kwargs – Keyword arguments for random phase generator

Returns:

Array of audio samples

Return type:

array

sample.sample.modal_energy(a: ndarray, d: ndarray, out: Optional[ndarray] = None) ndarray

Compute the integrals of the modal amplitude envelopes

Parameters:
  • a (array) – Amplitudes

  • d (array) – Decays

  • out (array) – Optional. Array to use for storing results

Returns:

Energies

Return type:

array