Esempio n. 1
0
 public override void SetBand(int i, float a)
 {
     if (a < 0)
     {
         MinimSharp.Error("Can't set a frequency band to a negative value.");
         return;
     }
     if (real[i] == 0 && imag[i] == 0)
     {
         real[i]     = a;
         spectrum[i] = a;
     }
     else
     {
         real[i]    /= spectrum[i];
         imag[i]    /= spectrum[i];
         spectrum[i] = a;
         real[i]    *= spectrum[i];
         imag[i]    *= spectrum[i];
     }
     if (i != 0 && i != timeSize / 2)
     {
         real[timeSize - i] = real[i];
         imag[timeSize - i] = -imag[i];
     }
 }
Esempio n. 2
0
 public void Portamento(int millis)
 {
     if (millis <= 0)
     {
         MinimSharp.Error("Oscillator.portamento: The portamento speed must be greater than zero.");
     }
     port      = true;
     portSpeed = millis;
 }
Esempio n. 3
0
 /// <summary>
 /// Constructs a Gauss window function.
 /// </summary>
 /// <param name="alpha">double: the alpha value to use for this window</param>
 public GaussWindow(double alpha)
 {
     if (alpha < 0.0 || alpha > 0.5)
     {
         MinimSharp.Error("Range for GaussWindow out of bounds. Value must be <= 0.5");
         return;
     }
     this.alpha = alpha;
 }
Esempio n. 4
0
 protected void SetComplex(float[] r, float[] i)
 {
     if (real.Length != r.Length && imag.Length != i.Length)
     {
         MinimSharp.Error("FourierTransform.setComplex: the two arrays must be the same length as their member counterparts.");
     }
     else
     {
         Array.Copy(r, 0, real, 0, r.Length);
         Array.Copy(i, 0, imag, 0, i.Length);
     }
 }
Esempio n. 5
0
        public void Forward(float[] buffer, int startAt)
        {
            if (buffer.Length - startAt < timeSize)
            {
                MinimSharp.Error("FourierTransform.forward: not enough samples in the buffer between " + startAt + " and " + buffer.Length + " to perform a transform.");
                return;
            }

            // copy the section of samples we want to analyze
            float[] section = new float[timeSize];
            Array.Copy(buffer, startAt, section, 0, section.Length);
            Forward(section);
        }
Esempio n. 6
0
 public void LinAverages(int numAvg)
 {
     if (numAvg > spectrum.Length / 2)
     {
         MinimSharp.Error("The number of averages for this transform can be at most " + spectrum.Length / 2 + ".");
         return;
     }
     else
     {
         averages = new float[numAvg];
     }
     whichAverage = LINAVG;
 }
Esempio n. 7
0
        public void LogAverages(int minBandwidth, int bandsPerOctave)
        {
            float nyq = (float)sampleRate / 2f;

            octaves = 1;
            while ((nyq /= 2) > minBandwidth)
            {
                octaves++;
            }
            MinimSharp.Debug("Number of octaves = " + octaves);
            avgPerOctave = bandsPerOctave;
            averages     = new float[octaves * bandsPerOctave];
            whichAverage = LOGAVG;
        }
Esempio n. 8
0
 public override void Forward(float[] buffer)
 {
     if (buffer.Length != timeSize)
     {
         MinimSharp.Error("FFT.forward: The length of the passed sample buffer must be equal to timeSize().");
         return;
     }
     DoWindow(buffer);
     // copy samples to real/imag in bit-reversed order
     BitReverseSamples(buffer, 0);
     // perform the fft
     Fft();
     // fill the spectrum buffer with amplitudes
     FillSpectrum();
 }
Esempio n. 9
0
        public override void ScaleBand(int i, float s)
        {
            if (s < 0)
            {
                MinimSharp.Error("Can't scale a frequency band by a negative value.");
                return;
            }

            real[i]     *= s;
            imag[i]     *= s;
            spectrum[i] *= s;

            if (i != 0 && i != timeSize / 2)
            {
                real[timeSize - i] = real[i];
                imag[timeSize - i] = -imag[i];
            }
        }
Esempio n. 10
0
        //public override void Forward(float[] buffer, int startAt)
        //{
        //    if (buffer.Length - startAt < timeSize)
        //    {
        //        //Minim.error("FourierTransform.forward: not enough samples in the buffer between " + startAt + " and " + buffer.Length + " to perform a transform.");
        //        return;
        //    }

        //    currentWindow.Apply(buffer, startAt, timeSize);
        //    BitReverseSamples(buffer, startAt);
        //    Fft();
        //    FillSpectrum();
        //}

        //public override void Forward(float[] buffReal, float[] buffImag)
        //{
        //    if (buffReal.Length != timeSize || buffImag.Length != timeSize)
        //    {
        //        //Minim.error("FFT.forward: The length of the passed buffers must be equal to timeSize().");
        //        return;
        //    }
        //    SetComplex(buffReal, buffImag);
        //    BitReverseComplex();
        //    Fft();
        //    FillSpectrum();
        //}

        public override void Inverse(float[] buffer)
        {
            if (buffer.Length > real.Length)
            {
                MinimSharp.Error("FFT.inverse: the passed array's length must equal FFT.timeSize().");
                return;
            }
            // conjugate
            for (int i = 0; i < timeSize; i++)
            {
                imag[i] *= -1;
            }
            BitReverseComplex();
            Fft();
            // copy the result in real into buffer, scaling as we do
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = real[i] / real.Length;
            }
        }
Esempio n. 11
0
        public override void Forward(float[] samples)
        {
            if (samples.Length != timeSize)
            {
                MinimSharp.Error("DFT.forward: The length of the passed sample buffer must be equal to DFT.timeSize().");
                return;
            }
            DoWindow(samples);
            int N = samples.Length;

            for (int f = 0; f <= N / 2; f++)
            {
                real[f] = 0.0f;
                imag[f] = 0.0f;
                for (int t = 0; t < N; t++)
                {
                    real[f] += samples[t] * Cos(t * f);
                    imag[f] += samples[t] * -Sin(t * f);
                }
            }
            FillSpectrum();
        }