Skip to content

Commit 1880be5

Browse files
committed
mirror spectrogram vertically to align with other software
1 parent 22be1d2 commit 1880be5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/handlers/meyda.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class meydaHandler implements FormatHandler {
172172
const frameData = new Float32Array(bufferSize);
173173

174174
for (let y = 0; y < imageHeight; y ++) {
175-
const pixelIndex = (x + y * imageWidth) * 4;
175+
const pixelIndex = (x + (imageHeight - y - 1) * imageWidth) * 4;
176176

177177
// Extract amplitude from R and G channels
178178
const magInt = pixelBuffer[pixelIndex] + (pixelBuffer[pixelIndex + 1] << 8);
@@ -246,14 +246,15 @@ class meydaHandler implements FormatHandler {
246246
for (let j = 0; j < imageHeight; j ++) {
247247
const magnitude = Math.sqrt(real[j] * real[j] + imaginary[j] * imaginary[j]);
248248
const phase = Math.atan2(imaginary[j], real[j]);
249+
const pixelIndex = (imageHeight - j - 1) * 4;
249250
// Encode magnitude in R, G channels
250251
const magInt = Math.floor(Math.min(magnitude * 65535, 65535));
251-
pixels[j * 4] = magInt & 0xFF;
252-
pixels[j * 4 + 1] = (magInt >> 8) & 0xFF;
252+
pixels[pixelIndex] = magInt & 0xFF;
253+
pixels[pixelIndex + 1] = (magInt >> 8) & 0xFF;
253254
// Encode phase in B channel
254255
const phaseNormalized = Math.floor(((phase + Math.PI) / (2 * Math.PI)) * 255);
255-
pixels[j * 4 + 2] = phaseNormalized;
256-
pixels[j * 4 + 3] = 0xFF;
256+
pixels[pixelIndex + 2] = phaseNormalized;
257+
pixels[pixelIndex + 3] = 0xFF;
257258
}
258259
const imageData = new ImageData(pixels as ImageDataArray, 1, imageHeight);
259260
this.#ctx.putImageData(imageData, i, 0);

0 commit comments

Comments
 (0)