[SCM] calf/master: + Organ: added bandlimiting for padfx waveforms (sadly, that results in calfjackhost allocating almost 100 MB of RAM right on start, and probably starting quite slowly on slower machines)

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:37:14 UTC 2013


The following commit has been merged in the master branch:
commit 6dcbb4d5902f2cbf3d6a86f10cd87e8c8e2337c6
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date:   Sat May 24 11:56:38 2008 +0000

    + Organ: added bandlimiting for padfx waveforms (sadly, that results in calfjackhost allocating almost 100 MB of RAM right on start, and probably starting quite slowly on slower machines)
    
    
    git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@186 78b06b96-2940-0410-b7fc-879d825d01d8

diff --git a/src/calf/organ.h b/src/calf/organ.h
index 228a5f2..7591a86 100644
--- a/src/calf/organ.h
+++ b/src/calf/organ.h
@@ -78,6 +78,8 @@ struct organ_parameters {
 #define ORGAN_WAVE_SIZE 4096
 #define ORGAN_BIG_WAVE_BITS 17
 #define ORGAN_BIG_WAVE_SIZE 131072
+/// 2^ORGAN_BIG_WAVE_SHIFT = how many (quasi)periods per sample
+#define ORGAN_BIG_WAVE_SHIFT 5
 
 class organ_voice_base
 {
@@ -123,10 +125,11 @@ public:
         perctrig_eachplus,
         perctrig_count
     };
-    typedef float big_wave_data[ORGAN_BIG_WAVE_SIZE + 1];
+    typedef waveform_family<ORGAN_WAVE_BITS> small_wave_family;
+    typedef waveform_family<ORGAN_BIG_WAVE_BITS> big_wave_family;
 protected:
-    static waveform_family<ORGAN_WAVE_BITS> waves[wave_count_small];
-    static big_wave_data big_waves[wave_count_big];
+    static small_wave_family waves[wave_count_small];
+    static big_wave_family big_waves[wave_count_big];
 
     // dsp::sine_table<float, ORGAN_WAVE_SIZE, 1> sine_wave;
     int note;
@@ -143,10 +146,10 @@ protected:
     }
 public:
     organ_parameters *parameters;
-    static inline waveform_family<ORGAN_WAVE_BITS> &get_wave(int wave) {
+    static inline small_wave_family &get_wave(int wave) {
         return waves[wave];
     }
-    static inline big_wave_data &get_big_wave(int wave) {
+    static inline big_wave_family &get_big_wave(int wave) {
         return big_waves[wave];
     }
 };
diff --git a/src/calf/osc.h b/src/calf/osc.h
index 0e6e991..52a1a58 100644
--- a/src/calf/osc.h
+++ b/src/calf/osc.h
@@ -124,14 +124,29 @@ struct waveform_family: public map<uint32_t, float *>
     using map<uint32_t, float *>::lower_bound;
     float original[SIZE];
     
-    void make(bandlimiter<SIZE_BITS> &bl, float input[SIZE], bool foldover = false)
+    void make(bandlimiter<SIZE_BITS> &bl, float input[SIZE], bool foldover = false, uint32_t limit = SIZE / 2)
     {
         memcpy(original, input, sizeof(original));
         bl.compute_spectrum(input);
         bl.remove_dc();
+        make_from_spectrum(bl, foldover);
         
         uint32_t multiple = 1, base = 1 << (32 - SIZE_BITS);
-        while(multiple < SIZE / 2) {
+        while(multiple < limit) {
+            float *wf = new float[SIZE+1];
+            bl.make_waveform(wf, (int)((1 << SIZE_BITS) / (1.5 * multiple)), foldover);
+            wf[SIZE] = wf[0];
+            (*this)[base * multiple] = wf;
+            multiple = multiple << 1;
+        }
+    }
+    
+    void make_from_spectrum(bandlimiter<SIZE_BITS> &bl, bool foldover = false, uint32_t limit = SIZE / 2)
+    {
+        bl.remove_dc();
+        
+        uint32_t multiple = 1, base = 1 << (32 - SIZE_BITS);
+        while(multiple < limit) {
             float *wf = new float[SIZE+1];
             bl.make_waveform(wf, (int)((1 << SIZE_BITS) / (1.5 * multiple)), foldover);
             wf[SIZE] = wf[0];
diff --git a/src/organ.cpp b/src/organ.cpp
index f8b3939..e9d74a3 100644
--- a/src/organ.cpp
+++ b/src/organ.cpp
@@ -310,7 +310,7 @@ bool organ_audio_module::get_graph(int index, int subindex, float *data, int poi
             int wave = dsp::clip((int)(parameters->waveforms[i]), 0, (int)organ_voice_base::wave_count - 1);
             if (wave >= small_waves)
             {
-                waveforms[i] = organ_voice_base::get_big_wave(wave - small_waves);
+                waveforms[i] = organ_voice_base::get_big_wave(wave - small_waves).original;
                 S[i] = ORGAN_BIG_WAVE_SIZE;
                 S2[i] = ORGAN_WAVE_SIZE / 64;
             }
@@ -490,8 +490,8 @@ parameter_properties organ_audio_module::param_props[] = {
 
 ////////////////////////////////////////////////////////////////////////////
 
-waveform_family<ORGAN_WAVE_BITS> organ_voice_base::waves[organ_voice_base::wave_count_small];
-organ_voice_base::big_wave_data organ_voice_base::big_waves[organ_voice_base::wave_count_big];
+organ_voice_base::small_wave_family organ_voice_base::waves[organ_voice_base::wave_count_small];
+organ_voice_base::big_wave_family organ_voice_base::big_waves[organ_voice_base::wave_count_big];
 
 static void smoothen(bandlimiter<ORGAN_WAVE_BITS> &bl, float tmp[ORGAN_WAVE_SIZE])
 {
@@ -518,7 +518,7 @@ static void phaseshift(bandlimiter<ORGAN_WAVE_BITS> &bl, float tmp[ORGAN_WAVE_SI
     normalize_waveform(tmp, ORGAN_WAVE_SIZE);
 }
 
-static void padsynth(bandlimiter<ORGAN_WAVE_BITS> blSrc, bandlimiter<ORGAN_BIG_WAVE_BITS> &blDest, organ_voice_base::big_wave_data result, int bwscale = 20, float bell_factor = 0)
+static void padsynth(bandlimiter<ORGAN_WAVE_BITS> blSrc, bandlimiter<ORGAN_BIG_WAVE_BITS> &blDest, organ_voice_base::big_wave_family &result, int bwscale = 20, float bell_factor = 0)
 {
     complex<float> orig_spectrum[ORGAN_WAVE_SIZE / 2];
     for (int i = 0; i < ORGAN_WAVE_SIZE / 2; i++) 
@@ -527,7 +527,7 @@ static void padsynth(bandlimiter<ORGAN_WAVE_BITS> blSrc, bandlimiter<ORGAN_BIG_W
 //        printf("@%d = %f\n", i, abs(orig_spectrum[i]));
     }
     
-    int periods = 64 * ORGAN_BIG_WAVE_SIZE / ORGAN_WAVE_SIZE;
+    int periods = (1 << ORGAN_BIG_WAVE_SHIFT) * ORGAN_BIG_WAVE_SIZE / ORGAN_WAVE_SIZE;
     for (int i = 0; i <= ORGAN_BIG_WAVE_SIZE / 2; i++) {
         blDest.spectrum[i] = 0;
     }
@@ -552,7 +552,7 @@ static void padsynth(bandlimiter<ORGAN_WAVE_BITS> blSrc, bandlimiter<ORGAN_BIG_W
         {
             float p = j * 1.0 / bw;
             float val = amp * exp(-p * p);
-            int pos = orig + j * bwscale / 20;
+            int pos = orig + j * bwscale / 40;
             if (pos < 1 || pos >= ORGAN_BIG_WAVE_SIZE / 2)
                 continue;
             int pos2 = 2 * orig - pos;
@@ -565,17 +565,20 @@ static void padsynth(bandlimiter<ORGAN_WAVE_BITS> blSrc, bandlimiter<ORGAN_BIG_W
     }
     for (int i = 1; i <= ORGAN_BIG_WAVE_SIZE / 2; i++) {
         float phase = M_PI * 2 * (rand() & 127) / 128;
-        complex<float> shift = complex<float>(cos(phase), sin(phase));
+        complex<float> shift = complex<float>(100 * cos(phase), 100 * sin(phase));
         blDest.spectrum[i] *= shift;        
 //      printf("@%d = %f\n", i, abs(blDest.spectrum[i]));
         
         blDest.spectrum[ORGAN_BIG_WAVE_SIZE - i] = conj(blDest.spectrum[i]);
     }
     
+    // limit is 1/2 of the number of harmonics of the original wave
+    result.make_from_spectrum(blDest, false, ORGAN_WAVE_SIZE >> (1 + ORGAN_BIG_WAVE_SHIFT));
+    memcpy(result.original, result.begin()->second, sizeof(result.original));
+    #if 0
     blDest.compute_waveform(result);
     normalize_waveform(result, ORGAN_BIG_WAVE_SIZE);
     result[ORGAN_BIG_WAVE_SIZE] = result[0];
-    #if 0
     for (int i =0 ; i<ORGAN_BIG_WAVE_SIZE + 1; i++)
         printf("%f\n", result[i]);
     #endif
@@ -886,13 +889,13 @@ void organ_voice::render_block() {
         uint32_t rate = (dphase * hm).get();
         if (waveid >= wave_count_small)
         {
-            float *data = big_waves[waveid - wave_count_small];
+            float *data = big_waves[waveid - wave_count_small].get_level(rate >> (ORGAN_BIG_WAVE_BITS - ORGAN_WAVE_BITS + ORGAN_BIG_WAVE_SHIFT));
             if (!data)
                 continue;
-            hm.set(hm.get() >> 6);
+            hm.set(hm.get() >> ORGAN_BIG_WAVE_SHIFT);
             dsp::fixed_point<int64_t, 20> tphase, tdphase;
             tphase.set(((phase * hm).get()) + parameters->phaseshift[h]);
-            tdphase.set(rate >> 6);
+            tdphase.set(rate >> ORGAN_BIG_WAVE_SHIFT);
             float ampl = amp * 0.5f * (1 - parameters->pan[h]);
             float ampr = amp * 0.5f * (1 + parameters->pan[h]);
             float (*out)[Channels] = aux_buffers[dsp::fastf2i_drm(parameters->routing[h])];

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list