Esempio n. 1
2
File: FFT.cs Progetto: leon196/WJ
    void Start()
    {
        Instance = this;

        crossovers[0] = 30; //guesstimating sample lengths for frequency bands
        crossovers[1] = 50;
        crossovers[2] = 600;
        crossovers[3] = freqData.Length;

        band = new float[BANDS];
        output = new float[BANDS];

        for (int i = 0; i < audioObj.Length; i++)
        {
          audioObj[i].player = (GameObject)Instantiate(playerPrefab);
          audioObj[i].player.transform.parent = transform;
          audioObj[i].player.transform.position = Vector3.zero;
          audioObj[i].clip = new AudioClip();
        }

        inputDevices = new string[Microphone.devices.Length];
        deviceNum = Microphone.devices.Length - 1;

        for (int i = 0; i < Microphone.devices.Length; i++)
        inputDevices[i] = Microphone.devices[i].ToString();

        CurrentAudioInput = Microphone.devices[deviceNum].ToString();

        InvokeRepeating("Check", 0, 1.0f / 15.0f);
        StartCoroutine(StartRecord());
    }
Esempio n. 2
0
    /**
     * Constructor, sets the {@link Decoder}, the sample window size and the
     * hop size for the spectra returned. Say the sample window size is 1024
     * samples. To get an overlapp of 50% you specify a hop size of 512 samples,
     * for 25% overlap you specify a hopsize of 256 and so on. Hop sizes are of
     * course not limited to powers of 2.
     *
     * @param decoder The decoder to get the samples from.
     * @param sampleWindowSize The sample window size.
     * @param hopSize The hop size.
     * @param useHamming Wheter to use hamming smoothing or not.
     */
    public SpectrumProvider( DecoderInterface decoder, int sampleWindowSize, int hopSize, bool useHamming )
    {
        if( decoder == null )
            throw new ArgumentException( "Decoder must be != null" );

        if( sampleWindowSize <= 0 )
            throw new ArgumentException( "Sample window size must be > 0" );
        if( hopSize <= 0 )
            throw new ArgumentException( "Hop size must be > 0" );

        if( sampleWindowSize < hopSize )
            throw new ArgumentException( "Hop size must be <= sampleSize" );

        this.sampleWindowSize = sampleWindowSize;

        this.decoder = decoder;
        this.samples = new float[sampleWindowSize];
        this.nextSamples = new float[sampleWindowSize];
        this.tempSamples = new float[sampleWindowSize];
        this.hopSize = hopSize;
        fft = new FFT( sampleWindowSize, AudioManager.frequency );
        if( useHamming )
            fft.window(FFT.HAMMING);

        decoder.readSamples( ref samples );
        decoder.readSamples( ref nextSamples );
    }
Esempio n. 3
0
    void Start()
    {
        _texPw = new Texture2D(n, n, TextureFormat.RGBA32, false, true);
        _texEtaX = new Texture2D(n, n, TextureFormat.RGBA32, false, true);
        _texEtaY = new Texture2D(n, n , TextureFormat.RGBA32, false, true);
        _cPw = _texPw.GetPixels();
        _cEtaX = _texEtaX.GetPixels();
        _cEtaY = _texEtaY.GetPixels();
        displacementMat.SetFloat("_L", L);
        floatDecoderMat.SetFloat("_L", L);
        floatDecoderMat.SetTexture("_XTex", _texEtaX);
        floatDecoderMat.SetTexture("_YTex", _texEtaY);
        floatDecoderMat.SetTexture("_ZTex", _texPw);

        _texUvw = new RenderTexture(n, n, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        displacementMat.mainTexture = _texUvw;

        _k = new K(n, L);
        _phillips = new Phillips(_k, wind.magnitude, wind.normalized);
        _h0 = new H0(_phillips);
        _w = new W(_k);
        _h = new H(_h0, _w);
        _eta = new Eta(n, _k, _h);

        _fft = new FFT(n);
        _pw = new float[2 * n * n];
        _etaX = new float[_pw.Length];
        _etaY = new float[_pw.Length];
    }
Esempio n. 4
0
 void Start()
 {
     thi = this;
     prevTime = Time.time;
     int n = freqData.Length;
     int k = 3;
     band = new float[k];
 }
Esempio n. 5
0
		public MFCC(int samplePerFrame, int samplingRate, int numCepstra)
		{
			this.samplePerFrame = samplePerFrame;
			this.samplingRate = samplingRate;
			this.numCepstra = numCepstra;
			upperFilterFreq = samplingRate / 2.0;
			
			fft = new FFT();
			dct = new DCT(this.numCepstra, numMelFilters);
		}
 void StartAnalysis()
 {
     spectogramTexture = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false);
     currentXCoord = 0;
     textureUpdateCount = 0;
     fft = new FFT(fftSampleRate, currentClip.frequency);
 }
Esempio n. 7
0
File: Main.cs Progetto: ptaa32/ARDOP
        private void UpdateWaterfall(ref byte[] bytNewSamples)
        {
            lock (static_UpdateWaterfall_dblI_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_dblI_Init))
                    {
                        static_UpdateWaterfall_dblI = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateWaterfall_dblI_Init.State = 1;
                }
            }
            lock (static_UpdateWaterfall_dblQ_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_dblQ_Init))
                    {
                        static_UpdateWaterfall_dblQ = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateWaterfall_dblQ_Init.State = 1;
                }
            }
            lock (static_UpdateWaterfall_dblReF_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_dblReF_Init))
                    {
                        static_UpdateWaterfall_dblReF = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateWaterfall_dblReF_Init.State = 1;
                }
            }
            lock (static_UpdateWaterfall_dblImF_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_dblImF_Init))
                    {
                        static_UpdateWaterfall_dblImF = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateWaterfall_dblImF_Init.State = 1;
                }
            }
            lock (static_UpdateWaterfall_aryLastY_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_aryLastY_Init))
                    {
                        static_UpdateWaterfall_aryLastY = new int[256];
                    }
                }
                finally
                {
                    static_UpdateWaterfall_aryLastY_Init.State = 1;
                }
            }
            lock (static_UpdateWaterfall_intPtr_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_intPtr_Init))
                    {
                        static_UpdateWaterfall_intPtr = 0;
                    }
                }
                finally
                {
                    static_UpdateWaterfall_intPtr_Init.State = 1;
                }
            }
            lock (static_UpdateWaterfall_dblMag_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_dblMag_Init))
                    {
                        static_UpdateWaterfall_dblMag = new double[207];
                    }
                }
                finally
                {
                    static_UpdateWaterfall_dblMag_Init.State = 1;
                }
            }
            lock (static_UpdateWaterfall_FFT_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateWaterfall_FFT_Init))
                    {
                        static_UpdateWaterfall_FFT = new FFT();
                    }
                }
                finally
                {
                    static_UpdateWaterfall_FFT_Init.State = 1;
                }
            }

            double dblMagAvg = 0;
            int intTrace = 0;
            Int32 intTuneLineLow = default(Int32);
            Int32 intTuneLineHi = default(Int32);
            Int32 intDelta = default(Int32);
            System.Drawing.Color clrTLC = Color.Chartreuse;
            int intBusyStatus = 0;
            for (int i = 0; i <= bytNewSamples.Length - 1; i += 2)
            {
                static_UpdateWaterfall_dblI(static_UpdateWaterfall_intPtr) = Convert.ToDouble(System.BitConverter.ToInt16(bytNewSamples, i));
                static_UpdateWaterfall_intPtr += 1;
                if (static_UpdateWaterfall_intPtr > 1023)
                    break; // TODO: might not be correct. Was : Exit For
            }
            if (static_UpdateWaterfall_intPtr < 1024)
                return;
            static_UpdateWaterfall_intPtr = 0;
            static_UpdateWaterfall_FFT.FourierTransform(1024, static_UpdateWaterfall_dblI, static_UpdateWaterfall_dblQ, static_UpdateWaterfall_dblReF, static_UpdateWaterfall_dblImF, false);
            for (int i = 0; i <= static_UpdateWaterfall_dblMag.Length - 1; i++)
            {
                //starting at ~300 Hz to ~2700 Hz Which puts the center of the signal in the center of the window (~1500Hz)
                static_UpdateWaterfall_dblMag(i) = (Math.Pow(static_UpdateWaterfall_dblReF(i + 25), 2) + Math.Pow(static_UpdateWaterfall_dblImF(i + 25), 2));
                // first pass
                dblMagAvg += static_UpdateWaterfall_dblMag(i);
            }
            intDelta = (stcConnection.intSessionBW / 2 + MCB.TuningRange) / 11.719;
            intTuneLineLow = Max((103 - intDelta), 3);
            intTuneLineHi = Min((103 + intDelta), 203);

            intBusyStatus = objBusy.BusyDetect(static_UpdateWaterfall_dblMag, intTuneLineLow, intTuneLineHi);
            if (intBusyStatus == 1)
            {
                clrTLC = Color.Fuchsia;

            }
            else if (intBusyStatus == 2)
            {
                clrTLC = Color.Gold;
            }
            if (static_UpdateWaterfall_intLastBusyStatus == 0 & intBusyStatus > 0)
            {
                objHI.QueueCommandToHost("BUSY TRUE");
                Debug.WriteLine("BUSY TRUE");
                static_UpdateWaterfall_intLastBusyStatus = intBusyStatus;
            }
            else if (intBusyStatus == 0 & static_UpdateWaterfall_intLastBusyStatus > 0)
            {
                objHI.QueueCommandToHost("BUSY FALSE");
                Debug.WriteLine("BUSY FALSE");
                static_UpdateWaterfall_intLastBusyStatus = intBusyStatus;
            }

            try
            {
                dblMagAvg = Math.Log10(dblMagAvg / 5000);
                for (int i = 0; i <= static_UpdateWaterfall_dblMag.Length - 1; i++)
                {
                    // The following provides some AGC over the waterfall to compensate for avg input level.
                    double y1 = (0.25 + 2.5 / dblMagAvg) * Math.Log10(0.01 + static_UpdateWaterfall_dblMag(i));
                    System.Drawing.Color objColor = default(System.Drawing.Color);
                    //  Set the pixel color based on the intensity (log) of the spectral line
                    if (y1 > 6.5)
                    {
                        objColor = Color.Orange;
                        // Strongest spectral line
                    }
                    else if (y1 > 6)
                    {
                        objColor = Color.Khaki;
                    }
                    else if (y1 > 5.5)
                    {
                        objColor = Color.Cyan;
                    }
                    else if (y1 > 5)
                    {
                        objColor = Color.DeepSkyBlue;
                    }
                    else if (y1 > 4.5)
                    {
                        objColor = Color.RoyalBlue;
                    }
                    else if (y1 > 4)
                    {
                        objColor = Color.Navy;
                    }
                    else
                    {
                        objColor = Color.Black;
                        // Weakest spectral line
                    }
                    if (i == 103)
                    {
                        bmpSpectrum.SetPixel(i, static_UpdateWaterfall_intWaterfallRow, Color.Tomato);
                        // 1500 Hz line (center)
                    }
                    else if ((i == intTuneLineLow | i == intTuneLineLow - 1 | i == intTuneLineHi | i == intTuneLineHi + 1))
                    {
                        bmpSpectrum.SetPixel(i, static_UpdateWaterfall_intWaterfallRow, clrTLC);
                    }
                    else
                    {
                        bmpSpectrum.SetPixel(i, static_UpdateWaterfall_intWaterfallRow, objColor);
                        // Else plot the pixel as received
                    }
                }
                // Using a new bit map allows merging the two parts of bmpSpectrum and plotting all at one time to eliminate GDI+ fault.
                intTrace = 1;
                bmpNewSpectrum = new Bitmap(bmpSpectrum.Width, bmpSpectrum.Height);
                // Top rectangle of the waterfall is Waterfall Row to bottom of bmpSpectrum
                intTrace = 2;
                Rectangle destRect1 = new Rectangle(0, 0, bmpSpectrum.Width, bmpSpectrum.Height - static_UpdateWaterfall_intWaterfallRow);
                // Now create rectangle for the bottom part of the waterfall. Top of bmpSpectrum to intWaterfallRow -1
                intTrace = 3;
                Rectangle destRect2 = new Rectangle(0, bmpSpectrum.Height - static_UpdateWaterfall_intWaterfallRow, bmpSpectrum.Width, static_UpdateWaterfall_intWaterfallRow);
                // Create a new graphics area to draw into the new bmpNewSpectrum
                intTrace = 4;
                Graphics graComposit = Graphics.FromImage(bmpNewSpectrum);
                // add the two rectangles to the graComposit
                intTrace = 5;
                graComposit.DrawImage(bmpSpectrum, destRect1, 0, static_UpdateWaterfall_intWaterfallRow, bmpSpectrum.Width, bmpSpectrum.Height - static_UpdateWaterfall_intWaterfallRow, GraphicsUnit.Pixel);
                intTrace = 6;
                graComposit.DrawImage(bmpSpectrum, destRect2, 0, 0, bmpSpectrum.Width, static_UpdateWaterfall_intWaterfallRow, GraphicsUnit.Pixel);
                intTrace = 7;
                graComposit.Dispose();
                //  the new composit bitmap has been constructed
                intTrace = 8;
                if ((graFrequency != null))
                {
                    intTrace = 9;
                    graFrequency.Dispose();
                    // this permits writing back to the graFrequency without a GDI+ fault.
                }
                intTrace = 10;
                graFrequency = pnlWaterfall.CreateGraphics;
                intTrace = 11;
                graFrequency.DrawImage(bmpNewSpectrum, 0, 0);
                // Draw the new bitmap in one update to avoid a possible GDI+ fault
                static_UpdateWaterfall_intWaterfallRow -= 1;
                // Move the WaterFallRow back to point to the oldest received spectrum
                intTrace = 12;
                if (static_UpdateWaterfall_intWaterfallRow < 0)
                    static_UpdateWaterfall_intWaterfallRow = bmpSpectrum.Height - 1;
                // Makes the bitmap a circular buffer
            }
            catch (Exception ex)
            {
                Logs.Exception("[Main.UpdateWaterfall] Err #: " + Err.Number.ToString + "  Exception: " + ex.ToString + "  intTrace=" + intTrace.ToString);
            }
        }
Esempio n. 8
0
File: Main.cs Progetto: ptaa32/ARDOP
        private void UpdateSpectrum(ref byte[] bytNewSamples)
        {
            lock (static_UpdateSpectrum_dblI_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_dblI_Init))
                    {
                        static_UpdateSpectrum_dblI = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateSpectrum_dblI_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_dblQ_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_dblQ_Init))
                    {
                        static_UpdateSpectrum_dblQ = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateSpectrum_dblQ_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_dblReF_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_dblReF_Init))
                    {
                        static_UpdateSpectrum_dblReF = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateSpectrum_dblReF_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_dblImF_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_dblImF_Init))
                    {
                        static_UpdateSpectrum_dblImF = new double[1024];
                    }
                }
                finally
                {
                    static_UpdateSpectrum_dblImF_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_aryLastY_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_aryLastY_Init))
                    {
                        static_UpdateSpectrum_aryLastY = new int[256];
                    }
                }
                finally
                {
                    static_UpdateSpectrum_aryLastY_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_intPtr_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_intPtr_Init))
                    {
                        static_UpdateSpectrum_intPtr = 0;
                    }
                }
                finally
                {
                    static_UpdateSpectrum_intPtr_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_dblMag_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_dblMag_Init))
                    {
                        static_UpdateSpectrum_dblMag = new double[207];
                    }
                }
                finally
                {
                    static_UpdateSpectrum_dblMag_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_FFT_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_FFT_Init))
                    {
                        static_UpdateSpectrum_FFT = new FFT();
                    }
                }
                finally
                {
                    static_UpdateSpectrum_FFT_Init.State = 1;
                }
            }
            lock (static_UpdateSpectrum_intPriorY_Init)
            {
                try
                {
                    if (InitStaticVariableHelper(static_UpdateSpectrum_intPriorY_Init))
                    {
                        static_UpdateSpectrum_intPriorY = new int[257];
                    }
                }
                finally
                {
                    static_UpdateSpectrum_intPriorY_Init.State = 1;
                }
            }

            double[] dblMagBusy = new double[207];
            double dblMagMax = 1E-10;
            double dblMagMin = 10000000000.0;
            Int32 intTuneLineLow = default(Int32);
            Int32 intTuneLineHi = default(Int32);
            Int32 intDelta = default(Int32);
            int intBusyStatus = 0;
            int Trace = 0;
            System.Drawing.Color clrTLC = Color.Chartreuse;

            for (int i = 0; i <= bytNewSamples.Length - 1; i += 2)
            {
                static_UpdateSpectrum_dblI(static_UpdateSpectrum_intPtr) = Convert.ToDouble(System.BitConverter.ToInt16(bytNewSamples, i));
                static_UpdateSpectrum_intPtr += 1;
                if (static_UpdateSpectrum_intPtr > 1023)
                    break; // TODO: might not be correct. Was : Exit For
            }

            if (static_UpdateSpectrum_intPtr < 1024)
                return;

            //FFT.FourierTransform(1024, dblI, dblQ, dblReF, dblImF, False)
            //For i As Integer = 0 To dblMag.Length - 1
            //    'starting at ~300 Hz to ~2700 Hz Which puts the center of the signal in the center of the window (~1500Hz)
            //    dblMag(i) = (dblReF(i + 25) ^ 2 + dblImF(i + 25) ^ 2) ' first pass
            //    dblMagAvg += dblMag(i)
            //Next i
            //intDelta = (stcConnection.intSessionBW \ 2 + MCB.TuningRange) / 11.719
            //intTuneLineLow = Max((103 - intDelta), 3)
            //intTuneLineHi = Min((103 + intDelta), 203)

            //intBusyStatus = objBusy.BusyDetect(dblMag, intTuneLineLow, intTuneLineHi)
            //If intBusyStatus = 1 Then
            //    clrTLC = Color.Fuchsia

            //ElseIf intBusyStatus = 2 Then
            //    clrTLC = Color.Orange
            //End If

            // Busy detector call needs work...OK in Waterfall!

            static_UpdateSpectrum_intPtr = 0;
            static_UpdateSpectrum_FFT.FourierTransform(1024, static_UpdateSpectrum_dblI, static_UpdateSpectrum_dblQ, static_UpdateSpectrum_dblReF, static_UpdateSpectrum_dblImF, false);
            Trace = 1;
            intDelta = ((stcConnection.intSessionBW / 2) + MCB.TuningRange) / 11.719;
            intTuneLineLow = Max((103 - intDelta), 3);
            intTuneLineHi = Min((103 + intDelta), 203);

            for (int i = 0; i <= static_UpdateSpectrum_dblMag.Length - 1; i++)
            {
                //starting at ~300 Hz to ~2700 Hz Which puts the center of the window at 1500Hz
                dblMagBusy(i) = (Math.Pow(static_UpdateSpectrum_dblReF(i + 25), 2) + Math.Pow(static_UpdateSpectrum_dblImF(i + 25), 2));
                //dblMag(i) = 0.2 * (dblReF(i + 25) ^ 2 + dblImF(i + 25) ^ 2) + 0.8 * dblMag(i) ' first pass
                static_UpdateSpectrum_dblMag(i) = 0.2 * dblMagBusy(i) + 0.8 * static_UpdateSpectrum_dblMag(i);
                // first pass
                dblMagMax = Math.Max(dblMagMax, static_UpdateSpectrum_dblMag(i));
                dblMagMin = Math.Min(dblMagMin, static_UpdateSpectrum_dblMag(i));
            }
            intBusyStatus = objBusy.BusyDetect(dblMagBusy, intTuneLineLow, intTuneLineHi);
            if (intBusyStatus == 1)
            {
                clrTLC = Color.Fuchsia;
            }
            else if (intBusyStatus == 2)
            {
                clrTLC = Color.Orange;
            }
            if (static_UpdateSpectrum_intLastBusyStatus == 0 & intBusyStatus > 0)
            {
                objHI.QueueCommandToHost("BUSY TRUE");
                Debug.WriteLine("BUSY TRUE");
                static_UpdateSpectrum_intLastBusyStatus = intBusyStatus;
            }
            else if (intBusyStatus == 0 & static_UpdateSpectrum_intLastBusyStatus > 0)
            {
                objHI.QueueCommandToHost("BUSY FALSE");
                Debug.WriteLine("BUSY FALSE");
                static_UpdateSpectrum_intLastBusyStatus = intBusyStatus;
            }
            // This performs an auto scaling mechansim with fast attack and slow release
            // more than 10000:1 difference Max:Min
            if (dblMagMin / dblMagMax < 0.0001)
            {
                static_UpdateSpectrum_dblMaxScale = Max(dblMagMax, static_UpdateSpectrum_dblMaxScale * 0.9);
            }
            else
            {
                static_UpdateSpectrum_dblMaxScale = Max(10000 * dblMagMin, dblMagMax);
            }
            Trace = 2;
            try
            {
                //            'InititializeSpectrum(Color.Black)
                bmpNewSpectrum = new Bitmap(intBMPSpectrumWidth, intBMPSpectrumHeight);
                for (int i = 0; i <= static_UpdateSpectrum_dblMag.Length - 1; i++)
                {
                    // The following provides some AGC over the waterfall to compensate for avg input level.
                    int y1 = Convert.ToInt32(-0.25 * (intBMPSpectrumHeight - 1) * Log10((Max(static_UpdateSpectrum_dblMag(i), static_UpdateSpectrum_dblMaxScale / 10000)) / static_UpdateSpectrum_dblMaxScale));
                    // range should be 0 to bmpSpectrumHeight -1
                    System.Drawing.Color objColor = Color.Yellow;
                    // Redraw center and bandwidth lines if change in display
                    if (intTuneLineLow != intSavedTuneLineLow)
                    {
                        for (int j = 0; j <= intBMPSpectrumHeight - 1; j++)
                        {
                            bmpNewSpectrum.SetPixel(103, j, Color.Tomato);
                            bmpNewSpectrum.SetPixel(intSavedTuneLineLow, j, Color.Black);
                            bmpNewSpectrum.SetPixel(intSavedTuneLineHi, j, Color.Black);
                            bmpNewSpectrum.SetPixel(Max(0, intSavedTuneLineLow - 1), j, Color.Black);
                            bmpNewSpectrum.SetPixel(intSavedTuneLineHi + 1, j, Color.Black);
                            bmpNewSpectrum.SetPixel(intTuneLineLow, j, clrTLC);
                            bmpNewSpectrum.SetPixel(intTuneLineHi, j, clrTLC);
                            bmpNewSpectrum.SetPixel(intTuneLineLow - 1, j, clrTLC);
                            bmpNewSpectrum.SetPixel(intTuneLineHi + 1, j, clrTLC);
                        }
                        intSavedTuneLineHi = intTuneLineHi;
                        intSavedTuneLineLow = intTuneLineLow;
                    }
                    // Clear the old pixels and put in new ones if not on a center or Tuning lines
                    if (!((i == 103) | (i == intTuneLineHi) | (i == intTuneLineLow) | (i == intTuneLineHi + 1) | (i == intTuneLineLow - 1)))
                    {
                        // Set the prior plotted pixels to black
                        bmpNewSpectrum.SetPixel(i, static_UpdateSpectrum_intPriorY(i), Color.Black);
                        if (static_UpdateSpectrum_intPriorY(i) < (intBMPSpectrumHeight - 2))
                            bmpNewSpectrum.SetPixel(i, static_UpdateSpectrum_intPriorY(i) + 1, Color.Black);
                        static_UpdateSpectrum_intPriorY(i) = y1;
                        bmpNewSpectrum.SetPixel(i, y1, Color.Yellow);
                        if (y1 < (intBMPSpectrumHeight - 2))
                            bmpNewSpectrum.SetPixel(i, y1 + 1, Color.Gold);
                    }
                }
                Trace = 10;
                if ((graFrequency != null))
                {
                    Trace = 11;
                    graFrequency.Dispose();
                    // this permits writing back to the graFrequency without a GDI+ fault.
                }
                graFrequency = pnlWaterfall.CreateGraphics;
                graFrequency.DrawImage(bmpNewSpectrum, 0, 0);
                // Draw the new bitmap in one update to avoid a possible GDI+ fault
            }
            catch (Exception ex)
            {
                Logs.Exception("[Main.UpdateSpectrum] Err #: " + Err.Number.ToString + "  Exception: " + ex.ToString + "  Trace=" + Trace.ToString);
            }
        }
Esempio n. 9
0
    private IEnumerator _AnalyseClip(AudioClip clip)
    {
        _clip = clip;

        _sampleRate = (int)sampleRate;
        _spectrumSamples = (int)(_clip.frequency * _clip.length / _sampleRate);
        _lastSpectrum = new float[_sampleRate / 2 + 1];
        _thresholdWindowSize = thresholdRadius * 2 + 1;

        _fft = new FFT(_sampleRate, _clip.frequency);

        //if(subBandFrequencies.Length > 1)
        {
            _fft.CustomAverages( subBands.ToArray() );
        //			_fft.CustomAverages(subBandFrequencies);
        //			subBands = subBandFrequencies.Length - 1;
        }
        //		else if(subBands > 1)
        //		_fft.LogAverages(subBands.Count);

        if(storeSpectrumData)
            _spectrumData = new List<float[]>(_spectrumSamples);

        _subBandWidth = _sampleRate / (subBands.Count * 2);

        _spectralFlux = new List< List <float> >(subBands.Count);
        _beats  = new List<List <float>>(subBands.Count);
        _nextBeatVals = new List<float>(subBands.Count);

        for(int i = 0 ; i < subBands.Count ; i++)
        {
            _spectralFlux.Add( new List<float>(_spectrumSamples) );
            _beats.Add( new List<float>(_spectrumSamples) );
            _nextBeatVals.Add(0);
        }

        _bpmCurve = new List<float>(_spectrumSamples);
        _summedSpectrum = new List<int>(_spectrumSamples);

        yield return StartCoroutine(_GetSpectrumData());
    }
Esempio n. 10
0
	// ************************************************************************ //
	// Initialization
	// ************************************************************************ //	

	/**
	 * 
	 */
	void Start() 
	{
		this.m_dispertion 	= new OceanDispertion( this.settings );
		this.m_spectrum 	= new OceanSpectrum( this.settings );
		this.m_fourier 		= new FFT();
	}