private void ReadAndUseAudioProcessor(int requestedBytes, double speedRatio) { if (AudioProcessorBuffer == null || AudioProcessorBuffer.Length < Convert.ToInt32(requestedBytes * Constants.MaxSpeedRatio)) { AudioProcessorBuffer = new short[Convert.ToInt32(requestedBytes * Constants.MaxSpeedRatio / Constants.AudioBytesPerSample)]; } var bytesToRead = Convert.ToInt32((requestedBytes * speedRatio).ToMultipleOf(SampleBlockSize)); var samplesToRequest = requestedBytes / SampleBlockSize; // Set the new tempo (without changing the pitch) according to the speed ratio AudioProcessor.SetTempo(Convert.ToSingle(speedRatio)); // Sending Samples to the processor while (AudioProcessor.AvailableSampleCount < samplesToRequest && AudioBuffer != null) { var realBytesToRead = Math.Min(AudioBuffer.ReadableCount, bytesToRead); if (realBytesToRead == 0) { break; } realBytesToRead = Convert.ToInt32((realBytesToRead * 1.0).ToMultipleOf(SampleBlockSize)); AudioBuffer.Read(realBytesToRead, ReadBuffer, 0); Buffer.BlockCopy(ReadBuffer, 0, AudioProcessorBuffer, 0, realBytesToRead); AudioProcessor.PutSamplesI16(AudioProcessorBuffer, Convert.ToUInt32(realBytesToRead / SampleBlockSize)); } // Receiving samples from the processor var numSamples = AudioProcessor.ReceiveSamplesI16(AudioProcessorBuffer, Convert.ToUInt32(samplesToRequest)); Array.Clear(ReadBuffer, 0, ReadBuffer.Length); Buffer.BlockCopy(AudioProcessorBuffer, 0, ReadBuffer, 0, Convert.ToInt32(numSamples * SampleBlockSize)); }