ICFFT.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: ICFFT.h
  4. * Description: Node for CMSIS-DSP icfft
  5. *
  6. * $Date: 30 July 2021
  7. * $Revision: V1.10.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #ifndef _ICFFT_H_
  29. #define _ICFFT_H_
  30. template<typename IN, int inputSize,typename OUT,int outputSize>
  31. class ICFFT;
  32. /*
  33. The CMSIS-DSP ICFFT F32
  34. */
  35. template<int inputSize>
  36. class ICFFT<float32_t,inputSize,float32_t,inputSize>: public GenericNode<float32_t,inputSize,float32_t,inputSize>
  37. {
  38. public:
  39. ICFFT(FIFOBase<float32_t> &src,FIFOBase<float32_t> &dst):GenericNode<float32_t,inputSize,float32_t,inputSize>(src,dst){
  40. arm_status status;
  41. status=arm_cfft_init_f32(&sifft,inputSize>>1);
  42. };
  43. int prepareForRunning() override
  44. {
  45. if (this->willOverflow() ||
  46. this->willUnderflow()
  47. )
  48. {
  49. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  50. }
  51. return(0);
  52. };
  53. int run(){
  54. float32_t *a=this->getReadBuffer();
  55. float32_t *b=this->getWriteBuffer();
  56. memcpy((void*)b,(void*)a,inputSize*sizeof(float32_t));
  57. arm_cfft_f32(&sifft,b,1,1);
  58. return(0);
  59. };
  60. arm_cfft_instance_f32 sifft;
  61. };
  62. #if defined(ARM_FLOAT16_SUPPORTED)
  63. /*
  64. The CMSIS-DSP ICFFT F32
  65. */
  66. template<int inputSize>
  67. class ICFFT<float16_t,inputSize,float16_t,inputSize>: public GenericNode<float16_t,inputSize,float16_t,inputSize>
  68. {
  69. public:
  70. ICFFT(FIFOBase<float16_t> &src,FIFOBase<float16_t> &dst):GenericNode<float16_t,inputSize,float16_t,inputSize>(src,dst){
  71. arm_status status;
  72. status=arm_cfft_init_f16(&sifft,inputSize>>1);
  73. };
  74. int prepareForRunning() override
  75. {
  76. if (this->willOverflow() ||
  77. this->willUnderflow()
  78. )
  79. {
  80. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  81. }
  82. return(0);
  83. };
  84. int run(){
  85. float16_t *a=this->getReadBuffer();
  86. float16_t *b=this->getWriteBuffer();
  87. memcpy((void*)b,(void*)a,inputSize*sizeof(float16_t));
  88. arm_cfft_f16(&sifft,b,1,1);
  89. return(0);
  90. };
  91. arm_cfft_instance_f16 sifft;
  92. };
  93. #endif
  94. /*
  95. The CMSIS-DSP ICFFT Q15
  96. */
  97. template<int inputSize>
  98. class ICFFT<q15_t,inputSize,q15_t,inputSize>: public GenericNode<q15_t,inputSize,q15_t,inputSize>
  99. {
  100. public:
  101. ICFFT(FIFOBase<q15_t> &src,FIFOBase<q15_t> &dst):GenericNode<q15_t,inputSize,q15_t,inputSize>(src,dst){
  102. arm_status status;
  103. status=arm_cfft_init_q15(&sifft,inputSize>>1);
  104. };
  105. int prepareForRunning() override
  106. {
  107. if (this->willOverflow() ||
  108. this->willUnderflow()
  109. )
  110. {
  111. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  112. }
  113. return(0);
  114. };
  115. int run(){
  116. q15_t *a=this->getReadBuffer();
  117. q15_t *b=this->getWriteBuffer();
  118. memcpy((void*)b,(void*)a,inputSize*sizeof(q15_t));
  119. arm_cfft_q15(&sifft,b,1,1);
  120. return(0);
  121. };
  122. arm_cfft_instance_f32 sifft;
  123. };
  124. #endif