diff --git a/FlaxEditor/Viewport/Previews/AudioClipPreview.cs b/FlaxEditor/Viewport/Previews/AudioClipPreview.cs index 2ea18725..6f3dd0c0 100644 --- a/FlaxEditor/Viewport/Previews/AudioClipPreview.cs +++ b/FlaxEditor/Viewport/Previews/AudioClipPreview.cs @@ -80,6 +80,9 @@ public override void Draw() // Sample count uint numSamplesPerChannel = info.NumSamples / info.NumChannels; uint samplesPerIndex = (uint)(numSamplesPerChannel / Width); + const uint maxSamplesPerIndex = 64; + uint actualSamplesPerIndex = Math.Min(samplesPerIndex, maxSamplesPerIndex); + uint samplesPerIndexDiff = Math.Max(1, samplesPerIndex / actualSamplesPerIndex); // Render each channel separately so outer loop is the sound wave channel index for (uint channelIndex = 0; channelIndex < info.NumChannels; channelIndex++) @@ -95,10 +98,11 @@ public override void Draw() int numSamplesInPixel = 0; // Loop through all pixels in this x-frame, sum all audio data. Track total frames rendered to avoid writing past buffer boundary - for (uint sampleIndex = 0; sampleIndex < samplesPerIndex && currentSample < numSamplesPerChannel; sampleIndex++) + uint samplesEnd = Math.Min(currentSample + samplesPerIndex, numSamplesPerChannel); + for (uint sampleIndex = currentSample; sampleIndex < samplesEnd; sampleIndex += samplesPerIndexDiff) { // Get the sample value - uint index = currentSample + channelIndex; + uint index = sampleIndex + channelIndex; float value = _pcmData[index]; // Sum the sample value with the running sum @@ -106,10 +110,8 @@ public override void Draw() // Track the number of samples we're actually summing to get an accurate average numSamplesInPixel++; - - // Move to the next sample - currentSample++; } + currentSample = samplesEnd; // If we actually added any audio data in this pixel if (numSamplesInPixel > Mathf.Epsilon)