new/reworked audio plugins ported from hv72 compressor/multi/reverb, glyph workaround...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / units.C
index 9c2f1d27106b7f4be2cee7ec37f70c5bd91edf04..e0a170dcc88711911d48ed9643f64a9a29ed3cc1 100644 (file)
@@ -90,14 +90,14 @@ int Freq::fromfreq()
        int i = 0;
        while( i<TOTALFREQS && freqtable[i]<freq ) ++i;
        return i;
-};
+}
 
 int Freq::fromfreq(int index)
 {
        int i = 0;
        while( i<TOTALFREQS && freqtable[i]<index ) ++i;
        return i;
-};
+}
 
 int Freq::tofreq(int index)
 {
@@ -105,6 +105,25 @@ int Freq::tofreq(int index)
        return freqtable[index];
 }
 
+// frequency doubles for every OCTAVE slots.  OCTAVE must be divisible by 3
+// 27.5 is at i=1
+// 55 is at i=106
+// 110 is at i=211
+// 220 is at i=316
+// 440 is at i=421
+// 880 is at i=526
+double Freq::tofreq_f(double index)
+{
+       if( index < 0.5 ) return 0;
+       return 440.0 * pow(2, (double)(index - 421) / OCTAVE);
+}
+double Freq::fromfreq_f(double f)
+{
+       if( f < 0.5 ) return 0;
+       double result = log(f / 440) / log(2.0) * OCTAVE + 421;
+       return result < 0 ? 0 : result;
+}
+
 Freq& Freq::operator++()
 {
        if(freq < TOTALFREQS) ++freq;
@@ -136,17 +155,8 @@ void Units::init()
        topower[INFINITYGAIN * 10] = 0;   // infinity gain
 
        Freq::freqtable = new int[TOTALFREQS + 1];
-// starting frequency
-       double freq1 = 27.5, freq2 = 55;
-// Some number divisable by three.  This depends on the value of TOTALFREQS
-       int scale = 105;
-
-       Freq::freqtable[0] = 0;
-       for(int i = 1, j = 0; i <= TOTALFREQS; i++, j++) {
-               Freq::freqtable[i] = (int)(freq1 + (freq2 - freq1) / scale * j + 0.5);
-               if(j < scale) continue;
-               freq1 = freq2;  freq2 *= 2;  j = 0;
-       }
+       for( int i=0; i<=TOTALFREQS; ++i )
+               Freq::freqtable[i] = Freq::tofreq_f(i);
 }
 void Units::finit()
 {