|
26 | 26 | // |
27 | 27 |
|
28 | 28 | // ported from stmlib: https://github.com/pichenettes/stmlib/blob/master/fft/shy_fft.h |
| 29 | +// plus some comments to document the input/output formats |
| 30 | +// extra notes here: |
| 31 | +// https://forum.electro-smith.com/t/my-battle-with-shy-fft-h-and-what-it-taught-me-shyfft-quick-guide/8455/5 |
29 | 32 | // @KitDSP |
30 | 33 | // ----------------------------------------------------------------------------- |
31 | 34 | // |
@@ -678,6 +681,12 @@ struct InverseTransform<T, 2, Phasor> { |
678 | 681 | } |
679 | 682 | }; |
680 | 683 |
|
| 684 | +/** |
| 685 | + * ShyFFT public class. |
| 686 | + * @param T the sample format |
| 687 | + * @param size the max number of samples in the input/output buffers |
| 688 | + * @param Phasor pick between LutPhasor (more memory, faster) and RotationPhaser |
| 689 | + */ |
681 | 690 | template <typename T = float, size_t size = 16, template <typename, size_t> class Phasor = LutPhasor> |
682 | 691 | class ShyFFT { |
683 | 692 | public: |
@@ -708,21 +717,44 @@ class ShyFFT { |
708 | 717 | phasor_.Init(); |
709 | 718 | } |
710 | 719 |
|
| 720 | + /** |
| 721 | + * perform direct FFT. |
| 722 | + * @param input the input buffer. should be `size` samples long. this is used destructively. |
| 723 | + * @param output the output buffer. should be `size` samples long, returns the real components (from [0, size*0.5), |
| 724 | + * then the imaginary components (from [size*0.5, size), non-interleaved. |
| 725 | + */ |
711 | 726 | void Direct(T* input, T* output) { |
712 | 727 | DirectTransform<T, num_passes, Phasor<T, num_passes> > d; |
713 | 728 | d(input, output, num_passes <= 8 ? &bit_rev_[0] : bit_rev_256_lut_, &phasor_); |
714 | 729 | } |
715 | 730 |
|
| 731 | + /** |
| 732 | + * perform inverse FFT. |
| 733 | + * @param input the input buffer. should be the real values, then the imaginary. this is used destructively. |
| 734 | + * @param output the output buffer. should be `size` samples long, this is an audio signal. |
| 735 | + */ |
716 | 736 | void Inverse(T* input, T* output) { |
717 | 737 | InverseTransform<T, num_passes, Phasor<T, num_passes> > i; |
718 | 738 | i(input, output, num_passes <= 8 ? &bit_rev_[0] : bit_rev_256_lut_, &phasor_); |
719 | 739 | } |
720 | 740 |
|
| 741 | + /** |
| 742 | + * perform direct FFT. |
| 743 | + * @param input the input buffer. should be `n` samples long. this is used destructively. |
| 744 | + * @param output the output buffer. should be `n` samples long, non-interleaved. |
| 745 | + * @param n the size of the buffer. |
| 746 | + */ |
721 | 747 | void Direct(T* input, T* output, size_t n) { |
722 | 748 | DirectTransform<T, num_passes, Phasor<T, num_passes> > d; |
723 | 749 | d(input, output, bit_rev_256_lut_, &phasor_, n); |
724 | 750 | } |
725 | 751 |
|
| 752 | + /** |
| 753 | + * perform inverse FFT. |
| 754 | + * @param input the input buffer. should be `n` samples long, non-interleaved. this is used destructively. |
| 755 | + * @param output the output buffer. should be `n` samples long. |
| 756 | + * @param n the size of the buffer. |
| 757 | + */ |
726 | 758 | void Inverse(T* input, T* output, size_t n) { |
727 | 759 | InverseTransform<T, num_passes, Phasor<T, num_passes> > i; |
728 | 760 | i(input, output, bit_rev_256_lut_, &phasor_, n); |
|
0 commit comments