diff --git a/packages/webamp/js/components/FFTNullsoft.ts b/packages/webamp/js/components/FFTNullsoft.ts index 4c321ed6d..b70e9dc2d 100644 --- a/packages/webamp/js/components/FFTNullsoft.ts +++ b/packages/webamp/js/components/FFTNullsoft.ts @@ -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(); @@ -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 @@ -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; } @@ -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; } @@ -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]); } } } diff --git a/packages/webamp/js/components/Vis.tsx b/packages/webamp/js/components/Vis.tsx index dfac3e64e..644a9a4fa 100644 --- a/packages/webamp/js/components/Vis.tsx +++ b/packages/webamp/js/components/Vis.tsx @@ -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( @@ -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"); @@ -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); }; diff --git a/packages/webamp/js/components/VisPainter.ts b/packages/webamp/js/components/VisPainter.ts index f1b8b4bdc..452b14633 100644 --- a/packages/webamp/js/components/VisPainter.ts +++ b/packages/webamp/js/components/VisPainter.ts @@ -13,7 +13,7 @@ export interface Vis { } import { range } from "lodash"; import { - out_spectraldata, + outSpectraldata, renderHeight, renderWidth, windowShade, @@ -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]; } }