Skip to content

Commit 66a6dee

Browse files
Partial Analyser implementation
1 parent 4b91f4f commit 66a6dee

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/effects/Analyser.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Sound from "../Sound"
2+
import Effect from "./Effect"
3+
import HighPassFilter from "./HighPassFilter";
4+
5+
export default class Analyser extends Effect {
6+
7+
constructor(binCount = 4){
8+
super();
9+
10+
this.analyserNode = Sound.context.createAnalyser();
11+
12+
this.effectBus.connect(this.analyserNode);
13+
this.analyserNode.connect(this.wetGainNode);
14+
}
15+
16+
// Outputs what is essentially a bar graph of how much each frequency is included in the current audio signal.
17+
getFrequencyData(storageArray){
18+
if(!storageArray){
19+
storageArray = new Float32Array(this.analyserNode.frequencyBinCount); // This will allow people to pass the same array to save on space and copying, but it's not necessary if they just want to check once.
20+
}
21+
return this.analyserNode.getFloatTimeDomainData(storageArray);
22+
}
23+
24+
// Outputs what is essentially a snapshot of the waveform of the audio signal at this instant.
25+
getTimeDomainData(storageArray){
26+
if(!storageArray){
27+
storageArray = new Float32Array(this.analyserNode.frequencyBinCount); // This will allow people to pass the same array to save on space and copying, but it's not necessary if they just want to check once.
28+
}
29+
return this.analyserNode.getFloatFrequencyData(storageArray);
30+
}
31+
32+
clone(){
33+
return new Analyser();
34+
}
35+
}

0 commit comments

Comments
 (0)