Skip to content

Fix audio playback and waveform rendering for the vsnd file preview widget#58

Closed
DrakeFruit wants to merge 3 commits intoFacepunch:masterfrom
DrakeFruit:master
Closed

Fix audio playback and waveform rendering for the vsnd file preview widget#58
DrakeFruit wants to merge 3 commits intoFacepunch:masterfrom
DrakeFruit:master

Conversation

@DrakeFruit
Copy link
Copy Markdown
Contributor

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

@DrakeFruit
Copy link
Copy Markdown
Contributor Author

related issue #1757

@lolleko lolleko requested a review from Copilot November 28, 2025 08:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Delta to RealTime.SmoothDelta for 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.

Comment thread game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs
Comment thread game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs
Copy link
Copy Markdown
Contributor

@lolleko lolleko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs Outdated
@DrakeFruit
Copy link
Copy Markdown
Contributor Author

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

@DrakeFruit DrakeFruit requested a review from lolleko December 1, 2025 02:29
Copy link
Copy Markdown
Contributor

@lolleko lolleko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me, definitely an improvement. Can you rebase s on to latest master, so the checks can run properly?

@DrakeFruit
Copy link
Copy Markdown
Contributor Author

done, I think. Never rebased before

@lolleko lolleko added the triaged triaged pull-requests are replicated on the internal sbox repo label Dec 2, 2025
@lolleko
Copy link
Copy Markdown
Contributor

lolleko commented Dec 2, 2025

I need you to rebase one more time sorry.

@lolleko lolleko removed the triaged triaged pull-requests are replicated on the internal sbox repo label Dec 2, 2025
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
@lolleko lolleko added the triaged triaged pull-requests are replicated on the internal sbox repo label Dec 3, 2025
@sboxbot sboxbot added the accepted this pull request was accepted, hurrah! label Dec 3, 2025
@sboxbot
Copy link
Copy Markdown
Contributor

sboxbot commented Dec 3, 2025

This PR has been merged upstream.

@sboxbot sboxbot closed this Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted this pull request was accepted, hurrah! triaged triaged pull-requests are replicated on the internal sbox repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants