Skip to content

Commit

Permalink
Bugfix: various memory issues/crashes fixed; final commit for v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
snail23 committed Aug 31, 2023
1 parent dcd582c commit 2245d12
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 48 deletions.
7 changes: 6 additions & 1 deletion dep/DaisySP/Source/Effects/chorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

using namespace daisysp;

#define DSY_SDRAM_BSS __attribute__((section(".sdram_bss")))
#define DSY_BUFFER_MAX_SIZE 2400

float DSY_SDRAM_BSS ChorusBuffer[DSY_BUFFER_MAX_SIZE];

//ChorusEngine stuff
void ChorusEngine::Init(float sample_rate)
{
sample_rate_ = sample_rate;

del_.Init();
del_.Init(ChorusBuffer, DSY_BUFFER_MAX_SIZE);
lfo_amp_ = 0.f;
feedback_ = .2f;
SetDelay(.75);
Expand Down
4 changes: 1 addition & 3 deletions dep/DaisySP/Source/Effects/chorus.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class ChorusEngine

private:
float sample_rate_;
static constexpr int32_t kDelayLength
= 2400; // 50 ms at 48kHz = .05 * 48000

//triangle lfos
float lfo_phase_;
Expand All @@ -69,7 +67,7 @@ class ChorusEngine

float delay_;

DelayLine<float, kDelayLength> del_;
DelayLine del_;

float ProcessLfo();
};
Expand Down
8 changes: 7 additions & 1 deletion dep/DaisySP/Source/Effects/flanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

using namespace daisysp;


#define DSY_SDRAM_BSS __attribute__((section(".sdram_bss")))
#define DSY_BUFFER_MAX_SIZE 960

float DSY_SDRAM_BSS FlangerBuffer[DSY_BUFFER_MAX_SIZE];

void Flanger::Init(float sample_rate)
{
sample_rate_ = sample_rate;

SetFeedback(.2f);

del_.Init();
del_.Init(FlangerBuffer, DSY_BUFFER_MAX_SIZE);
lfo_amp_ = 0.f;
SetDelay(.75);

Expand Down
3 changes: 1 addition & 2 deletions dep/DaisySP/Source/Effects/flanger.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class Flanger

private:
float sample_rate_;
static constexpr int32_t kDelayLength = 960; // 20 ms at 48kHz = .02 * 48000

float feedback_;

Expand All @@ -66,7 +65,7 @@ class Flanger

float delay_;

DelayLine<float, kDelayLength> del_;
DelayLine del_;

float ProcessLfo();
};
Expand Down
8 changes: 7 additions & 1 deletion dep/DaisySP/Source/Effects/phaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

using namespace daisysp;


#define DSY_SDRAM_BSS __attribute__((section(".sdram_bss")))
#define DSY_BUFFER_MAX_SIZE 2400

float DSY_SDRAM_BSS PhaserBuffer[DSY_BUFFER_MAX_SIZE];

//PhaserEngine stuff
void PhaserEngine::Init(float sample_rate)
{
sample_rate_ = sample_rate;

del_.Init();
del_.Init(PhaserBuffer, DSY_BUFFER_MAX_SIZE);
lfo_amp_ = 0.f;
feedback_ = .2f;
SetFreq(200.f);
Expand Down
4 changes: 1 addition & 3 deletions dep/DaisySP/Source/Effects/phaser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class PhaserEngine

private:
float sample_rate_;
static constexpr int32_t kDelayLength
= 2400; // 50 ms at 48kHz = .05 * 48000

//triangle lfo
float lfo_phase_;
Expand All @@ -68,7 +66,7 @@ class PhaserEngine
float deltime_;
float last_sample_;

DelayLine<float, kDelayLength> del_;
DelayLine del_;

float ProcessLfo();
};
Expand Down
7 changes: 5 additions & 2 deletions dep/DaisySP/Source/Effects/pitchshifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
//#define SHIFT_BUFFER_SIZE 8192
//#define SHIFT_BUFFER_SIZE 1024

#define DSY_SDRAM_BSS __attribute__((section(".sdram_bss")))
float DSY_SDRAM_BSS ShiftBuffer[SHIFT_BUFFER_SIZE];

namespace daisysp
{
static inline uint32_t hash_xs32(uint32_t x)
Expand Down Expand Up @@ -67,7 +70,7 @@ class PitchShifter
mod_freq_ = 5.0f;
SetSemitones();
gain_ = 0.0f;
d_.Init();
d_.Init(ShiftBuffer, SHIFT_BUFFER_SIZE);
phs_.Init(sr, 50, 0);
shift_up_ = true;
del_size_ = SHIFT_BUFFER_SIZE;
Expand Down Expand Up @@ -167,7 +170,7 @@ class PitchShifter
semitone_ratios_[i] = powf(2.0f, (float)i / 12);
}
}
typedef DelayLine<float, SHIFT_BUFFER_SIZE> ShiftDelay;
typedef DelayLine ShiftDelay;
ShiftDelay d_;
float pitch_shift_, mod_freq_;
uint32_t del_size_;
Expand Down
10 changes: 8 additions & 2 deletions dep/DaisySP/Source/PhysicalModeling/KarplusString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

using namespace daisysp;

#define DSY_SDRAM_BSS __attribute__((section(".sdram_bss")))
#define DSY_BUFFER_MAX_SIZE 1024

float DSY_SDRAM_BSS KarplusBuffer[DSY_BUFFER_MAX_SIZE];
float DSY_SDRAM_BSS KarplusBuffer2[DSY_BUFFER_MAX_SIZE / 4];

void String::Init(float sample_rate)
{
sample_rate_ = sample_rate;
Expand All @@ -14,8 +20,8 @@ void String::Init(float sample_rate)
brightness_ = .5f;
damping_ = .5f;

string_.Init();
stretch_.Init();
string_.Init(KarplusBuffer, DSY_BUFFER_MAX_SIZE);
stretch_.Init(KarplusBuffer2, DSY_BUFFER_MAX_SIZE / 4);
Reset();

SetFreq(440.f);
Expand Down
6 changes: 2 additions & 4 deletions dep/DaisySP/Source/PhysicalModeling/KarplusString.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class String


private:
static constexpr size_t kDelayLineSize = 1024;

enum StringNonLinearity
{
NON_LINEARITY_CURVED_BRIDGE,
Expand All @@ -77,8 +75,8 @@ class String
template <String::StringNonLinearity non_linearity>
float ProcessInternal(const float in);

DelayLine<float, kDelayLineSize> string_;
DelayLine<float, kDelayLineSize / 4> stretch_;
DelayLine string_;
DelayLine stretch_;

float frequency_, non_linearity_amount_, brightness_, damping_;

Expand Down
49 changes: 28 additions & 21 deletions dep/DaisySP/Source/Utility/delayline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@ DelayLine<float, SAMPLE_RATE> del;
By: shensley
*/
template <typename T, size_t max_size>

class DelayLine
{
public:
DelayLine() {}
~DelayLine() {}
/** initializes the delay line by clearing the values within, and setting delay to 1 sample.
*/
void Init() { Reset(); }
void Init(float *buffer, size_t buffer_size)
{
max_size = buffer_size;
line_ = buffer;

Reset();
}
/** clears buffer, sets write ptr to 0, and delay to 1 sample.
*/
void Reset()
{
for(size_t i = 0; i < max_size; i++)
{
line_[i] = T(0);
line_[i] = 0.0f;
}
write_ptr_ = 0;
delay_ = 1;
Expand All @@ -57,43 +63,43 @@ class DelayLine
: max_size - 1;
}

/** writes the sample of type T to the delay line, and advances the write ptr
/** writes the sample of type float to the delay line, and advances the write ptr
*/
inline void Write(const T sample)
inline void Write(const float sample)
{
line_[write_ptr_] = sample;
write_ptr_ = (write_ptr_ - 1 + max_size) % max_size;
}

/** returns the next sample of type T in the delay line, interpolated if necessary.
/** returns the next sample of type float in the delay line, interpolated if necessary.
*/
inline const T Read() const
inline const float Read() const
{
T a = line_[(write_ptr_ + delay_) % max_size];
T b = line_[(write_ptr_ + delay_ + 1) % max_size];
float a = line_[(write_ptr_ + delay_) % max_size];
float b = line_[(write_ptr_ + delay_ + 1) % max_size];
return a + (b - a) * frac_;
}

/** Read from a set location */
inline const T Read(float delay) const
inline const float Read(float delay) const
{
int32_t delay_integral = static_cast<int32_t>(delay);
float delay_fractional = delay - static_cast<float>(delay_integral);
const T a = line_[(write_ptr_ + delay_integral) % max_size];
const T b = line_[(write_ptr_ + delay_integral + 1) % max_size];
const float a = line_[(write_ptr_ + delay_integral) % max_size];
const float b = line_[(write_ptr_ + delay_integral + 1) % max_size];
return a + (b - a) * delay_fractional;
}

inline const T ReadHermite(float delay) const
inline const float ReadHermite(float delay) const
{
int32_t delay_integral = static_cast<int32_t>(delay);
float delay_fractional = delay - static_cast<float>(delay_integral);

int32_t t = (write_ptr_ + delay_integral + max_size);
const T xm1 = line_[(t - 1) % max_size];
const T x0 = line_[(t) % max_size];
const T x1 = line_[(t + 1) % max_size];
const T x2 = line_[(t + 2) % max_size];
const float xm1 = line_[(t - 1) % max_size];
const float x0 = line_[(t) % max_size];
const float x1 = line_[(t + 1) % max_size];
const float x2 = line_[(t + 2) % max_size];
const float c = (x1 - xm1) * 0.5f;
const float v = x0 - x1;
const float w = c + v;
Expand All @@ -103,10 +109,10 @@ class DelayLine
return (((a * f) - b_neg) * f + c) * f + x0;
}

inline const T Allpass(const T sample, size_t delay, const T coefficient)
inline const float Allpass(const float sample, size_t delay, const float coefficient)
{
T read = line_[(write_ptr_ + delay) % max_size];
T write = sample + coefficient * read;
float read = line_[(write_ptr_ + delay) % max_size];
float write = sample + coefficient * read;
Write(write);
return -write * coefficient + read;
}
Expand All @@ -115,7 +121,8 @@ class DelayLine
float frac_;
size_t write_ptr_;
size_t delay_;
T line_[max_size];
size_t max_size;
float *line_;
};
} // namespace daisysp
#endif
2 changes: 1 addition & 1 deletion dep/SSD1351-Driver-Library/src/ssd1351.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ssd1351.h"
#include <string.h>

DisplayRAM DRAM;
DisplayRAM __attribute__((section(".sdram_bss"))) DRAM;
#define DRAM_16 DRAM.halfw
#define DRAM_8 DRAM.byte

Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// https://github.com/snail23/ironpedal

#define PROFILES 20 // 416 bytes per profile
#define VERSION "1.1.1"
#define VERSION "1.1.2"
6 changes: 4 additions & 2 deletions src/effects/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Effect
{
float DSY_SDRAM_BSS DelayBuffer[2400];

class Delay
{
public:
Expand All @@ -12,7 +14,7 @@ namespace Effect

this->delay.Init(this->ironpedal->knobs[PedalPCB::KNOB_2], 0.0f, 50.01f, daisy::Parameter::LINEAR);

this->delay_line.Init();
this->delay_line.Init(DelayBuffer, sizeof(DelayBuffer) / sizeof(float));
this->delay_line.SetDelay((size_t)(this->ironpedal->AudioSampleRate() / this->ironpedal->GetEffect(EFFECT_DELAY).values[PedalPCB::KNOB_2]));
}

Expand Down Expand Up @@ -50,7 +52,7 @@ namespace Effect

private:
daisy::Parameter delay;
daisysp::DelayLine<float, 48000 / 50> delay_line;
daisysp::DelayLine delay_line;

Snailsoft::Ironpedal *ironpedal;
};
Expand Down
6 changes: 3 additions & 3 deletions src/effects/looper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Effect
{
float DSY_SDRAM_BSS Buffer[48000 * 60 * 5];
float DSY_SDRAM_BSS LooperBuffer[48000 * 60 * 5];

class Looper
{
Expand Down Expand Up @@ -42,10 +42,10 @@ namespace Effect
for (size_t i = 0; i < size; ++i)
{
if (this->ironpedal->GetEffect(EFFECT_LOOPER).values[PedalPCB::KNOB_2] > 0.5f)
Buffer[this->buffer_size = this->buffer_size < sizeof(Buffer) / sizeof(float) ? this->buffer_size + 1 : 0] = in[i];
LooperBuffer[this->buffer_size = this->buffer_size < sizeof(LooperBuffer) / sizeof(float) ? this->buffer_size + 1 : 0] = in[i];

else
out[i] = in[i] + Buffer[this->buffer_index = this->buffer_index < this->buffer_size ? this->buffer_index + 1 : 0] * this->ironpedal->GetEffect(EFFECT_LOOPER).values[PedalPCB::KNOB_5];
out[i] = in[i] + LooperBuffer[this->buffer_index = this->buffer_index < this->buffer_size ? this->buffer_index + 1 : 0] * this->ironpedal->GetEffect(EFFECT_LOOPER).values[PedalPCB::KNOB_5];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/effects/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Effect
{
if (this->ironpedal->GetEffect(i).enabled)
{
sprintf(buf, "%s%s%u", buf, first ? "" : ", ", i);
sprintf(buf, first ? "%s%u" : "%s, %u", buf, i);

if (first)
first = false;
Expand Down

0 comments on commit 2245d12

Please sign in to comment.