Beispiel #1
0
        private void CreateObserver()
        {
            var fftDataLeft  = new Complex[fftComplexCount];
            var fftDataRight = new Complex[fftComplexCount];

            observer            = new StreamObserver <float>(fftSize, (int)(fftSize / moveSpeed), 2, true);
            observer.Completed += multiChannelData => {
                lock (@lock) {
                    Span <double> tempIn = stackalloc double[fftSize];

                    ReadSingleChannel(ref multiChannelData[0], tempIn);
                    fftWindow?.Apply(tempIn, tempIn);
                    fft.WriteRealToInput(tempIn);
                    fft.Execute();
                    fft.ReadOutput <Complex>(fftDataLeft);

                    ReadSingleChannel(ref multiChannelData[1], tempIn);
                    fftWindow?.Apply(tempIn, tempIn);
                    fft.WriteRealToInput(tempIn);
                    fft.Execute();
                    fft.ReadOutput <Complex>(fftDataRight);

                    fftCompleted?.Invoke(fftDataLeft, fftDataRight);
                }
            };
        }
            private void StreamObserver_Completed(float[] data)
            {
                Span <double> left  = stackalloc double[fft.FFTSize];
                Span <double> right = stackalloc double[fft.FFTSize];

                ReadSingleChannel(data, left);
                if (fftWindow != null)
                {
                    Span <double> temp = stackalloc double[fft.FFTSize];
                    fftWindow.Apply(left, temp);
                    fft.WriteRealToInput(temp);
                }
                else
                {
                    fft.WriteRealToInput(left);
                }
                fft.Execute();
                fft.ReadOutput <Complex>(leftFFTData);

                ReadSingleChannel(data.AsSpan(1), right);
                if (fftWindow != null)
                {
                    Span <double> temp = stackalloc double[fft.FFTSize];
                    fftWindow.Apply(right, temp);
                    fft.WriteRealToInput(temp);
                }
                else
                {
                    fft.WriteRealToInput(right);
                }
                fft.Execute();
                fft.ReadOutput <Complex>(rightFFTData);

                FFTCompleted?.Invoke(left, right, leftFFTData, rightFFTData);
            }