示例#1
0
        /// <summary>
        /// Fetch data from input buffer to OpenGL buffer
        /// </summary>
        /// <param name="level">level in MinMax cascade. -1 being raw data, 0..N being MinMax data</param>
        /// <param name="offset">Offset in source buffer in samples</param>
        /// <param name="samples">Number of samples to copy from source buffer</param>
        /// <returns></returns>
        private int FillBuffer(int level, int offset, int samples)
        {
            if (level < -1 || level > _minMax.Length)
            {
                throw new IndexOutOfRangeException($"Level must be in range [-1..{_minMax.Length - 1}]");
            }

            if (level == -1)
            {
                var c = Math.Min(samples, _signalBuffer.Length - offset);
                if (c < 0)
                {
                    c = 0;
                }
                _signalBuffer.Peek(_floatTemp, offset, 0, c);
                _ringBuffer.ResetPointer();
                _ringBuffer.AddVertices(_floatTemp, 0, c);
                return(c);
            }
            else
            {
                var c = Math.Min(samples, _minMax[level].Samples.Length - offset);
                if (c < 0)
                {
                    c = 0;
                }
                _minMax[level].Samples.Peek(_minMaxTemp, offset, 0, c);

                for (int i = 0; i < c; i += 2)
                {
                    _floatTemp[i + 0] = _minMaxTemp[i >> 1].Max;
                    _floatTemp[i + 1] = _minMaxTemp[i >> 1].Min;
                }
                _ringBuffer.ResetPointer();
                _ringBuffer.AddVertices(_floatTemp, 0, c);

                for (int i = 0; i < c / 2; i++)
                {
                    _floatTemp[i] = _minMaxTemp[i].Max;
                }
                _ringBufferMax.ResetPointer();
                _ringBufferMax.AddVertices(_floatTemp, 0, c / 2);

                for (int i = 0; i < c / 2; i++)
                {
                    _floatTemp[i] = _minMaxTemp[i].Min;
                }
                _ringBufferMin.ResetPointer();
                _ringBufferMin.AddVertices(_floatTemp, 0, c / 2);

                return(c);
            }
        }
示例#2
0
        /// <summary>
        /// Fetch data from input buffer to OpenGL buffer
        /// </summary>
        /// <param name="level">level in MinMax cascade. -1 being raw data, 0..N being MinMax data</param>
        /// <param name="offset">Offset in source buffer in samples</param>
        /// <param name="samples">Number of samples to copy from source buffer</param>
        /// <returns></returns>
        private int FillBuffer(int level, long offset, int samples)
        {
            if (level < -1 || level > _minMax.Length)
            {
                throw new IndexOutOfRangeException($"Level must be in range [-1..{_minMax.Length - 1}]");
            }

            if (level == -1)
            {
                // read from file
                _reader.Seek(offset, System.IO.SeekOrigin.Begin);
                var read = _reader.ReadSamples(_doubleTemp, 0, samples);
                for (int i = 0; i < read; i++)
                {
                    _floatTemp[i] = (float)_doubleTemp[i];
                }
                _ringBuffer.ResetPointer();
                _ringBuffer.AddVertices(_floatTemp, 0, (int)read);
                return((int)read);
            }
            else
            {
                var c = Math.Min(samples, _minMax[level].Samples.Length - offset);
                if (c < 0)
                {
                    c = 0;
                }
                _minMax[level].Samples.Peek(_minMaxTemp, (int)offset, 0, (int)c);
                for (int i = 0; i < 2 * c; i += 2)
                {
                    _floatTemp[i + 0] = _minMaxTemp[i >> 1].Max;
                    _floatTemp[i + 1] = _minMaxTemp[i >> 1].Min;
                }
                _ringBuffer.ResetPointer();
                _ringBuffer.AddVertices(_floatTemp, 0, 2 * (int)c);

                for (int i = 0; i < c; i++)
                {
                    _floatTemp[i] = _minMaxTemp[i].Max;
                }
                _ringBufferMax.ResetPointer();
                _ringBufferMax.AddVertices(_floatTemp, 0, (int)c);

                for (int i = 0; i < c / 2; i++)
                {
                    _floatTemp[i] = _minMaxTemp[i].Min;
                }
                _ringBufferMin.ResetPointer();
                _ringBufferMin.AddVertices(_floatTemp, 0, (int)c);

                return(2 * (int)c);
            }
        }