diff options
author | joshua <joshua@joshuayun.com> | 2023-12-30 23:54:31 -0500 |
---|---|---|
committer | joshua <joshua@joshuayun.com> | 2023-12-30 23:54:31 -0500 |
commit | 86608c6770cf08c138a2bdab5855072f64be09ef (patch) | |
tree | 494a61b3ef37e76f9235a0d10f5c93d97290a35f /Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions | |
download | sdr-software-86608c6770cf08c138a2bdab5855072f64be09ef.tar.gz |
Diffstat (limited to 'Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions')
5 files changed, 1023 insertions, 0 deletions
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/TransformFunctions.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/TransformFunctions.c new file mode 100644 index 0000000..d100918 --- /dev/null +++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/TransformFunctions.c @@ -0,0 +1,4 @@ +
+#include "cfft.c"
+#include "dct4.c"
+#include "rfft.c"
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/bitreversal.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/bitreversal.c new file mode 100644 index 0000000..b5a4068 --- /dev/null +++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/bitreversal.c @@ -0,0 +1,30 @@ +#include "ref.h"
+
+
+;/*
+;* @brief In-place bit reversal function.
+;* @param[in, out] *pSrc points to the in-place buffer of unknown 32-bit data type.
+;* @param[in] bitRevLen bit reversal table length
+;* @param[in] *pBitRevTab points to bit reversal table.
+;* @return none.
+;*/
+void ref_arm_bitreversal_32(uint32_t *pSrc, uint32_t bitRevLen, uint32_t *pBitRevTab)
+{
+ uint32_t a,b,i,tmp;
+
+ for(i=0; i<bitRevLen; i++)
+ {
+ a = pBitRevTab[2*i];
+ b = pBitRevTab[2*i + 1];
+
+ //real
+ tmp = pSrc[a];
+ pSrc[a] = pSrc[b];
+ pSrc[b] = tmp;
+
+ //complex
+ tmp = pSrc[a+1];
+ pSrc[a+1] = pSrc[b+1];
+ pSrc[b+1] = tmp;
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/cfft.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/cfft.c new file mode 100644 index 0000000..ede4da6 --- /dev/null +++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/cfft.c @@ -0,0 +1,598 @@ +#include "ref.h"
+#include "arm_const_structs.h"
+
+void ref_cfft_f32(
+ const arm_cfft_instance_f32 * S,
+ float32_t * p1,
+ uint8_t ifftFlag,
+ uint8_t bitReverseFlag)
+{
+ int n, mmax, m, j, istep, i;
+ float32_t wtemp, wr, wpr, wpi, wi, theta;
+ float32_t tempr, tempi;
+ float32_t * data = p1;
+ uint32_t N = S->fftLen;
+ int32_t dir = (ifftFlag) ? -1 : 1;
+
+ // decrement pointer since the original version used fortran style indexing.
+ data--;
+
+ n = N << 1;
+ j = 1;
+ for (i = 1; i < n; i += 2) {
+ if (j > i) {
+ tempr = data[j]; data[j] = data[i]; data[i] = tempr;
+ tempr = data[j+1]; data[j+1] = data[i+1]; data[i+1] = tempr;
+ }
+ m = n >> 1;
+ while (m >= 2 && j > m) {
+ j -= m;
+ m >>= 1;
+ }
+ j += m;
+ }
+ mmax = 2;
+ while (n > mmax) {
+ istep = 2*mmax;
+ theta = -6.283185307179586f/(dir*mmax);
+ wtemp = sinf(0.5f*theta);
+ wpr = -2.0f*wtemp*wtemp;
+ wpi = sinf(theta);
+ wr = 1.0f;
+ wi = 0.0f;
+ for (m = 1; m < mmax; m += 2) {
+ for (i = m; i <= n; i += istep) {
+ j =i + mmax;
+ tempr = wr*data[j] - wi*data[j+1];
+ tempi = wr*data[j+1] + wi*data[j];
+ data[j] = data[i] - tempr;
+ data[j+1] = data[i+1] - tempi;
+ data[i] += tempr;
+ data[i+1] += tempi;
+ }
+ wr = (wtemp = wr)*wpr - wi*wpi + wr;
+ wi = wi*wpr + wtemp*wpi + wi;
+ }
+ mmax = istep;
+ }
+
+ // Inverse transform is scaled by 1/N
+ if (ifftFlag)
+ {
+ data++;
+ for(i = 0; i<2*N; i++)
+ {
+ data[i] /= N;
+ }
+ }
+}
+
+void ref_cfft_q31(
+ const arm_cfft_instance_q31 * S,
+ q31_t * p1,
+ uint8_t ifftFlag,
+ uint8_t bitReverseFlag)
+{
+ uint32_t i;
+ float32_t *fSrc = (float32_t*)p1;
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the q31 data, cast to float, scale down for float
+ fSrc[i] = (float32_t)p1[i] / 2147483648.0f;
+ }
+
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, ifftFlag, bitReverseFlag);
+ break;
+ }
+
+ if (ifftFlag)
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ p1[i] = (q31_t)( fSrc[i] * 2147483648.0f );
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ p1[i] = (q31_t)( fSrc[i] * 2147483648.0f / (float32_t)S->fftLen);
+ }
+ }
+}
+
+void ref_cfft_q15(
+ const arm_cfft_instance_q15 * S,
+ q15_t * pSrc,
+ uint8_t ifftFlag,
+ uint8_t bitReverseFlag)
+{
+ uint32_t i;
+ float32_t *fSrc = (float32_t*)pSrc;
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the q15 data, cast to float, scale down for float, place in temporary buffer
+ scratchArray[i] = (float32_t)pSrc[i] / 32768.0f;
+ }
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //copy from temp buffer to final buffer
+ fSrc[i] = scratchArray[i];
+ }
+
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, ifftFlag, bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, ifftFlag, bitReverseFlag);
+ break;
+ }
+
+ if (ifftFlag)
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q15, cast to q15
+ pSrc[i] = (q15_t)( fSrc[i] * 32768.0f );
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q15, cast to q15
+ pSrc[i] = (q15_t)( fSrc[i] * 32768.0f / (float32_t)S->fftLen);
+ }
+ }
+}
+
+void ref_cfft_radix2_f32(
+ const arm_cfft_radix2_instance_f32 * S,
+ float32_t * pSrc)
+{
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+ }
+}
+
+void ref_cfft_radix2_q31(
+ const arm_cfft_radix2_instance_q31 * S,
+ q31_t * pSrc)
+{
+ uint32_t i;
+ float32_t *fSrc = (float32_t*)pSrc;
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the q31 data, cast to float, scale down for float
+ fSrc[i] = (float32_t)pSrc[i] / 2147483648.0f;
+ }
+
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+ }
+
+ if (S->ifftFlag)
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f );
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f / (float32_t)S->fftLen);
+ }
+ }
+}
+
+void ref_cfft_radix2_q15(
+ const arm_cfft_radix2_instance_q15 * S,
+ q15_t * pSrc)
+{
+ uint32_t i;
+ float32_t *fSrc = (float32_t*)pSrc;
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the q15 data, cast to float, scale down for float, place in temporary buffer
+ scratchArray[i] = (float32_t)pSrc[i] / 32768.0f;
+ }
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //copy from temp buffer to final buffer
+ fSrc[i] = scratchArray[i];
+ }
+
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+ }
+
+ if (S->ifftFlag)
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q15, cast to q15
+ pSrc[i] = (q15_t)( fSrc[i] * 32768.0f );
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q15, cast to q15
+ pSrc[i] = (q15_t)( fSrc[i] * 32768.0f / (float32_t)S->fftLen);
+ }
+ }
+}
+
+void ref_cfft_radix4_f32(
+ const arm_cfft_radix4_instance_f32 * S,
+ float32_t * pSrc)
+{
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, pSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+ }
+}
+
+void ref_cfft_radix4_q31(
+ const arm_cfft_radix4_instance_q31 * S,
+ q31_t * pSrc)
+{
+ uint32_t i;
+ float32_t *fSrc = (float32_t*)pSrc;
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the q31 data, cast to float, scale down for float
+ fSrc[i] = (float32_t)pSrc[i] / 2147483648.0f;
+ }
+
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+ }
+
+ if (S->ifftFlag)
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f );
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f / (float32_t)S->fftLen);
+ }
+ }
+}
+
+void ref_cfft_radix4_q15(
+ const arm_cfft_radix4_instance_q15 * S,
+ q15_t * pSrc)
+{
+ uint32_t i;
+ float32_t *fSrc = (float32_t*)pSrc;
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the q15 data, cast to float, scale down for float, place in temporary buffer
+ scratchArray[i] = (float32_t)pSrc[i] / 32768.0f;
+ }
+
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //copy from temp buffer to final buffer
+ fSrc[i] = scratchArray[i];
+ }
+
+ switch(S->fftLen)
+ {
+ case 16:
+ ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag);
+ break;
+ }
+
+ if (S->ifftFlag)
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q15, cast to q15
+ pSrc[i] = (q15_t)( fSrc[i] * 32768.0f );
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLen*2;i++)
+ {
+ //read the float data, scale up for q15, cast to q15
+ pSrc[i] = (q15_t)( fSrc[i] * 32768.0f / (float32_t)S->fftLen);
+ }
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/dct4.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/dct4.c new file mode 100644 index 0000000..9c1f207 --- /dev/null +++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/dct4.c @@ -0,0 +1,89 @@ +#include "ref.h"
+
+void ref_dct4_f32(
+ const arm_dct4_instance_f32 * S,
+ float32_t * pState,
+ float32_t * pInlineBuffer)
+{
+ uint32_t n,k;
+ float32_t sum;
+ float32_t pi_by_N = 3.14159265358979f / (float32_t)S->N;
+ float32_t tmp;
+ float32_t normalize = sqrtf(2.0f / (float32_t)S->N);
+
+ for(k=0;k<S->N;k++)
+ {
+ sum=0.0f;
+ tmp = ((float32_t)k + 0.5f)*pi_by_N;
+ for(n=0;n<S->N;n++)
+ {
+ sum += pInlineBuffer[n] * cosf(tmp * ((float32_t)n + 0.5f));
+ }
+ scratchArray[k] = normalize * sum;
+ }
+
+ for(k=0;k<S->N;k++)
+ {
+ pInlineBuffer[k] = scratchArray[k];
+ }
+}
+
+void ref_dct4_q31(
+ const arm_dct4_instance_q31 * S,
+ q31_t * pState,
+ q31_t * pInlineBuffer)
+{
+ arm_dct4_instance_f32 SS;
+ float32_t *fSrc = (float32_t*)pInlineBuffer;
+ uint32_t i;
+
+ SS.N = S->N;
+
+ for(i=0;i<S->N;i++)
+ {
+ //read the q31 data, cast to float, scale down for float
+ fSrc[i] = (float32_t)pInlineBuffer[i] / 2147483648.0f;
+ }
+
+ ref_dct4_f32(&SS,(float32_t*)0,fSrc);
+
+ for(i=0;i<S->N;i++)
+ {
+ fSrc[i] = fSrc[i] * 2147483648.0f / (float32_t)S->N ;
+ fSrc[i] += (fSrc[i] > 0) ? 0.5f : -0.5f;
+ pInlineBuffer[i] = (q31_t)fSrc[i];
+ }
+}
+
+void ref_dct4_q15(
+ const arm_dct4_instance_q15 * S,
+ q15_t * pState,
+ q15_t * pInlineBuffer)
+{
+ arm_dct4_instance_f32 SS;
+ float32_t *fSrc = (float32_t*)pInlineBuffer;
+ uint32_t i;
+
+ SS.N = S->N;
+
+ for(i=0;i<S->N;i++)
+ {
+ //read the q15 data, cast to float, scale down for float, place in temporary buffer
+ scratchArray[i] = (float32_t)pInlineBuffer[i] / 32768.0f;
+ }
+
+ for(i=0;i<S->N;i++)
+ {
+ //copy from temp buffer to final buffer
+ fSrc[i] = scratchArray[i];
+ }
+
+ ref_dct4_f32(&SS,(float32_t*)0,fSrc);
+
+ for(i=0;i<S->N;i++)
+ {
+ fSrc[i] = fSrc[i] * 32768.0f / (float32_t)S->N;
+ fSrc[i] += (fSrc[i] > 0) ? 0.5f : -0.5f;
+ pInlineBuffer[i] = (q15_t)fSrc[i];
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/rfft.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/rfft.c new file mode 100644 index 0000000..79738f0 --- /dev/null +++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/rfft.c @@ -0,0 +1,302 @@ +#include "ref.h"
+#include "arm_const_structs.h"
+
+void ref_rfft_f32(
+ arm_rfft_instance_f32 * S,
+ float32_t * pSrc,
+ float32_t * pDst)
+{
+ uint32_t i;
+
+ if (S->ifftFlagR)
+ {
+ for(i=0;i<S->fftLenReal*2;i++)
+ {
+ pDst[i] = pSrc[i];
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ pDst[2*i+0] = pSrc[i];
+ pDst[2*i+1] = 0.0f;
+ }
+ }
+
+ switch(S->fftLenReal)
+ {
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, pDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, pDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, pDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 8192:
+ ref_cfft_f32(&ref_cfft_sR_f32_len8192, pDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+ }
+
+ if (S->ifftFlagR)
+ {
+ //throw away the imaginary part which should be all zeros
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ pDst[i] = pDst[2*i];
+ }
+ }
+}
+
+void ref_rfft_fast_f32(
+ arm_rfft_fast_instance_f32 * S,
+ float32_t * p, float32_t * pOut,
+ uint8_t ifftFlag)
+{
+ uint32_t i,j;
+
+ if (ifftFlag)
+ {
+ for(i=0;i<S->fftLenRFFT;i++)
+ {
+ pOut[i] = p[i];
+ }
+ //unpack first sample's complex part into middle sample's real part
+ pOut[S->fftLenRFFT] = pOut[1];
+ pOut[S->fftLenRFFT+1] = 0;
+ pOut[1] = 0;
+ j=4;
+ for(i = S->fftLenRFFT / 2 + 1;i < S->fftLenRFFT;i++)
+ {
+ pOut[2*i+0] = p[2*i+0 - j];
+ pOut[2*i+1] = -p[2*i+1 - j];
+ j+=4;
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLenRFFT;i++)
+ {
+ pOut[2*i+0] = p[i];
+ pOut[2*i+1] = 0.0f;
+ }
+ }
+
+ switch(S->fftLenRFFT)
+ {
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, pOut, ifftFlag, 1);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, pOut, ifftFlag, 1);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, pOut, ifftFlag, 1);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, pOut, ifftFlag, 1);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, pOut, ifftFlag, 1);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, pOut, ifftFlag, 1);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, pOut, ifftFlag, 1);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, pOut, ifftFlag, 1);
+ break;
+ }
+
+ if (ifftFlag)
+ {
+ //throw away the imaginary part which should be all zeros
+ for(i=0;i<S->fftLenRFFT;i++)
+ {
+ pOut[i] = pOut[2*i];
+ }
+ }
+ else
+ {
+ //pack last sample's real part into first sample's complex part
+ pOut[1] = pOut[S->fftLenRFFT];
+ }
+}
+
+void ref_rfft_q31(
+ const arm_rfft_instance_q31 * S,
+ q31_t * pSrc,
+ q31_t * pDst)
+{
+ uint32_t i;
+ float32_t *fDst = (float32_t*)pDst;
+
+ if (S->ifftFlagR)
+ {
+ for(i=0;i<S->fftLenReal*2;i++)
+ {
+ fDst[i] = (float32_t)pSrc[i] / 2147483648.0f;
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ fDst[2*i+0] = (float32_t)pSrc[i] / 2147483648.0f;
+ fDst[2*i+1] = 0.0f;
+ }
+ }
+
+ switch(S->fftLenReal)
+ {
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 8192:
+ ref_cfft_f32(&ref_cfft_sR_f32_len8192, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+ }
+
+ if (S->ifftFlagR)
+ {
+ //throw away the imaginary part which should be all zeros
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ pDst[i] = (q31_t)( fDst[2*i] * 2147483648.0f);
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ //read the float data, scale up for q31, cast to q31
+ pDst[i] = (q31_t)( fDst[i] * 2147483648.0f / (float32_t)S->fftLenReal);
+ }
+ }
+}
+
+void ref_rfft_q15(
+ const arm_rfft_instance_q15 * S,
+ q15_t * pSrc,
+ q15_t * pDst)
+{
+ uint32_t i;
+ float32_t *fDst = (float32_t*)pDst;
+
+
+ if (S->ifftFlagR)
+ {
+ for(i=0;i<S->fftLenReal*2;i++)
+ {
+ fDst[i] = (float32_t)pSrc[i] / 32768.0f;
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ //read the q15 data, cast to float, scale down for float
+ fDst[2*i+0] = (float32_t)pSrc[i] / 32768.0f;
+ fDst[2*i+1] = 0.0f;
+ }
+ }
+
+ switch(S->fftLenReal)
+ {
+ case 32:
+ ref_cfft_f32(&arm_cfft_sR_f32_len32, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 64:
+ ref_cfft_f32(&arm_cfft_sR_f32_len64, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 128:
+ ref_cfft_f32(&arm_cfft_sR_f32_len128, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 256:
+ ref_cfft_f32(&arm_cfft_sR_f32_len256, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 512:
+ ref_cfft_f32(&arm_cfft_sR_f32_len512, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 1024:
+ ref_cfft_f32(&arm_cfft_sR_f32_len1024, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 2048:
+ ref_cfft_f32(&arm_cfft_sR_f32_len2048, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 4096:
+ ref_cfft_f32(&arm_cfft_sR_f32_len4096, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+
+ case 8192:
+ ref_cfft_f32(&ref_cfft_sR_f32_len8192, fDst, S->ifftFlagR, S->bitReverseFlagR);
+ break;
+ }
+
+ if (S->ifftFlagR)
+ {
+ //throw away the imaginary part which should be all zeros
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ pDst[i] = (q15_t)( fDst[2*i] * 32768.0f);
+ }
+ }
+ else
+ {
+ for(i=0;i<S->fftLenReal;i++)
+ {
+ pDst[i] = (q15_t)( fDst[i] * 32768.0f / (float32_t)S->fftLenReal);
+ }
+ }
+}
|