[947ae6]: ltfatmex.m Maximize Restore History

Download this file

ltfatmex.m    241 lines (179 with data), 6.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
function ltfatmex(varargin)
%LTFATMEX Compile Mex/Oct interfaces
% Usage: ltfatmex;
% ltfatmex('clean');
%
% LTFATMEX compiles certain functions written in C in order to speed
% up the execution of the toolbox.
%
% LTFATMEX('clean') removes the compiled functions.
% AUTHOR : Peter Soendergaard.
% TESTING: NA
% REFERENCE: NA
global TF_CONF;
% Verify that TF_CONF has been initialized
if numel(TF_CONF)==0
disp('');
disp('--- LTFAT - The Linear Time Frequency Analysis toolbox. ---');
disp('')
disp('To start the toolbox, call LTFATSTART as the first command.');
disp('');
return;
end;
bp=TF_CONF.basepath;
defnopos.flags.target={'auto','lib','mex','oct','gpc'};
defnopos.flags.command={'compile','clean'};
[flags,kv]=ltfatarghelper({},defnopos,varargin);
% Remember the current directory.
curdir=pwd;
do_lib = flags.do_lib || (flags.do_auto && isoctave);
do_oct = flags.do_oct || (flags.do_auto && isoctave);
do_mex = flags.do_mex || (flags.do_auto && ~isoctave);
do_gpc = flags.do_gpc || (flags.do_auto && ~isoctave);
if flags.do_clean
if ~isoctave
% Delete files permanently (bypass trashcan on Windows/Mac
% but remember the old state
oldstate = recycle('off');
end;
if do_oct
deletefiles([bp,'oct'],'*.oct');
deletefiles([bp,'oct'],'*.o');
end;
if do_mex
deletefiles([bp,'mex'],['*.',mexext]);
end;
if do_gpc
deletefiles([bp,'thirdparty',filesep,'PolygonClip'],
['PolygonClip.',mexext]);
end;
if ~isoctave
recycle(oldstate);
end;
return;
end;
if do_lib
s=['cd ',bp,'src; make'];
s
system(s);
end;
if do_oct
if compile_ltfat(bp)>1;
if isoctave
extname='oct';
else
extname='mex';
end;
fprintf('The %s interfaces was not built.', extname);
end;
end;
if do_gpc && ~isoctave
if exist([bp,filesep,'thirdparty',filesep,'GPC',filesep,'gpc.c'], ...
'file')
% Compile the PolygonClip interface to GPC for use with mulaclab
cd([bp,filesep,'thirdparty',filesep,'PolygonClip']);
mex('-I../GPC','PolygonClip.c','../GPC/gpc.c');
else
error('Unable to compile GPC');
end;
end;
% Jump back to the original directory.
cd(curdir);
function deletefiles(base,files)
L=dir([base,filesep,files]);
for ii=1:numel(L)
s=[base,filesep,L(ii).name];
delete(s);
end;
function status=compile_ltfat(bp)
% If we exit early, it is because of an error, so set status=1
status=1;
% Determine the name of the ltfat library
s=[bp,'lib',filesep,'libltfat-nomem.a'];
if ispc || ~isoctave
s=[bp,'lib',filesep,'libltfat-nomem.lib'];
end;
if ~exist(s,'file')
disp(['The LTFAT C library cannot be found. Please compile ' ...
'as described in the INSTALL file, or download ' ...
'a binary release.']);
return;
end;
if ispc && ~isoctave
if ~exist([bp,'mex\libfftw3-3.dll'],'file')
disp(['Please download the FFTW binary release for Windows as ' ...
'described in the INSTALL file.']);
return;
end;
% Create the .lib file for the Matlab FFTW3 lib.
if ~exist([bp,'mex\libfftw3-3.lib'],'file')
system(['"',matlabroot,'\sys\lcc\bin\lcc_implib.exe" -u "',...
bp,'mex\LIBFFTW3-3.DLL"']);
end;
if ~exist([bp,'mex\libfftw3f-3.dll'],'file')
disp(['Please download the FFTW binary release for Windows as ' ...
'described in the INSTALL file.']);
return;
end;
if ~exist([bp,'mex\libfftw3f-3.lib'],'file')
system(['"',matlabroot,'\sys\lcc\bin\lcc_implib.exe" -u "',...
bp,'mex\libfftw3f-3.dll"']);
end;
end;
if isoctave
cd([bp,'oct']);
ext='oct';
% Get the list of files.
L=dir('*.cc');
endchar=2;
else
cd([bp,'mex']);
ext=mexext;
% Get the list of files.
L=dir('comp_*.c');
endchar=1;
end;
for ii=1:numel(L)
filename = L(ii).name;
objname = [filename(1:end-endchar),ext];
objdirinfo = dir(objname);
% Make-like behaviour: build only the files where the src file is
% newer than the object file, or the object file is missing.
if isempty(objdirinfo) || (objdirinfo.datenum<L(ii).datenum)
fprintf('Compiling %s\n',filename);
if isoctave
mkoctfile('-c','oct-memalloc.c');
mkoctfile('-I../thirdparty',...
'-I.','-I../src','-L../src','-L../lib',...
filename,'oct-memalloc.o',...
'-lltfat-nomem',...
'-lfftw3',...
'-lfftw3f',...
'-llapack',...
'-lblas');
else
if ispc
mex('-c','mex-memalloc.c');
mex('-I../thirdparty',...
'-I.','-I../src','-L../src',...
filename,'mex-memalloc.obj',...
'../lib/libltfat-nomem.lib',...
'../mex/LIBFFTW3-3.LIB',...
'../mex/LIBFFTW3F-3.LIB',...
[matlabroot '\extern\lib\win32\lcc\libmwlapack.lib'],...
[matlabroot '\extern\lib\win32\lcc\libmwblas.lib']);
else
mex('-c','mex-memalloc.c');
mex('-I../thirdparty',...
'-I.','-I../src','-L../src','-L../lib',...
filename,'mex-memalloc.o',...
'-lltfat-nomem',...
'-lfftw3',...
'-lfftw3f',...
'-llapack',...
'-lblas');
end;
end;
end;
end;
status=0;