@@ -348,20 +348,6 @@ class AudioFFTBase : public AudioStream {
348
348
// / time before the fft
349
349
unsigned long resultTimeBegin () { return timestamp_begin; }
350
350
351
- // / Determines the frequency of the indicated bin
352
- float frequency (int bin) {
353
- if (bin >= bins) {
354
- LOGE (" Invalid bin %d" , bin);
355
- return 0 ;
356
- }
357
- return static_cast <float >(bin) * cfg.sample_rate / cfg.length ;
358
- }
359
-
360
- // / Determine the bin number from the frequency
361
- int frequencyToBin (int freq){
362
- int max_freq = cfg.sample_rate / 2 ;
363
- return map (freq, 0 , max_freq, 0 , size ());
364
- }
365
351
366
352
// / Determines the result values in the max magnitude bin
367
353
AudioFFTResult result () {
@@ -401,6 +387,21 @@ class AudioFFTBase : public AudioStream {
401
387
// / functionality
402
388
FFTDriver *driver () { return p_driver; }
403
389
390
+ // / Determines the frequency of the indicated bin
391
+ float frequency (int bin) {
392
+ if (bin >= bins) {
393
+ LOGE (" Invalid bin %d" , bin);
394
+ return 0 ;
395
+ }
396
+ return static_cast <float >(bin) * cfg.sample_rate / cfg.length ;
397
+ }
398
+
399
+ // / Determine the bin number from the frequency
400
+ int frequencyToBin (int freq){
401
+ int max_freq = cfg.sample_rate / 2 ;
402
+ return map (freq, 0 , max_freq, 0 , size ());
403
+ }
404
+
404
405
// / Calculates the magnitude of the fft result to determine the max value (bin
405
406
// / is 0 to size())
406
407
float magnitude (int bin) {
@@ -418,6 +419,17 @@ class AudioFFTBase : public AudioStream {
418
419
}
419
420
return p_driver->magnitudeFast (bin);
420
421
}
422
+
423
+ // / calculates the phase
424
+ float phase (int bin){
425
+ FFTBin fft_bin;
426
+ getBin (bin, fft_bin);
427
+ return atan2 (fft_bin.img , fft_bin.real );
428
+ }
429
+
430
+
431
+
432
+
421
433
// / Provides the magnitudes as array of size size(). Please note that this
422
434
// / method is allocating additinal memory!
423
435
float *magnitudes () {
0 commit comments