rfft.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang)
  3. *
  4. * See LICENSE for clarification regarding multiple authors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef KALDI_NATIVE_FBANK_CSRC_RFFT_H_
  19. #define KALDI_NATIVE_FBANK_CSRC_RFFT_H_
  20. #include <memory>
  21. namespace knf {
  22. // n-point Real discrete Fourier transform
  23. // where n is a power of 2. n >= 2
  24. //
  25. // R[k] = sum_j=0^n-1 in[j]*cos(2*pi*j*k/n), 0<=k<=n/2
  26. // I[k] = sum_j=0^n-1 in[j]*sin(2*pi*j*k/n), 0<k<n/2
  27. class Rfft {
  28. public:
  29. // @param n Number of fft bins. it should be a power of 2.
  30. explicit Rfft(int32_t n);
  31. ~Rfft();
  32. /** @param in_out A 1-D array of size n.
  33. * On return:
  34. * in_out[0] = R[0]
  35. * in_out[1] = R[n/2]
  36. * for 1 < k < n/2,
  37. * in_out[2*k] = R[k]
  38. * in_out[2*k+1] = I[k]
  39. *
  40. */
  41. void Compute(float *in_out);
  42. void Compute(double *in_out);
  43. private:
  44. class RfftImpl;
  45. std::unique_ptr<RfftImpl> impl_;
  46. };
  47. } // namespace knf
  48. #endif // KALDI_NATIVE_FBANK_CSRC_RFFT_H_