init() public method

public init ( uint logN ) : void
logN uint
return void
Beispiel #1
0
        void Awake()
        {
            if (fftSize == FFTSize.Custom)
            {
                _appliedFFTSize = Mathf.NextPowerOfTwo(customFftSize);
                if (_appliedFFTSize != customFftSize)
                {
                    Debug.LogWarning("This FFT implementation only supports power of 2 lengths, defaulting to next possible value: " + _appliedFFTSize);
                    customFftSize = _appliedFFTSize;
                }
            }
            else
            {
                _appliedFFTSize = GATInfo.AudioBufferSizePerChannel;
            }

            if (useWindowFunction)
            {
                SetWindow(window);
            }

            _im = new float[_appliedFFTSize];               //Shared imaginary part

            _fft = new FloatFFT();
            uint fftLogSize = ( uint )Mathf.Log(_appliedFFTSize, 2);

            _fft.init(fftLogSize);

            FirstOutputBinIndex = fromFrequency * _appliedFFTSize / GATInfo.OutputSampleRate;
            LastOutputBinIndex  = toFrequency * _appliedFFTSize / GATInfo.OutputSampleRate;
        }
Beispiel #2
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();
        }
Beispiel #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();
        }
Beispiel #4
0
        void Awake()
        {
            if( fftSize == FFTSize.Custom )
            {
                _appliedFFTSize = Mathf.NextPowerOfTwo( customFftSize );
                if( _appliedFFTSize != customFftSize )
                {
                    Debug.LogWarning("This FFT implementation only supports power of 2 lengths, defaulting to next possible value: "+_appliedFFTSize );
                    customFftSize = _appliedFFTSize;
                }
            }
            else
            {
                _appliedFFTSize = GATInfo.AudioBufferSizePerChannel;
            }

            if( useWindowFunction )
            {
                SetWindow( window );
            }

            _im = new float[ _appliedFFTSize ]; //Shared imaginary part

            _fft = new FloatFFT();
            uint fftLogSize = ( uint )Mathf.Log ( _appliedFFTSize, 2 );
            _fft.init( fftLogSize );

            FirstOutputBinIndex = fromFrequency * _appliedFFTSize / GATInfo.OutputSampleRate;
            LastOutputBinIndex  = toFrequency   * _appliedFFTSize / GATInfo.OutputSampleRate;
        }