Eliminate WASAPI haptic start/stop click by keeping the stream running#76
Closed
tomaabe wants to merge 1 commit into
Closed
Eliminate WASAPI haptic start/stop click by keeping the stream running#76tomaabe wants to merge 1 commit into
tomaabe wants to merge 1 commit into
Conversation
The Advanced Haptics WASAPI path started the IAudioClient on each Play and stopped it when the clip ended, so the actuator was driven through a fresh start/stop every time. That produced an audible click/pop at the start of playback. The XAudio2 path does not have this problem because its mastering voice runs continuously and only the source voice starts and stops. Mirror that lifecycle for WASAPI: start the render stream once in InitializeDevice and keep it running for the life of the device. Idle time renders silence, Play installs a sample generator, and end-of-clip/Stop simply clears the generator instead of stopping the device. Playback completion is now tracked with an atomic m_clipActive flag so IsPlaying() reflects the active clip (both when the generator reaches EOF and when it is consumed on the idle path), which also keeps the UI's play buttons enabled/disabled correctly. The render stream and worker thread are torn down in the destructor.
|
Fixed internally, will be in the next github publish. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Advanced Haptics WASAPI playback path produced an audible click/pop at the start of every clip. This was caused by starting and stopping the
IAudioClient(and therefore the haptic actuator) on each play. This change keeps the WASAPI render stream running continuously — mirroring how the XAudio2 path already behaves — so the device is never started/stopped mid-session and the click is eliminated.Repro steps
Root cause
The WASAPI path called
IAudioClient::Start()on eachPlay()andIAudioClient::Stop()when the clip ended. Each start/stop drives the actuator through a transient, which is audible as a click. The XAudio2 path does not have this issue because its mastering voice runs continuously and only the source voice starts/stops.Fix
InitializeDeviceand keep it running for the lifetime of the device.Play()installs a sample generator; end-of-clip andStop()clear the generator instead of stopping the device.m_clipActiveflag soIsPlaying()reflects the active clip — set false both when the generator reaches EOF and when it is found exhausted on the idle render path. This also keeps the UI's play buttons enabled/disabled correctly.Testing
Notes
WASAPIManager.