function autil(filename,filepath,mode)

%   autil

%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      


rauschslider=findobj('tag','rauschslider');
rauschverhaeltnisroot=get(rauschslider,'value');
rauschverhaeltnis=rauschverhaeltnisroot*1;
if isempty(rauschverhaeltnis)
   rauschverhaeltnis=0;
end

if mode==0
   modefehler
   return
      
% directory mode   
elseif mode==11
	cd (filepath);
	filelist=dir(filepath);
   filelistsize=size(filelist);
      
	% Schleife für Files
   for filezaehler=3:filelistsize(1)
      [audio.signal,audio.fs,audio.bits]=wavread(filelist(filezaehler).name);
      [audio.modsignal,audio.spektrum,audio.modspektrum,audio.realspektrum,audio.modrealspektrum,audio.imagspektrum,audio.modimagspektrum,audio.mag,audio.modmag,audio.phasen,audio.modphasen,phasenrandvec] = randphase(audio.signal,audio.fs,audio.bits,rauschverhaeltnis);
		audio.modsignal=[audio.modsignal audio.modsignal];
		% modifiziertes Signal abspeichern
		targetfilename=strrep(filelist(filezaehler).name, '.wav','mod.wav');
		wavwrite(audio.modsignal,audio.fs,audio.bits,targetfilename);
   end
   ok
   
% batchfile mode   
elseif mode==12
   filemat=batchfiletomat(filename,filepath);
   filematgroessevec=size(filemat);
   filematgroesse=filematgroessevec(2);
   for l=1:filematgroesse
      [audio.signal,audio.fs,audio.bits]=wavread(filemat{l});
      [audio.modsignal,audio.spektrum,audio.modspektrum,audio.realspektrum,audio.modrealspektrum,audio.imagspektrum,audio.modimagspektrum,audio.mag,audio.modmag,audio.phasen,audio.modphasen,phasenrandvec] = randphase(audio.signal,audio.fs,audio.bits,rauschverhaeltnis);
      audio.modsignal=[audio.modsignal audio.modsignal];
     	targetfilename=strrep(filemat{l},'.wav','mod.wav');
		wavwrite(audio.modsignal,audio.fs,audio.bits,targetfilename);
   end
   return
      
% single file mode   
elseif mode==2
   [audio.signal,audio.fs,audio.bits]=wavread(filename);
   [audio.modsignal,audio.spektrum,audio.modspektrum,audio.realspektrum,audio.modrealspektrum,audio.imagspektrum,audio.modimagspektrum,audio.mag,audio.modmag,audio.phasen,audio.modphasen,phasenrandvec]=randphase(audio.signal,audio.fs,audio.bits,rauschverhaeltnis);
   
   %stereo-sound
   audio.modsignal=[audio.modsignal audio.modsignal];
   sound(audio.modsignal,audio.fs);
   
   figure(5)
   subplot(2,1,1)
   plot(audio.mag)
   subplot(2,1,2)
   plot(audio.modmag)
   
	% modifiziertes Signal abspeichern
	targetfilename=strrep(filename, '.wav','mod.wav');
	wavwrite(audio.modsignal,audio.fs,audio.bits,targetfilename);
	ok
  
end
autilfenster=findobj('tag','autilfenster');
close(figure(autilfenster));
return
