private void OnBufferNeeded(object sender, EventArgs e) { Array.Clear(_buffer, 0, _buffer.Length); var available = _audioSampleProvider != null?_audioSampleProvider.Read(_buffer, _buffer.Length) : 0; _dsei.SubmitBuffer(_buffer, available); }
public void FillWith(IAudioSampleProvider audioSampleProvider) { Array.Clear(_samples, 0, _samples.Length); audioSampleProvider.Read(_samples, _samples.Length); _dataStream.Position = 0; _dataStream.Write(_samples, 0, _samples.Length); }
public void FillWith(IAudioSampleProvider audioSampleProvider) { Array.Clear(_samples, 0, _samples.Length); audioSampleProvider.Read(_samples, _samples.Length); _dataStream.Position = 0; _dataStream.Write(_samples, 0, _samples.Length); }
public int ReadBuffer(short[] samples, int numSamples) { var buffer = new byte[numSamples * 2]; var numBytes = _audioSampleProvider.Read(buffer, buffer.Length); var numSamplesRead = numBytes / 2; for (int i = 0; i < numSamplesRead; i++) { samples[i] = buffer.ToInt16(i * 2); } return(numSamplesRead); }
public int Read(byte[] samples, int count) { var numSamples = count / 2; var monoBuffer = new byte[numSamples]; var numBytes = _audioSampleProvider.Read(monoBuffer, numSamples); int offs = 0; for (int i = 0; i < numBytes; i += 2) { var value = monoBuffer.ToInt16(i); samples.WriteInt16(offs += 2, value); samples.WriteInt16(offs += 2, value); } return(numBytes * 2); }
void WriteJob() { _state = AudioOutputState.Playing; var data = new byte[_audioSampleProvider.AudioFormat.AverageBytesPerSecond]; while (_state == AudioOutputState.Playing) { Array.Clear(data, 0, data.Length); var bytesRead = _audioSampleProvider.Read(data, data.Length); //if (bytesRead != 0) { _writer.Write(data, 0, bytesRead); _dataChunkSize += bytesRead; } } UpdateHeader(); }