Derive buffer length

This commit is contained in:
Jordan Eldredge 2020-01-01 14:03:14 -08:00
parent a8f2dcb40e
commit e705766081
2 changed files with 6 additions and 9 deletions

View file

@ -94,14 +94,14 @@ class Visualizer extends React.Component {
// update.
this.props.analyser.fftSize = 2048;
if (this.props.style === VISUALIZERS.OSCILLOSCOPE) {
this.bufferLength = this.props.analyser.fftSize;
this.dataArray = new Uint8Array(this.bufferLength);
this.dataArray = new Uint8Array(this.props.analyser.fftSize);
} else if (this.props.style === VISUALIZERS.BAR) {
this.bufferLength = this.props.analyser.frequencyBinCount;
this.dataArray = new Uint8Array(this.bufferLength);
this.dataArray = new Uint8Array(this.props.analyser.frequencyBinCount);
if (!this.octaveBuckets) {
this.octaveBuckets = octaveBucketsForBufferLength(this.bufferLength);
this.octaveBuckets = octaveBucketsForBufferLength(
this.dataArray.length
);
}
}
}
@ -116,7 +116,6 @@ class Visualizer extends React.Component {
canvasCtx: this.canvasCtx,
height: this.props.height,
width: this.props.width,
bufferLength: this.bufferLength,
colors: this.props.colors,
renderWidth: this.props.renderWidth,
});

View file

@ -116,7 +116,6 @@ export function paintOscilloscopeFrame({
canvasCtx,
height,
width,
bufferLength,
colors,
renderWidth,
}: {
@ -125,7 +124,6 @@ export function paintOscilloscopeFrame({
canvasCtx: CanvasRenderingContext2D;
height: number;
width: number;
bufferLength: number;
colors: string[];
renderWidth: number;
}) {
@ -142,7 +140,7 @@ export function paintOscilloscopeFrame({
//
// We use the 2x scale here since we only want to plot values for
// "real" pixels.
const sliceWidth = Math.floor(bufferLength / width) * PIXEL_DENSITY;
const sliceWidth = Math.floor(dataArray.length / width) * PIXEL_DENSITY;
const h = height;