Skip to content

Commit 784e531

Browse files
committed
AudioFFTBase; phase()
1 parent 1aa4e71 commit 784e531

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/AudioTools/AudioLibs/AudioFFT.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,6 @@ class AudioFFTBase : public AudioStream {
348348
/// time before the fft
349349
unsigned long resultTimeBegin() { return timestamp_begin; }
350350

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-
}
365351

366352
/// Determines the result values in the max magnitude bin
367353
AudioFFTResult result() {
@@ -401,6 +387,21 @@ class AudioFFTBase : public AudioStream {
401387
/// functionality
402388
FFTDriver *driver() { return p_driver; }
403389

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+
404405
/// Calculates the magnitude of the fft result to determine the max value (bin
405406
/// is 0 to size())
406407
float magnitude(int bin) {
@@ -418,6 +419,17 @@ class AudioFFTBase : public AudioStream {
418419
}
419420
return p_driver->magnitudeFast(bin);
420421
}
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+
421433
/// Provides the magnitudes as array of size size(). Please note that this
422434
/// method is allocating additinal memory!
423435
float *magnitudes() {

0 commit comments

Comments
 (0)