Skip to content

Commit 5ff849a

Browse files
committed
Fix audio thumbnail generation
1 parent 2c0248c commit 5ff849a

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

modules/yup_audio_gui/waveform/yup_AudioPeakProfileCache.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,14 @@ void AudioPeakProfileCache::notifyProfileReady (const String& cacheKey, std::sha
349349
notify();
350350
return;
351351
}
352-
}
353352

354-
if (MessageManager::callAsync (notify))
353+
// Always use callAsync when not on message thread - don't fall back to synchronous call
354+
MessageManager::callAsync (notify);
355355
return;
356+
}
356357
#endif
357358

359+
// Fallback for when message manager is not available
358360
notify();
359361
}
360362

@@ -376,12 +378,14 @@ void AudioPeakProfileCache::notifyProfileProgress (const String& cacheKey, doubl
376378
notify();
377379
return;
378380
}
379-
}
380381

381-
if (MessageManager::callAsync (notify))
382+
// Always use callAsync when not on message thread - don't fall back to synchronous call
383+
MessageManager::callAsync (notify);
382384
return;
385+
}
383386
#endif
384387

388+
// Fallback for when message manager is not available
385389
notify();
386390
}
387391

modules/yup_audio_gui/waveform/yup_AudioThumbnail.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,14 @@ void AudioThumbnail::paintChannel (Graphics& g,
195195
// Calculate zoom level and select best aggregation level
196196
const int numSamplesInRange = static_cast<int> (sampleRange.getLength());
197197
const float samplesPerPixel = static_cast<float> (numSamplesInRange) / static_cast<float> (pixelColumns);
198+
const int baseResolution = currentProfile->getBaseResolution();
198199

199200
int bestLevel = 0;
200201
for (int i = 0; i < currentProfile->getNumAggregationLevels(); ++i)
201202
{
202203
const int factor = currentProfile->getAggregationFactor (i);
203-
if (samplesPerPixel >= factor * 2.0f)
204+
const float samplesPerPeakAtLevel = static_cast<float> (baseResolution * factor);
205+
if (samplesPerPixel >= samplesPerPeakAtLevel * 2.0f)
204206
bestLevel = i;
205207
else
206208
break;
@@ -233,7 +235,11 @@ void AudioThumbnail::paintChannel (Graphics& g,
233235
for (int pixel = 0; pixel < pixelColumns; ++pixel)
234236
{
235237
const int peakStart = startPeak + static_cast<int> (pixel * peaksPerPixelColumn);
236-
const int peakEnd = startPeak + static_cast<int> ((pixel + 1) * peaksPerPixelColumn);
238+
int peakEnd = startPeak + static_cast<int> ((pixel + 1) * peaksPerPixelColumn);
239+
240+
// Ensure we always render at least one peak per pixel (fixes spiky appearance when zoomed in)
241+
if (peakEnd <= peakStart)
242+
peakEnd = peakStart + 1;
237243

238244
// Aggregate all peaks for this pixel column
239245
float minValue = 0.0f;

0 commit comments

Comments
 (0)