2022-11-15 23:49:51 +00:00
|
|
|
/*
|
|
|
|
* Brickworks
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Orastron Srl unipersonale
|
|
|
|
*
|
|
|
|
* Brickworks is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3 of the License.
|
|
|
|
*
|
|
|
|
* Brickworks is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
*
|
|
|
|
* File author: Stefano D'Angelo
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* module_type {{{ dsp }}}
|
2022-11-19 01:25:38 +00:00
|
|
|
* version {{{ 0.2.0 }}}
|
2022-11-22 14:28:16 +00:00
|
|
|
* requires {{{ bw_config bw_common bw_one_pole bw_math }}}
|
2022-11-15 23:49:51 +00:00
|
|
|
* description {{{
|
|
|
|
* Pulse oscillator waveshaper with variable pulse width (actually, duty
|
|
|
|
* cycle) and PolyBLEP antialiasing.
|
|
|
|
* }}}
|
|
|
|
* changelog {{{
|
|
|
|
* <ul>
|
2022-11-19 01:25:38 +00:00
|
|
|
* <li>Version <strong>0.2.0</strong>:
|
|
|
|
* <ul>
|
|
|
|
* <li>Refactored API to avoid dynamic memory allocation.</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
2022-11-15 23:49:51 +00:00
|
|
|
* <li>Version <strong>0.1.0</strong>:
|
|
|
|
* <ul>
|
|
|
|
* <li>First release.</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </ul>
|
|
|
|
* }}}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BW_OSC_PULSE_H
|
|
|
|
#define _BW_OSC_PULSE_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*! api {{{
|
|
|
|
* #### bw_osc_pulse
|
|
|
|
* ```>>> */
|
2022-11-19 01:25:38 +00:00
|
|
|
typedef struct _bw_osc_pulse bw_osc_pulse;
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-11-19 01:25:38 +00:00
|
|
|
* Instance object.
|
2022-11-15 23:49:51 +00:00
|
|
|
* >>> */
|
|
|
|
|
|
|
|
/*! ...
|
2022-11-19 01:25:38 +00:00
|
|
|
* #### bw_osc_pulse_init()
|
2022-11-15 23:49:51 +00:00
|
|
|
* ```>>> */
|
2022-11-19 01:25:38 +00:00
|
|
|
void bw_osc_pulse_init(bw_osc_pulse *instance);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-11-19 01:25:38 +00:00
|
|
|
* Initializes the `instance` object.
|
2022-11-15 23:49:51 +00:00
|
|
|
* >>> */
|
|
|
|
|
|
|
|
/*! ...
|
|
|
|
* #### bw_osc_pulse_set_sample_rate()
|
|
|
|
* ```>>> */
|
2022-11-19 01:25:38 +00:00
|
|
|
void bw_osc_pulse_set_sample_rate(bw_osc_pulse *instance, float sample_rate);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Sets the `sample_rate` (Hz) value for the given `instance`.
|
|
|
|
* >>> */
|
|
|
|
|
|
|
|
/*! ...
|
|
|
|
* #### bw_osc_pulse_reset()
|
|
|
|
* ```>>> */
|
2022-11-19 01:25:38 +00:00
|
|
|
void bw_osc_pulse_reset(bw_osc_pulse *instance);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Resets the given `instance` to its initial state.
|
|
|
|
* >>> */
|
|
|
|
|
|
|
|
/*! ...
|
|
|
|
* #### bw_osc_pulse_process()
|
|
|
|
* ```>>> */
|
2022-11-19 01:25:38 +00:00
|
|
|
void bw_osc_pulse_process(bw_osc_pulse *instance, const float *x, const float *x_phase_inc, float* y, int n_samples);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Lets the given `instance` process `n_samples` samples from the input
|
|
|
|
* buffer `x` containing the normalized phase signal and fills the
|
|
|
|
* corresponding `n_samples` samples in the output buffer `y`.
|
|
|
|
*
|
|
|
|
* If antialiasing is on, `x_phase_inc` must contain phase increment values,
|
|
|
|
* otherwise it is ignored and can be `NULL`.
|
|
|
|
* >>> */
|
|
|
|
|
|
|
|
/*! ...
|
|
|
|
* #### bw_osc_pulse_set_antialiasing()
|
|
|
|
* ```>>> */
|
2022-11-19 01:25:38 +00:00
|
|
|
void bw_osc_pulse_set_antialiasing(bw_osc_pulse *instance, char value);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Sets whether the antialiasing is on (`value` non-`0`) or off (`0`) for the
|
|
|
|
* given `instance`.
|
|
|
|
*
|
|
|
|
* Default value: `0`.
|
|
|
|
* >>> */
|
|
|
|
|
|
|
|
/*! ...
|
|
|
|
* #### bw_osc_pulse_set_pulse_width()
|
|
|
|
* ```>>> */
|
2022-11-19 01:25:38 +00:00
|
|
|
void bw_osc_pulse_set_pulse_width(bw_osc_pulse *instance, float value);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Sets the pulse width (actually, the duty cycle) to `value` (range
|
|
|
|
* [`0.f`, `1.f`]) for the given `instance`.
|
|
|
|
*
|
|
|
|
* Default value: `0.5f`.
|
|
|
|
* }}} */
|
|
|
|
|
2022-11-19 01:25:38 +00:00
|
|
|
/* WARNING: the internal definition of this struct is not part of the public
|
|
|
|
* API. Its content may change at any time in future versions. Please, do not
|
|
|
|
* access its members directly. */
|
|
|
|
struct _bw_osc_pulse {
|
|
|
|
// Coefficients
|
|
|
|
float smooth_mA1;
|
|
|
|
|
|
|
|
// Parameters
|
|
|
|
char first_run;
|
|
|
|
char antialiasing;
|
|
|
|
float pulse_width;
|
|
|
|
|
|
|
|
// State
|
|
|
|
float pw_z1;
|
|
|
|
};
|
|
|
|
|
2022-11-15 23:49:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|