Skip to content

Commit

Permalink
eml_fft: Use floats everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnor committed Dec 29, 2018
1 parent 4407c33 commit d2ad0b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions bindings/eml_audio.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions emlearn/eml_fft.h
Expand Up @@ -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;


Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/bench.c
Expand Up @@ -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));

Expand Down
1 change: 0 additions & 1 deletion test/test_audio.py
Expand Up @@ -14,7 +14,6 @@
256,
512,
1024,
2048,
]
@pytest.mark.parametrize('n_fft', FFT_SIZES)
def test_rfft_simple(n_fft):
Expand Down

0 comments on commit d2ad0b1

Please sign in to comment.