perf+ux: cache reassignment, keep manual dB floor, dedupe load paths

- Split GenerateSpectrogramTexture into ComputeSpectrogramReassignment
  (the expensive synchrosqueezing, cached in app.reassignBuffer) and
  ColorizeSpectrogram (cheap). dB-floor and colormap changes now only
  re-colorize instead of recomputing the whole reassignment every frame —
  the dB slider and colormap switching are smooth on large files.
- AutoScaleAmplitude no longer overwrites a dB floor the user set by hand
  (amplitudeUserSet flag, reset per file load).
- Extract ResetForNewSignal() used by all three load paths; removes the
  duplicated reset blocks and the double ComputeSTFTInit per load. Drag-drop
  now resets the selection like the browser already did.
- Remove the dead lastInteractedFrame field.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 01:26:51 -07:00
parent 3a8f20b783
commit ddbbe2734c
6 changed files with 94 additions and 70 deletions
+34 -32
View File
@@ -53,6 +53,37 @@ static bool IsUserInteracting(void)
return false;
}
// Reset all per-signal state after a new signal has been loaded into app.signal.
// Drops the cached STFT/FFT-size cache and the on-screen textures so the main
// loop recomputes from scratch (loadingPhase 0 handles the STFT (re)alloc).
void ResetForNewSignal(void)
{
app.loaded = true;
app.stftComputed = false;
app.loadingPhase = 0;
app.loadingProgress = 0.0f;
app.currentSTFTSegment = 0;
app.skipFactor = 1;
app.highResFinished = false;
app.bgHighResSeg = 0;
app.bgFinished = false;
app.isBgProcessing = false;
app.amplitudeUserSet = false; // re-enable auto-scaling for the new file
// Cached STFT results are tied to the old signal data.
FreeAllCacheEntries(&app.fftCache);
// Reset view + selection to full range.
app.viewStart = 0.0f; app.viewEnd = 1.0f;
app.timeSelectionStart = 0.0f; app.timeSelectionEnd = 1.0f;
app.freqSelectionStart = 0.0f; app.freqSelectionEnd = 1.0f;
// Invalidate the cached visible texture.
if (app.visibleTexture.id != 0) UnloadTexture(app.visibleTexture);
app.visibleTexture = (Texture2D){ 0 };
app.visibleTextureValid = false;
}
// ============================================================================
// Main Application
// ============================================================================
@@ -108,7 +139,6 @@ int main(int argc, char* argv[])
app.highResFinished = false;
app.bgHighResSeg = 0;
app.bgFinished = false;
app.lastInteractedFrame = 0;
app.isBgProcessing = false;
// Initialize FFT cache
app.fftCache.count = 0;
@@ -151,19 +181,7 @@ int main(int argc, char* argv[])
if (FileExists(pathToLoad) && LoadWavFile(pathToLoad, &app.signal)) {
fileLoaded = true;
app.loaded = true;
app.stftComputed = false;
app.loadingPhase = 0;
app.loadingProgress = 0.0f;
app.currentSTFTSegment = 0;
app.skipFactor = 1;
app.highResFinished = false;
app.bgHighResSeg = 0;
app.bgFinished = false;
app.isBgProcessing = false;
// Signal changed — free cache (results are tied to signal data)
FreeAllCacheEntries(&app.fftCache);
ComputeSTFTInit(&app.signal, &app.stft, app.fftSize);
ResetForNewSignal();
TraceLog(LOG_INFO, "File loaded successfully");
}
}
@@ -180,24 +198,7 @@ int main(int argc, char* argv[])
bool isWav = ext && (strcmp(ext, ".wav") == 0 || strcmp(ext, ".WAV") == 0 || strcmp(ext, ".Wave") == 0 || strcmp(ext, ".Wav") == 0);
if (isWav && FileExists(dropped.paths[0])) {
if (LoadWavFile(dropped.paths[0], &app.signal)) {
app.loaded = true;
app.stftComputed = false;
app.loadingPhase = 0;
app.loadingProgress = 0.0f;
app.currentSTFTSegment = 0;
app.skipFactor = 1;
app.highResFinished = false;
app.bgHighResSeg = 0;
app.bgFinished = false;
app.isBgProcessing = false;
// Signal changed — free cache (results are tied to signal data)
FreeAllCacheEntries(&app.fftCache);
app.viewStart = 0.0f; app.viewEnd = 1.0f;
ComputeSTFTInit(&app.signal, &app.stft, app.fftSize);
// Invalidate visible texture cache
if (app.visibleTexture.id != 0) UnloadTexture(app.visibleTexture);
app.visibleTexture = (Texture2D){ 0 };
app.visibleTextureValid = false;
ResetForNewSignal();
}
}
}
@@ -986,6 +987,7 @@ int main(int argc, char* argv[])
UnloadTexture(colormapTexture);
FreeBrowserFiles();
FreeAllCacheEntries(&app.fftCache);
free(app.reassignBuffer);
FreeSignal(&app.signal);
CloseAudioDevice();
CloseWindow();