run() 공개 메소드

public run ( float xRe, float xIm, bool inverse = false ) : void
xRe float
xIm float
inverse bool
리턴 void
예제 #1
0
        public void GetMidiCodes(int offset, int fftSize = 4096, int maxFreq = 5000)
        {
            AudioClip clip;

            float[]           real, im, window;
            FloatFFT          fft;
            string            assetPath;
            float             binWidth;
            List <FFTBinInfo> binInfos;
            int i;

            real   = new float[fftSize];
            im     = new float[fftSize];
            window = new float[fftSize];

            GATMaths.MakeHammingWindow(window);

            fft = new FloatFFT();
            fft.init(( uint )Mathf.Log(fftSize, 2));
            binWidth = ( float )_sampleRate / fftSize;

            int maxBin = ( int )(( float )maxFreq / binWidth);

            foreach (GATSampleInfo info in _sampleInfos)
            {
                assetPath = AssetDatabase.GUIDToAssetPath(info.GUID);
                clip      = AssetDatabase.LoadAssetAtPath(assetPath, typeof(AudioClip)) as AudioClip;
                if (clip.channels > 1)
                {
                    throw new GATException("Get Midi Codes is a beta feature only available for mono clips");
                }
                clip.GetData(real, offset);
                System.Array.Clear(im, 0, im.Length);
                fft.run(real, im);

                for (i = 0; i < maxBin; i++)
                {
                    real[i] = Mathf.Sqrt(real[i] * real[i] + im[i] * im[i]);
                }

                binInfos = FFTBinInfo.GetLowerMaxBins(real, 0, maxBin, binWidth, .2f);

                info.MidiCode = binInfos[binInfos.Count - 1].GetMidiCode();
            }

            SortByMidiCode();
        }
예제 #2
0
        /// <summary>
        /// Performs windowed in place real FFT of the passed
        /// data array, reusing a cached array for the
        /// imaginary part.
        /// Formats the specified frequency bins according to
        /// FFTOutput.
        /// </summary>
        public void RealFFT(float[] data)
        {
            int i;

            if (data.Length != _appliedFFTSize)
            {
                Debug.LogError("Expected data lengt: " + _appliedFFTSize + ", received " + data.Length);
                return;
            }

            if (useWindowFunction)
            {
                for (i = 0; i < _appliedFFTSize; i++)
                {
                    data[i] *= _windowData[i];
                }
            }

            _fft.run(data, _im, false);

            switch (output)
            {
            case FFTOutput.Decibels:
                ComputeDB(data);
                break;

            case FFTOutput.Magnitudes:
                ComputeMagnitudes(data);
                break;

            case FFTOutput.SquareMagnitudes:
                ComputeSquareMagnitudes(data);
                break;

            case FFTOutput.Real:
                break;
            }

            System.Array.Clear(_im, 0, _im.Length);               //Clear imaginary part
        }
예제 #3
0
        public void GetMidiCodes( int offset, int fftSize = 4096, int maxFreq = 5000 )
        {
            AudioClip clip;
            float[] real, im, window;
            FloatFFT fft;
            string assetPath;
            float binWidth;
            List< FFTBinInfo > binInfos;
            int i;

            real = new float[ fftSize ];
            im   = new float[ fftSize ];
            window = new float[ fftSize ];

            GATMaths.MakeHammingWindow( window );

            fft = new FloatFFT();
            fft.init( ( uint )Mathf.Log ( fftSize, 2 ) );
            binWidth = ( float )_sampleRate / fftSize;

            int maxBin = ( int )( ( float )maxFreq / binWidth );

            foreach( GATSampleInfo info in _sampleInfos )
            {
                assetPath = AssetDatabase.GUIDToAssetPath( info.GUID );
                clip = AssetDatabase.LoadAssetAtPath( assetPath, typeof( AudioClip ) ) as AudioClip;
                if( clip.channels > 1 )
                {
                    throw new GATException( "Get Midi Codes is a beta feature only available for mono clips" );
                }
                clip.GetData( real, offset );
                System.Array.Clear( im, 0, im.Length );
                fft.run( real, im );

                for( i = 0; i < maxBin; i++ )
                {
                    real[ i ] = Mathf.Sqrt( real[ i ] * real[ i ] + im[ i ] * im[ i ] );
                }

                binInfos = FFTBinInfo.GetLowerMaxBins( real, 0, maxBin, binWidth, .2f );

                info.MidiCode = binInfos[ binInfos.Count - 1 ].GetMidiCode();
            }

            SortByMidiCode();
        }