brickworks/examples/fxpp_ring_mod/src/impl.cpp

86 lines
2.2 KiB
C++

/*
* Brickworks
*
* Copyright (C) 2022-2024 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
*/
#include "impl.h"
#include "common.h"
#include <bw_ring_mod.h>
#include <bw_phase_gen.h>
#include <bw_osc_sin.h>
using namespace Brickworks;
class Engine {
public:
PhaseGen<1> phase_gen;
RingMod<1> ring_mod;
};
extern "C" {
impl impl_new(void) {
Engine *instance = new Engine();
return reinterpret_cast<impl>(instance);
}
void impl_free(impl handle) {
Engine *instance = reinterpret_cast<Engine *>(handle);
delete instance;
}
void impl_set_sample_rate(impl handle, float sample_rate) {
Engine *instance = reinterpret_cast<Engine *>(handle);
instance->phase_gen.setSampleRate(sample_rate);
instance->ring_mod.setSampleRate(sample_rate);
}
void impl_reset(impl handle) {
Engine *instance = reinterpret_cast<Engine *>(handle);
instance->phase_gen.reset();
instance->ring_mod.reset();
}
void impl_set_parameter(impl handle, size_t index, float value) {
Engine *instance = reinterpret_cast<Engine *>(handle);
switch (index) {
case plugin_parameter_frequency:
instance->phase_gen.setFrequency(value);
break;
case plugin_parameter_amount:
instance->ring_mod.setAmount(0.01f * value);
break;
}
}
float impl_get_parameter(impl handle, size_t index) {
(void)handle;
(void)index;
return 0.f;
}
void impl_process(impl handle, const float **inputs, float **outputs, size_t n_samples) {
Engine *instance = reinterpret_cast<Engine *>(handle);
instance->phase_gen.process(nullptr, outputs, nullptr, n_samples);
oscSinProcess<1>(outputs, outputs, n_samples);
instance->ring_mod.process(inputs, outputs, outputs, n_samples);
}
}