Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal chain in float32_t #73

Merged
merged 7 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ sudo losetup -d "${DEV}"
rm -r boot

# Write to SD card
sudo dd if="${IMG}" of=/dev/mmcblk0 bs=512k status=progress
sudo dd if="${IMG}" of=/dev/mmcblk0 bs=512k status=progress && sync
```

## Acknowledgements
Expand Down
2 changes: 1 addition & 1 deletion Synth_Dexed
Submodule Synth_Dexed updated from 70293a to e414a8
2 changes: 1 addition & 1 deletion src/Synth_Dexed.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ INCLUDE += -I $(SYNTH_DEXED_DIR)
INCLUDE += -I $(CMSIS_CORE_INCLUDE_DIR)
INCLUDE += -I $(CMSIS_DSP_INCLUDE_DIR)
INCLUDE += -I $(CMSIS_DSP_PRIVATE_INCLUDE_DIR)
CXXFLAGS += -DARM_MATH_NEON
CXXFLAGS += -DARM_MATH_NEON -DHAVE_NEON

EXTRACLEAN = $(SYNTH_DEXED_DIR)/*.[od] $(CMSIS_DSP_SOURCE_DIR)/SupportFunctions/*.[od] $(CMSIS_DSP_SOURCE_DIR)/SupportFunctions/*.[od] $(CMSIS_DSP_SOURCE_DIR)/BasicMathFunctions/*.[od] $(CMSIS_DSP_SOURCE_DIR)/FastMathFunctions/*.[od] $(CMSIS_DSP_SOURCE_DIR)/FilteringFunctions/*.[od] $(CMSIS_DSP_SOURCE_DIR)/CommonTables/*.[od]
21 changes: 21 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#ifndef _common_h
#define _common_h

inline long maplong(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

inline float32_t mapfloat(float32_t val, float32_t in_min, float32_t in_max, float32_t out_min, float32_t out_max)
{
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

#define constrain(amt, low, high) ({ \
__typeof__(amt) _amt = (amt); \
__typeof__(low) _low = (low); \
__typeof__(high) _high = (high); \
(_amt < _low) ? _low : ((_amt > _high) ? _high : _amt); \
})

#endif
5 changes: 3 additions & 2 deletions src/dexedadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#ifndef _dexedadapter_h
#define _dexedadapter_h

Expand Down Expand Up @@ -56,10 +57,10 @@ class CDexedAdapter : public Dexed
m_SpinLock.Release ();
}

void getSamples (uint16_t n_samples, int16_t* buffer)
void getSamples (float32_t* buffer, uint16_t n_samples)
{
m_SpinLock.Acquire ();
Dexed::getSamples (n_samples, buffer);
Dexed::getSamples (buffer, n_samples);
m_SpinLock.Release ();
}

Expand Down
27 changes: 7 additions & 20 deletions src/effect_platervbstereo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ AudioEffectPlateReverb::AudioEffectPlateReverb(float32_t samplerate)
lfo2_phase_acc = 0;
lfo2_adder = (UINT32_MAX + 1)/(samplerate * LFO2_FREQ_HZ);

send_level = 0.0;
reverb_level = 0.0f;
}

// #define sat16(n, rshift) signed_saturate_rshift((n), 16, (rshift))

void AudioEffectPlateReverb::doReverb(uint16_t len, int16_t audioblock[][2])
void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t* inblockR, float32_t* rvbblockL, float32_t* rvbblockR, uint16_t len)
{
int i;
float32_t input, acc, temp1, temp2;
uint16_t temp16;
float32_t rv_time;
Expand Down Expand Up @@ -203,7 +202,7 @@ void AudioEffectPlateReverb::doReverb(uint16_t len, int16_t audioblock[][2])

rv_time = rv_time_k;

for (i=0; i < len; i++)
for (uint16_t i=0; i < len; i++)
{
// do the LFOs
lfo1_phase_acc += lfo1_adder;
Expand Down Expand Up @@ -236,7 +235,7 @@ void AudioEffectPlateReverb::doReverb(uint16_t len, int16_t audioblock[][2])
y += (int64_t)y1 * idx;
lfo2_out_cos = (int32_t) (y >> (32-8)); // 16bit output

input = (float32_t(audioblock[i][0])/32767.0f) * input_attn;
input = inblockL[i] * input_attn;

// chained input allpasses, channel L
acc = in_allp1_bufL[in_allp1_idxL] + input * in_allp_k;
Expand All @@ -259,7 +258,7 @@ void AudioEffectPlateReverb::doReverb(uint16_t len, int16_t audioblock[][2])
in_allp_out_L = acc;
if (++in_allp4_idxL >= sizeof(in_allp4_bufL)/sizeof(float32_t)) in_allp4_idxL = 0;

input = (float32_t(audioblock[i][1])/32767.0f) * input_attn;
input = inblockR[i] * input_attn;

// chained input allpasses, channel R
acc = in_allp1_bufR[in_allp1_idxR] + input * in_allp_k;
Expand Down Expand Up @@ -406,13 +405,7 @@ void AudioEffectPlateReverb::doReverb(uint16_t len, int16_t audioblock[][2])
temp1 = acc - master_lowpass_l;
master_lowpass_l += temp1 * master_lowpass_f;

int32_t out = audioblock[i][0] + int16_t(master_lowpass_l * 32767.0f * send_level);
if(out > INT16_MAX)
audioblock[i][0] = INT16_MAX;
else if(out < INT16_MIN)
audioblock[i][0] = INT16_MIN;
else
audioblock[i][0] = out;
rvbblockL[i] = master_lowpass_l;

// Channel R
#ifdef TAP1_MODULATED
Expand Down Expand Up @@ -456,12 +449,6 @@ void AudioEffectPlateReverb::doReverb(uint16_t len, int16_t audioblock[][2])
temp1 = acc - master_lowpass_r;
master_lowpass_r += temp1 * master_lowpass_f;

out = audioblock[i][1] + int16_t(master_lowpass_l * 32767.0f * send_level);
if(out > INT16_MAX)
audioblock[i][1] = INT16_MAX;
else if(out < INT16_MIN)
audioblock[i][1] = INT16_MIN;
else
audioblock[i][1] = out;
rvbblockR[i] = master_lowpass_r;
}
}
49 changes: 7 additions & 42 deletions src/effect_platervbstereo.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,9 @@
#ifndef _EFFECT_PLATERVBSTEREO_H
#define _EFFECT_PLATERVBSTEREO_H

#include "arm_math.h"
#include <stdint.h>

#define constrain(amt, low, high) ({ \
__typeof__(amt) _amt = (amt); \
__typeof__(low) _low = (low); \
__typeof__(high) _high = (high); \
(_amt < _low) ? _low : ((_amt > _high) ? _high : _amt); \
})

/*
template<typename T>
inline static T min(const T& a, const T& b) {
return a < b ? a : b;
}

template<typename T>
inline static T max(const T& a, const T& b) {
return a > b ? a : b;
}

inline long maplong(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
*/

inline float32_t mapfloat(float32_t val, float32_t in_min, float32_t in_max, float32_t out_min, float32_t out_max)
{
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

#include <arm_math.h>
#include "common.h"

/***
* Loop delay modulation: comment/uncomment to switch sin/cos
Expand All @@ -89,34 +61,28 @@ class AudioEffectPlateReverb
{
public:
AudioEffectPlateReverb(float32_t samplerate);
void doReverb(uint16_t len, int16_t audioblock[][2]);
void doReverb(const float32_t* inblockL, const float32_t* inblockR, float32_t* rvbblockL, float32_t* rvbblockR,uint16_t len);

void size(float n)
{
n = constrain(n, 0.0f, 1.0f);
n = mapfloat(n, 0.0f, 1.0f, 0.2f, rv_time_k_max);
float32_t attn = mapfloat(n, 0.0f, rv_time_k_max, 0.5f, 0.25f);
//__disable_irq();
rv_time_k = n;
input_attn = attn;
//__enable_irq();
}

void hidamp(float n)
{
n = constrain(n, 0.0f, 1.0f);
//__disable_irq();
lp_hidamp_k = 1.0f - n;
//__enable_irq();
}

void lodamp(float n)
{
n = constrain(n, 0.0f, 1.0f);
//__disable_irq();
lp_lodamp_k = -n;
rv_time_scaler = 1.0f - n * 0.12f; // limit the max reverb time, otherwise it will clip
//__enable_irq();
}

void lowpass(float n)
Expand All @@ -130,24 +96,23 @@ class AudioEffectPlateReverb
{
n = constrain(n, 0.0f, 1.0f);
n = mapfloat(n, 0.0f, 1.0f, 0.005f, 0.65f);
//__disable_irq();
in_allp_k = n;
loop_allp_k = n;
//__enable_irq();
}

void send(float n)
void level(float n)
{
send_level = constrain(n, 0.0f, 1.0f);
reverb_level = constrain(n, 0.0f, 1.0f);
}

float32_t get_size(void) {return rv_time_k;}
bool get_bypass(void) {return bypass;}
void set_bypass(bool state) {bypass = state;};
void tgl_bypass(void) {bypass ^=1;}
float32_t get_level(void) {return reverb_level;}
private:
bool bypass = false;
float32_t send_level;
float32_t reverb_level;
float32_t input_attn;

float32_t in_allp_k; // input allpass coeff
Expand Down
Loading