Exemplo n.º 1
0
        /// <summary>
        /// Same as <see cref="MakeDocument()"/>, only this method creates a document of the
        /// given size input by <paramref name="size"/>.
        /// </summary>
        public virtual Document MakeDocument(int size)
        {
            LeftOver lvr = leftovr.Value;

            if (lvr is null || lvr.DocData is null || lvr.DocData.Body is null ||
                lvr.DocData.Body.Length == 0)
            {
                ResetLeftovers();
            }
            DocData docData = GetDocState().docData;
            DocData dd      = (lvr is null ? m_source.GetNextDocData(docData) : lvr.DocData);
            int     cnt     = (lvr is null ? 0 : lvr.Count);

            while (dd.Body is null || dd.Body.Length < size)
            {
                DocData dd2 = dd;
                dd      = m_source.GetNextDocData(new DocData());
                cnt     = 0;
                dd.Body = (dd2.Body + dd.Body);
            }
            Document doc = CreateDocument(dd, size, cnt);

            if (dd.Body is null || dd.Body.Length == 0)
            {
                ResetLeftovers();
            }
Exemplo n.º 2
0
        void ComputeFFT()
        {
            if (FftQueue.Count > 0)
            {
                System.Numerics.Complex[] samples = new System.Numerics.Complex[NumberOfSamples];

                int index = 0;
                if (LeftOver != null)
                {
                    int count = Math.Min(LeftOver.Length, NumberOfSamples);
                    for (; count > index; index++)
                    {
                        samples[index] = new System.Numerics.Complex(LeftOver[index], 0);
                    }

                    if (index + 1 == LeftOver.Length)
                    {
                        LeftOver = null;
                    }
                    else
                    {
                        LeftOver = LeftOver.Skip(index + 1).ToArray();
                    }
                }

                if (index + 1 < NumberOfSamples)
                {
                    while (index + 1 < NumberOfSamples)
                    {
                        if (FftQueue.Count == 0)
                        {
                            break;
                        }
                        float[]  array   = FftQueue.Dequeue();
                        double[] hamming = Window.Hamming(array.Length);

                        array = array.Select((f, i) => (float)(hamming[i] * f)).ToArray();

                        int count = Math.Min(array.Length, NumberOfSamples - index);
                        for (int i = 0; count > i; i++)
                        {
                            samples[index] = new System.Numerics.Complex(array[i], 0);
                            index++;
                        }

                        if (array.Length > count)
                        {
                            int diff = array.Length - count;
                            LeftOver = array.Skip(count).ToArray();
                        }
                    }
                }

                FourierOptions options = FourierOptions.Matlab;
                Fourier.Forward(samples, options);
                FftFinished?.Invoke(this, new FourierEventArgs(samples, options));
            }
        }