sample.sms.sm module¶
Sinusoidal model
- class sample.sms.sm.SineTracker(fs: int = 44100, h: int = 500, max_n_sines: int = 100, min_sine_dur: int = 0.04, freq_dev_offset: float = 20, freq_dev_slope: float = 0.01, **kwargs)¶
Bases:
BaseEstimator
Model for keeping track of sines across frames
- Parameters:
fs (int) – Sampling frequency
h (int) – Hop size (in samples)
max_n_sines (int) – Maximum number of tracks per frame
min_sine_dur (float) – Minimum duration of a track in seconds
freq_dev_offset (float) – Frequency deviation threshold at 0Hz
freq_dev_slope (float) – Slope of frequency deviation threshold
**kwargs – Additional parameters for sub-models
- tracks_¶
Deactivated tracks
- Type:
list of dict
- property all_tracks_: Iterable[dict]¶
All deactivated tracks in
tracks_
and those active tracks that would pass the cleanliness check at the current state of the tracker
- deactivate(track_index: int) dict ¶
Remove track from list of active tracks and save it in
tracks_
if it meets cleanliness criteria- Parameters:
track_index (int) – Index of track to deactivate
- Returns:
Deactivated track
- Return type:
dict
- df(f: float) float ¶
Frequency deviation threshold at given frequency
- Parameters:
f (float) – Frequency in Hz
- Returns:
Frequency deviation threshold in Hz
- Return type:
float
- property frame_rate: float¶
Number of DFT frames per seconds
- property min_sine_len: int¶
Minimum duration of a track in number of frames
- property n_active_tracks: int¶
Number of currently active tracks
- static numpy_track(track: dict) dict ¶
Convert to numpy arrays all values in a track
- Parameters:
track (dict) – Track to convert
- Returns:
Converted track
- Return type:
dict
- reset()¶
Reset tracker state
- Returns:
self
- Return type:
- track_ok(track: dict) bool ¶
Check if a deactivated track is ok to be saved
- Parameters:
track (dict) – Track to check
- Returns:
Whether the track is ok or not
- Return type:
bool
- class sample.sms.sm.SinusoidalModel(w: ndarray = None, n: int = 2048, t: float = -90, tracker: SineTracker = None, intermediate: OptionalStorage = None, padded: bool = False, **kwargs)¶
Bases:
TransformerMixin
,BaseEstimator
Model for sinusoidal tracking
- Parameters:
w – Analysis window
n (int) – FFT size. Defaults to 2048
t (float) – threshold in dB. Defaults to -90
tracker (SineTracker) – Sine tracker
intermediate (OptionalStorage) – Optionally-activatable storage
padded (bool) – Analyse a zero-padded version of the input
**kwargs – Additional parameters for sub-models. See
sample.sms.sm.SineTracker
andsample.utils.learn.OptionalStorage
- w_¶
Effective analysis window
- Type:
array
- dft_frames(x: ndarray) Iterable[Tuple[ndarray, ndarray]] ¶
Iterable of DFT frames for a given input
- Parameters:
x (array) – Input
- Returns:
Iterable of overlapping DFT frames (magnitude and phase) of the padded input
- Return type:
iterable
- fit(x: ndarray, y=None, **kwargs)¶
Analyze audio data
- Parameters:
x (array) – audio input
y (ignored) – exists for compatibility
kwargs – Any parameter, overrides initialization. Mainly meant for setting the sampling frequency (
tracker__fs
)
- Returns:
self
- Return type:
- property frame_rate: float¶
Number of DFT frames per seconds
- property fs¶
Sampling frequency
- property h¶
Hop size (in samples)
- property intermediate¶
Optionally-activatable storage
- pad_input(x: ndarray) Tuple[ndarray, int] ¶
Pad input at the beginning (so that the first window is centered at the first sample) and at the end (to analyze all samples)
- Parameters:
x (array) – The input array
- Returns:
The padded array and the initial padding length
- Return type:
(array, int)
- 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
- time_frames(x: ndarray) ndarray ¶
Generator of frames for a given input
- Parameters:
x (array) – Input
- Returns:
Generator of overlapping frames of the padded input
- Return type:
generator
- property tracker¶
Sine tracker
- property tracks_: List[Dict[str, ndarray]]¶
Tracked sinusoids
- property w¶
Analysis window
- sample.sms.sm.min_key(it: Iterable, key: Callable) Tuple[Any, Any] ¶
Minimum value and corresponding argument
- Parameters:
it (iterable) – Iterable of function arguments
key (callable) – Function
- Returns:
Argmin and min of
key(i) for i in it