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