bwpp_{phase_gen,osc_saw,osc_pulse,osc_tri}

This commit is contained in:
Stefano D'Angelo 2023-06-27 18:01:25 +02:00
parent 7a0c76652f
commit fccb7712a9
5 changed files with 322 additions and 0 deletions

1
TODO
View File

@ -60,6 +60,7 @@ code:
* src(_int) process_multi?
* fix definitions leading to X ** -> const X ** error https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion, fix fx_balance, fx_pan, synth_poly
* drywet -> dry_wet, ringmod -> ring_mod, etc?
* allow nullptr in C++ wrappers where process_multi arg can be NULL
build system:
* make makefiles handle paths with spaces etc

83
include/bwpp_osc_pulse.h Normal file
View File

@ -0,0 +1,83 @@
/*
* Brickworks
*
* Copyright (C) 2023 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
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_OSC_PULSE_H
#define BWPP_OSC_PULSE_H
#include <bw_osc_pulse.h>
#include <array>
namespace Brickworks {
template<BW_SIZE_T N_CHANNELS>
class OscPulse {
public:
OscPulse();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> x_phase_inc,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setAntialiasing(bool value);
void setPulseWidth(float value);
private:
bw_osc_pulse_coeffs coeffs;
};
template<BW_SIZE_T N_CHANNELS>
OscPulse<N_CHANNELS>::OscPulse() {
bw_osc_pulse_init(&coeffs);
}
template<BW_SIZE_T N_CHANNELS>
void OscPulse<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_osc_pulse_set_sample_rate(&coeffs, sampleRate);
}
template<BW_SIZE_T N_CHANNELS>
void OscPulse<N_CHANNELS>::reset() {
bw_osc_pulse_reset_coeffs(&coeffs);
}
template<BW_SIZE_T N_CHANNELS>
void OscPulse<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> x_phase_inc,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_osc_pulse_process_multi(&coeffs, x.data(), x_phase_inc.data(), y.data(), N_CHANNELS, nSamples);
}
template<BW_SIZE_T N_CHANNELS>
void OscPulse<N_CHANNELS>::setAntialiasing(bool value) {
bw_osc_pulse_set_antialiasing(&coeffs, value);
}
template<BW_SIZE_T N_CHANNELS>
void OscPulse<N_CHANNELS>::setPulseWidth(bool value) {
bw_osc_pulse_set_pulse_width(&coeffs, value);
}
}
#endif

66
include/bwpp_osc_saw.h Normal file
View File

@ -0,0 +1,66 @@
/*
* Brickworks
*
* Copyright (C) 2023 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
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_OSC_SAW_H
#define BWPP_OSC_SAW_H
#include <bw_osc_saw.h>
#include <array>
namespace Brickworks {
template<BW_SIZE_T N_CHANNELS>
class OscSaw {
public:
OscSaw();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> x_phase_inc,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setAntialiasing(bool value);
private:
bw_osc_saw_coeffs coeffs;
};
template<BW_SIZE_T N_CHANNELS>
OscSaw<N_CHANNELS>::OscSaw() {
bw_osc_saw_init(&coeffs);
}
template<BW_SIZE_T N_CHANNELS>
void OscSaw<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> x_phase_inc,
std::array<float *, N_CHANNELS> y,
int nSamples) {
for (BW_SIZE_T i = 0; i < N_CHANNELS; i++)
bw_osc_saw_process(&coeffs, x.data()[i], x_phase_inc.data()[i], y.data()[i], nSamples);
}
template<BW_SIZE_T N_CHANNELS>
void OscSaw<N_CHANNELS>::setAntialiasing(bool value) {
bw_osc_saw_set_antialiasing(&coeffs, value);
}
}
#endif

83
include/bwpp_osc_tri.h Normal file
View File

@ -0,0 +1,83 @@
/*
* Brickworks
*
* Copyright (C) 2023 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
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_OSC_TRI_H
#define BWPP_OSC_TRI_H
#include <bw_osc_tri.h>
#include <array>
namespace Brickworks {
template<BW_SIZE_T N_CHANNELS>
class OscTri {
public:
OscTri();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> x_phase_inc,
std::array<float *, N_CHANNELS> y,
int nSamples);
void setAntialiasing(bool value);
void setSlope(float value);
private:
bw_osc_tri_coeffs coeffs;
};
template<BW_SIZE_T N_CHANNELS>
OscTri<N_CHANNELS>::OscTri() {
bw_osc_tri_init(&coeffs);
}
template<BW_SIZE_T N_CHANNELS>
void OscTri<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_osc_tri_set_sample_rate(&coeffs, sampleRate);
}
template<BW_SIZE_T N_CHANNELS>
void OscTri<N_CHANNELS>::reset() {
bw_osc_tri_reset_coeffs(&coeffs);
}
template<BW_SIZE_T N_CHANNELS>
void OscTri<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> x_phase_inc,
std::array<float *, N_CHANNELS> y,
int nSamples) {
bw_osc_tri_process_multi(&coeffs, x.data(), x_phase_inc.data(), y.data(), N_CHANNELS, nSamples);
}
template<BW_SIZE_T N_CHANNELS>
void OscTri<N_CHANNELS>::setAntialiasing(bool value) {
bw_osc_tri_set_antialiasing(&coeffs, value);
}
template<BW_SIZE_T N_CHANNELS>
void OscTri<N_CHANNELS>::setSlope(bool value) {
bw_osc_tri_set_slope(&coeffs, value);
}
}
#endif

89
include/bwpp_phase_gen.h Normal file
View File

@ -0,0 +1,89 @@
/*
* Brickworks
*
* Copyright (C) 2023 Orastron Srl unipersonale
*
* Brickworks is free software: you can rephase_genribute 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 phase_genributed 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
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo
*/
#ifndef BWPP_PHASE_GEN_H
#define BWPP_PHASE_GEN_H
#include <bw_phase_gen.h>
#include <array>
namespace Brickworks {
template<BW_SIZE_T N_CHANNELS>
class PhaseGen {
public:
PhaseGen();
void setSampleRate(float sampleRate);
void reset();
void process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<float *, N_CHANNELS> y,
std::array<float *, N_CHANNELS> y_phase_inc,
int nSamples);
void setFrequency(float value);
void setPortamentoTau(float value);
private:
bw_phase_gen_coeffs coeffs;
bw_phase_gen_state states[N_CHANNELS];
bw_phase_gen_state *statesP[N_CHANNELS];
};
template<BW_SIZE_T N_CHANNELS>
PhaseGen<N_CHANNELS>::PhaseGen() {
bw_phase_gen_init(&coeffs);
for (BW_SIZE_T i = 0; i < N_CHANNELS; i++)
statesP[i] = states + i;
}
template<BW_SIZE_T N_CHANNELS>
void PhaseGen<N_CHANNELS>::setSampleRate(float sampleRate) {
bw_phase_gen_set_sample_rate(&coeffs, sampleRate);
}
template<BW_SIZE_T N_CHANNELS>
void PhaseGen<N_CHANNELS>::reset() {
bw_phase_gen_reset_coeffs(&coeffs);
for (BW_SIZE_T i = 0; i < N_CHANNELS; i++)
bw_phase_gen_reset_state(&coeffs, states + i);
}
template<BW_SIZE_T N_CHANNELS>
void PhaseGen<N_CHANNELS>::process(
std::array<const float *, N_CHANNELS> x_mod,
std::array<float *, N_CHANNELS> y,
std::array<float *, N_CHANNELS> y_phase_inc,
int nSamples) {
bw_phase_gen_process_multi(&coeffs, statesP, x_mod.data(), y.data(), y_phase_inc.data(), N_CHANNELS, nSamples);
}
template<BW_SIZE_T N_CHANNELS>
void PhaseGen<N_CHANNELS>::setFrequency(float value) {
bw_phase_gen_set_frequency(&coeffs, value);
}
template<BW_SIZE_T N_CHANNELS>
void PhaseGen<N_CHANNELS>::setPortamentoTau(float value) {
bw_phase_gen_set_portamento_tau(&coeffs, value);
}
}
#endif