mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Add more fft_swap bit reversal functions.
This commit is contained in:
parent
8f7e26b5c1
commit
882fbbef31
@ -29,6 +29,7 @@
|
||||
#include <type_traits>
|
||||
#include <array>
|
||||
|
||||
#include "dsp_types.hpp"
|
||||
#include "complex.hpp"
|
||||
#include "hal.h"
|
||||
|
||||
@ -54,6 +55,20 @@ constexpr size_t log_2(const size_t n, const size_t p = 0) {
|
||||
return (n <= 1) ? p : log_2(n / 2, p + 1);
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void fft_swap(const buffer_c16_t src, std::array<T, N>& dst) {
|
||||
static_assert(power_of_two(N), "only defined for N == power of two");
|
||||
|
||||
for(size_t i=0; i<N; i++) {
|
||||
const size_t i_rev = __RBIT(i) >> (32 - log_2(N));
|
||||
const auto s = src.p[i];
|
||||
dst[i_rev] = {
|
||||
static_cast<typename T::value_type>(s.real()),
|
||||
static_cast<typename T::value_type>(s.imag())
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void fft_swap(const std::array<complex16_t, N>& src, std::array<T, N>& dst) {
|
||||
static_assert(power_of_two(N), "only defined for N == power of two");
|
||||
@ -69,10 +84,20 @@ void fft_swap(const std::array<complex16_t, N>& src, std::array<T, N>& dst) {
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void fft_swap_in_place(std::array<T, N>& data) {
|
||||
void fft_swap(const std::array<T, N>& src, std::array<T, N>& dst) {
|
||||
static_assert(power_of_two(N), "only defined for N == power of two");
|
||||
|
||||
for(size_t i=0; i<N; i++) {
|
||||
const size_t i_rev = __RBIT(i) >> (32 - log_2(N));
|
||||
dst[i_rev] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void fft_swap_in_place(std::array<T, N>& data) {
|
||||
static_assert(power_of_two(N), "only defined for N == power of two");
|
||||
|
||||
for(size_t i=0; i<N/2; i++) {
|
||||
const size_t i_rev = __RBIT(i) >> (32 - log_2(N));
|
||||
std::swap(data[i], data[i_rev]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user