File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,13 @@ describe("FFT", () => {
35
35
fft . dispose ( ) ;
36
36
} ) ;
37
37
38
+ it ( "can get the frequency values of each index of the return array" , ( ) => {
39
+ const fft = new FFT ( 32 ) ;
40
+ expect ( fft . getFrequencyOfIndex ( 0 ) ) . to . be . closeTo ( 0 , 1 ) ;
41
+ expect ( fft . getFrequencyOfIndex ( 16 ) ) . to . be . closeTo ( fft . context . sampleRate / 4 , 1 ) ;
42
+ fft . dispose ( ) ;
43
+ } ) ;
44
+
38
45
it ( "can run waveform analysis" , ( done ) => {
39
46
const noise = new Noise ( ) ;
40
47
const fft = new FFT ( 256 ) ;
Original file line number Diff line number Diff line change 1
1
import { ToneAudioNode } from "../../core/context/ToneAudioNode" ;
2
2
import { dbToGain } from "../../core/type/Conversions" ;
3
- import { NormalRange , PowerOfTwo } from "../../core/type/Units" ;
3
+ import { Hertz , NormalRange , PowerOfTwo } from "../../core/type/Units" ;
4
4
import { optionsFromArguments } from "../../core/util/Defaults" ;
5
5
import { MeterBase , MeterBaseOptions } from "./MeterBase" ;
6
+ import { assert } from "../../core/util/Debug" ;
6
7
7
8
export interface FFTOptions extends MeterBaseOptions {
8
9
size : PowerOfTwo ;
@@ -77,4 +78,15 @@ export class FFT extends MeterBase<FFTOptions> {
77
78
set smoothing ( val ) {
78
79
this . _analyser . smoothing = val ;
79
80
}
81
+
82
+ /**
83
+ * Returns the frequency value in hertz of each of the indices of the FFT's [[getValue]] response.
84
+ * @example
85
+ * const fft = new Tone.FFT(32);
86
+ * console.log(fft.getIndexFrequency());
87
+ */
88
+ getFrequencyOfIndex ( index : number ) : Hertz {
89
+ assert ( 0 <= index && index < this . size , `index must be greater than or equal to 0 and less than ${ this . size } ` ) ;
90
+ return index * this . context . sampleRate / ( this . size * 2 ) ;
91
+ }
80
92
}
You can’t perform that action at this time.
0 commit comments