Skip to content

Commit 6f63ef1

Browse files
author
Maciej Makowski
committed
fix: fixed frequencyBinCount prop
1 parent 6962b98 commit 6f63ef1

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

apps/common-app/src/examples/AudioVisualizer/AudioVisualizer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import FreqTimeChart from './FreqTimeChart';
1212
import { Container, Button } from '../../components';
1313
import { layout } from '../../styles';
1414

15-
const FFT_SIZE = 2048;
15+
const FFT_SIZE = 256;
1616
const SMOOTHING_TIME_CONSTANT = 0.8;
1717
const MIN_DECIBELS = -140;
1818
const MAX_DECIBELS = 0;
@@ -82,6 +82,8 @@ const AudioVisualizer: React.FC = () => {
8282
analyserRef.current.minDecibels = MIN_DECIBELS;
8383
analyserRef.current.maxDecibels = MAX_DECIBELS;
8484

85+
console.log('analyser');
86+
8587
analyserRef.current.connect(audioContextRef.current.destination);
8688
}
8789

packages/react-native-audio-api/common/cpp/core/AnalyserNode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ AnalyserNode::AnalyserNode(audioapi::BaseAudioContext *context)
1919
vWriteIndex_(0) {
2020
inputBuffer_ = std::make_unique<AudioArray>(MAX_FFT_SIZE * 2);
2121
fftFrame_ = std::make_unique<FFTFrame>(fftSize_);
22-
magnitudeBuffer_ = std::make_unique<AudioArray>(DEFAULT_FFT_SIZE / 2);
22+
magnitudeBuffer_ = std::make_unique<AudioArray>(fftSize_ / 2);
2323
isInitialized_ = true;
2424
}
2525

@@ -50,6 +50,7 @@ void AnalyserNode::setFftSize(size_t fftSize) {
5050

5151
fftSize_ = fftSize;
5252
fftFrame_ = std::make_unique<FFTFrame>(fftSize_);
53+
magnitudeBuffer_ = std::make_unique<AudioArray>(fftSize_ / 2);
5354
}
5455

5556
void AnalyserNode::setMinDecibels(double minDecibels) {

packages/react-native-audio-api/src/core/AnalyserNode.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
import { IndexSizeError } from '../errors';
22
import { IAnalyserNode } from '../interfaces';
33
import AudioNode from './AudioNode';
4-
import BaseAudioContext from './BaseAudioContext';
54

65
export default class AnalyserNode extends AudioNode {
7-
readonly frequencyBinCount: number;
86
private static allowedFFTSize: number[] = [
97
32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768,
108
];
119

12-
constructor(context: BaseAudioContext, analyser: IAnalyserNode) {
13-
super(context, analyser);
14-
15-
this.fftSize = analyser.fftSize;
16-
this.frequencyBinCount = analyser.frequencyBinCount;
17-
this.minDecibels = analyser.minDecibels;
18-
this.maxDecibels = analyser.maxDecibels;
19-
this.smoothingTimeConstant = analyser.smoothingTimeConstant;
20-
}
21-
2210
public get fftSize(): number {
2311
return (this.node as IAnalyserNode).fftSize;
2412
}
@@ -75,6 +63,10 @@ export default class AnalyserNode extends AudioNode {
7563
(this.node as IAnalyserNode).smoothingTimeConstant = value;
7664
}
7765

66+
public get frequencyBinCount(): number {
67+
return (this.node as IAnalyserNode).frequencyBinCount;
68+
}
69+
7870
public getFloatFrequencyData(array: number[]): void {
7971
(this.node as IAnalyserNode).getFloatFrequencyData(array);
8072
}

0 commit comments

Comments
 (0)