4 # include "CMSIS_DSP.h"
6 #if defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_RP2040)
7 # include "arm_vec_fft.h"
25 bool begin(
int len)
override {
28 input =
new float[len];
29 output =
new float[len*2];
30 output_magn =
new float[len];
31 status = arm_rfft_fast_init_f32(&fft_instance, len);
32 if (status!=ARM_MATH_SUCCESS){
33 LOGE(
"arm_rfft_fast_init_f32: %d", status);
35 assert(input!=
nullptr);
36 assert(output!=
nullptr);
37 assert(output_magn !=
nullptr);
38 return input!=
nullptr && output !=
nullptr && output_magn !=
nullptr;
42 if (input!=
nullptr)
delete input;
43 if (output!=
nullptr)
delete output;
44 if (output_magn!=
nullptr)
delete output_magn;
47 output_magn =
nullptr;
56 arm_rfft_fast_f32(&fft_instance, input, output,
false);
57 arm_cmplx_mag_f32(output, output_magn, len / 2);
59 arm_max_f32(output_magn, len / 2, &result_max_value, &result_index);
64 arm_rfft_fast_f32(&fft_instance, output, input,
true);
68 return output_magn[idx];
73 return output_magn[idx];
76 float getValue(
int idx)
override {
return input[idx];}
78 bool setBin(
int pos,
float real,
float img)
override {
79 if (pos>=len)
return false;
81 output[pos*2+1] = img;
85 if (pos>=len)
return false;
86 bin.real = output[pos*2];
87 bin.img = output[pos*2+1];
93 bool isValid()
override{
return status==ARM_MATH_SUCCESS; }
95 arm_rfft_fast_instance_f32 fft_instance;
99 float *output_magn=
nullptr;
100 float *output=
nullptr;
101 float result_max_value;
102 uint32_t result_index = 0;
118 return driverEx()->output;
121 float* magnitudes() {
122 return driverEx()->output_magn;
125 AudioFFTResult result() {
126 AudioFFTResult ret_value;
127 ret_value.magnitude = driverEx()->result_max_value;
128 ret_value.bin = driverEx()->result_index;
132 FFTDriverCmsisFFT* driverEx() {
133 return (FFTDriverCmsisFFT*)
driver();