Skip to content

Commit

Permalink
first commit of nts1mkii port
Browse files Browse the repository at this point in the history
  • Loading branch information
boochow committed Mar 30, 2024
1 parent 66f44aa commit 20b8b4c
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 126 deletions.
19 changes: 9 additions & 10 deletions header.c
Expand Up @@ -43,14 +43,14 @@
// ---- Unit header definition --------------------------------------------------------------------

const __unit_header unit_header_t unit_header = {
.header_size = sizeof(unit_header_t), // Size of this header. Leave as is.
.target = UNIT_TARGET_PLATFORM | k_unit_module_modfx, // Target platform and module pair for this unit
.api = UNIT_API_VERSION, // API version for which unit was built. See runtime.h
.dev_id = 0x0, // Developer ID. See https://github.com/korginc/logue-sdk/blob/master/developer_ids.md
.unit_id = 0x0U, // ID for this unit. Scoped within the context of a given dev_id.
.version = 0x00010000U, // This unit's version: major.minor.patch (major<<16 minor<<8 patch).
.name = "dummy", // Name for this unit, will be displayed on device
.num_params = 3, // Number of valid parameter descriptors. (max. 10)
.header_size = sizeof(unit_header_t),
.target = UNIT_TARGET_PLATFORM | k_unit_module_modfx,
.api = UNIT_API_VERSION,
.dev_id = 0x42636877U, // "Bchw"
.unit_id = 0x03030000, // Product number(03),Unit type(03=ModFX),reserved
.version = 0x00010000U,
.name = "TeleConf",
.num_params = 3,

.params = {
// Format: min, max, center, default, type, frac. bits, frac. mode, <reserved>, name
Expand All @@ -64,8 +64,7 @@ const __unit_header unit_header_t unit_header = {
// B knob
{0, 1023, 0, 256, k_unit_param_type_none, 1, 0, 0, {"DPTH"}},

// 8 Edit menu parameters
{0, 3, 0, 1, k_unit_param_type_strings, 0, 0, 0, {"PARAM3"}}, // Example of a strings type parameter
{0, 0, 0, 0, k_unit_param_type_none, 0, 0, 0, {""}},
{0, 0, 0, 0, k_unit_param_type_none, 0, 0, 0, {""}},
{0, 0, 0, 0, k_unit_param_type_none, 0, 0, 0, {""}},
{0, 0, 0, 0, k_unit_param_type_none, 0, 0, 0, {""}},
Expand Down
219 changes: 103 additions & 116 deletions teleconf.cc
Expand Up @@ -2,10 +2,14 @@
* File: teleconf.cpp
*/

#include "usermodfx.h"
#include "biquad.hpp"
#include "unit_modfx.h"
#include "dsp/biquad.hpp"

#define SUBTIMBRE 0
#define k_user_modfx_param_time 0
#define k_user_modfx_param_depth 1

static unit_runtime_desc_t s_runtime_desc;
static int32_t s_params[10];

// filter parameters
#define LPF_FC 3000.f
Expand All @@ -17,23 +21,11 @@ static dsp::BiQuad s_bq_lpf_r;
static dsp::BiQuad s_bq_hpf_r;
static dsp::BiQuad s_bq_lpf_l;
static dsp::BiQuad s_bq_hpf_l;
#if SUBTIMBRE
static dsp::BiQuad s_bqs_lpf_r;
static dsp::BiQuad s_bqs_hpf_r;
static dsp::BiQuad s_bqs_lpf_l;
static dsp::BiQuad s_bqs_hpf_l;
#endif
// filters after downsampling
static dsp::BiQuad s_bq_lpf_out_r;
static dsp::BiQuad s_bq_lpf_out2_r;
static dsp::BiQuad s_bq_lpf_out_l;
static dsp::BiQuad s_bq_lpf_out2_l;
#if SUBTIMBRE
static dsp::BiQuad s_bqs_lpf_out_r;
static dsp::BiQuad s_bqs_lpf_out2_r;
static dsp::BiQuad s_bqs_lpf_out_l;
static dsp::BiQuad s_bqs_lpf_out2_l;
#endif

static const float s_fs_recip = 1.f / 48000.f;

Expand All @@ -42,34 +34,41 @@ static float wet = 1.f;
static uint32_t count = 0;
static float lastmy_r;
static float lastmy_l;
#if SUBTIMBRE
static float lastsy_r;
static float lastsy_l;
#endif

void init_lpf(const float f, const float q) {
float wc = s_bq_lpf_r.mCoeffs.wc(f, s_fs_recip);
s_bq_lpf_r.mCoeffs.setSOLP(fx_tanpif(wc), q);
s_bq_lpf_out_r.mCoeffs = s_bq_lpf_r.mCoeffs;
s_bq_lpf_out2_r.mCoeffs = s_bq_lpf_r.mCoeffs;
#if SUBTIMBRE
s_bqs_lpf_r.mCoeffs = s_bq_lpf_r.mCoeffs;
s_bqs_lpf_out_r.mCoeffs = s_bq_lpf_r.mCoeffs;
s_bqs_lpf_out2_r.mCoeffs = s_bq_lpf_r.mCoeffs;
#endif

s_bq_lpf_l.mCoeffs = s_bq_lpf_r.mCoeffs;
s_bq_lpf_out_l.mCoeffs = s_bq_lpf_r.mCoeffs;
s_bq_lpf_out2_l.mCoeffs = s_bq_lpf_r.mCoeffs;
#if SUBTIMBRE
s_bqs_lpf_l.mCoeffs = s_bq_lpf_r.mCoeffs;
s_bqs_lpf_out_l.mCoeffs = s_bq_lpf_r.mCoeffs;
s_bqs_lpf_out2_l.mCoeffs = s_bq_lpf_r.mCoeffs;
#endif
}

void MODFX_INIT(uint32_t platform, uint32_t api)
{
__unit_callback int8_t unit_init(const unit_runtime_desc_t * desc) {
if (!desc)
return k_unit_err_undef;

// Note: make sure the unit is being loaded to the correct platform/module target
if (desc->target != unit_header.target)
return k_unit_err_target;

// Note: check API compatibility with the one this unit was built against
if (!UNIT_API_IS_COMPAT(desc->api))
return k_unit_err_api_version;

// Check compatibility of samplerate with unit, for NTS-1 MKII should be 48000
if (desc->samplerate != 48000)
return k_unit_err_samplerate;

// Check compatibility of frame geometry
if (desc->input_channels != 2 || desc->output_channels != 2) // should be stereo input/output
return k_unit_err_geometry;

// Cache the runtime descriptor for later use
s_runtime_desc = *desc;

s_bq_lpf_r.flush();
s_bq_lpf_out_r.flush();
s_bq_lpf_out2_r.flush();
Expand All @@ -78,30 +77,18 @@ void MODFX_INIT(uint32_t platform, uint32_t api)
s_bq_lpf_out2_l.flush();
s_bq_hpf_r.flush();
s_bq_hpf_l.flush();
#if SUBTIMBRE
s_bqs_lpf_r.flush();
s_bqs_lpf_out_r.flush();
s_bqs_lpf_out2_r.flush();
s_bqs_lpf_l.flush();
s_bqs_lpf_out_l.flush();
s_bqs_lpf_out2_l.flush();
s_bqs_hpf_r.flush();
s_bqs_hpf_l.flush();
#endif

init_lpf(LPF_FC, LPF_Q);

float wc = s_bq_hpf_r.mCoeffs.wc(HPF_FC, s_fs_recip);

s_bq_hpf_r.mCoeffs.setSOHP(fx_tanpif(wc), 0.5);
s_bq_hpf_l.mCoeffs = s_bq_hpf_r.mCoeffs;
#if SUBTIMBRE
s_bqs_hpf_r.mCoeffs = s_bq_hpf_r.mCoeffs;
s_bqs_hpf_l.mCoeffs = s_bq_hpf_r.mCoeffs;
#endif

return k_unit_err_none;
}

__fast_inline float g711(const float s) {
fast_inline float g711(const float s) {
q15_t val = f32_to_q15(s);
int16_t sign = (val < 0) ? -1 : 1;
val = q15abs(val);
Expand All @@ -120,78 +107,78 @@ __fast_inline float g711(const float s) {
return q15_to_f32(val);
}

void MODFX_PROCESS(const float *main_xn, float *main_yn,
const float *sub_xn, float *sub_yn,
uint32_t frames)
{
const float * mx = main_xn;
float * __restrict my = main_yn;
const float * my_e = my + 2*frames;

const float * sx = sub_xn;
float * __restrict sy = sub_yn;

float vmx;
float vsx;
for (; my != my_e; ) {

// Left channel
vmx = s_bq_hpf_l.process_so(s_bq_lpf_l.process_so(*mx));
#if SUBTIMBRE
vsx = s_bqs_hpf_l.process_so(s_bqs_lpf_l.process_so(*sx));
#endif

if (count == 0) {
lastmy_l = g711(vmx);
#if SUBTIMBRE
lastsy_l = g711(vsx);
#endif
}

*my++ = dry * (*mx++) + wet * \
s_bq_lpf_out2_l.process_so(s_bq_lpf_out_l.process_so(lastmy_l));
#if SUBTIMBRE
*sy++ = dry * (*sx++) + wet * \
s_bq_lpf_out2_l.process_so(s_bqs_lpf_out_l.process_so(lastsy_l));
#endif
__unit_callback void unit_render(const float * in, float * out, uint32_t frames) {
const float * mx = in;
float * __restrict my = out;
const float * my_e = my + 2*frames;

float vmx;
float vsx;
for (; my != my_e; ) {

// Left channel
vmx = s_bq_hpf_l.process_so(s_bq_lpf_l.process_so(*mx));

if (count == 0) {
lastmy_l = g711(vmx);
}

*my++ = dry * (*mx++) + wet * \
s_bq_lpf_out2_l.process_so(s_bq_lpf_out_l.process_so(lastmy_l));

// Right channel
vmx = s_bq_hpf_r.process_so(s_bq_lpf_r.process_so(*mx));
#if SUBTIMBRE
vsx = s_bqs_hpf_r.process_so(s_bqs_lpf_r.process_so(*sx));
#endif

if (count == 0) {
lastmy_r = g711(vmx);
#if SUBTIMBRE
lastsy_r = g711(vsx);
#endif
}

*my++ = dry * (*mx++) + wet * \
s_bq_lpf_out2_r.process_so(s_bq_lpf_out_r.process_so(lastmy_r));
#if SUBTIMBRE
*sy++ = dry * (*sx++) + wet * \
s_bq_lpf_out2_r.process_so(s_bqs_lpf_out_r.process_so(lastsy_r));
#endif

count = (count + 1) % 6;
}
vmx = s_bq_hpf_r.process_so(s_bq_lpf_r.process_so(*mx));

if (count == 0) {
lastmy_r = g711(vmx);
}

*my++ = dry * (*mx++) + wet * \
s_bq_lpf_out2_r.process_so(s_bq_lpf_out_r.process_so(lastmy_r));

count = (count + 1) % 6;
}
}

__unit_callback void unit_set_param_value(uint8_t id, int32_t value) {
const float valf = param_10bit_to_f32(value);

switch (id) {
case k_user_modfx_param_time:
init_lpf(LPF_FC, LPF_Q + 1.6 * valf);
break;
case k_user_modfx_param_depth:
wet = valf;
dry = 1.0 - wet;
break;
default:
break;
}
s_params[id] = value;
}

__unit_callback void unit_teardown() {
}

__unit_callback void unit_reset() {
}

__unit_callback void unit_resume() {
}

__unit_callback void unit_suspend() {
}

__unit_callback int32_t unit_get_param_value(uint8_t id) {
return s_params[id];
}

__unit_callback const char * unit_get_param_str_value(uint8_t id, int32_t value) {
return nullptr;
}

__unit_callback void unit_set_tempo(uint32_t tempo) {
}

void MODFX_PARAM(uint8_t index, int32_t value)
{
const float valf = q31_to_f32(value);

switch (index) {
case k_user_modfx_param_time:
init_lpf(LPF_FC, LPF_Q + 1.6 * valf);
break;
case k_user_modfx_param_depth:
wet = valf;
dry = 1.0 - wet;
break;
default:
break;
}
__unit_callback void unit_tempo_4ppqn_tick(uint32_t counter) {
}

0 comments on commit 20b8b4c

Please sign in to comment.