/*! 
     This can be used to create a new minimum phase bandlimited step function
     to store for later use as a lookup table.
  
     Note that BLEPOscillator.cpp already has a runtime constant version of a BLEP
     for use with the BLEP-based oscillators.
  
  */
 float *GenerateMinBLEP(int zeroCrossings, int overSampling)
 {
   int i, n, m;
   float r, a, b;
   float *buffer1, *buffer2, *minBLEP;
   
   // use power-of-two for DFT/Cepstrum for potential future
   // speed boost
   n = (zeroCrossings * 2 * overSampling) + 1;
   m = n-1;
   
   buffer1 = new float[m];
   buffer2 = new float[m];
   
   // Generate Sinc
   
   a = (float)-zeroCrossings;
   b = (float)zeroCrossings;
   for(i = 0; i < m; i++)
   {
     r = ((float)i) / ((float)m);
     buffer1[i] = sinc(a + (r * (b - a)));
   }
   
   GenerateBlackmanWindow(m, buffer2);
   for(i = 0; i < m; i++)
   {
     buffer1[i] *= buffer2[i];
   }
       
   // Minimum Phase Reconstruction
   
   RealCepstrum(m, buffer1, buffer2);
   MinimumPhase(m, buffer2, buffer1);
   
   // Integrate Into MinBLEP
   
   minBLEP = new float[n];
   a = 0.0f;
   for(i = 0; i < m; i++)
   {
       a += buffer1[i];
       minBLEP[i] = a;
   }
   
   // copy next-to-last sample
   minBLEP[m] = minBLEP[m-1];
   
   // Normalize
   a = minBLEP[m];
   a = 1.0f / a;
   for(i = 0; i < n; i++)
   {
     minBLEP[i] *= a;
   }
       
   delete buffer1;
   delete buffer2;
   return minBLEP;
 }
Exemple #2
0
// Generate MinBLEP And Return It In An Array Of Floating Point Values
float *GenerateMinBLEP(int zeroCrossings, int overSampling)
{
  int i, n;
  float r, a, b;
  float *buffer1, *buffer2, *minBLEP;

  n = (zeroCrossings * 2 * overSampling) + 1;

  buffer1 = new float[n];
  buffer2 = new float[n];

  // Generate Sinc

  a = (float)-zeroCrossings;
  b = (float)zeroCrossings;
  for(i = 0; i < n; i++)
  {
    r = ((float)i) / ((float)(n - 1));
    buffer1[i] = SINC(a + (r * (b - a)));
  }

  // Window Sinc

  BlackmanWindow(n, buffer2);
  for(i = 0; i < n; i++)
    buffer1[i] *= buffer2[i];

  // Minimum Phase Reconstruction

  RealCepstrum(n, buffer1, buffer2);
  MinimumPhase(n, buffer2, buffer1);

  // Integrate Into MinBLEP

  minBLEP = new float[n];
  a = 0.0f;
  for(i = 0; i < n; i++)
  {
    a += buffer1[i];
    minBLEP[i] = a;
  }

  // Normalize
  a = minBLEP[n - 1];
  a = 1.0f / a;
  for(i = 0; i < n; i++)
    minBLEP[i] *= a;

  delete buffer1;
  delete buffer2;
  return minBLEP;
}