Skip to content
Permalink
Browse files

eml_fft: Use floats everywhere

  • Loading branch information...
jonnor committed Dec 5, 2018
1 parent 4407c33 commit d2ad0b1c33913872545881c2a144aa98f5dfe1cf
Showing with 11 additions and 12 deletions.
  1. +4 −4 bindings/eml_audio.cpp
  2. +5 −5 emlearn/eml_fft.h
  3. +2 −2 test/bench.c
  4. +0 −1 test/test_audio.py
@@ -23,8 +23,8 @@ rfft_py(py::array_t<float, py::array::c_style | py::array::forcecast> in) {

// Precompute FFT table
const int n_fft_table = n_fft/2;
std::vector<double> fft_sin(n_fft_table);
std::vector<double> fft_cos(n_fft_table);
std::vector<float> fft_sin(n_fft_table);
std::vector<float> fft_cos(n_fft_table);
EmlFFT fft = { n_fft_table, fft_sin.data(), fft_cos.data() };
eml_fft_fill(fft, n_fft);

@@ -66,8 +66,8 @@ melspectrogram_py(py::array_t<float, py::array::c_style | py::array::forcecast>

// FFT table
const int n_fft_table = n_fft/2;
std::vector<double> fft_sin(n_fft_table);
std::vector<double> fft_cos(n_fft_table);
std::vector<float> fft_sin(n_fft_table);
std::vector<float> fft_cos(n_fft_table);
EmlFFT fft = { n_fft_table, fft_sin.data(), fft_cos.data() };
eml_fft_fill(fft, n_fft);

@@ -45,8 +45,8 @@ static size_t reverse_bits(size_t x, int n) {

typedef struct _EmlFFT {
int length; // (n/2)
double *sin;
double *cos;
float *sin;
float *cos;
} EmlFFT;


@@ -77,7 +77,7 @@ eml_fft_forward(EmlFFT table, float real[], float imag[], size_t n) {
for (size_t i = 0; i < n; i++) {
size_t j = reverse_bits(i, levels);
if (j > i) {
double temp = real[i];
float temp = real[i];
real[i] = real[j];
real[j] = temp;
temp = imag[i];
@@ -93,8 +93,8 @@ eml_fft_forward(EmlFFT table, float real[], float imag[], size_t n) {
for (size_t i = 0; i < n; i += size) {
for (size_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
size_t l = j + halfsize;
double tpre = real[l] * table.cos[k] + imag[l] * table.sin[k];
double tpim = -real[l] * table.sin[k] + imag[l] * table.cos[k];
float tpre = real[l] * table.cos[k] + imag[l] * table.sin[k];
float tpim = -real[l] * table.sin[k] + imag[l] * table.cos[k];
real[l] = real[j] - tpre;
imag[l] = imag[j] - tpim;
real[j] += tpre;
@@ -19,8 +19,8 @@ bench_melspec()
eml_benchmark_fill(input_data, frame_length);

const int n_fft_table = n_fft/2;
double fft_sin[n_fft_table];
double fft_cos[n_fft_table];
float fft_sin[n_fft_table];
float fft_cos[n_fft_table];
EmlFFT fft = { n_fft_table, fft_sin, fft_cos };
EML_CHECK_ERROR(eml_fft_fill(fft, n_fft));

@@ -14,7 +14,6 @@
256,
512,
1024,
2048,
]
@pytest.mark.parametrize('n_fft', FFT_SIZES)
def test_rfft_simple(n_fft):

0 comments on commit d2ad0b1

Please sign in to comment.
You can’t perform that action at this time.