Skip to content

Instantly share code, notes, and snippets.

@nzjrs
nzjrs / Makefile
Created May 25, 2011 07:09
Python ctypes example
all: test libtest.so testmodule
libtest.so: libtest.c
$(CC) -Wall -g -fPIC -shared -o $@ $? -lc
test: test_main.c libtest.o
$(CC) -o $@ $?
testmodule: testmodule.c
python setup.py build
@nicolamontecchio
nicolamontecchio / ctypes_stuff.py
Created August 6, 2012 19:34
python ctypes - array conversion
#let's say f_TI is something like
#void blabla(int *data, int data_length);
#then
f_TI.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.c_int]
lll = [4,7,2,8]
lll_c = (ctypes.c_int * len(lll))(*lll)
f_TI(lll_c, len(lll))
/* fix_fft.c - Fixed-point in-place Fast Fourier Transform */
/*
All data are fixed-point short integers, in which -32768
to +32768 represent -1.0 to +1.0 respectively. Integer
arithmetic is used for speed, instead of the more natural
floating-point.
For the forward FFT (time -> freq), fixed scaling is
performed to prevent arithmetic overflow, and to map a 0dB
sine/cosine wave (i.e. amplitude = 32767) to two -6dB freq