Add Debian source format file
[cl-fftw3.git] / ffi.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          ffi.lisp
6 ;;;; Purpose:       CFFI interface for FFTW3 package
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Mar 2009
9 ;;;;
10 ;;;; This file and CL-FFTW3 are Copyright (c) 2009-2011 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; FFTW3 users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
16
17 (in-package #:fftw3)
18
19 (cffi:define-foreign-library fftw3
20     ((or :darwin :macosx) (:or #P"/opt/local/lib/libfftw3.dylib"
21                                #P"/usr/lib/libfftw3.dylib"))
22     (:linux (:or #P"/usr/lib/libfftw3.so"
23                  #P"/usr/local/lib/libfftw3.so"))
24   (t (:default "libfftw3")))
25
26 (cffi:use-foreign-library fftw3)
27
28 (cffi:defcstruct fftw-complex-struct
29   "Complex number structure."
30   (re :double)
31   (im :double))
32
33 (cffi:defctype fftw-plan :pointer)
34
35 (declaim (inline fftw-plan-dft-1d))
36 (cffi:defcfun ("fftw_plan_dft_1d" fftw-plan-dft-1d) fftw-plan
37   (n :int)
38   (in (:pointer fftw-complex-struct))
39   (out (:pointer fftw-complex-struct))
40   (sign :int)
41   (flags :uint))
42
43 (declaim (inline fftw-plan-dft-2d))
44 (cffi:defcfun ("fftw_plan_dft_2d" fftw-plan-dft-2d) fftw-plan
45   (n0 :int)
46   (n1 :int)
47   (in (:pointer fftw-complex-struct))
48   (out (:pointer fftw-complex-struct))
49   (sign :int)
50   (flags :uint))
51
52 (declaim (inline fftw-plan-dft-3d))
53 (cffi:defcfun ("fftw_plan_dft_3d" fftw-plan-dft-3d) fftw-plan
54   (n0 :int)
55   (n1 :int)
56   (n2 :int)
57   (in (:pointer fftw-complex-struct))
58   (out (:pointer fftw-complex-struct))
59   (sign :int)
60   (flags :uint))
61
62 (declaim (inline fftw-plan-dft))
63 (cffi:defcfun ("fftw_plan_dft" fftw-plan-dft) fftw-plan
64   (rank :int)
65   (n (:pointer :int))
66   (in (:pointer fftw-complex-struct))
67   (out (:pointer fftw-complex-struct))
68   (sign :int)
69   (flags :uint))
70
71 (declaim (inline fftw-plan-r2r-1d))
72 (cffi:defcfun ("fftw_plan_r2r_1d" fftw-plan-r2r-1d) fftw-plan
73   (n :int)
74   (in :pointer)
75   (out :pointer)
76   (kind :int)
77   (flags :uint))
78
79 (declaim (inline fftw-plan-r2r-2d))
80 (cffi:defcfun ("fftw_plan_r2r_2d" fftw-plan-r2r-2d) fftw-plan
81   (n0 :int)
82   (n1 :int)
83   (in :pointer)
84   (out :pointer)
85   (kind :int)
86   (flags :uint))
87
88 (declaim (inline fftw-plan-r2r-3d))
89 (cffi:defcfun ("fftw_plan_r2r_3d" fftw-plan-r2r-3d) fftw-plan
90   (n0 :int)
91   (n1 :int)
92   (n2 :int)
93   (in :pointer)
94   (out :pointer)
95   (kind :int)
96   (flags :uint))
97
98 (declaim (inline fftw-plan-dft-r2c-1d))
99 (cffi:defcfun ("fftw_plan_dft_r2c_1d" fftw-plan-dft-r2c-1d) fftw-plan
100   (n :int)
101   (in :pointer)
102   (out :pointer)
103   (flags :uint))
104
105 (declaim (inline fftw-plan-dft-r2c-2d))
106 (cffi:defcfun ("fftw_plan_dft_r2c_2d" fftw-plan-dft-r2c-2d) fftw-plan
107   (n0 :int)
108   (n1 :int)
109   (in :pointer)
110   (out :pointer)
111   (flags :uint))
112
113 (declaim (inline fftw-plan-dft-r2c-3d))
114 (cffi:defcfun ("fftw_plan_dft_r2c_3d" fftw-plan-dft-r2c-3d) fftw-plan
115   (n0 :int)
116   (n1 :int)
117   (n2 :int)
118   (in :pointer)
119   (out :pointer)
120   (flags :uint))
121
122 (declaim (inline fftw-plan-dft-r2c))
123 (cffi:defcfun ("fftw_plan_dft_r2c" fftw-plan-dft-r2c) fftw-plan
124   (rank :int)
125   (n (:pointer :int))
126   (in :pointer)
127   (out :pointer)
128   (flags :uint))
129
130 (declaim (inline fftw-plan-dft-c2r-1d))
131 (cffi:defcfun ("fftw_plan_dft_c2r_1d" fftw-plan-dft-c2r-1d) fftw-plan
132     (n :int)
133     (in :pointer)
134     (out :pointer)
135     (flags :uint))
136
137 (declaim (inline fftw-plan-dft-c2r-2d))
138 (cffi:defcfun ("fftw_plan_dft_c2r_2d" fftw-plan-dft-c2r-2d) fftw-plan
139     (n0 :int)
140     (n1 :int)
141     (in :pointer)
142     (out :pointer)
143     (flags :uint))
144
145 (declaim (inline fftw-plan-dft-c2r-3d))
146 (cffi:defcfun ("fftw_plan_dft_c2r_3d" fftw-plan-dft-c2r-3d) fftw-plan
147     (n0 :int)
148     (n1 :int)
149     (n2 :int)
150     (in :pointer)
151     (out :pointer)
152     (flags :uint))
153
154 (declaim (inline fftw-plan-dft-c2r))
155 (cffi:defcfun ("fftw_plan_dft_c2r" fftw-plan-dft-c2r) fftw-plan
156     (rank :int)
157     (n (:pointer :int))
158     (in :pointer)
159     (out :pointer)
160     (flags :uint))
161
162 (declaim (inline fftw-plan-many-dft))
163 (cffi:defcfun ("fftw_plan_many_dft" fftw-plan-many-dft) fftw-plan
164     (rank :int)
165     (n (:pointer :int))
166     (howmany :int)
167     (in (:pointer fftw-complex-struct))
168     (inembed (:pointer :int))
169     (istride :int)
170     (idist :int)
171     (out (:pointer fftw-complex-struct))
172     (onembed (:pointer :int))
173     (ostride :int)
174     (odist :int)
175     (sign :int)
176     (flags :uint))
177
178 (declaim (inline fftw-plan-many-dft_r2c))
179 (cffi:defcfun ("fftw_plan_many_dft_r2c" fftw-plan-many-dft-r2c) fftw-plan
180     (rank :int)
181     (n (:pointer :int))
182     (howmany :int)
183     (in (:pointer :double))
184     (inembed (:pointer :int))
185     (istride :int)
186     (idist :int)
187     (out (:pointer fftw-complex-struct))
188     (onembed (:pointer :int))
189     (ostride :int)
190     (odist :int)
191     (flags :uint))
192
193 (declaim (inline fftw-plan-many-dft_c2r))
194 (cffi:defcfun ("fftw_plan_many_dft_c2r" fftw-plan-many-dft-c2r) fftw-plan
195     (rank :int)
196     (n (:pointer :int))
197     (howmany :int)
198     (in (:pointer fftw-complex-struct))
199     (inembed (:pointer :int))
200     (istride :int)
201     (idist :int)
202     (out (:pointer :double))
203     (onembed (:pointer :int))
204     (ostride :int)
205     (odist :int)
206     (flags :uint))
207
208 (declaim (inline fftw-plan-many-dft_r2r))
209 (cffi:defcfun ("fftw_plan_many_dft_r2r" fftw-plan-many-dft-r2r) fftw-plan
210     (rank :int)
211     (n (:pointer :int))
212     (howmany :int)
213     (in (:pointer :double))
214     (inembed (:pointer :int))
215     (istride :int)
216     (idist :int)
217     (out (:pointer :double))
218     (onembed (:pointer :int))
219     (ostride :int)
220     (odist :int)
221     (kind (:pointer :int))
222     (flags :uint))
223
224
225 (declaim (inline fftw-malloc))
226 (cffi:defcfun ("fftw_malloc" fftw-malloc) (:pointer fftw-complex-struct)
227   (n :int))
228
229 (declaim (inline fftw-execute))
230 (cffi:defcfun ("fftw_execute" fftw-execute) :void
231     (p fftw-plan))
232
233 (declaim (inline fftw-destroy-plan))
234 (cffi:defcfun ("fftw_destroy_plan" fftw-destroy-plan) :void
235     (p fftw-plan))
236
237 (declaim (inline fftw-free))
238 (cffi:defcfun ("fftw_free" fftw-free) :void
239     (p :pointer))
240
241
242 ;;; Wisdom functions
243
244 (cffi:defcfun ("fftw_import_wisdom_from_string" fftw-import-wisdom-from-string) :int
245   (input-string :string))
246
247 (cffi:defcfun ("fftw_export_wisdom_to_string" fftw-export-wisdom-to-string) :string+ptr
248   )
249
250 (cffi:defcfun free :void
251   (ptr :pointer))