%   CutWav.m

%   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.


NSecNew=2
ReadPath='Data:IADS:Sounds.wav:';
SavePath=['Data:IADS:Sounds',int2str(NSecNew),'s.wav:']
FileInd=708;
while FileInd<709
                                                                      
    ExistStatus=0;
    while ExistStatus~=2 & FileInd<709
        FileInd=FileInd+1;
		File=[int2str(FileInd),'.wav']
        FilePath=[ReadPath,File]
        ExistStatus=exist(FilePath)
    end
   
    [Y,F,NBits]=wavread(FilePath);
    NSamp=size(Y,1)
    NSec=NSamp/F
    NBits=NBits
    NSampNew=NSecNew*Fs
    NSampTmp=NSamp-NSampNew
    if floor(NSampTmp/2)==NSampTmp/2
        Ys=Y(NSampTmp/2+1:NSampTmp/2+NSampNew,:);
    else
        Ys=Y(floor(NSampTmp/2)+1:floor(NSampTmp/2)+NSampNew,:);
    end
    NSampNew=size(Ys,1)
    NSecNew=NSampNew/F
    %Sound(Ys,F)
    wavwrite(Ys,F,NBits,[SavePath,File(1:length(File)-3),int2str(NSecNew),'s.wav']) 
    %pause(1)
end
