[SCM] calf/master: More cleanup work.
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:40:02 UTC 2013
The following commit has been merged in the master branch:
commit fef852ce9120013bc94dc8c0332cd1c0fc22da87
Author: Krzysztof Foltman <wdev at foltman.com>
Date: Mon Apr 5 16:48:30 2010 +0100
More cleanup work.
Make phaser a normal class instead of template, and move it to a separate file.
Untangle dependencies a little bit by separating organ from other synths. This
increases pessimistic single-threaded build time by one second, but in case
of partial builds there may be a benefit due to avoiding unnecessary compilation.
diff --git a/src/Makefile.am b/src/Makefile.am
index dd7d6a0..7942667 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,7 +52,7 @@ calfbenchmark_CXXFLAGS = $(AM_CXXFLAGS) -DTEST_OSC
calfbenchmark_LDADD += libcalfgui.la
endif
-calf_la_SOURCES = modules.cpp modules_dsp.cpp fluidsynth.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp osctlnet.cpp plugin.cpp preset.cpp synth.cpp utils.cpp wavetable.cpp modmatrix.cpp
+calf_la_SOURCES = audio_fx.cpp modules.cpp modules_dsp.cpp fluidsynth.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp osctlnet.cpp plugin.cpp preset.cpp synth.cpp utils.cpp wavetable.cpp modmatrix.cpp
calf_la_LIBADD ?= $(FLUIDSYNTH_DEPS_LIBS)
if USE_DEBUG
calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -disable-static $(FLUIDSYNTH_DEPS_LIBS)
@@ -69,7 +69,7 @@ calflv2gui_la_LDFLAGS = -rpath $(lv2dir) -avoid-version -module -lexpat -export-
endif
endif
-libcalfstatic_la_SOURCES = modules.cpp modules_dsp.cpp fluidsynth.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp osctlnet.cpp preset.cpp synth.cpp utils.cpp wavetable.cpp modmatrix.cpp
+libcalfstatic_la_SOURCES = audio_fx.cpp modules.cpp modules_dsp.cpp fluidsynth.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp osctlnet.cpp preset.cpp synth.cpp utils.cpp wavetable.cpp modmatrix.cpp
libcalfstatic_la_LDFLAGS = -static -lexpat -disable-shared $(FLUIDSYNTH_DEPS_LIBS)
if USE_GUI
diff --git a/src/audio_fx.cpp b/src/audio_fx.cpp
new file mode 100644
index 0000000..88f6764
--- /dev/null
+++ b/src/audio_fx.cpp
@@ -0,0 +1,119 @@
+/* Calf DSP Library utility application.
+ * Reusable audio effect classes - implementation.
+ * Copyright (C) 2007 Krzysztof Foltman
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#include <calf/audio_fx.h>
+
+using namespace dsp;
+
+simple_phaser::simple_phaser(int _max_stages, float *x1vals, float *y1vals)
+{
+ max_stages = _max_stages;
+ x1 = x1vals;
+ y1 = y1vals;
+
+ set_base_frq(1000);
+ set_mod_depth(1000);
+ set_fb(0);
+ state = 0;
+ cnt = 0;
+ stages = 0;
+ set_stages(_max_stages);
+}
+
+void simple_phaser::set_stages(int _stages)
+{
+ if (_stages > stages)
+ {
+ assert(_stages <= max_stages);
+ if (_stages > max_stages)
+ _stages = max_stages;
+ for (int i = stages; i < _stages; i++)
+ {
+ x1[i] = x1[stages-1];
+ y1[i] = y1[stages-1];
+ }
+ }
+ stages = _stages;
+}
+
+void simple_phaser::reset()
+{
+ cnt = 0;
+ state = 0;
+ phase.set(0);
+ for (int i = 0; i < max_stages; i++)
+ x1[i] = y1[i] = 0;
+ control_step();
+}
+
+void simple_phaser::control_step()
+{
+ cnt = 0;
+ int v = phase.get() + 0x40000000;
+ int sign = v >> 31;
+ v ^= sign;
+ // triangle wave, range from 0 to INT_MAX
+ double vf = (double)((v >> 16) * (1.0 / 16384.0) - 1);
+
+ float freq = base_frq * pow(2.0, vf * mod_depth / 1200.0);
+ freq = dsp::clip<float>(freq, 10.0, 0.49 * sample_rate);
+ stage1.set_ap_w(freq * (M_PI / 2.0) * odsr);
+ phase += dphase * 32;
+ for (int i = 0; i < stages; i++)
+ {
+ dsp::sanitize(x1[i]);
+ dsp::sanitize(y1[i]);
+ }
+ dsp::sanitize(state);
+}
+
+void simple_phaser::process(float *buf_out, float *buf_in, int nsamples)
+{
+ for (int i=0; i<nsamples; i++) {
+ cnt++;
+ if (cnt == 32)
+ control_step();
+ float in = *buf_in++;
+ float fd = in + state * fb;
+ for (int j = 0; j < stages; j++)
+ fd = stage1.process_ap(fd, x1[j], y1[j]);
+ state = fd;
+
+ float sdry = in * gs_dry.get();
+ float swet = fd * gs_wet.get();
+ *buf_out++ = sdry + swet;
+ }
+}
+
+float simple_phaser::freq_gain(float freq, float sr) const
+{
+ typedef std::complex<double> cfloat;
+ freq *= 2.0 * M_PI / sr;
+ cfloat z = 1.0 / exp(cfloat(0.0, freq)); // z^-1
+
+ cfloat p = cfloat(1.0);
+ cfloat stg = stage1.h_z(z);
+
+ for (int i = 0; i < stages; i++)
+ p = p * stg;
+
+ p = p / (cfloat(1.0) - cfloat(fb) * p);
+ return std::abs(cfloat(gs_dry.get_last()) + cfloat(gs_wet.get_last()) * p);
+}
diff --git a/src/calf/audio_fx.h b/src/calf/audio_fx.h
index bf61f94..7d61035 100644
--- a/src/calf/audio_fx.h
+++ b/src/calf/audio_fx.h
@@ -95,26 +95,17 @@ public:
* A monophonic phaser. If you want stereo, combine two :)
* Also, gave up on using template args for signal type.
*/
-template<int MaxStages>
class simple_phaser: public modulation_effect
{
protected:
float base_frq, mod_depth, fb;
float state;
- int cnt, stages;
+ int cnt, stages, max_stages;
dsp::onepole<float, float> stage1;
- float x1[MaxStages], y1[MaxStages];
+ float *x1, *y1;
public:
- simple_phaser()
- {
- set_base_frq(1000);
- set_mod_depth(1000);
- set_fb(0);
- state = 0;
- cnt = 0;
- stages = 0;
- set_stages(6);
- }
+ simple_phaser(int _max_stages, float *x1vals, float *y1vals);
+
float get_base_frq() const {
return base_frq;
}
@@ -124,93 +115,30 @@ public:
int get_stages() const {
return stages;
}
- void set_stages(int _stages) {
- if (_stages > stages)
- {
- for (int i = stages; i < _stages; i++)
- {
- x1[i] = x1[stages-1];
- y1[i] = y1[stages-1];
- }
- }
- stages = _stages;
- }
+ void set_stages(int _stages);
+
float get_mod_depth() const {
return mod_depth;
}
void set_mod_depth(float _mod_depth) {
mod_depth = _mod_depth;
}
+
float get_fb() const {
return fb;
}
void set_fb(float fb) {
this->fb = fb;
}
+
virtual void setup(int sample_rate) {
modulation_effect::setup(sample_rate);
reset();
}
- void reset()
- {
- cnt = 0;
- state = 0;
- phase.set(0);
- for (int i = 0; i < MaxStages; i++)
- x1[i] = y1[i] = 0;
- control_step();
- }
- inline void control_step()
- {
- cnt = 0;
- int v = phase.get() + 0x40000000;
- int sign = v >> 31;
- v ^= sign;
- // triangle wave, range from 0 to INT_MAX
- double vf = (double)((v >> 16) * (1.0 / 16384.0) - 1);
-
- float freq = base_frq * pow(2.0, vf * mod_depth / 1200.0);
- freq = dsp::clip<float>(freq, 10.0, 0.49 * sample_rate);
- stage1.set_ap_w(freq * (M_PI / 2.0) * odsr);
- phase += dphase * 32;
- for (int i = 0; i < stages; i++)
- {
- dsp::sanitize(x1[i]);
- dsp::sanitize(y1[i]);
- }
- dsp::sanitize(state);
- }
- void process(float *buf_out, float *buf_in, int nsamples) {
- for (int i=0; i<nsamples; i++) {
- cnt++;
- if (cnt == 32)
- control_step();
- float in = *buf_in++;
- float fd = in + state * fb;
- for (int j = 0; j < stages; j++)
- fd = stage1.process_ap(fd, x1[j], y1[j]);
- state = fd;
-
- float sdry = in * gs_dry.get();
- float swet = fd * gs_wet.get();
- *buf_out++ = sdry + swet;
- }
- }
- float freq_gain(float freq, float sr) const
- {
- typedef std::complex<double> cfloat;
- freq *= 2.0 * M_PI / sr;
- cfloat z = 1.0 / exp(cfloat(0.0, freq)); // z^-1
-
- cfloat p = cfloat(1.0);
- cfloat stg = stage1.h_z(z);
-
- for (int i = 0; i < stages; i++)
- p = p * stg;
-
- p = p / (cfloat(1.0) - cfloat(fb) * p);
- return std::abs(cfloat(gs_dry.get_last()) + cfloat(gs_wet.get_last()) * p);
- }
+ void reset();
+ void control_step();
+ void process(float *buf_out, float *buf_in, int nsamples);
+ float freq_gain(float freq, float sr) const;
};
/**
diff --git a/src/calf/modules.h b/src/calf/modules.h
index c256b79..5e76cdb 100644
--- a/src/calf/modules.h
+++ b/src/calf/modules.h
@@ -77,18 +77,18 @@ public:
class phaser_audio_module: public audio_module<phaser_metadata>, public frequency_response_line_graph
{
public:
+ enum { MaxStages = 12 };
float *ins[in_count];
float *outs[out_count];
float *params[param_count];
uint32_t srate;
bool clear_reset;
float last_r_phase;
- dsp::simple_phaser<12> left, right;
+ dsp::simple_phaser left, right;
+ float x1vals[2][MaxStages], y1vals[2][MaxStages];
bool is_active;
public:
- phaser_audio_module() {
- is_active = false;
- }
+ phaser_audio_module();
void params_changed();
void params_reset();
void activate();
diff --git a/src/calf/modules_synths.h b/src/calf/modules_synths.h
index d546874..06061df 100644
--- a/src/calf/modules_synths.h
+++ b/src/calf/modules_synths.h
@@ -29,8 +29,8 @@
#include "osc.h"
#include "synth.h"
#include "envelope.h"
-#include "organ.h"
#include "modmatrix.h"
+#include "metadata.h"
namespace calf_plugins {
@@ -149,48 +149,6 @@ public:
uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask);
};
-struct organ_audio_module: public audio_module<organ_metadata>, public dsp::drawbar_organ, public line_graph_iface
-{
-public:
- using drawbar_organ::note_on;
- using drawbar_organ::note_off;
- using drawbar_organ::control_change;
- enum { param_count = drawbar_organ::param_count};
- float *ins[in_count];
- float *outs[out_count];
- float *params[param_count];
- dsp::organ_parameters par_values;
- uint32_t srate;
- bool panic_flag;
- /// Value for configure variable map_curve
- std::string var_map_curve;
-
- organ_audio_module();
-
- void post_instantiate();
-
- void set_sample_rate(uint32_t sr) {
- srate = sr;
- }
- void params_changed();
- inline void pitch_bend(int amt)
- {
- drawbar_organ::pitch_bend(amt);
- }
- void activate();
- void deactivate();
- uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask);
- /// No CV inputs for now
- bool is_cv(int param_no) { return false; }
- /// Practically all the stuff here is noisy
- bool is_noisy(int param_no) { return true; }
- void execute(int cmd_no);
- bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
- char *configure(const char *key, const char *value);
- void send_configures(send_configure_iface *);
- uint32_t message_run(const void *valid_inputs, void *output_ports);
-};
-
};
#if ENABLE_EXPERIMENTAL
diff --git a/src/calf/organ.h b/src/calf/organ.h
index 466342a..c45b6b0 100644
--- a/src/calf/organ.h
+++ b/src/calf/organ.h
@@ -22,6 +22,7 @@
#ifndef __CALF_ORGAN_H
#define __CALF_ORGAN_H
+#include "osc.h"
#include "synth.h"
#include "envelope.h"
#include "metadata.h"
@@ -281,4 +282,50 @@ struct drawbar_organ: public dsp::basic_synth, public calf_plugins::organ_enums
};
+namespace calf_plugins {
+
+struct organ_audio_module: public audio_module<organ_metadata>, public dsp::drawbar_organ, public line_graph_iface
+{
+public:
+ using drawbar_organ::note_on;
+ using drawbar_organ::note_off;
+ using drawbar_organ::control_change;
+ enum { param_count = drawbar_organ::param_count};
+ float *ins[in_count];
+ float *outs[out_count];
+ float *params[param_count];
+ dsp::organ_parameters par_values;
+ uint32_t srate;
+ bool panic_flag;
+ /// Value for configure variable map_curve
+ std::string var_map_curve;
+
+ organ_audio_module();
+
+ void post_instantiate();
+
+ void set_sample_rate(uint32_t sr) {
+ srate = sr;
+ }
+ void params_changed();
+ inline void pitch_bend(int amt)
+ {
+ drawbar_organ::pitch_bend(amt);
+ }
+ void activate();
+ void deactivate();
+ uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask);
+ /// No CV inputs for now
+ bool is_cv(int param_no) { return false; }
+ /// Practically all the stuff here is noisy
+ bool is_noisy(int param_no) { return true; }
+ void execute(int cmd_no);
+ bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
+ char *configure(const char *key, const char *value);
+ void send_configures(send_configure_iface *);
+ uint32_t message_run(const void *valid_inputs, void *output_ports);
+};
+
+};
+
#endif
diff --git a/src/calf/primitives.h b/src/calf/primitives.h
index 79cbe3f..bd68f50 100644
--- a/src/calf/primitives.h
+++ b/src/calf/primitives.h
@@ -25,6 +25,7 @@
#include <map>
#include <cmath>
#include <cstdlib>
+#include <assert.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index 6ef116a..2628dd8 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -32,6 +32,7 @@
#include <calf/jackhost.h>
#include <calf/modules.h>
#include <calf/modules_dev.h>
+#include <calf/organ.h>
#include <calf/gui.h>
#include <calf/preset.h>
#include <calf/preset_gui.h>
diff --git a/src/modules_dsp.cpp b/src/modules_dsp.cpp
index 0e6543b..dfaa18c 100644
--- a/src/modules_dsp.cpp
+++ b/src/modules_dsp.cpp
@@ -126,6 +126,13 @@ void flanger_audio_module::params_reset()
///////////////////////////////////////////////////////////////////////////////////////////////
+phaser_audio_module::phaser_audio_module()
+: left(MaxStages, x1vals[0], y1vals[0])
+, right(MaxStages, x1vals[1], y1vals[1])
+{
+ is_active = false;
+}
+
void phaser_audio_module::set_sample_rate(uint32_t sr)
{
srate = sr;
diff --git a/src/organ.cpp b/src/organ.cpp
index 51f2760..60ca39b 100644
--- a/src/organ.cpp
+++ b/src/organ.cpp
@@ -27,7 +27,7 @@
#include <jack/jack.h>
#endif
#include <calf/giface.h>
-#include <calf/modules_synths.h>
+#include <calf/organ.h>
#include <iostream>
using namespace std;
diff --git a/src/plugin.cpp b/src/plugin.cpp
index e258ad7..12c2f0e 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -23,6 +23,7 @@
#include <calf/lv2wrap.h>
#include <calf/modules.h>
#include <calf/modules_dev.h>
+#include <calf/organ.h>
using namespace calf_plugins;
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list