Skip to content

Fix spectrum frequency and amplitude mapping - #1

Closed
Muimi272 wants to merge 1 commit into
masterfrom
fix-waveform-spectrum-log-scale
Closed

Muimi272 wants to merge 1 commit into
masterfrom
fix-waveform-spectrum-log-scale

Conversation

@Muimi272

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI lite review requested due to automatic review settings August 25, 2026 18:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new frequency and dB mappings appear incompatible with the existing spectrum producers (already banded/log-compressed), likely causing distorted/flattened spectrum display.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the spectrum visualization logic in WaveformView to change how FFT/spectrum bins are mapped across display bands and how amplitudes are normalized for rendering.

Changes:

  • Changed band-to-source mapping in pushSpectrum to a log-frequency-based mapping (20Hz–20kHz) and expanded the input clamp range.
  • Changed spectrum bar and peak rendering to convert values to dB and then normalize into a 0–1 magnitude range.
File summaries
File Description
src/main/java/club/muimi/kimusic/view/component/WaveformView.java Adjusts spectrum bin selection and amplitude normalization used to render the spectrum/peaks.
Review details

Suppressed comments (1)

src/main/java/club/muimi/kimusic/view/component/WaveformView.java:166

  • Same as the main bar: converting spectrumPeaks[index] to dB again likely distorts peak behavior because peak values are already normalized/log-compressed by the producers. Keeping the previous peak scaling keeps peak decay semantics consistent with spectrumPeaks[index] = ... - 0.018f.
            float peakRaw = (float) (spectrumPeaks[index] * displayScale);
            double peakDb = 20 * Math.log10(peakRaw + 1e-12);
            double peakNormalized = (peakDb + 120) / 120;
            double peakMagnitude = Math.max(0.025, Math.min(1.0, peakNormalized));
  • Files reviewed: 1/1 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +66 to +69
double normalized = (double) index / spectrum.length;
double freq = 20.0 * Math.pow(20000.0 / 20.0, normalized);
int source = (int) (freq / (20000.0 / values.length));
source = Math.min(values.length - 1, Math.max(0, source));
source = Math.min(values.length - 1, Math.max(0, source));
// Preserve headroom so dense peaks can be normalized during drawing.
float value = Math.max(0, Math.min(4, values[source]));
float value = Math.max(0, Math.min(20, values[source]));
Comment on lines +156 to +159
float raw = (float) (spectrum[index] * displayScale);
double db = 20 * Math.log10(raw + 1e-12);
double normalized = (db + 120) / 120;
double magnitude = Math.max(0.025, Math.min(1.0, normalized));
@Muimi272 Muimi272 closed this Aug 25, 2026
@Muimi272
Muimi272 deleted the fix-waveform-spectrum-log-scale branch August 25, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants