diff --git a/components/analysis/FrequencyAnalyzer.tsx b/components/analysis/FrequencyAnalyzer.tsx
index fb5f710..ea8d50b 100644
--- a/components/analysis/FrequencyAnalyzer.tsx
+++ b/components/analysis/FrequencyAnalyzer.tsx
@@ -29,13 +29,16 @@ export function FrequencyAnalyzer({ analyserNode, className }: FrequencyAnalyzer
const bufferLength = analyserNode.frequencyBinCount;
const dataArray = new Uint8Array(bufferLength);
+ // Get background color from computed styles
+ const bgColor = getComputedStyle(canvas.parentElement!).backgroundColor;
+
const draw = () => {
animationFrameRef.current = requestAnimationFrame(draw);
analyserNode.getByteFrequencyData(dataArray);
- // Clear canvas
- ctx.fillStyle = 'rgb(15, 15, 15)';
+ // Clear canvas with parent background color
+ ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, rect.width, rect.height);
const barWidth = rect.width / bufferLength;
@@ -77,10 +80,12 @@ export function FrequencyAnalyzer({ analyserNode, className }: FrequencyAnalyzer
Frequency Analyzer
-
+
+
+
);
}
diff --git a/components/analysis/Spectrogram.tsx b/components/analysis/Spectrogram.tsx
index ba2107a..352329e 100644
--- a/components/analysis/Spectrogram.tsx
+++ b/components/analysis/Spectrogram.tsx
@@ -30,6 +30,13 @@ export function Spectrogram({ analyserNode, className }: SpectrogramProps) {
const bufferLength = analyserNode.frequencyBinCount;
const dataArray = new Uint8Array(bufferLength);
+ // Get background color from computed styles
+ const bgColorStr = getComputedStyle(canvas.parentElement!).backgroundColor;
+ const bgMatch = bgColorStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
+ const bgR = bgMatch ? parseInt(bgMatch[1]) : 240;
+ const bgG = bgMatch ? parseInt(bgMatch[2]) : 240;
+ const bgB = bgMatch ? parseInt(bgMatch[3]) : 240;
+
// Initialize spectrogram data
spectrogramDataRef.current = ctx.createImageData(rect.width, rect.height);
@@ -61,13 +68,14 @@ export function Spectrogram({ analyserNode, className }: SpectrogramProps) {
const freqIndex = Math.floor((1 - y / rect.height) * bufferLength);
const value = dataArray[freqIndex];
- // Color mapping: black (0) -> blue -> cyan -> green -> yellow -> red (255)
+ // Color mapping: background color (0) -> blue -> cyan -> green -> yellow -> red (255)
let r, g, b;
if (value < 64) {
- // Black to blue
- r = 0;
- g = 0;
- b = value * 4;
+ // Background to blue
+ const t = value / 64;
+ r = Math.round(bgR * (1 - t));
+ g = Math.round(bgG * (1 - t));
+ b = Math.round(bgB * (1 - t) + 255 * t);
} else if (value < 128) {
// Blue to cyan
r = 0;
@@ -118,10 +126,12 @@ export function Spectrogram({ analyserNode, className }: SpectrogramProps) {
Spectrogram
-
+
+
+
);
}