Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# Prism change log
2.4.0

Rainbow:
~33% to ~50% Rack CPU load improvement - thanks [@danngreen](https://github.com/danngreen)
* Populate state only when needed
* Added faster brown noise gen
* Use std::clamp
* Some type changes

Audio: Optimized output summing

Small fixes for Spread and Morph

CI builds: use C++17 for ``std::clamp``

2.3.4
* Rainbow: Fix intermittent wayward output levels in audio processor (due to Audio module init bug)
* Rainbow: Fix CPU mode menu
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# FLAGS will be passed to both the C and C++ compiler
FLAGS += -flto
CFLAGS +=
CXXFLAGS +=
CXXFLAGS += -std=c++17

# Careful about linking to shared libraries, since you can't assume much about the user's environment and library search path.
# Static libraries are fine.
Expand All @@ -19,3 +19,5 @@ RACK_DIR ?= ../..

# Include the VCV Rack plugin Makefile framework
include $(RACK_DIR)/plugin.mk

CXXFLAGS := $(filter-out -std=c++11,$(CXXFLAGS))
13 changes: 4 additions & 9 deletions src/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void Audio::ChannelProcess1(rainbow::IO &io, rack::engine::Input &input, rack::e
nInputBuffer[i].startIncr(inLen);

for (int j = 0; j < NUM_SAMPLES; j++) {
int32_t v = (int32_t)clamp(nInputFrames[i][j].samples[0] * MAX_12BIT, MIN_12BIT, MAX_12BIT);
int32_t v = std::clamp(nInputFrames[i][j].samples[0] * MAX_12BIT, MIN_12BIT, MAX_12BIT);

switch(inChannels) {
case 1:
Expand Down Expand Up @@ -89,14 +89,9 @@ void Audio::ChannelProcess1(rainbow::IO &io, rack::engine::Input &input, rack::e
filterbank.process_audio_block();

// Convert output buffer
for (int chan = 0; chan < NUM_CHANNELS; chan++) {
for (int i = 0; i < NUM_SAMPLES; i++) {
outputFrames1[i].samples[0] = 0;
}
}

for (int chan = 0; chan < NUM_CHANNELS; chan++) {
for (int i = 0; i < NUM_SAMPLES; i++) {
for (int i = 0; i < NUM_SAMPLES; i++) {
outputFrames1[i].samples[0] = 0;
for (int chan = 0; chan < NUM_CHANNELS; chan++) {
outputFrames1[i].samples[0] += io.out[chan][i] / MAX_12BIT;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace prism::core {

const double PI = 3.14159265358979323846264338327950288;
constexpr static double PI = 3.14159265358979323846264338327950288;

struct PrismModule : rack::Module {
PrismModule(int numParams, int numInputs, int numOutputs, int numLights = 0) {
Expand Down
58 changes: 25 additions & 33 deletions src/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void Filter::filter_twopass(FilterBank *fb, float **filter_out) {
// limit q knob range on second filter
if (qc[channel_num] < 3900.0f) {
qval_b[channel_num] = 1000.0f;
} else if (qc[channel_num] >= 3900.0f) {
} else {
qval_b[channel_num] = 1000.0f + (qc[channel_num] - 3900.0f) * 15.0f;
} // 1000 to 3925

Expand Down Expand Up @@ -150,7 +150,6 @@ void Filter::filter_twopass(FilterBank *fb, float **filter_out) {
filter_out_b[j][i] = buf[channel_num][scale_num][filter_num][1];

filter_out[j][i] = (ratio_a * filter_out_a[j][i]) - filter_out_b[j][i]; // output of filter two needs to be inverted to avoid phase cancellation

}

// Set VOCT output
Expand Down Expand Up @@ -442,42 +441,40 @@ void Filter::filter_bpre(FilterBank *fb, float **filter_out) {

void Filter::reset_buffer(int i, bool twopass) {

float *ff = (float *)buf[i];
float *ff = reinterpret_cast<float *>(buf[i]);
for (int j = 0; j < (NUM_SCALES * NUM_FILTS); j++) {
*(ff+j) = 0.0f;
*(ff+j+1) = 0.0f;
*(ff+j+2) = 0.0f;
*(ff+j) = 0.0f;
*(ff+j+1) = 0.0f;
*(ff+j+2) = 0.0f;
}

if (twopass) {
float *ffa = (float *)buf_a[i];
float *ffa = reinterpret_cast<float *>(buf_a[i]);
for (int j = 0; j < (NUM_SCALES * NUM_FILTS); j++) {
*(ffa+j) = 0.0f;
*(ffa+j+1) = 0.0f;
*(ffa+j+2) = 0.0f;
*(ffa+j) = 0.0f;
*(ffa+j+1) = 0.0f;
*(ffa+j+2) = 0.0f;
}
}

}

void MaxQFilter::reset(FilterBank *fb) {

float *ff = (float *)buf;
float *ff = reinterpret_cast<float *>(buf);
for (int j = 0; j < (NUM_SCALES * NUM_FILTS); j++) {
*(ff+j) = 0.0f;
*(ff+j+1) = 0.0f;
*(ff+j+2) = 0.0f;
*(ff+j) = 0.0f;
*(ff+j+1) = 0.0f;
*(ff+j+2) = 0.0f;
}

if (fb->filter_mode == TWOPASS) {
float *ffa = (float *)buf_a;
float *ffa = reinterpret_cast<float *>(buf_a);
for (int j = 0; j < (NUM_SCALES * NUM_FILTS); j++) {
*(ffa+j) = 0.0f;
*(ffa+j+1) = 0.0f;
*(ffa+j+2) = 0.0f;
*(ffa+j) = 0.0f;
*(ffa+j+1) = 0.0f;
*(ffa+j+2) = 0.0f;
}
}

}

void MaxQFilter::filter(FilterBank *fb, int channel_num, float **filter_out) {
Expand All @@ -487,7 +484,6 @@ void MaxQFilter::filter(FilterBank *fb, int channel_num, float **filter_out) {
} else {
onepass(fb, channel_num, filter_out);
}

}

void MaxQFilter::onepass(FilterBank *fb, int channel_num, float **filter_out) {
Expand Down Expand Up @@ -576,7 +572,6 @@ void MaxQFilter::onepass(FilterBank *fb, int channel_num, float **filter_out) {
}
}
}

}

void MaxQFilter::twopass(FilterBank *fb, int channel_num, float **filter_out) {
Expand Down Expand Up @@ -616,13 +611,13 @@ void MaxQFilter::twopass(FilterBank *fb, int channel_num, float **filter_out) {
// limit q knob range on second filter
if (qc < 3900.0f) {
qval_b = 1000.0f;
} else if (qc >= 3900.0f) {
} else {
qval_b = 1000.0f + (qc - 3900.0f) * 15.0f;
} // 1000 to 3925

// Q/RESONANCE: c0 = 1 - 2/(decay * samplerate), where decay is around 0.01 to 4.0
uint32_t qval_b_idx = (qval_b / 1.4f) + 200;
qval_b_idx = clamp(qval_b_idx, 200, 3125);
qval_b_idx = std::clamp<uint32_t>(qval_b_idx, 200, 3125);

if (fb->io->HICPUMODE) {
c0_a = 1.0f - exp_4096[(uint32_t)(qval_a / 1.4f) + 200] / 10.0f; //exp[200...3125]
Expand Down Expand Up @@ -663,8 +658,8 @@ void MaxQFilter::twopass(FilterBank *fb, int channel_num, float **filter_out) {
// FIXME: 43801543.68f gain could be directly printed into calibration vector

// AMPLITUDE: Boost high freqs and boost low resonance
c2_a = (0.003f * c1) - (0.1f * c0_a) + 0.102f;
c2 = (0.003f * c1) - (0.1f * c0) + 0.102f;
c2_a = (0.003f * c1) - (0.1f * c0_a) + 0.102f;
c2 = (0.003f * c1) - (0.1f * c0) + 0.102f;
c2 *= ratio_b;

ptmp_i32 = fb->io->in[channel_num];
Expand All @@ -691,7 +686,6 @@ void MaxQFilter::twopass(FilterBank *fb, int channel_num, float **filter_out) {
filter_out_b[filter_index][sample_index] = buf[scale_num][filter_num][1];

filter_out[filter_index][sample_index] = (ratio_a * filter_out_a[filter_index][sample_index]) - filter_out_b[filter_index][sample_index]; // output of filter two needs to be inverted to avoid phase cancellation

}

// Set VOCT output
Expand Down Expand Up @@ -758,13 +752,12 @@ void MaxQFilter::twopass(FilterBank *fb, int channel_num, float **filter_out) {

void BpreFilter::reset(FilterBank *fb) {

float *ff = (float *)buf;
float *ff = reinterpret_cast<float *>(buf);
for (int j = 0; j < (NUM_SCALES * NUM_FILTS); j++) {
*(ff+j) = 0.0f;
*(ff+j+1) = 0.0f;
*(ff+j+2) = 0.0f;
*(ff+j) = 0.0f;
*(ff+j+1) = 0.0f;
*(ff+j+2) = 0.0f;
}

}

void BpreFilter::filter(FilterBank *fb, int channel_num, float **filter_out) {
Expand Down Expand Up @@ -872,7 +865,6 @@ void BpreFilter::filter(FilterBank *fb, int channel_num, float **filter_out) {
buf[scale_num][filter_num][1] = iir;

filter_out[filter_index][sample_index] = fir;

}

// VOCT output with glissando
Expand Down
25 changes: 5 additions & 20 deletions src/Q.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* params.c - Parameters
*
Expand Down Expand Up @@ -28,13 +27,12 @@
*/

#include <math.h>

#include "Rainbow.hpp"

using namespace rainbow;

void Q::configure(IO *_io) {
io = _io;
io = _io;
}

void Q::update(void) {
Expand All @@ -44,26 +42,14 @@ void Q::update(void) {

float lpf = io->HICPUMODE ? Q_LPF_96 : Q_LPF_48;

//Check jack + LPF
int32_t qg = io->GLOBAL_Q_LEVEL + io->GLOBAL_Q_CONTROL;
if (qg < 0) {
qg = 0;
}
if (qg > 4095) {
qg = 4095;
}
//Check jack + LPF
int32_t qg = std::clamp<int32_t>(io->GLOBAL_Q_LEVEL + io->GLOBAL_Q_CONTROL, 0, 4095);

global_lpf *= lpf;
global_lpf += (1.0f - lpf) * qg;

for (int i = 0; i < NUM_CHANNELS; i++){
int32_t qc = io->CHANNEL_Q_LEVEL[i] + io->CHANNEL_Q_CONTROL[i];
if (qc < 0) {
qc = 0;
}
if (qc > 4095) {
qc = 4095;
}
int32_t qc = std::clamp<int32_t>(io->CHANNEL_Q_LEVEL[i] + io->CHANNEL_Q_CONTROL[i], 0, 4095);

qlockpot_lpf[i] *= lpf;
qlockpot_lpf[i] += (1.0f - lpf) * qc;
Expand All @@ -81,5 +67,4 @@ void Q::update(void) {
for (int i = 0; i < NUM_CHANNELS; i++) {
qval[i] = (uint32_t)(prev_qval[i] + (q_update_ctr * (qval_goal[i] - prev_qval[i]) / 51.0f)); // Q_UPDATE_RATE + 1
}

}
}
Loading