Skip to content

Commit

Permalink
Improved harmonik functionality by adding an additional harmonic osci…
Browse files Browse the repository at this point in the history
…llator
  • Loading branch information
leandrob13 committed Apr 5, 2022
1 parent 9d9a6a0 commit b22074c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 29 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ In order to run user units built with SDK version 1.1-0, the following firmware

## Compiled Oscillators

The compiled oscillators are found in the oscillators folder under its respective platform name:
- nts-1.
- minilogue-xd.
The compiled oscillators are found in the releases section of this repo.

## Prerequisites

Expand Down
4 changes: 2 additions & 2 deletions builds/nts-1/osc/harmon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"api" : "1.1-0",
"dev_id" : 0,
"prg_id" : 0,
"version" : "0.1-0",
"version" : "1.0-0",
"name" : "harm",
"num_param" : 6,
"params" : [
["ROOT", 0, 100, "%"],
["P1", 0, 100, "%"],
["P2", 0, 100, "%"],
["P3", 0, 100, "%"],
["P4", 0, 100, "%"],
["P5", 0, 100, "%"],
["SPRD", 0, 2, "%"]
]
}
Expand Down
2 changes: 1 addition & 1 deletion builds/nts-1/osc/kord/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"api" : "1.1-0",
"dev_id" : 0,
"prg_id" : 0,
"version" : "0.1-0",
"version" : "1.0-0",
"name" : "kord",
"num_param" : 6,
"params" : [
Expand Down
Binary file removed oscillators/nts-1/harmonikv1.0.ntkdigunit
Binary file not shown.
Binary file removed oscillators/nts-1/subharmonikorgv1.1.ntkdigunit
Binary file not shown.
35 changes: 15 additions & 20 deletions src/nts-1/osc/harmon/harmon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ static Oscillator osc;
void OSC_INIT(uint32_t platform, uint32_t api) {
osc.drive = 0.f;
osc.spread = harmonic;

}

static inline float fold(float x) {
Expand Down Expand Up @@ -47,34 +46,25 @@ void OSC_CYCLE(
int32_t *yn,
const uint32_t frames
) {
float signals[5] = { 0 };
const float w0 = osc_w0f_for_note((params->pitch)>>8, params->pitch & 0xFF);
const float drive = osc.drive;
const float lfo = q31_to_f32(params->shape_lfo);

q31_t * __restrict y = (q31_t *)yn;
const q31_t * y_e = y + frames;

for (; y != y_e; ) {
for (int i = 0; i < 5; i++) {
float sig = 0.f;
for (int i = 0; i < 6; i++) {
float p = osc.phases[i];
float g = osc.gains[i];
int div = spread(i);
float w = w0 * div;
p = (p < 0.f) ? 1.f - p : p - (uint32_t)p;
float folded = 0.75f * (drive + lfo) * fold(osc_sinf(p));
float folded = 0.75f * (osc.drive + lfo) * fold(osc_sinf(p));
p = p + folded;
signals[i] = (osc_sinf(p)) * g;
sig += osc_sinf(p) * osc.gains[i];
osc.phases[i] += w;
osc.phases[i] -= (uint32_t)osc.phases[i];
}

// Main signal
float sig = 0.f;
for (int i = 0; i < 5 ; i++) {
sig += signals[i];
}
sig *= osc.total_gain;

*(y++) = f32_to_q31(sig);
}
Expand All @@ -88,24 +78,29 @@ void OSC_NOTEOFF(const user_osc_param_t * const params) {
(void)params;
}

float scale_input(int value) {
float ratio = (float)value / 100.f;
return ratio / 6.f;
}

void OSC_PARAM(uint16_t index, uint16_t value) {
const float valf = param_val_to_f32(value);

switch (index) {
case k_user_osc_param_id1:
osc.gains[0] = valf;
osc.gains[1] = scale_input(value);
break;
case k_user_osc_param_id2:
osc.gains[1] = valf;
osc.gains[2] = scale_input(value);
break;
case k_user_osc_param_id3:
osc.gains[2] = valf;
osc.gains[3] = scale_input(value);
break;
case k_user_osc_param_id4:
osc.gains[3] = valf;
osc.gains[4] = scale_input(value);
break;
case k_user_osc_param_id5:
osc.gains[4] = valf;
osc.gains[5] = scale_input(value);
break;
case k_user_osc_param_id6:
switch (value) {
Expand All @@ -124,7 +119,7 @@ void OSC_PARAM(uint16_t index, uint16_t value) {
osc.drive = valf;
break;
case k_user_osc_param_shiftshape:
osc.total_gain = valf * 5.f;
osc.gains[0] = valf / 6.f;
break;
default:
break;
Expand Down
5 changes: 2 additions & 3 deletions src/nts-1/osc/harmon/harmon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ typedef enum {
} Spread;

typedef struct Oscillator {
float phases[5] = { 0 };
float gains[5]= { 1.f, 0.f, 0.f, 0.f, 0.f };
float phases[6] = { 0 };
float gains[6]= { 0.17, 0.f, 0.f, 0.f, 0.f, 0.f };
float drive;
Spread spread;
float total_gain;
} Oscillator;

0 comments on commit b22074c

Please sign in to comment.