mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-27 06:47:13 -05: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 <type_traits>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include "dsp_types.hpp"
|
||||||
#include "complex.hpp"
|
#include "complex.hpp"
|
||||||
#include "hal.h"
|
#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);
|
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>
|
template<typename T, size_t N>
|
||||||
void fft_swap(const std::array<complex16_t, N>& src, std::array<T, N>& dst) {
|
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");
|
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>
|
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");
|
static_assert(power_of_two(N), "only defined for N == power of two");
|
||||||
|
|
||||||
for(size_t i=0; i<N; i++) {
|
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));
|
const size_t i_rev = __RBIT(i) >> (32 - log_2(N));
|
||||||
std::swap(data[i], data[i_rev]);
|
std::swap(data[i], data[i_rev]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user