o
odinpkg.dev
packages / binding / fftw3-odin-bindings

fftw3-odin-bindings

7ef151bbinding

Odin Bindings for the C library FFTW3 (Fastest Fourier Transform in the West)

MIT · updated 1 month ago

Odin Bindings for the Fastest Fourier Transform in the West FFTW3

Bindings for single precision (float, f32, fftwf_) and double precision (double, f64, fftw_) FFTW3 functions.

No bindings for long double (fftwl_) functions.

License

This repository is under MIT license. FFTW3 have their own license, see their website.

Quick Start

Get FFTW3

For example

sudo apt install libfftw3-dev

Run Tests

make test

Examples

Take a look at the tests for more example usage.

import fftw3 "./fftw3"

// DFT length
n: i32 = 10

// complex input
buf_x := make([^]fftw3.fftw_complex, n)
defer free(buf_x)

// complex result of forward transform
buf_x_forward := make([^]fftw3.fftw_complex, n)
defer free(buf_x_forward)

// initialize complex input
for i in 0 ..< n {
    buf_x[i][0] = f64(i) + 0.123 * f64(i)
    buf_x[i][1] = f64(n - i) - 0.456 * f64(n - i)
}

// plan a forward transform
plan := fftw3.fftw_plan_dft_1d(
    n,
    buf_x,
    buf_x_forward,
    fftw3.Sign.FORWARD,
    fftw3.Flags.ESTIMATE,
)
defer fftw3.fftw_destroy_plan(plan)

// execute the forward transform
fftw3.fftw_execute_dft(plan, buf_x, buf_x_forward)

How fftw3.odin was Created

  1. generate fftw3.odin using the Odin Bindings Generator for C Libraries
  2. remove all fftwl_* functions
  3. add FILE :: c.FILE
  4. add foreign import lib "system:fftw3" with @(extra_linker_flags = "-lfftw3_threads -lfftw3 -lm -lpthread"); same for the single precision version
  5. convert flags like FFTW_MEASURE to enum Flags.MEASURE and replace flags: u32 with flags: Flags in signatures
  6. convert FFTW_FORWARD and FFTW_BACKWARD to enum Sign.FORWARD and Sign.BACKWARD and replace sign: i32 with sign: Sign in signatures
  7. replace pointers ^ with [^]