Skip to content

Commit

Permalink
Missed a few variables that weren't in camelCase
Browse files Browse the repository at this point in the history
Finetuned the data going into timeToFrequencyDomain
  • Loading branch information
0x5066 committed Aug 24, 2024
1 parent 2d1457f commit dc59c28
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
24 changes: 12 additions & 12 deletions packages/webamp/js/components/FFTNullsoft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export class FFT {
}

public init(
samples_in: number,
samples_out: number,
samplesIn: number,
samplesOut: number,
bEqualize = 1,
envelopePower = 1.0,
mode = false
): void {
this.mSamplesIn = samples_in;
this.NFREQ = samples_out * 2;
this.mSamplesIn = samplesIn;
this.NFREQ = samplesOut * 2;

this.initBitRevTable();
this.initCosSinTable();
Expand Down Expand Up @@ -119,13 +119,13 @@ export class FFT {
}

public timeToFrequencyDomain(
in_wavedata: Float32Array,
out_spectraldata: Float32Array
inWavedata: Float32Array,
outSpectraldata: Float32Array
): void {
if (!this.bitrevtable || !this.temp1 || !this.temp2 || !this.cossintable)
return;
// Converts time-domain samples from in_wavedata[]
// into frequency-domain samples in out_spectraldata[].
// Converts time-domain samples from inWavedata[]
// into frequency-domain samples in outSpectraldata[].
// The array lengths are the two parameters to Init().

// The last sample of the output data will represent the frequency
Expand Down Expand Up @@ -172,7 +172,7 @@ export class FFT {
for (let i = 0; i < this.NFREQ; i++) {
const idx = this.bitrevtable[i];
if (idx < this.mSamplesIn) {
this.temp1[i] = in_wavedata[idx] * this.envelope[idx];
this.temp1[i] = inWavedata[idx] * this.envelope[idx];
} else {
this.temp1[i] = 0;
}
Expand All @@ -181,7 +181,7 @@ export class FFT {
for (let i = 0; i < this.NFREQ; i++) {
const idx = this.bitrevtable[i];
if (idx < this.mSamplesIn) {
this.temp1[i] = in_wavedata[idx];
this.temp1[i] = inWavedata[idx];
} else {
this.temp1[i] = 0;
}
Expand Down Expand Up @@ -225,12 +225,12 @@ export class FFT {
// 3. take the magnitude & equalize it (on a log10 scale) for output
if (this.equalize) {
for (let i = 0; i < this.NFREQ / 2; i++) {
out_spectraldata[i] =
outSpectraldata[i] =
this.equalize[i] * Math.sqrt(real[i] * real[i] + imag[i] * imag[i]);
}
} else {
for (let i = 0; i < this.NFREQ / 2; i++) {
out_spectraldata[i] = Math.sqrt(real[i] * real[i] + imag[i] * imag[i]);
outSpectraldata[i] = Math.sqrt(real[i] * real[i] + imag[i] * imag[i]);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/webamp/js/components/Vis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ type Props = {
export let PIXEL_DENSITY = 1;

const fft = new FFT();
const SAMPLESIN = 1024; // Example input size
const SAMPLESOUT = 512; // Example output size
const SAMPLESIN = 1024;
const SAMPLESOUT = 512;
export let renderWidth: number;
export let renderHeight: number;
export let windowShade: boolean | undefined;
export let doubled: boolean | undefined;
fft.init(SAMPLESIN, SAMPLESOUT, 1, 1.0, true);

let in_wavedata = new Float32Array(SAMPLESIN); // Fill this with your input data
export let out_spectraldata = new Float32Array(SAMPLESOUT);
let inWavedata = new Float32Array(SAMPLESIN);
export let outSpectraldata = new Float32Array(SAMPLESOUT);

// Pre-render the background grid
function preRenderBg(
Expand Down Expand Up @@ -85,7 +85,7 @@ export default function Vis({ analyser }: Props) {
const dataArray = new Uint8Array(1024);
analyser.getByteTimeDomainData(dataArray);

in_wavedata = new Float32Array(dataArray.length);
inWavedata = new Float32Array(dataArray.length);

const toggleVisualizerStyle = useActionCreator(Actions.toggleVisualizerStyle);
windowShade = getWindowShade("main");
Expand Down Expand Up @@ -163,9 +163,9 @@ export default function Vis({ analyser }: Props) {
painter.prepare();
analyser.getByteTimeDomainData(dataArray);
for (let i = 0; i < dataArray.length; i++) {
in_wavedata[i] = (dataArray[i] - 128) / 32;
inWavedata[i] = (dataArray[i] - 128) / 28;
}
fft.timeToFrequencyDomain(in_wavedata, out_spectraldata);
fft.timeToFrequencyDomain(inWavedata, outSpectraldata);
painter.paintFrame();
animationRequest = window.requestAnimationFrame(loop);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/webamp/js/components/VisPainter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Vis {
}
import { range } from "lodash";
import {
out_spectraldata,
outSpectraldata,
renderHeight,
renderWidth,
windowShade,
Expand Down Expand Up @@ -287,12 +287,12 @@ export class BarPaintHandler extends VisPaintHandler {
}

if (index1 == index2) {
sample[x] = out_spectraldata[index1];
sample[x] = outSpectraldata[index1];
} else {
let frac2 = scaledIndex - index1;
let frac1 = 1.0 - frac2;
sample[x] =
frac1 * out_spectraldata[index1] + frac2 * out_spectraldata[index2];
frac1 * outSpectraldata[index1] + frac2 * outSpectraldata[index2];
}
}

Expand Down

0 comments on commit dc59c28

Please sign in to comment.