pumpp.sampler.Sampler

class pumpp.sampler.Sampler(n_samples, duration, *ops)[source]

Generate samples from a pumpp data dict.

Examples

>>> # Set up the parameters
>>> sr, n_fft, hop_length = 22050, 512, 2048
>>> # Instantiate some transformers
>>> p_stft = pumpp.feature.STFTMag('stft', sr=sr, n_fft=n_fft,
...                                hop_length=hop_length)
>>> p_beat = pumpp.task.BeatTransformer('beat', sr=sr,
...                                     hop_length=hop_length)
>>> # Apply the transformers to the data
>>> data = pumpp.transform('test.ogg', 'test.jams', p_stft, p_beat)
>>> # We'll sample 10 patches of duration = 32 frames
>>> stream = pumpp.Sampler(10, 32, p_stft, p_beat)
>>> # Apply the streamer to the data dict
>>> for example in stream(data):
...     process(data)

Attributes

n_samples (int or None) the number of samples to generate. If None, generate indefinitely.
duration (int > 0) the duration (in frames) of each sample
ops (one or more pumpp.feature.FeatureExtractor or pumpp.task.BaseTaskTransformer) The operators to include when sampling data.
__init__(n_samples, duration, *ops)[source]

Methods

__init__(n_samples, duration, *ops)
data_duration(data) Compute the valid data duration of a dict
sample(data, interval) Sample a patch from the data object