Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0015 committed Jul 15, 2021
1 parent a219f69 commit 4950d86
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

a vst plugin for CodeParade's fractal sound explorer program.

BUGGY AF
No longer as buggy, produces clean audio.

TODO: add automation support for changing the fractal type and point(and maybe dampening and volume)
3 changes: 2 additions & 1 deletion plugins/Fractal/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_NUM_INPUTS 2
#define DISTRHO_PLUGIN_NUM_INPUTS 0
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1
#define DISTRHO_PLUGIN_IS_SYNTH 0

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
19 changes: 10 additions & 9 deletions plugins/Fractal/Main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//Constants
static const int target_fps = 60;
static const int sample_rate = 41100;
static int sample_rate = 41100;
static const int max_freq = 4000;
static const int window_w_init = 1280;
static const int window_h_init = 720;
Expand Down Expand Up @@ -137,7 +137,8 @@ class Synth{
bool audio_reset;

static const int NUM_AUDIO_BUFFS = 5;
static const int AUDIO_BUFF_SIZE = 4196;
double DEFAULT_VOLUME = 1;
int AUDIO_BUFF_SIZE = 4196;

struct Chunk {
int16_t* samples;
Expand All @@ -155,7 +156,7 @@ struct Chunk {
Synth(){
audio_reset = true;
audio_pause = false;
volume = 8000.0;
volume = DEFAULT_VOLUME;
play_x = 0.0;
play_y = 0.0;
play_cx = 0.0;
Expand Down Expand Up @@ -190,7 +191,7 @@ struct Chunk {
play_py = play_ny;
mean_x = play_nx;
mean_y = play_ny;
volume = 8000.0;
volume = DEFAULT_VOLUME;
audio_reset = false;
}

Expand All @@ -201,7 +202,7 @@ struct Chunk {

//Generate the tones
const int steps = sample_rate / max_freq;
for (int i = 0; i < frames; i+=2) {
for (int i = 0; i < frames; i++) {
const int j = m_audio_time % steps;
if (j == 0) {
play_px = play_x;
Expand Down Expand Up @@ -257,21 +258,21 @@ struct Chunk {

//Cosine interpolation
double t = double(j) / double(steps);
t = 0.5 - 0.5*std::cos(t * 3.14159);
t = 0.5 - 0.5*std::cos(t * 3.141592653589);
double wx = t*dx + (1.0 - t)*dpx;
double wy = t*dy + (1.0 - t)*dpy;

//Save the audio to the 2 channels
*out1++ = (int16_t)std::min(std::max(wx * volume, -32000.0), 32000.0);
*out2++ = (int16_t)std::min(std::max(wy * volume, -32000.0), 32000.0);
*out1++ = std::min(std::max(wx * volume, -32000.0), 32000.0);
*out2++ = std::min(std::max(wy * volume, -32000.0), 32000.0);
m_audio_time += 1;
}

//Return the sound clip
return !audio_reset;
}

int16_t m_samples[AUDIO_BUFF_SIZE];
//int16_t m_samples[AUDIO_BUFF_SIZE];
int32_t m_audio_time;
double mean_x;
double mean_y;
Expand Down
9 changes: 6 additions & 3 deletions plugins/Fractal/PluginFractal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ DistrhoPluginFractal::DistrhoPluginFractal()
ReadWrite(false),
EnvOld(0.0f)
{
synth = new Synth();
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -82,7 +83,9 @@ void DistrhoPluginFractal::activate()
ReadWrite = false;
EnvOld = 0.0f;
running = true;
GUIthread = std::thread(fractal_main, &running, &synth);
sample_rate = getSampleRate();
synth->AUDIO_BUFF_SIZE = getBufferSize();
GUIthread = std::thread(fractal_main, &running, synth);
}

void DistrhoPluginFractal::deactivate(){
Expand All @@ -105,15 +108,15 @@ void DistrhoPluginFractal::run(const float** inputs, float** outputs, uint32_t f
const float* in2 = inputs[1];
float* out2 = outputs[1];

synth.onGetData(out1, out2, frames);
synth->onGetData(out1, out2, frames);
return;

}


Plugin* createPlugin()
{
return new DistrhoPluginFractal();
return(new DistrhoPluginFractal());
}

// -----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions plugins/Fractal/PluginFractal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class DistrhoPluginFractal : public Plugin

const char* getLabel() const noexcept override
{
return "Node Plugin";
return "FractalSoundExplorer";
}

const char* getDescription() const override
{
return "A node graph of more simple effects to give more interesting resuls.";
return "The Fractal Sound explorer plugin.";
}

const char* getMaker() const noexcept override
Expand Down Expand Up @@ -85,7 +85,7 @@ class DistrhoPluginFractal : public Plugin
float fInputVolume;
bool running = true;
std::thread GUIthread;
Synth synth;
Synth* synth;
//std::vector<audioNode*> nodes;
//audioNodeInput* inputNode1;
//audioNodeOutput* outputNode1;
Expand Down

0 comments on commit 4950d86

Please sign in to comment.