Skip to content

Commit 7ae89c7

Browse files
committed
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
1 parent eb563ad commit 7ae89c7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.Waveform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void Analyse()
101101
float fRange = maxVal - minVal;
102102

103103
int columns = MathX.FloorToInt( TimelineView.PositionFromTime( TimelineView.Duration ) / LineSize );
104-
SamplesPerColumn = (sampleCount / columns);
104+
SamplesPerColumn = Math.Max(1, sampleCount / columns);
105105

106106
for ( int i = 0; i < columns - 1; i++ )
107107
{

game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected void OnFrame()
7878
{
7979
Timeline.OnFrame();
8080
Time = Timeline.Time;
81-
81+
8282
PlayOption.Text = Playing ? "Pause" : "Play";
8383
PlayOption.Icon = Playing ? "pause" : "play_arrow";
8484

@@ -180,7 +180,6 @@ public void OnFrame()
180180

181181
if ( Timeline.Playing && !Scrubbing )
182182
{
183-
Time += RealTime.Delta;
184183
var time = Time % Duration;
185184
if ( time < Time )
186185
{
@@ -194,21 +193,24 @@ public void OnFrame()
194193
}
195194
else
196195
{
197-
time = 0;
198-
Time = time;
199196
SoundHandle?.Stop( 0.0f );
197+
time = 0;
198+
Time = 0;
199+
MoveScrubber( 0 );
200200
Timeline.Playing = false;
201201
}
202202
}
203203

204204
if ( Timeline.Playing && !SoundHandle.IsValid() )
205205
{
206206
SoundHandle = EditorUtility.PlaySound( Sound, Time );
207+
SoundHandle.Time = 0;
207208
SoundHandle.Occlusion = false;
208209
SoundHandle.DistanceAttenuation = false;
209210
}
210211

211212
Scrubber.Position = Scrubber.Position.WithX( PositionFromTime( Time ) - 3 ).SnapToGrid( 1.0f );
213+
Time += RealTime.SmoothDelta;
212214
}
213215

214216
if ( SoundHandle.IsValid() )

0 commit comments

Comments
 (0)