private void PlayNextBuffer() { if (_currentBuffer == _maxBuffers) { return; } var newCurrentBuffer = Interlocked.Increment(ref _currentBuffer); AudioBuffer buffer; if (!_audioBuffers.TryGetValue(newCurrentBuffer, out buffer) || buffer == null) { return; } if (PreviousWorkItem.Volume != CurrentPlayWorkItem.Volume) { SourceVoice.SetVolume((float)CurrentPlayWorkItem.Volume, OperationId); PreviousWorkItem.Volume = CurrentPlayWorkItem.Volume; } if (PreviousWorkItem.Pan != CurrentPlayWorkItem.Pan) { SourceVoice.SetPan(CurrentPlayWorkItem.Pan, OperationId); PreviousWorkItem.Pan = CurrentPlayWorkItem.Pan; } if (PreviousWorkItem.Pitch != CurrentPlayWorkItem.Pitch) { SourceVoice.SetFrequencyRatio((float)CurrentPlayWorkItem.Pitch, OperationId); PreviousWorkItem.Pitch = CurrentPlayWorkItem.Pitch; } SourceVoice.SubmitSourceBuffer(buffer, null); AudioDefines.XAudio.CommitChanges(OperationId); }