Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
18c7d41d87 | ||
![]() |
10b7c3834a | ||
![]() |
422cdcdb8d | ||
![]() |
2ceca5cc0c | ||
e319de1a1f | |||
11f49b4276 | |||
f960114cfb | |||
5f494781ac | |||
97790bc330 | |||
5c185738c2 | |||
c91dbd5c95 | |||
d008662ffb | |||
b5cdf2ad19 |
@ -65,13 +65,12 @@ ifeq ($(TEMPLATE), android)
|
||||
SDK_DIR := $(HOME)/Android/Sdk
|
||||
ANDROIDX_DIR := $(HOME)/Android/androidx
|
||||
KOTLIN_DIR := $(HOME)/Android/kotlin
|
||||
NDK_VERSION := 28.0.12674087
|
||||
BUILD_TOOLS_VERSION := 35.0.0
|
||||
ANDROID_VERSION := 35
|
||||
ANDROIDX_CORE_VERSION := 1.15.0
|
||||
NDK_VERSION := 28.0.13004108
|
||||
BUILD_TOOLS_VERSION := 36.0.0
|
||||
ANDROIDX_CORE_VERSION := 1.16.0
|
||||
ANDROIDX_LIFECYCLE_COMMON_VERSION := 2.8.7
|
||||
ANDROIDX_VERSIONEDPARCELABLE_VERSION := 1.2.1
|
||||
KOTLIN_STDLIB_VERSION := 2.1.10
|
||||
KOTLINX_COROUTINES_CORE_VERSION := 1.10.1
|
||||
KOTLINX_COROUTINES_CORE_JVM_VERSION := 1.10.1
|
||||
KOTLIN_STDLIB_VERSION := 2.1.20
|
||||
KOTLINX_COROUTINES_CORE_VERSION := 1.10.2
|
||||
KOTLINX_COROUTINES_CORE_JVM_VERSION := 1.10.2
|
||||
endif
|
||||
|
5
examples/synth_sampler/src/android.json
Normal file
5
examples/synth_sampler/src/android.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"android": {
|
||||
"javaPackageName": "com.orastron.bw_example_synth_sampler"
|
||||
}
|
||||
}
|
6
examples/synth_sampler/src/daisy-seed.json
Normal file
6
examples/synth_sampler/src/daisy-seed.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"daisy_seed": {
|
||||
"parameterPins": [ -1, -1, 22 ],
|
||||
"midiCCMaps": [ 7, 3, -1 ]
|
||||
}
|
||||
}
|
5
examples/synth_sampler/src/ios.json
Normal file
5
examples/synth_sampler/src/ios.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ios": {
|
||||
"productBundleIdentifier": "com.orastron.bw_example_synth_sampler"
|
||||
}
|
||||
}
|
10
examples/synth_sampler/src/lv2.json
Normal file
10
examples/synth_sampler/src/lv2.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"lv2": {
|
||||
"prefixes": {
|
||||
"bw_examples": "https://www.orastron.com/brickworks/examples/"
|
||||
},
|
||||
"uri": "@bw_examples:synth_sampler",
|
||||
"types": [ "@lv2:InstrumentPlugin" ],
|
||||
"version": "0.0"
|
||||
}
|
||||
}
|
136
examples/synth_sampler/src/plugin.h
Normal file
136
examples/synth_sampler/src/plugin.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2025 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 "common.h"
|
||||
#include <bw_math.h>
|
||||
#include <bw_sampler.h>
|
||||
#include <bw_gain.h>
|
||||
#include <bw_ppm.h>
|
||||
#include <bw_buf.h>
|
||||
|
||||
#define SAMPLE_LENGTH 10 // seconds
|
||||
|
||||
typedef struct plugin {
|
||||
bw_sampler_coeffs sampler_coeffs;
|
||||
bw_sampler_state sampler_state;
|
||||
bw_gain_coeffs gain_coeffs;
|
||||
bw_ppm_coeffs ppm_coeffs;
|
||||
bw_ppm_state ppm_state;
|
||||
|
||||
float fs;
|
||||
float * sample;
|
||||
size_t sample_length;
|
||||
|
||||
float master_tune;
|
||||
int note;
|
||||
} plugin;
|
||||
|
||||
static void plugin_init(plugin *instance, plugin_callbacks *cbs) {
|
||||
(void)cbs;
|
||||
bw_sampler_init(&instance->sampler_coeffs);
|
||||
bw_gain_init(&instance->gain_coeffs);
|
||||
bw_ppm_init(&instance->ppm_coeffs);
|
||||
}
|
||||
|
||||
static void plugin_fini(plugin *instance) {
|
||||
(void)instance;
|
||||
}
|
||||
|
||||
static void plugin_set_sample_rate(plugin *instance, float sample_rate) {
|
||||
bw_sampler_set_sample_rate(&instance->sampler_coeffs, sample_rate);
|
||||
bw_gain_set_sample_rate(&instance->gain_coeffs, sample_rate);
|
||||
bw_ppm_set_sample_rate(&instance->ppm_coeffs, sample_rate);
|
||||
|
||||
instance->fs = sample_rate;
|
||||
instance->sample_length = (size_t)bw_ceilf(sample_rate * SAMPLE_LENGTH);
|
||||
}
|
||||
|
||||
static size_t plugin_mem_req(plugin *instance) {
|
||||
return instance->sample_length * sizeof(float);
|
||||
}
|
||||
|
||||
static void plugin_mem_set(plugin *instance, void *mem) {
|
||||
instance->sample = (float *)mem;
|
||||
}
|
||||
|
||||
static void plugin_reset(plugin *instance) {
|
||||
float p = 0.f;
|
||||
float inc = 440.f / instance->fs;
|
||||
for (size_t i = 0; i < instance->sample_length; i++) {
|
||||
p += inc;
|
||||
p = p - bw_floorf(p);
|
||||
instance->sample[i] = bw_sin2pif(p);
|
||||
}
|
||||
bw_sampler_reset_coeffs(&instance->sampler_coeffs);
|
||||
bw_sampler_reset_state(&instance->sampler_coeffs, &instance->sampler_state, instance->sample, instance->sample_length, 0.f);
|
||||
bw_gain_reset_coeffs(&instance->gain_coeffs);
|
||||
bw_ppm_reset_coeffs(&instance->ppm_coeffs);
|
||||
bw_ppm_reset_state(&instance->ppm_coeffs, &instance->ppm_state, 0.f);
|
||||
instance->note = -1;
|
||||
}
|
||||
|
||||
static void plugin_set_parameter(plugin *instance, size_t index, float value) {
|
||||
switch (index) {
|
||||
case plugin_parameter_volume:
|
||||
{
|
||||
float v = 0.01f * value;
|
||||
bw_gain_set_gain_lin(&instance->gain_coeffs, v * v * v);
|
||||
}
|
||||
break;
|
||||
case plugin_parameter_master_tune:
|
||||
instance->master_tune = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static float plugin_get_parameter(plugin *instance, size_t index) {
|
||||
(void)index;
|
||||
return bw_clipf(bw_ppm_get_y_z1(&instance->ppm_state), -60.f, 0.f);
|
||||
}
|
||||
|
||||
static void plugin_process(plugin *instance, const float **inputs, float **outputs, size_t n_samples) {
|
||||
(void)inputs;
|
||||
|
||||
if (instance->note >= 0) {
|
||||
bw_sampler_set_rate(&instance->sampler_coeffs,
|
||||
(1.f / 440.f) * instance->master_tune * bw_pow2f(8.333333333333333e-2f * (instance->note - 69)));
|
||||
bw_sampler_process(&instance->sampler_coeffs, &instance->sampler_state, instance->sample, instance->sample_length, outputs[0], n_samples);
|
||||
} else
|
||||
bw_sampler_reset_state(&instance->sampler_coeffs, &instance->sampler_state, instance->sample, instance->sample_length, 0.f); // sloppy but simple coding
|
||||
bw_gain_process(&instance->gain_coeffs, outputs[0], outputs[0], n_samples);
|
||||
bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, outputs[0], NULL, n_samples);
|
||||
}
|
||||
|
||||
static void plugin_midi_msg_in(plugin *instance, size_t index, const uint8_t * data) {
|
||||
(void)index;
|
||||
switch (data[0] & 0xf0) {
|
||||
case 0x90: // note on
|
||||
if (data[2] == 0) { // no, note off actually
|
||||
if (data[1] == instance->note)
|
||||
instance->note = -1;
|
||||
} else
|
||||
instance->note = data[1];
|
||||
break;
|
||||
case 0x80: // note off
|
||||
if (data[1] == instance->note)
|
||||
instance->note = -1;
|
||||
break;
|
||||
}
|
||||
}
|
58
examples/synth_sampler/src/product.json
Normal file
58
examples/synth_sampler/src/product.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"product": {
|
||||
"name": "Brickworks sampler synth example",
|
||||
"bundleName": "bw_example_synth_sampler",
|
||||
"buses": [
|
||||
{
|
||||
"type": "midi",
|
||||
"direction": "input",
|
||||
"name": "MIDI input",
|
||||
"shortName": "MIDI input",
|
||||
"id": "midi_in"
|
||||
},
|
||||
{
|
||||
"type": "audio",
|
||||
"direction": "output",
|
||||
"channels": "mono",
|
||||
"name": "Output",
|
||||
"shortName": "Output",
|
||||
"id": "output"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "Volume",
|
||||
"shortName": "Volume",
|
||||
"id": "volume",
|
||||
"direction": "input",
|
||||
"defaultValue": 50.0,
|
||||
"minimum": 0.0,
|
||||
"maximum": 100.0,
|
||||
"unit": "pc",
|
||||
"map": "linear"
|
||||
},
|
||||
{
|
||||
"name": "Master tune",
|
||||
"shortName": "Master tune",
|
||||
"id": "master_tune",
|
||||
"direction": "input",
|
||||
"defaultValue": 440.0,
|
||||
"minimum": 415.304697579945,
|
||||
"maximum": 466.1637615180899,
|
||||
"unit": "hz",
|
||||
"map": "logarithmic"
|
||||
},
|
||||
{
|
||||
"name": "Level",
|
||||
"shortName": "Level",
|
||||
"id": "level",
|
||||
"direction": "output",
|
||||
"defaultValue": -60.0,
|
||||
"minimum": -60.0,
|
||||
"maximum": 0.0,
|
||||
"unit": "db",
|
||||
"map": "linear"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
11
examples/synth_sampler/src/vst3.json
Normal file
11
examples/synth_sampler/src/vst3.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"vst3": {
|
||||
"plugin": {
|
||||
"cid": "7f8982241131453cbb649f1e09e17ad3"
|
||||
},
|
||||
"controller": {
|
||||
"cid": "5dd7bef0661a4f7583b4260586a5d400"
|
||||
},
|
||||
"subCategory": "Instrument|Synth"
|
||||
}
|
||||
}
|
5
examples/synthpp_sampler/src/android.json
Normal file
5
examples/synthpp_sampler/src/android.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"android": {
|
||||
"javaPackageName": "com.orastron.bw_example_synthpp_sampler"
|
||||
}
|
||||
}
|
6
examples/synthpp_sampler/src/daisy-seed.json
Normal file
6
examples/synthpp_sampler/src/daisy-seed.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"daisy_seed": {
|
||||
"parameterPins": [ -1, -1, 22 ],
|
||||
"midiCCMaps": [ 7, 3, -1 ]
|
||||
}
|
||||
}
|
157
examples/synthpp_sampler/src/impl.cpp
Normal file
157
examples/synthpp_sampler/src/impl.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2025 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_math.h>
|
||||
#include <bw_sampler.h>
|
||||
#include <bw_gain.h>
|
||||
#include <bw_ppm.h>
|
||||
#include <bw_buf.h>
|
||||
|
||||
#define SAMPLE_LENGTH 10 // seconds
|
||||
|
||||
using namespace Brickworks;
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
Sampler<1> sampler;
|
||||
Gain<1> gain;
|
||||
PPM<1> ppm;
|
||||
|
||||
float fs;
|
||||
float * sample;
|
||||
size_t sampleLength;
|
||||
|
||||
float masterTune;
|
||||
int note;
|
||||
};
|
||||
|
||||
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->sampler.setSampleRate(sample_rate);
|
||||
instance->gain.setSampleRate(sample_rate);
|
||||
instance->ppm.setSampleRate(sample_rate);
|
||||
|
||||
instance->fs = sample_rate;
|
||||
instance->sampleLength = (size_t)bw_ceilf(sample_rate * SAMPLE_LENGTH);
|
||||
|
||||
instance->sample = new float[instance->sampleLength];
|
||||
}
|
||||
|
||||
void impl_reset(impl handle) {
|
||||
Engine *instance = reinterpret_cast<Engine *>(handle);
|
||||
float p = 0.f;
|
||||
float inc = 440.f / instance->fs;
|
||||
for (size_t i = 0; i < instance->sampleLength; i++) {
|
||||
p += inc;
|
||||
p = p - bw_floorf(p);
|
||||
instance->sample[i] = bw_sin2pif(p);
|
||||
}
|
||||
#ifdef WASM
|
||||
const float *sample[1] = {instance->sample};
|
||||
const size_t sampleLength[1] = {instance->sampleLength};
|
||||
instance->sampler.reset(sample, sampleLength);
|
||||
#else
|
||||
instance->sampler.reset({instance->sample}, {instance->sampleLength}, 0.f, {BW_NULL});
|
||||
#endif
|
||||
instance->gain.reset();
|
||||
instance->ppm.reset();
|
||||
instance->note = -1;
|
||||
}
|
||||
|
||||
void impl_set_parameter(impl handle, size_t index, float value) {
|
||||
Engine *instance = reinterpret_cast<Engine *>(handle);
|
||||
switch (index) {
|
||||
case plugin_parameter_volume:
|
||||
{
|
||||
float v = 0.01f * value;
|
||||
instance->gain.setGainLin(v * v * v);
|
||||
}
|
||||
break;
|
||||
case plugin_parameter_master_tune:
|
||||
instance->masterTune = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float impl_get_parameter(impl handle, size_t index) {
|
||||
(void)index;
|
||||
Engine *instance = reinterpret_cast<Engine *>(handle);
|
||||
return bw_clipf(instance->ppm.getYZ1(0), -60.f, 0.f);
|
||||
}
|
||||
|
||||
void impl_process(impl handle, const float **inputs, float **outputs, size_t n_samples) {
|
||||
(void)inputs;
|
||||
|
||||
Engine *instance = reinterpret_cast<Engine *>(handle);
|
||||
|
||||
#ifdef WASM
|
||||
const float *sample[1] = {instance->sample};
|
||||
const size_t sampleLength[1] = {instance->sampleLength};
|
||||
float *y[1] = {outputs[0]};
|
||||
if (instance->note >= 0) {
|
||||
instance->sampler.setRate((1.f / 440.f) * instance->masterTune * bw_pow2f(8.333333333333333e-2f * (instance->note - 69)));
|
||||
instance->sampler.process(sample, sampleLength, y, n_samples);
|
||||
} else
|
||||
instance->sampler.reset(sample, sampleLength); // sloppy but simple coding
|
||||
#else
|
||||
if (instance->note >= 0) {
|
||||
instance->sampler.setRate((1.f / 440.f) * instance->masterTune * bw_pow2f(8.333333333333333e-2f * (instance->note - 69)));
|
||||
instance->sampler.process({instance->sample}, {instance->sampleLength}, {outputs[0]}, n_samples);
|
||||
} else
|
||||
instance->sampler.reset({instance->sample}, {instance->sampleLength}, 0.f, {BW_NULL}); // sloppy but simple coding
|
||||
#endif
|
||||
instance->gain.process(outputs, outputs, n_samples);
|
||||
instance->ppm.process(outputs, nullptr, n_samples);
|
||||
}
|
||||
|
||||
void impl_midi_msg_in(impl handle, size_t index, const uint8_t * data) {
|
||||
(void)index;
|
||||
Engine *instance = reinterpret_cast<Engine *>(handle);
|
||||
switch (data[0] & 0xf0) {
|
||||
case 0x90: // note on
|
||||
if (data[2] == 0) { // no, note off actually
|
||||
if (data[1] == instance->note)
|
||||
instance->note = -1;
|
||||
} else
|
||||
instance->note = data[1];
|
||||
break;
|
||||
case 0x80: // note off
|
||||
if (data[1] == instance->note)
|
||||
instance->note = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
5
examples/synthpp_sampler/src/ios.json
Normal file
5
examples/synthpp_sampler/src/ios.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ios": {
|
||||
"productBundleIdentifier": "com.orastron.bw_example_synthpp_sampler"
|
||||
}
|
||||
}
|
10
examples/synthpp_sampler/src/lv2.json
Normal file
10
examples/synthpp_sampler/src/lv2.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"lv2": {
|
||||
"prefixes": {
|
||||
"bw_examples": "https://www.orastron.com/brickworks/examples/"
|
||||
},
|
||||
"uri": "@bw_examples:synthpp_sampler",
|
||||
"types": [ "@lv2:InstrumentPlugin" ],
|
||||
"version": "0.0"
|
||||
}
|
||||
}
|
58
examples/synthpp_sampler/src/product.json
Normal file
58
examples/synthpp_sampler/src/product.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"product": {
|
||||
"name": "Brickworks sampler synth example (C++)",
|
||||
"bundleName": "bw_example_synthpp_sampler",
|
||||
"buses": [
|
||||
{
|
||||
"type": "midi",
|
||||
"direction": "input",
|
||||
"name": "MIDI input",
|
||||
"shortName": "MIDI input",
|
||||
"id": "midi_in"
|
||||
},
|
||||
{
|
||||
"type": "audio",
|
||||
"direction": "output",
|
||||
"channels": "mono",
|
||||
"name": "Output",
|
||||
"shortName": "Output",
|
||||
"id": "output"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "Volume",
|
||||
"shortName": "Volume",
|
||||
"id": "volume",
|
||||
"direction": "input",
|
||||
"defaultValue": 50.0,
|
||||
"minimum": 0.0,
|
||||
"maximum": 100.0,
|
||||
"unit": "pc",
|
||||
"map": "linear"
|
||||
},
|
||||
{
|
||||
"name": "Master tune",
|
||||
"shortName": "Master tune",
|
||||
"id": "master_tune",
|
||||
"direction": "input",
|
||||
"defaultValue": 440.0,
|
||||
"minimum": 415.304697579945,
|
||||
"maximum": 466.1637615180899,
|
||||
"unit": "hz",
|
||||
"map": "logarithmic"
|
||||
},
|
||||
{
|
||||
"name": "Level",
|
||||
"shortName": "Level",
|
||||
"id": "level",
|
||||
"direction": "output",
|
||||
"defaultValue": -60.0,
|
||||
"minimum": -60.0,
|
||||
"maximum": 0.0,
|
||||
"unit": "db",
|
||||
"map": "linear"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
11
examples/synthpp_sampler/src/vst3.json
Normal file
11
examples/synthpp_sampler/src/vst3.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"vst3": {
|
||||
"plugin": {
|
||||
"cid": "00de68a0424c4b3b9a260cd6e2d01f5c"
|
||||
},
|
||||
"controller": {
|
||||
"cid": "659dbfa4fedb43fb8fcb1b52168dd0b2"
|
||||
},
|
||||
"subCategory": "Instrument|Synth"
|
||||
}
|
||||
}
|
@ -85,8 +85,8 @@ for d in $dirs; do
|
||||
cd $d && $TIBIA_DIR/tibia --data ../common/src/company.json,src/product.json,src/vst3.json,../common/src/$make_json $TIBIA_DIR/templates/vst3-make vst3 $ARGS && cd ..
|
||||
echo "include ../../common/vst3/Makefile" > $d/vst3/Makefile
|
||||
|
||||
cd $d && $TIBIA_DIR/tibia --data ../common/src/company.json,src/product.json,src/android.json $TIBIA_DIR/templates/android android $ARGS && cd ..
|
||||
cd $d && $TIBIA_DIR/tibia --data ../common/src/company.json,src/product.json,src/android.json,../common/src/$make_json $TIBIA_DIR/templates/android-make android $ARGS && cd ..
|
||||
cd $d && $TIBIA_DIR/tibia --data ../common/src/company.json,src/product.json,src/android.json $TIBIA_DIR/templates/android android $ARGS android.androidVersion=\"36\" && cd ..
|
||||
cd $d && $TIBIA_DIR/tibia --data ../common/src/company.json,src/product.json,src/android.json,../common/src/$make_json $TIBIA_DIR/templates/android-make android $ARGS android.androidVersion=\"36\" && cd ..
|
||||
echo "include ../../common/android/Makefile" > $d/android/Makefile
|
||||
|
||||
cd $d && $TIBIA_DIR/tibia --data ../common/src/company.json,src/product.json,src/ios.json $TIBIA_DIR/templates/ios ios $ARGS && cd ..
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 20230-2025 Orastron Srl unipersonale
|
||||
* Copyright (C) 2023-2025 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
|
||||
|
@ -20,9 +20,9 @@
|
||||
|
||||
/*!
|
||||
* module_type {{{ dsp }}}
|
||||
* version {{{ 1.2.1 }}}
|
||||
* version {{{ 1.2.2 }}}
|
||||
* requires {{{
|
||||
* bw_common bw_gain bw_hs1 bw_lp1 bw_math bw_mm2 bw_one_pole bw_peak
|
||||
* bw_common bw_gain bw_hs1 bw_lp1 bw_math bw_mm1 bw_mm2 bw_one_pole bw_peak
|
||||
* bw_satur bw_svf
|
||||
* }}}
|
||||
* description {{{
|
||||
@ -32,6 +32,11 @@
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
* <li>Version <strong>1.2.2</strong>:
|
||||
* <ul>
|
||||
* <li>Added missing bw_mm1 to list of dependencies.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>1.2.1</strong>:
|
||||
* <ul>
|
||||
* <li>Now using <code>BW_NULL</code> in the C++ API and
|
||||
@ -464,9 +469,9 @@ static inline float bw_drive_reset_state(
|
||||
static inline void bw_drive_reset_state_multi(
|
||||
const bw_drive_coeffs * BW_RESTRICT coeffs,
|
||||
bw_drive_state * BW_RESTRICT const * BW_RESTRICT state,
|
||||
const float * x_0,
|
||||
float * y_0,
|
||||
size_t n_channels) {
|
||||
const float * x_0,
|
||||
float * y_0,
|
||||
size_t n_channels) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_drive_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_drive_coeffs_state_reset_coeffs);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2021-2024 Orastron Srl unipersonale
|
||||
* Copyright (C) 2021-2025 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
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
/*!
|
||||
* module_type {{{ utility }}}
|
||||
* version {{{ 1.1.0 }}}
|
||||
* version {{{ 1.2.0 }}}
|
||||
* requires {{{ bw_common }}}
|
||||
* description {{{
|
||||
* A collection of mathematical routines that strive to be better suited to
|
||||
@ -44,6 +44,11 @@
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
* <li>Version <strong>1.2.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_sechf()</code>.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>1.1.0</strong>:
|
||||
* <ul>
|
||||
* <li>Added <code>bw_signfilli64()</code>, <code>bw_mini64()</code>,
|
||||
@ -630,6 +635,15 @@ static inline float bw_coshf(
|
||||
*
|
||||
* Relative error < 0.07%.
|
||||
*
|
||||
* #### bw_sechf()
|
||||
* ```>>> */
|
||||
static inline float bw_sechf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the hyperbolic secant of `x`.
|
||||
*
|
||||
* Absolute error < 1e-9 or relative error < 0.07%, whatever is worse.
|
||||
*
|
||||
* #### bw_asinhf()
|
||||
* ```>>> */
|
||||
static inline float bw_asinhf(
|
||||
@ -1142,6 +1156,17 @@ static inline float bw_coshf(
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_sechf(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
if (x * x >= 22.f * 22.f)
|
||||
return 0.f;
|
||||
float y = bw_rcpf(bw_expf(x) + bw_expf(-x));
|
||||
y = y + y;
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_asinhf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
|
858
include/bw_sampler.h
Normal file
858
include/bw_sampler.h
Normal file
@ -0,0 +1,858 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2025 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
|
||||
*/
|
||||
|
||||
/*!
|
||||
* module_type {{{ dsp }}}
|
||||
* version {{{ 1.0.0 }}}
|
||||
* requires {{{ bw_common }}}
|
||||
* description {{{
|
||||
* Very basic sampler with variable playback speed.
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
* <li>Version <strong>1.0.0</strong>:
|
||||
* <ul>
|
||||
* <li>First release.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
* }}}
|
||||
*/
|
||||
|
||||
#ifndef BW_SAMPLER_H
|
||||
#define BW_SAMPLER_H
|
||||
|
||||
#ifdef BW_INCLUDE_WITH_QUOTES
|
||||
# include "bw_common.h"
|
||||
#else
|
||||
# include <bw_common.h>
|
||||
#endif
|
||||
|
||||
#if !defined(BW_CXX_NO_EXTERN_C) && defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*** Public API ***/
|
||||
|
||||
/*! api {{{
|
||||
* #### bw_sampler_coeffs
|
||||
* ```>>> */
|
||||
typedef struct bw_sampler_coeffs bw_sampler_coeffs;
|
||||
/*! <<<```
|
||||
* Coefficients and related.
|
||||
*
|
||||
* #### bw_sampler_state
|
||||
* ```>>> */
|
||||
typedef struct bw_sampler_state bw_sampler_state;
|
||||
/*! <<<```
|
||||
* Internal state and related.
|
||||
*
|
||||
* #### bw_sampler_phase
|
||||
* ```>>> */
|
||||
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.
|
||||
*
|
||||
* #### bw_sampler_init()
|
||||
* ```>>> */
|
||||
static inline void bw_sampler_init(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Initializes input parameter values in `coeffs`.
|
||||
*
|
||||
* #### bw_sampler_set_sample_rate()
|
||||
* ```>>> */
|
||||
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`.
|
||||
*
|
||||
* #### bw_sampler_reset_coeffs()
|
||||
* ```>>> */
|
||||
static inline void bw_sampler_reset_coeffs(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Resets coefficients in `coeffs` to assume their target values.
|
||||
*
|
||||
* #### bw_sampler_reset_state()
|
||||
* ```>>> */
|
||||
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.
|
||||
*
|
||||
* #### bw_sampler_reset_state_multi()
|
||||
* ```>>> */
|
||||
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` `state`s to its initial values using the
|
||||
* given `coeffs`, the `n_channels` audio `sample`s and their corresponding
|
||||
* `sample_length`s, 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.
|
||||
*
|
||||
* #### bw_sampler_update_coeffs_ctrl()
|
||||
* ```>>> */
|
||||
static inline void bw_sampler_update_coeffs_ctrl(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Triggers control-rate update of coefficients in `coeffs`.
|
||||
*
|
||||
* #### bw_sampler_update_coeffs_audio()
|
||||
* ```>>> */
|
||||
static inline void bw_sampler_update_coeffs_audio(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs);
|
||||
/*! <<<```
|
||||
* Triggers audio-rate update of coefficients in `coeffs`.
|
||||
*
|
||||
* #### bw_sampler_process1()
|
||||
* ```>>> */
|
||||
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.
|
||||
*
|
||||
* #### bw_sampler_process()
|
||||
* ```>>> */
|
||||
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.
|
||||
*
|
||||
* #### bw_sampler_process_multi()
|
||||
* ```>>> */
|
||||
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 `sample`s and their
|
||||
* corresponding `sample_length`s, while using and updating both the common
|
||||
* `coeffs` and each of the `n_channels` `state`s (control and audio rate).
|
||||
*
|
||||
* All values in `sample_length` must be strictly positive.
|
||||
*
|
||||
* #### bw_sampler_set_rate()
|
||||
* ```>>> */
|
||||
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`.
|
||||
*
|
||||
* #### bw_sampler_get_phase()
|
||||
* ```>>> */
|
||||
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`.
|
||||
*
|
||||
* #### bw_sampler_coeffs_is_valid()
|
||||
* ```>>> */
|
||||
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`.
|
||||
*
|
||||
* #### bw_sampler_state_is_valid()
|
||||
* ```>>> */
|
||||
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`.
|
||||
* }}} */
|
||||
|
||||
#if !defined(BW_CXX_NO_EXTERN_C) && defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*** Implementation ***/
|
||||
|
||||
/* WARNING: This part of the file is not part of the public API. Its content may
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
#if !defined(BW_CXX_NO_EXTERN_C) && defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
enum bw_sampler_coeffs_state {
|
||||
bw_sampler_coeffs_state_invalid,
|
||||
bw_sampler_coeffs_state_init,
|
||||
bw_sampler_coeffs_state_set_sample_rate,
|
||||
bw_sampler_coeffs_state_reset_coeffs
|
||||
};
|
||||
#endif
|
||||
|
||||
struct bw_sampler_coeffs {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
enum bw_sampler_coeffs_state state;
|
||||
uint32_t reset_id;
|
||||
#endif
|
||||
|
||||
// Parameters
|
||||
float rate;
|
||||
};
|
||||
|
||||
struct bw_sampler_state {
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
uint32_t hash;
|
||||
uint32_t coeffs_reset_id;
|
||||
#endif
|
||||
|
||||
// States
|
||||
float pos;
|
||||
bw_sampler_phase phase;
|
||||
};
|
||||
|
||||
static inline void bw_sampler_init(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
|
||||
coeffs->rate = 1.f;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->hash = bw_hash_sdbm("bw_sampler_coeffs");
|
||||
coeffs->state = bw_sampler_coeffs_state_init;
|
||||
coeffs->reset_id = coeffs->hash + 1;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_sampler_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline void bw_sampler_set_sample_rate(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs,
|
||||
float sample_rate) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(sample_rate) && sample_rate > 0.f);
|
||||
|
||||
(void)coeffs;
|
||||
(void)sample_rate;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->state = bw_sampler_coeffs_state_set_sample_rate;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_sampler_coeffs_state_set_sample_rate);
|
||||
}
|
||||
|
||||
static inline void bw_sampler_reset_coeffs(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_set_sample_rate);
|
||||
|
||||
(void)coeffs;
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
coeffs->state = bw_sampler_coeffs_state_reset_coeffs;
|
||||
coeffs->reset_id++;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state == bw_sampler_coeffs_state_reset_coeffs);
|
||||
}
|
||||
|
||||
static inline float bw_sampler_interpolate(
|
||||
const float * BW_RESTRICT sample,
|
||||
size_t sample_length,
|
||||
float pos) {
|
||||
BW_ASSERT(sample_length > 0);
|
||||
|
||||
float xm1, x0, x1, x2, d;
|
||||
if (pos >= 1.f) {
|
||||
const size_t p = (size_t)pos;
|
||||
if (p + 2 < sample_length) {
|
||||
xm1 = sample[p - 1];
|
||||
x0 = sample[p];
|
||||
x1 = sample[p + 1];
|
||||
x2 = sample[p + 2];
|
||||
} else if (p + 2 == sample_length) {
|
||||
xm1 = sample[p - 1];
|
||||
x0 = sample[p];
|
||||
x1 = sample[p + 1];
|
||||
x2 = 0.f;
|
||||
} else if (p + 1 == sample_length) {
|
||||
xm1 = sample[p - 1];
|
||||
x0 = sample[p];
|
||||
x1 = 0.f;
|
||||
x2 = 0.f;
|
||||
} else if (p == sample_length) {
|
||||
xm1 = sample[p - 1];
|
||||
x0 = 0.f;
|
||||
x1 = 0.f;
|
||||
x2 = 0.f;
|
||||
} else
|
||||
return 0.f;
|
||||
d = pos - p;
|
||||
} else if (pos >= 0.f) {
|
||||
xm1 = 0.f;
|
||||
x0 = sample[0];
|
||||
if (sample_length > 1) {
|
||||
x1 = sample[1];
|
||||
x2 = sample_length > 2 ? sample[2] : 0.f;
|
||||
} else {
|
||||
x1 = 0.f;
|
||||
x2 = 0.f;
|
||||
}
|
||||
d = pos;
|
||||
} else if (pos >= -1.f) {
|
||||
xm1 = 0.f;
|
||||
x0 = 0.f;
|
||||
x1 = sample[0];
|
||||
x2 = sample_length > 1 ? sample[1] : 0.f;
|
||||
d = pos + 1.f;
|
||||
} else if (pos >= -2.f) {
|
||||
xm1 = 0.f;
|
||||
x0 = 0.f;
|
||||
x1 = 0.f;
|
||||
x2 = sample[0];
|
||||
d = pos + 2.f;
|
||||
} else
|
||||
return 0.f;
|
||||
|
||||
// 3rd degree B-spline
|
||||
return (d * ((0.5f - 0.1666666666666667f * d) * d - 0.5f) + 0.1666666666666667f) * xm1
|
||||
+ ((0.5f * d - 1.f) * d * d + 0.6666666666666666f) * x0
|
||||
+ (d * ((0.5f - 0.5f * d) * d + 0.5f) + 0.1666666666666667f) * x1
|
||||
+ 0.1666666666666667f * d * d * d * x2;
|
||||
}
|
||||
|
||||
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) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != BW_NULL);
|
||||
BW_ASSERT(sample != BW_NULL);
|
||||
BW_ASSERT(sample_length > 0);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(sample, sample_length));
|
||||
BW_ASSERT(bw_is_finite(pos_0));
|
||||
BW_ASSERT(pos_0 >= 0.f);
|
||||
|
||||
(void)coeffs;
|
||||
state->pos = pos_0;
|
||||
state->phase = bw_sampler_phase_before;
|
||||
const float y = bw_sampler_interpolate(sample, sample_length, pos_0);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
state->hash = bw_hash_sdbm("bw_sampler_state");
|
||||
state->coeffs_reset_id = coeffs->reset_id;
|
||||
#endif
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
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) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != BW_NULL);
|
||||
#ifndef BW_NO_DEBUG
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
for (size_t j = i + 1; j < n_channels; j++)
|
||||
BW_ASSERT(state[i] != state[j]);
|
||||
#endif
|
||||
BW_ASSERT(sample != BW_NULL);
|
||||
BW_ASSERT(sample_length != BW_NULL);
|
||||
BW_ASSERT(pos_0 != BW_NULL);
|
||||
#ifndef BW_NO_DEBUG
|
||||
for (size_t i = 0; i < n_channels; i++) {
|
||||
BW_ASSERT(sample[i] != pos_0);
|
||||
BW_ASSERT(sample[i] != y_0);
|
||||
for (size_t j = i + 1; j < n_channels; j++)
|
||||
BW_ASSERT(sample[i] != sample[j]);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (y_0 != BW_NULL)
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
y_0[i] = bw_sampler_reset_state(coeffs, state[i], sample[i], sample_length[i], pos_0[i]);
|
||||
else
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
bw_sampler_reset_state(coeffs, state[i], sample[i], sample_length[i], pos_0[i]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(y_0 != BW_NULL ? bw_has_only_finite(y_0, n_channels) : 1);
|
||||
}
|
||||
|
||||
static inline void bw_sampler_update_coeffs_ctrl(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
|
||||
(void)coeffs;
|
||||
}
|
||||
|
||||
static inline void bw_sampler_update_coeffs_audio(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
|
||||
(void)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) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(sample != BW_NULL);
|
||||
BW_ASSERT(sample_length > 0);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(sample, sample_length));
|
||||
|
||||
float y;
|
||||
if (state->pos <= sample_length + 2) {
|
||||
y = bw_sampler_interpolate(sample, sample_length, state->pos);
|
||||
state->pos += coeffs->rate;
|
||||
state->phase = bw_sampler_phase_playing;
|
||||
} else {
|
||||
y = 0.f;
|
||||
state->phase = bw_sampler_phase_done;
|
||||
}
|
||||
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
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) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(coeffs, state));
|
||||
BW_ASSERT(sample != BW_NULL);
|
||||
BW_ASSERT(sample_length > 0);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(sample, sample_length));
|
||||
BW_ASSERT(y != BW_NULL);
|
||||
BW_ASSERT(sample != y);
|
||||
|
||||
for (size_t i = 0; i < n_samples; i++)
|
||||
y[i] = bw_sampler_process1(coeffs, state, sample, sample_length);
|
||||
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(coeffs, state));
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(y, n_samples));
|
||||
}
|
||||
|
||||
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) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
BW_ASSERT(state != BW_NULL);
|
||||
#ifndef BW_NO_DEBUG
|
||||
for (size_t i = 0; i < n_channels; i++) {
|
||||
BW_ASSERT(state[i] != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(coeffs, state[i]));
|
||||
}
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
for (size_t j = i + 1; j < n_channels; j++)
|
||||
BW_ASSERT(state[i] != state[j]);
|
||||
#endif
|
||||
BW_ASSERT(sample != BW_NULL);
|
||||
BW_ASSERT(sample_length != BW_NULL);
|
||||
BW_ASSERT(y != BW_NULL);
|
||||
#ifndef BW_NO_DEBUG
|
||||
for (size_t i = 0; i < n_channels; i++) {
|
||||
BW_ASSERT(sample[i] != BW_NULL);
|
||||
BW_ASSERT(sample_length[i] > 0);
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(sample[i], sample_length[i]));
|
||||
BW_ASSERT(y[i] != BW_NULL);
|
||||
}
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
for (size_t j = i + 1; j < n_channels; j++)
|
||||
BW_ASSERT(y[i] != y[j]);
|
||||
for (size_t i = 0; i < n_channels; i++)
|
||||
for (size_t j = 0; j < n_channels; j++)
|
||||
BW_ASSERT(sample[i] != y[j]);
|
||||
#endif
|
||||
|
||||
for (size_t j = 0; j < n_channels; j++)
|
||||
for (size_t i = 0; i < n_samples; i++)
|
||||
y[j][i] = bw_sampler_process1(coeffs, state[j], sample[j], sample_length[j]);
|
||||
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_reset_coeffs);
|
||||
#ifndef BW_NO_DEBUG
|
||||
for (size_t i = 0; i < n_channels; i++) {
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(coeffs, state[i]));
|
||||
BW_ASSERT_DEEP(bw_has_only_finite(y[i], n_samples));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void bw_sampler_set_rate(
|
||||
bw_sampler_coeffs * BW_RESTRICT coeffs,
|
||||
float value) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_init);
|
||||
BW_ASSERT(bw_is_finite(value));
|
||||
BW_ASSERT(value >= 0.f);
|
||||
|
||||
coeffs->rate = value;
|
||||
|
||||
BW_ASSERT_DEEP(bw_sampler_coeffs_is_valid(coeffs));
|
||||
BW_ASSERT_DEEP(coeffs->state >= bw_sampler_coeffs_state_init);
|
||||
}
|
||||
|
||||
static inline bw_sampler_phase bw_sampler_get_phase(
|
||||
const bw_sampler_state * BW_RESTRICT state) {
|
||||
BW_ASSERT(state != BW_NULL);
|
||||
BW_ASSERT_DEEP(bw_sampler_state_is_valid(BW_NULL, state));
|
||||
|
||||
return state->phase;
|
||||
}
|
||||
|
||||
static inline char bw_sampler_coeffs_is_valid(
|
||||
const bw_sampler_coeffs * BW_RESTRICT coeffs) {
|
||||
BW_ASSERT(coeffs != BW_NULL);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (coeffs->hash != bw_hash_sdbm("bw_sampler_coeffs"))
|
||||
return 0;
|
||||
if (coeffs->state < bw_sampler_coeffs_state_init || coeffs->state > bw_sampler_coeffs_state_reset_coeffs)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (!bw_is_finite(coeffs->rate) || coeffs->rate < 0.f)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline char bw_sampler_state_is_valid(
|
||||
const bw_sampler_coeffs * BW_RESTRICT coeffs,
|
||||
const bw_sampler_state * BW_RESTRICT state) {
|
||||
BW_ASSERT(state != BW_NULL);
|
||||
|
||||
#ifdef BW_DEBUG_DEEP
|
||||
if (state->hash != bw_hash_sdbm("bw_sampler_state"))
|
||||
return 0;
|
||||
|
||||
if (coeffs != BW_NULL && coeffs->reset_id != state->coeffs_reset_id)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
(void)coeffs;
|
||||
|
||||
if (!bw_is_finite(state->pos) || state->pos < 0.f)
|
||||
return 0;
|
||||
if (state->phase < bw_sampler_phase_before || state->phase > bw_sampler_phase_done)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if !defined(BW_CXX_NO_EXTERN_C) && defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BW_NO_CXX) && defined(__cplusplus)
|
||||
|
||||
# ifndef BW_CXX_NO_ARRAY
|
||||
# include <array>
|
||||
# endif
|
||||
|
||||
namespace Brickworks {
|
||||
|
||||
/*** Public C++ API ***/
|
||||
|
||||
/*! api_cpp {{{
|
||||
* ##### Brickworks::Sampler
|
||||
* ```>>> */
|
||||
template<size_t N_CHANNELS>
|
||||
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,
|
||||
std::array<float, N_CHANNELS> * BW_RESTRICT y0);
|
||||
# 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);
|
||||
/*! <<<...
|
||||
* }
|
||||
* ```
|
||||
* }}} */
|
||||
|
||||
/*** Implementation ***/
|
||||
|
||||
/* WARNING: This part of the file is not part of the public API. Its content may
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
private:
|
||||
bw_sampler_coeffs coeffs;
|
||||
bw_sampler_state states[N_CHANNELS];
|
||||
bw_sampler_state * BW_RESTRICT statesP[N_CHANNELS];
|
||||
};
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline Sampler<N_CHANNELS>::Sampler() {
|
||||
bw_sampler_init(&coeffs);
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
statesP[i] = states + i;
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::setSampleRate(
|
||||
float sampleRate) {
|
||||
bw_sampler_set_sample_rate(&coeffs, sampleRate);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::reset(
|
||||
const float * BW_RESTRICT const * BW_RESTRICT sample,
|
||||
const size_t * BW_RESTRICT sampleLength,
|
||||
float pos0,
|
||||
float * BW_RESTRICT y0) {
|
||||
bw_sampler_reset_coeffs(&coeffs);
|
||||
if (y0 != BW_NULL)
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
y0[i] = bw_sampler_reset_state(&coeffs, states + i, sample[i], sampleLength[i], pos0);
|
||||
else
|
||||
for (size_t i = 0; i < N_CHANNELS; i++)
|
||||
bw_sampler_reset_state(&coeffs, states + i, sample[i], sampleLength[i], pos0);
|
||||
}
|
||||
|
||||
# ifndef BW_CXX_NO_ARRAY
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::reset(
|
||||
std::array<const float * BW_RESTRICT, N_CHANNELS> sample,
|
||||
std::array<size_t, N_CHANNELS> sampleLength,
|
||||
float pos0,
|
||||
std::array<float, N_CHANNELS> * BW_RESTRICT y0) {
|
||||
reset(sample.data(), sampleLength.data(), pos0, y0 != BW_NULL ? y0->data() : BW_NULL);
|
||||
}
|
||||
# endif
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::reset(
|
||||
const float * BW_RESTRICT const * BW_RESTRICT sample,
|
||||
const size_t * BW_RESTRICT sampleLength,
|
||||
const float * pos0,
|
||||
float * y0) {
|
||||
bw_sampler_reset_coeffs(&coeffs);
|
||||
bw_sampler_reset_state_multi(&coeffs, statesP, sample, sampleLength, pos0, y0, N_CHANNELS);
|
||||
}
|
||||
|
||||
# ifndef BW_CXX_NO_ARRAY
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::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) {
|
||||
reset(sample.data(), sampleLength.data(), pos0.data(), y0 != BW_NULL ? y0->data() : BW_NULL);
|
||||
}
|
||||
# endif
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::process(
|
||||
const float * BW_RESTRICT const * BW_RESTRICT sample,
|
||||
const size_t * BW_RESTRICT sampleLength,
|
||||
float * const * y,
|
||||
size_t nSamples) {
|
||||
bw_sampler_process_multi(&coeffs, statesP, sample, sampleLength, y, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
# ifndef BW_CXX_NO_ARRAY
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::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) {
|
||||
process(sample.data(), sampleLength.data(), y.data(), nSamples);
|
||||
}
|
||||
# endif
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void Sampler<N_CHANNELS>::setRate(
|
||||
float value) {
|
||||
bw_sampler_set_rate(&coeffs, value);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline bw_sampler_phase Sampler<N_CHANNELS>::getPhase(
|
||||
size_t channel) {
|
||||
return bw_sampler_get_phase(states + channel);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -20,13 +20,20 @@
|
||||
|
||||
/*!
|
||||
* module_type {{{ dsp }}}
|
||||
* version {{{ 1.2.1 }}}
|
||||
* version {{{ 1.2.2 }}}
|
||||
* requires {{{ bw_common bw_math }}}
|
||||
* description {{{
|
||||
* Slew-rate limiter with separate maximum increasing and decreasing rates.
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
* <li>Version <strong>1.2.2</strong>:
|
||||
* <ul>
|
||||
* <li>Fixed typos in the documentation of
|
||||
* <code>bw_slew_lim_set_max_rate()</code> and
|
||||
* <code>bw_slew_lim_set_max_rate_down()</code>.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>1.2.1</strong>:
|
||||
* <ul>
|
||||
* <li>Now using <code>BW_NULL</code> in the C++ API and
|
||||
@ -281,8 +288,8 @@ static inline void bw_slew_lim_set_max_rate(
|
||||
* `value` represents the maximum variation per second and must be
|
||||
* non-negative.
|
||||
*
|
||||
* This is equivalent to calling both `bw_slew_lim_set_max_inc_rate()` and
|
||||
* `bw_slew_lim_set_max_dec_rate()` with same `coeffs` and `value`.
|
||||
* This is equivalent to calling both `bw_slew_lim_set_max_rate_up()` and
|
||||
* `bw_slew_lim_set_max_rate_down()` with same `coeffs` and `value`.
|
||||
*
|
||||
* Default value: `INFINITY`.
|
||||
* >>> */
|
||||
@ -304,7 +311,7 @@ static inline void bw_slew_lim_set_max_rate_up(
|
||||
* >>> */
|
||||
|
||||
/*! ...
|
||||
* #### bw_slew_lim_set_max_inc_rate()
|
||||
* #### bw_slew_lim_set_max_rate_up()
|
||||
* ```>>> */
|
||||
static inline void bw_slew_lim_set_max_rate_down(
|
||||
bw_slew_lim_coeffs * BW_RESTRICT coeffs,
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
/*!
|
||||
* module_type {{{ dsp }}}
|
||||
* version {{{ 1.2.1 }}}
|
||||
* version {{{ 1.2.2 }}}
|
||||
* requires {{{ bw_common bw_math bw_one_pole }}}
|
||||
* description {{{
|
||||
* State variable filter (2nd order, 12 dB/oct) model with separated lowpass,
|
||||
@ -28,6 +28,11 @@
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
* <li>Version <strong>1.2.2</strong>:
|
||||
* <ul>
|
||||
* <li>Small implementation optimization.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>1.2.1</strong>:
|
||||
* <ul>
|
||||
* <li>Now using <code>BW_NULL</code> in the C++ API and
|
||||
@ -396,7 +401,6 @@ struct bw_svf_coeffs {
|
||||
float t_k;
|
||||
float prewarp_freq_max;
|
||||
|
||||
float t;
|
||||
float kf;
|
||||
float kbl;
|
||||
float k;
|
||||
@ -481,8 +485,7 @@ static inline void bw_svf_do_update_coeffs(
|
||||
if (prewarp_freq_changed) {
|
||||
prewarp_freq_cur = bw_one_pole_process1_sticky_rel(&coeffs->smooth_coeffs, &coeffs->smooth_prewarp_freq_state, prewarp_freq);
|
||||
const float f = bw_minf(prewarp_freq_cur, coeffs->prewarp_freq_max);
|
||||
coeffs->t = bw_tanf(coeffs->t_k * f);
|
||||
coeffs->kf = coeffs->t * bw_rcpf(f);
|
||||
coeffs->kf = bw_tanf(coeffs->t_k * f) * bw_rcpf(f);
|
||||
}
|
||||
coeffs->kbl = coeffs->kf * cutoff_cur;
|
||||
}
|
||||
@ -1052,8 +1055,6 @@ static inline char bw_svf_coeffs_is_valid(
|
||||
}
|
||||
|
||||
if (coeffs->state >= bw_svf_coeffs_state_reset_coeffs) {
|
||||
if (!bw_is_finite(coeffs->t) || coeffs->t <= 0.f)
|
||||
return 0;
|
||||
if (!bw_is_finite(coeffs->kf) || coeffs->kf <= 0.f)
|
||||
return 0;
|
||||
if (!bw_is_finite(coeffs->kbl) || coeffs->kbl <= 0.f)
|
||||
|
Loading…
Reference in New Issue
Block a user