[SCM] calf/master: + Wavetable: first version that uses something vaguely resembling precalculated wavetables

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:39:24 UTC 2013


The following commit has been merged in the master branch:
commit 5a61f06b25266248896983c1689eb62b1220a131
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sat Feb 28 21:11:52 2009 +0000

    + Wavetable: first version that uses something vaguely resembling precalculated wavetables

diff --git a/src/calf/wavetable.h b/src/calf/wavetable.h
index 1d405ad..47f4eef 100644
--- a/src/calf/wavetable.h
+++ b/src/calf/wavetable.h
@@ -14,6 +14,29 @@ namespace calf_plugins {
 
 #define WAVETABLE_WAVE_BITS 8
 
+class wavetable_audio_module;
+    
+struct wavetable_oscillator: public dsp::simple_oscillator
+{
+    enum { SIZE = 1 << 8, MASK = SIZE - 1, SCALE = 1 << (32 - 8) };
+    int16_t (*tables)[256];
+    inline float get(uint8_t slice)
+    {
+        int16_t *waveform = tables[slice];
+        float value = 0.f;
+        uint32_t cphase = phase, cphasedelta = phasedelta >> 3;
+        for (int j = 0; j < 8; j++)
+        {
+            uint32_t wpos = cphase >> (32 - 8);
+            value += dsp::lerp((float)waveform[wpos], (float)waveform[(wpos + 1) & MASK], (cphase & (SCALE - 1)) * (1.0f / SCALE));
+            cphase += cphasedelta;
+        }
+        value = value * (1.0 / 8.0) * (1.0 / 32768.0);
+        phase += phasedelta;
+        return value;
+    }
+};
+
 class wavetable_voice: public dsp::voice
 {
 public:
@@ -21,13 +44,14 @@ public:
     float output_buffer[BlockSize][Channels];
 protected:
     int note;
+    wavetable_audio_module *parent;
     float **params;
     dsp::decay amp;
-    dsp::simple_oscillator oscs[OscCount];
+    wavetable_oscillator oscs[OscCount];
     dsp::adsr envs[EnvCount];
 public:
     wavetable_voice();
-    void set_params_ptr(float **_params, int _srate) { params = _params; sample_rate = _srate; }
+    void set_params_ptr(wavetable_audio_module *_parent, int _srate);
     void reset();
     void note_on(int note, int vel);
     void note_off(int /* vel */);
@@ -58,16 +82,14 @@ public:
     float *ins[in_count]; 
     float *outs[out_count];
     float *params[param_count];
+    int16_t tables[256][256];
 
 public:
-    wavetable_audio_module()
-    {
-        panic_flag = false;
-    }
+    wavetable_audio_module();
 
     dsp::voice *alloc_voice() {
         dsp::block_voice<wavetable_voice> *v = new dsp::block_voice<wavetable_voice>();
-        v->set_params_ptr(params, sample_rate);
+        v->set_params_ptr(this, sample_rate);
         return v;
     }
     
diff --git a/src/wavetable.cpp b/src/wavetable.cpp
index 0e26c40..1dbc7a5 100644
--- a/src/wavetable.cpp
+++ b/src/wavetable.cpp
@@ -40,6 +40,13 @@ wavetable_voice::wavetable_voice()
     sample_rate = -1;
 }
 
+void wavetable_voice::set_params_ptr(wavetable_audio_module *_parent, int _srate)
+{
+    parent = _parent;
+    params = parent->params;
+    sample_rate = _srate;
+}
+
 void wavetable_voice::reset()
 {
     note = -1;
@@ -50,6 +57,7 @@ void wavetable_voice::note_on(int note, int vel)
     this->note = note;
     amp.set(1.0);
     for (int i = 0; i < OscCount; i++) {
+        oscs[i].tables = parent->tables;
         oscs[i].reset();
         oscs[i].set_freq(note_to_hz(note, 0), sample_rate);
     }
@@ -72,10 +80,32 @@ void wavetable_voice::steal()
 
 void wavetable_voice::render_block()
 {
-    for (int i = 0; i < BlockSize; i++)
-        output_buffer[i][0] = output_buffer[i][1] = oscs[0].get() * envs[0].value * envs[0].value;
+    
+    for (int i = 0; i < BlockSize; i++) {
+        int slice = dsp::clip(fastf2i_drm(envs[0].value * 127.0), 0, 127);
+        
+        float value = oscs[0].get(slice);
+        
+        output_buffer[i][0] = output_buffer[i][1] = value * envs[0].value * envs[0].value * 0.25;
+    }
     for (int i = 0; i < EnvCount; i++)
         envs[i].advance();    
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////////////////
+
+wavetable_audio_module::wavetable_audio_module()
+{
+    panic_flag = false;
+    for (int i = 0; i < 256; i++)
+    {
+        for (int j = 0; j < 256; j++)
+        {
+            tables[i][j] = i < j ? -32767 : 32767;
+        }
+    }
+}
+
+
+
 #endif

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list