public bool TryPlay(AudioUpdatedEventArgs e) { AssertUndisposed(); if (!_isBusy.TryAcquire(true)) { return false; } if (_isPaused) { _sourceVoice.Start(); _isPaused = false; } _audioBuffer.AudioData = _bufferStreams[_bufferCursor]; _audioBuffer.AudioBytes = (int)e.SampleCount * 4; e.AudioBuffer.ReadRange<byte>(_buffers[_bufferCursor], 0, _audioBuffer.AudioBytes); _sourceVoice.SubmitSourceBuffer(_audioBuffer); _bufferCursor = _bufferCursor >= BufferCount -1 ? 0 : _bufferCursor + 1; if (_sourceVoice.State.BuffersQueued >= BufferCount) { _isBusy.Value = true; } if (_sourceVoice.State.BuffersQueued < BufferCount) { _isBusy.Value = false; } return true; }
void Snes_AudioUpdated(object sender, AudioUpdatedEventArgs e) { if (_isAudioSynced) { _audioDriver.Play(e); } else { _audioDriver.TryPlay(e); } }
public void Play(AudioUpdatedEventArgs e) { while (!TryPlay(e)) { _isBusy.WaitWhile(); } }