Skip to content

Commit d44e57f

Browse files
committed
nearest factor of 2
1 parent 31394dd commit d44e57f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/website/js/renderer/channel_analysers.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ export function updateFftSize(this: Renderer) {
99
const mul = drum
1010
? STABILIZE_WAVEFORMS_FFT_MULTIPLIER / 2
1111
: STABILIZE_WAVEFORMS_FFT_MULTIPLIER;
12+
13+
const targetFFT = this._stabilizeWaveforms ? fft * mul : fft;
14+
1215
this.channelAnalysers[i].fftSize = Math.min(
1316
32768,
14-
this._stabilizeWaveforms ? fft * mul : fft
17+
// Nearest factor of 2
18+
1 << (31 - Math.clz32(targetFFT * this.sampleRateFactor))
1519
);
1620
}
1721
this.bigAnalyser.fftSize = Math.min(
1822
32768,
19-
this._normalAnalyserFft * STABILIZE_WAVEFORMS_FFT_MULTIPLIER * 2
23+
// Nearest factor of 2
24+
1 <<
25+
(31 -
26+
Math.clz32(
27+
this._normalAnalyserFft *
28+
STABILIZE_WAVEFORMS_FFT_MULTIPLIER *
29+
2 *
30+
this.sampleRateFactor
31+
))
2032
);
2133
}
2234

src/website/js/renderer/renderer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export class Renderer {
116116
protected readonly renderBigFft = renderBigFft.bind(this);
117117
protected readonly inputNode: AudioNode;
118118
protected readonly workerMode: boolean;
119+
protected readonly sampleRateFactor: number;
119120

120121
/**
121122
* Creates a new midi renderer for rendering notes visually.
@@ -137,6 +138,8 @@ export class Renderer {
137138
this.canvas = canvas;
138139
this.plainColors = channelColors;
139140
this.workerMode = workletMode;
141+
// All data has been adjusted for 44.1kHz, correct it here
142+
this.sampleRateFactor = this.synth.context.sampleRate / 44_100;
140143

141144
// Will be updated by locale manager
142145
locale.bindObjectProperty(

0 commit comments

Comments
 (0)