static void Listen() { while (isWorking) { if (captureBuffer.Capturing) { if ((!BufferAverage_Calculating && !BufferAmp_Calculating && !LastNValues_Busy) && !stopFlag) { int pos = captureBuffer.CurrentRealPosition; int startIndex = (pos > BufferSize) ? pos - BufferSize : 0; int count = (pos > BufferSize) ? ((pos + BufferSize > captureBufferDescription.BufferBytes) ? (captureBufferDescription.BufferBytes - pos) : BufferSize) : pos; if (count == 0) { continue; } kek = captureBuffer.Lock(startIndex, count, LockFlags.None, out kek2); byte[] _tmpBuf = new byte[count]; kek.Read(_tmpBuf, 0, count); Buffer.BlockCopy(_tmpBuf, 0, _Buffer, (int)(BufferCursor % BufferSize), count); BufferCursor += count / 2; FourierTransformer.SetValues(LastNValues(ref _Buffer, 48000), 1.0f); captureBuffer.Unlock(kek, kek2); //stopFlag = true; //captureBuffer.Read(_Buffer, 0, count, startIndex, LockFlags.None); } dBytes = captureBuffer.CurrentCapturePosition - pCurrentCapturePosition; if (dBytes < 0) { dBytes = dBytes + 192000; } pCurrentCapturePosition = captureBuffer.CurrentCapturePosition; SecondsCaptured += 2 * (float)dBytes / captureBufferDescription.BufferBytes; } else { captureBuffer.Start(new RawBool()); } Thread.Sleep(5); } }