/// <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); } }
private long FillBuffer(long samples) { var arr = _buffer.GetSamples(); var res = true; var read = 0L; read = _reader.ReadSamples(arr, 0, samples); if (_seekWindow != null) { _seekWindow.ValueBackground = _reader.Position; } _buffer.SetWritten((int)read); return(read); }