[SCM] calf/master: + Small plugins: add square and saw oscillators
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:37:35 UTC 2013
The following commit has been merged in the master branch:
commit 0a8c545bacbebd46129135b5473491c12702cde6
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date: Thu Sep 18 18:35:16 2008 +0000
+ Small plugins: add square and saw oscillators
git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@289 78b06b96-2940-0410-b7fc-879d825d01d8
diff --git a/src/calf/lv2wrap.h b/src/calf/lv2wrap.h
index 9c9c303..c81fb65 100644
--- a/src/calf/lv2wrap.h
+++ b/src/calf/lv2wrap.h
@@ -291,7 +291,7 @@ struct lv2_small_wrapper
{
instance *mod = new instance();
// XXXKF some people use fractional sample rates; we respect them ;-)
- mod->srate = (uint32_t)sample_rate;
+ mod->set_sample_rate((uint32_t)sample_rate);
return mod;
}
diff --git a/src/calf/modulelist.h b/src/calf/modulelist.h
index 9caee66..df98076 100644
--- a/src/calf/modulelist.h
+++ b/src/calf/modulelist.h
@@ -20,6 +20,8 @@
PER_SMALL_MODULE_ITEM(small_mul)
PER_SMALL_MODULE_ITEM(small_neg)
PER_SMALL_MODULE_ITEM(small_map_lin2exp)
+ PER_SMALL_MODULE_ITEM(small_square_osc)
+ PER_SMALL_MODULE_ITEM(small_saw_osc)
#endif
#undef PER_MODULE_ITEM
#undef PER_SMALL_MODULE_ITEM
diff --git a/src/calf/modules_small.h b/src/calf/modules_small.h
index d3a1cec..9d6ef38 100644
--- a/src/calf/modules_small.h
+++ b/src/calf/modules_small.h
@@ -51,7 +51,7 @@ public:
uint32_t srate;
void activate() {
- filter.reset();
+ filter.reset_d1();
}
void set_sample_rate(uint32_t sr) {
srate = sr;
@@ -314,6 +314,101 @@ public:
}
};
+#define SMALL_OSC_TABLE_BITS 12
+
+class small_freq_only_osc_audio_module: public null_audio_module
+{
+public:
+ typedef waveform_family<SMALL_OSC_TABLE_BITS> waves_type;
+ enum { in_freq, in_count };
+ enum { out_signal, out_count};
+ enum { wave_size = 1 << SMALL_OSC_TABLE_BITS };
+ float *ins[in_count];
+ float *outs[out_count];
+ waves_type *waves;
+ waveform_oscillator<SMALL_OSC_TABLE_BITS> osc;
+ uint32_t srate;
+ double odsr;
+
+ /// Fill the array with the original, non-bandlimited, waveform
+ virtual void get_original_waveform(float data[wave_size]) = 0;
+ /// This function needs to be virtual to ensure a separate wave family for each class (but not each instance)
+ virtual waves_type *get_waves() = 0;
+ void activate() {
+ waves = get_waves();
+ }
+ void set_sample_rate(uint32_t sr) {
+ srate = sr;
+ odsr = 1.0 / sr;
+ }
+ void process(uint32_t count)
+ {
+ osc.set_freq_odsr(*ins[in_freq], odsr);
+ osc.waveform = waves->get_level(osc.phasedelta);
+ if (osc.waveform)
+ {
+ for (uint32_t i = 0; i < count; i++)
+ outs[out_signal][i] = osc.get();
+ }
+ else
+ dsp::zero(outs[out_signal], count);
+ }
+ static void port_info(plugin_info_iface *pii)
+ {
+ pii->control_port("freq", "Frequency", 440).input().log_range(20, 20000);
+ pii->audio_port("out", "Out").output();
+ }
+ /// Generate a wave family (bandlimit levels) from the original wave
+ waves_type *create_waves() {
+ waves_type *ptr = new waves_type;
+ float source[wave_size];
+ get_original_waveform(source);
+ bandlimiter<SMALL_OSC_TABLE_BITS> bl;
+ ptr->make(bl, source);
+ return ptr;
+ }
+};
+
+#define OSC_MODULE_GET_WAVES() \
+ virtual waves_type *get_waves() { \
+ static waves_type *waves = NULL; \
+ if (!waves) \
+ waves = create_waves(); \
+ return waves; \
+ }
+
+class small_square_osc_audio_module: public small_freq_only_osc_audio_module
+{
+public:
+ OSC_MODULE_GET_WAVES()
+
+ virtual void get_original_waveform(float data[wave_size]) {
+ for (int i = 0; i < wave_size; i++)
+ data[i] = (i < wave_size / 2) ? +1 : -1;
+ }
+ static void plugin_info(plugin_info_iface *pii)
+ {
+ pii->names("square_osc", "squareosc", "Square Oscillator", "lv2:Oscillator");
+ port_info(pii);
+ }
+};
+
+class small_saw_osc_audio_module: public small_freq_only_osc_audio_module
+{
+public:
+ OSC_MODULE_GET_WAVES()
+
+ virtual void get_original_waveform(float data[wave_size]) {
+ for (int i = 0; i < wave_size; i++)
+ data[i] = (i * 2.0 / wave_size) - 1;
+ }
+ static void plugin_info(plugin_info_iface *pii)
+ {
+ pii->names("saw_osc", "sawosc", "Saw Oscillator", "lv2:Oscillator");
+ port_info(pii);
+ }
+};
+
};
#endif
diff --git a/src/calf/osc.h b/src/calf/osc.h
index d1ffdb2..68c4e90 100644
--- a/src/calf/osc.h
+++ b/src/calf/osc.h
@@ -48,6 +48,11 @@ struct simple_oscillator
{
phasedelta = (int)(freq * 65536.0 * 256.0 * 16.0 / sr) << 4;
}
+ /// Set phase delta based on oscillator frequency and inverse of sample rate.
+ void set_freq_odsr(float freq, double odsr)
+ {
+ phasedelta = (int)(freq * 65536.0 * 256.0 * 16.0 * odsr) << 4;
+ }
inline float get()
{
float value = (phase >> 16 ) / 65535.0 - 0.5;
diff --git a/src/modules.cpp b/src/modules.cpp
index cee15f2..7a7c118 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -198,6 +198,9 @@ SMALL_WRAPPERS(small_mul, "mul")
SMALL_WRAPPERS(small_neg, "neg")
SMALL_WRAPPERS(small_map_lin2exp, "lin2exp")
+SMALL_WRAPPERS(small_square_osc, "square_osc")
+SMALL_WRAPPERS(small_saw_osc, "saw_osc")
+
#endif
#if USE_LV2
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list