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:
sinusoidal (SinusoidalModel) – Sinusoidal analysis model. Default is an instance of
sample.sms.mm.ModalModel
regressor – Modal parameters regression model. Default is an instance of
sample.hinge.HingeRegression
regressor_k (str) – Attribute name for the estimated slope coefficient of
regressor
regressor_q (str) – Attribute name for the estimated intercept coefficient of
regressor
freq_reduce (callable) – Callable function for reducing the frequency track into a single frequency. Defaults to
numpy.mean()
max_n_modes (int) – Number of modes to use in resynthesis. If
None
(default), then synthesise all modes**kwargs – Additional parameters for sub-models. See
sample.sms.mm.ModalTracker
,sample.sms.mm.ModalModel
,sample.hinge.HingeRegression
, andsample.utils.learn.OptionalStorage
- 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:
- 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 themax_n_modes
parameterorder (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