Very basic sampler with variable playback speed.
Version: 1.0.0
License:
Requires:
Included in Brickworks, which is:
Here you can download one or more example VST3 plugins for Windows, macOS and Linux. Source code of the audio engine(s) is included in the archive(s).
| Description | Link |
|---|---|
| Simple monophonic sampler | Download |

Module type: DSP
typedef struct bw_sampler_coeffs bw_sampler_coeffs;
Coefficients and related.
typedef struct bw_sampler_state bw_sampler_state;
Internal state and related.
typedef enum {
bw_sampler_phase_before,
bw_sampler_phase_playing,
bw_sampler_phase_done
} bw_sampler_phase;
Sampler playback phase:
bw_sampler_phase_before: playback has not yet started;bw_sampler_phase_playing: playback ongoing;bw_sampler_phase_done: playback finished.static inline void bw_sampler_init(
bw_sampler_coeffs * BW_RESTRICT coeffs);
Initializes input parameter values in coeffs.
static inline void bw_sampler_set_sample_rate(
bw_sampler_coeffs * BW_RESTRICT coeffs,
float sample_rate);
Sets the sample_rate (Hz) value in coeffs.
static inline void bw_sampler_reset_coeffs(
bw_sampler_coeffs * BW_RESTRICT coeffs);
Resets coefficients in coeffs to assume their target values.
static inline float bw_sampler_reset_state(
const bw_sampler_coeffs * BW_RESTRICT coeffs,
bw_sampler_state * BW_RESTRICT state,
const float * BW_RESTRICT sample,
size_t sample_length,
float pos_0);
Resets the given state to its initial values using the given coeffs, the audio sample and its corresponding sample_length, and the initial and the initial playback position pos_0.
Returns the corresponding initial output value.
sample_length must be strictly positive.
static inline void bw_sampler_reset_state_multi(
const bw_sampler_coeffs * BW_RESTRICT coeffs,
bw_sampler_state * BW_RESTRICT const * BW_RESTRICT state,
const float * BW_RESTRICT const * BW_RESTRICT sample,
const size_t * BW_RESTRICT sample_length,
const float * pos_0,
float * y_0,
size_t n_channels);
Resets each of the n_channels states to its initial values using the given coeffs, the n_channels audio samples and their corresponding sample_lengths, and the corresponding initial playback positions in the pos_0 array.
The corresponding initial output values are written into the y_0 array, if not BW_NULL.
All values in sample_length must be strictly positive.
static inline void bw_sampler_update_coeffs_ctrl(
bw_sampler_coeffs * BW_RESTRICT coeffs);
Triggers control-rate update of coefficients in coeffs.
static inline void bw_sampler_update_coeffs_audio(
bw_sampler_coeffs * BW_RESTRICT coeffs);
Triggers audio-rate update of coefficients in coeffs.
static inline float bw_sampler_process1(
const bw_sampler_coeffs * BW_RESTRICT coeffs,
bw_sampler_state * BW_RESTRICT state,
const float * BW_RESTRICT sample,
size_t sample_length);
Computes and returns the next output sample from the input audio sample of length sample_length using coeffs, while using and updating state (audio rate only).
sample_length must be strictly positive.
static inline void bw_sampler_process(
bw_sampler_coeffs * BW_RESTRICT coeffs,
bw_sampler_state * BW_RESTRICT state,
const float * BW_RESTRICT sample,
size_t sample_length,
float * BW_RESTRICT y,
size_t n_samples);
Computes and fills the first n_samples of the output buffer y from the input audio sample of length sample_length, while using and updating both coeffs and state (control and audio rate).
sample_length must be strictly positive.
static inline void bw_sampler_process_multi(
bw_sampler_coeffs * BW_RESTRICT coeffs,
bw_sampler_state * BW_RESTRICT const * BW_RESTRICT state,
const float * BW_RESTRICT const * BW_RESTRICT sample,
const size_t * BW_RESTRICT sample_length,
float * BW_RESTRICT const * BW_RESTRICT y,
size_t n_channels,
size_t n_samples);
Computes and fills the first n_samples of the n_channels output buffers y using the given n_channels input audio samples and their corresponding sample_lengths, while using and updating both the common coeffs and each of the n_channels states (control and audio rate).
All values in sample_length must be strictly positive.
static inline void bw_sampler_set_rate(
bw_sampler_coeffs * BW_RESTRICT coeffs,
float value);
Sets the playback rate value in coeffs.
value must be non-negative.
Default value: 1.f.
static inline bw_sampler_phase bw_sampler_get_phase(
const bw_sampler_state * BW_RESTRICT state);
Returns the current playback phase as stored in state.
static inline char bw_sampler_coeffs_is_valid(
const bw_sampler_coeffs * BW_RESTRICT coeffs);
Tries to determine whether coeffs is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.
coeffs must at least point to a readable memory block of size greater than or equal to that of bw_sampler_coeffs.
static inline char bw_sampler_state_is_valid(
const bw_sampler_coeffs * BW_RESTRICT coeffs,
const bw_sampler_state * BW_RESTRICT state);
Tries to determine whether state is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.
If coeffs is not BW_NULL extra cross-checks might be performed (state is supposed to be associated to coeffs).
state must at least point to a readable memory block of size greater than or equal to that of bw_sampler_state.
template<size_t N_CHANNELS = 1>
class Sampler {
public:
Sampler();
void setSampleRate(
float sampleRate);
void reset(
const float * BW_RESTRICT const * BW_RESTRICT sample,
const size_t * BW_RESTRICT sampleLength,
float pos0 = 0.f,
float * BW_RESTRICT y0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
std::array<const float * BW_RESTRICT, N_CHANNELS> sample,
std::array<size_t, N_CHANNELS> sampleLength,
float pos0 = 0.f,
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = BW_NULL);
# endif
void reset(
const float * BW_RESTRICT const * BW_RESTRICT sample,
const size_t * BW_RESTRICT sampleLength,
const float * pos0,
float * y0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
std::array<const float * BW_RESTRICT, N_CHANNELS> sample,
std::array<size_t, N_CHANNELS> sampleLength,
std::array<float, N_CHANNELS> pos0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = BW_NULL);
# endif
void process(
const float * BW_RESTRICT const * BW_RESTRICT sample,
const size_t * BW_RESTRICT sampleLength,
float * const * y,
size_t nSamples);
# ifndef BW_CXX_NO_ARRAY
void process(
std::array<const float * BW_RESTRICT, N_CHANNELS> sample,
std::array<size_t, N_CHANNELS> sampleLength,
std::array<float *, N_CHANNELS> y,
size_t nSamples);
# endif
void setRate(
float value);
bw_sampler_phase getPhase(
size_t channel);
...
}