Skip to content

Commit

Permalink
Moves DustGate into the sig_dsp namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbdclark committed Nov 5, 2023
1 parent 6ab885c commit 5c9de1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ struct sig_daisy_FilteredCVIn* durationKnob;
struct sig_daisy_AudioIn* clockIn;
struct sig_dsp_ClockFreqDetector* clockFrequency;
struct sig_dsp_BinaryOp* densityClockSum;
struct cc_sig_DustGate* cvDustGate;
struct sig_dsp_DustGate* cvDustGate;
struct sig_dsp_BinaryOp* audioDensity;
struct sig_dsp_ConstantValue* audioDensityScale;
struct cc_sig_DustGate* audioDustGate;
struct sig_dsp_DustGate* audioDustGate;
struct sig_daisy_CVOut* dustCVOut;
struct sig_daisy_CVOut* clockCVOut;
struct sig_daisy_AudioOut* leftAudioOut;
Expand Down Expand Up @@ -100,7 +100,7 @@ void buildGraph(struct sig_SignalContext* context, struct sig_Status* status) {
densityClockSum->inputs.left = clockFrequency->outputs.main;
densityClockSum->inputs.right = densityKnob->outputs.main;

cvDustGate = cc_sig_DustGate_new(&allocator, context);
cvDustGate = sig_dsp_DustGate_new(&allocator, context);
sig_List_append(&signals, cvDustGate, status);
cvDustGate->inputs.density = densityClockSum->outputs.main;
cvDustGate->inputs.durationPercentage = durationKnob->outputs.main;
Expand All @@ -124,7 +124,7 @@ void buildGraph(struct sig_SignalContext* context, struct sig_Status* status) {
audioDensity->inputs.left = densityClockSum->outputs.main;
audioDensity->inputs.right = audioDensityScale->outputs.main;

audioDustGate = cc_sig_DustGate_new(&allocator, context);
audioDustGate = sig_dsp_DustGate_new(&allocator, context);
sig_List_append(&signals, audioDustGate, status);
audioDustGate->parameters.bipolar = 1.0f;
audioDustGate->inputs.density = audioDensity->outputs.main;
Expand Down
20 changes: 10 additions & 10 deletions libsignaletic/include/libsignaletic.h
Original file line number Diff line number Diff line change
Expand Up @@ -1414,36 +1414,36 @@ void sig_dsp_TimedGate_destroy(struct sig_Allocator* allocator,
struct sig_dsp_TimedGate* self);


struct cc_sig_DustGate_Inputs {
struct sig_dsp_DustGate_Inputs {
float_array_ptr density;
float_array_ptr durationPercentage;
};

struct cc_sig_DustGate_Parameters {
struct sig_dsp_DustGate_Parameters {
float bipolar;
};

struct cc_sig_DustGate {
struct sig_dsp_DustGate {
struct sig_dsp_Signal signal;
struct cc_sig_DustGate_Inputs inputs;
struct cc_sig_DustGate_Parameters parameters;
struct sig_dsp_DustGate_Inputs inputs;
struct sig_dsp_DustGate_Parameters parameters;
struct sig_dsp_Signal_SingleMonoOutput outputs;
struct sig_dsp_Dust* dust;
struct sig_dsp_BinaryOp* reciprocalDensity;
struct sig_dsp_BinaryOp* densityDurationMultiplier;
struct sig_dsp_TimedGate* gate;
};

struct cc_sig_DustGate* cc_sig_DustGate_new(struct sig_Allocator* allocator,
struct sig_dsp_DustGate* sig_dsp_DustGate_new(struct sig_Allocator* allocator,
struct sig_SignalContext* context);

void cc_sig_DustGate_init(struct cc_sig_DustGate* self,
void sig_dsp_DustGate_init(struct sig_dsp_DustGate* self,
struct sig_SignalContext* context);

void cc_sig_DustGate_generate(void* signal);
void sig_dsp_DustGate_generate(void* signal);

void cc_sig_DustGate_destroy(struct sig_Allocator* allocator,
struct cc_sig_DustGate* self);
void sig_dsp_DustGate_destroy(struct sig_Allocator* allocator,
struct sig_dsp_DustGate* self);


struct sig_dsp_ClockFreqDetector_Inputs {
Expand Down
22 changes: 12 additions & 10 deletions libsignaletic/src/libsignaletic.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ inline float sig_clamp(float value, float min, float max) {
return sig_fminf(sig_fmaxf(value, min), max);
}

// TODO: Implement a fast fmodf
// See: https://github.com/electro-smith/DaisySP/blob/0cc02b37579e3619efde73be49a1fa01ffee5cf6/Source/Utility/dsp.h#L89-L95
// TODO: Unit tests
inline float sig_flooredfmodf(float numer, float denom) {
float remain = fmodf(numer, denom);
Expand Down Expand Up @@ -1789,10 +1791,10 @@ void sig_dsp_TimedGate_destroy(struct sig_Allocator* allocator,
}


struct cc_sig_DustGate* cc_sig_DustGate_new(struct sig_Allocator* allocator,
struct sig_dsp_DustGate* sig_dsp_DustGate_new(struct sig_Allocator* allocator,
struct sig_SignalContext* context) {
struct cc_sig_DustGate* self = sig_MALLOC(allocator,
struct cc_sig_DustGate);
struct sig_dsp_DustGate* self = sig_MALLOC(allocator,
struct sig_dsp_DustGate);

self->reciprocalDensity = sig_dsp_Div_new(allocator, context);
self->reciprocalDensity->inputs.left = context->unity->outputs.main;
Expand All @@ -1808,22 +1810,22 @@ struct cc_sig_DustGate* cc_sig_DustGate_new(struct sig_Allocator* allocator,
self->gate->inputs.duration =
self->densityDurationMultiplier->outputs.main;

cc_sig_DustGate_init(self, context);
sig_dsp_DustGate_init(self, context);
self->outputs.main = self->gate->outputs.main;

return self;
}


void cc_sig_DustGate_init(struct cc_sig_DustGate* self,
void sig_dsp_DustGate_init(struct sig_dsp_DustGate* self,
struct sig_SignalContext* context) {
sig_dsp_Signal_init(self, context, *cc_sig_DustGate_generate);
sig_dsp_Signal_init(self, context, *sig_dsp_DustGate_generate);
sig_CONNECT_TO_SILENCE(self, density, context);
sig_CONNECT_TO_SILENCE(self, durationPercentage, context);
};

void cc_sig_DustGate_generate(void* signal) {
struct cc_sig_DustGate* self = (struct cc_sig_DustGate*) signal;
void sig_dsp_DustGate_generate(void* signal) {
struct sig_dsp_DustGate* self = (struct sig_dsp_DustGate*) signal;

// Bind all parameters (remove this when we have change events).
self->dust->inputs.density = self->inputs.density;
Expand All @@ -1842,8 +1844,8 @@ void cc_sig_DustGate_generate(void* signal) {
}


void cc_sig_DustGate_destroy(struct sig_Allocator* allocator,
struct cc_sig_DustGate* self) {
void sig_dsp_DustGate_destroy(struct sig_Allocator* allocator,
struct sig_dsp_DustGate* self) {
sig_dsp_TimedGate_destroy(allocator, self->gate);

sig_dsp_Mul_destroy(allocator, self->densityDurationMultiplier);
Expand Down

0 comments on commit 5c9de1e

Please sign in to comment.