Fix audio playback and waveform rendering for the vsnd file preview widget#58
Fix audio playback and waveform rendering for the vsnd file preview widget#58DrakeFruit wants to merge 3 commits intoFacepunch:masterfrom
Conversation
|
related issue #1757 |
There was a problem hiding this comment.
Pull request overview
This PR fixes two issues in the vsnd file preview widget: audio playback skipping the first few milliseconds and waveform rendering failing for very short sounds in wide inspectors.
- Moved time increment to end of frame to prevent premature audio advancement
- Added minimum sample constraint for waveform rendering to handle edge cases
- Switched from
RealTime.DeltatoRealTime.SmoothDeltafor more consistent playback
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs | Reordered time increment logic, added explicit time reset on sound start, and switched to smooth delta for playback |
| game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.Waveform.cs | Added Math.Max constraint to ensure SamplesPerColumn is at least 1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lolleko
left a comment
There was a problem hiding this comment.
Thanks for the PR, seems reasonable, just needs some clarification:
I don't really understand why we do SoundHandle.Time = 0; after PlaySound shouldnt we instead set this.Time to 0 before calling PlaySound.
|
I don't really understand why it works myself I just know that if you don't set the time to zero immediately after calling play it will skip the first few milliseconds of audio on subsequent playbacks. I'll run dotnet format, thanks |
lolleko
left a comment
There was a problem hiding this comment.
Fine with me, definitely an improvement. Can you rebase s on to latest master, so the checks can run properly?
|
done, I think. Never rebased before |
|
I need you to rebase one more time sorry. |
only increment Time after everything else has finished happening, this fixes the first few milliseconds of audio being cut off Ensure SamplesPerColumn is greater than 1, this fixes the waveaform being a solid line if a sound file was too short and the inspector was too wide Fix subsequent playback skipping time by setting time to 0 after EditorUtility.PlaySound Use SmoothDelta to fix inconsistent playback
|
This PR has been merged upstream. |
When playing a vsnd file, it would skip past the first few milliseconds of audio. Especially obvious with short sounds where nothing would seem to play at all.
Second, if the inspector was too wide some of these very short vsnd files wouldn't render properly (e.g. sounds/kenney/ui/click_002.wav) because it was taking less than 1 sample per column, resulting in 0 or negative samples.
Audio Playback
Before:
sbox-dev_HB1jIg5Xbg.mp4
After:
sbox-dev_noqAehl4NU.mp4
Waveform Rendering
Before:
before.mp4
After:
sbox-dev_9tkxKVZQiC.mp4
Changes
only increment Time after everything else has finished happening, this fixes the first few milliseconds of audio being cut off
Ensure SamplesPerColumn is greater than 1, this fixes the waveform being a solid line if a sound file was too short and the inspector was too wide
Fix subsequent playback skipping time by setting time to 0 after EditorUtility.PlaySound
Use SmoothDelta to fix inconsistent playback