I must say that the more I use the ffi pack the more impressed I am It is a great piece of well done software engineering. It is just a joy be able to call C code directly from prolog with just a header and the shared library.
I am having trouble on using enum values.
C declaration like this:
enum window_t
{
// No window functions
WIN_NONE, // Rectangle window (or no window)
// High-resolution window functions
WIN_SINE, // Sine window
WIN_HAMMING, // Hamming window
WIN_BLACKMAN, // Blackman window
// Low-resolution window functions
WIN_BLACKMAN_NUTTALL // Blackman-Nuttall window
};
bool Filter_Diff_flt32 (flt32_t filter[], size_t size, flt32_t lowfreq, flt32_t highfreq, enum window_t window);
Prolog like this:
:- c_import("#include \"Filter.h\"", % ffi:cpp_hook provides -I flag
[ linasm(lib/'liblinasm.so') ],
[
'Filter_Diff_flt32'(
*float, % flt32_t filter[],
int, % size_t size,
float, % flt32_t lowfreq,
float, % flt32_t highfreq,
%int, % window_t window
enum(window_t), % window_t window
[void]) % bool, but we ignore for now until fix
]).
e(F) :-
filter_diff(_,F,5,0,0.4,'WIN_NONE').
filter_diff(FloatType, Filter, OrderHalf, LowFreq, HighFreq, Window) :-
Count is 2*OrderHalf+1,
array(float32, Count, Filter),
'Filter_Diff_flt32'(Filter, OrderHalf, LowFreq, HighFreq, Window).
array(float32, Count, ArrayPtr) :-
var(ArrayPtr), !,
c_alloc(ArrayPtr, float[Count]).
Error:
ERROR: enum_id `'WIN_NONE'' does not exist in filter:window_t
How can I access the enum value in the call to the C function?