Fix audio playback and waveform rendering for the vsnd file preview widget (#3540)

* Fix vsnd playback skipping the first few milliseconds

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

Co-authored-by: DrakeFruit <foxflowgaming@gmail.com>
This commit is contained in:
sboxbot
2025-12-03 06:32:11 +00:00
committed by GitHub
parent d72ffaf059
commit 22dc5b1f24
2 changed files with 6 additions and 4 deletions

View File

@@ -101,7 +101,7 @@ public partial class SoundPlayer
float fRange = maxVal - minVal;
int columns = MathX.FloorToInt( TimelineView.PositionFromTime( TimelineView.Duration ) / LineSize );
SamplesPerColumn = (sampleCount / columns);
SamplesPerColumn = Math.Max( 1, sampleCount / columns );
for ( int i = 0; i < columns - 1; i++ )
{

View File

@@ -180,7 +180,6 @@ public partial class SoundPlayer : Widget
if ( Timeline.Playing && !Scrubbing )
{
Time += RealTime.Delta;
var time = Time % Duration;
if ( time < Time )
{
@@ -194,9 +193,10 @@ public partial class SoundPlayer : Widget
}
else
{
time = 0;
Time = time;
SoundHandle?.Stop( 0.0f );
time = 0;
Time = 0;
MoveScrubber( 0 );
Timeline.Playing = false;
}
}
@@ -204,11 +204,13 @@ public partial class SoundPlayer : Widget
if ( Timeline.Playing && !SoundHandle.IsValid() )
{
SoundHandle = EditorUtility.PlaySound( Sound, Time );
SoundHandle.Time = 0;
SoundHandle.Occlusion = false;
SoundHandle.DistanceAttenuation = false;
}
Scrubber.Position = Scrubber.Position.WithX( PositionFromTime( Time ) - 3 ).SnapToGrid( 1.0f );
Time += RealTime.SmoothDelta;
}
if ( SoundHandle.IsValid() )