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


global Signal1 Signal2 Fs Bits
Vec2=[709
279
285
278
                                                                    
277
276
600
424
286
712
422
115
290
626
106
261
625
711
241
319
280
706
292];

Vec1=[225
112
206
811
230
216
202
200
802
401
816
226
151
352
221
820
220
353
351
810
215
201
110];

Vec3=[279
285
278
277
287
276
291
600
424
286
502
712
422
115
290
709
626
106
116
627
261
625
698
711
730
241
501
319
280
706
130
380
252
292
420
500
253
723
133
423
722
710
100
120
702
708
322
699
358
251
310
101
105
320
425
704
325
410
726
403
602
262
707
311
171
132
720
610
700
725
362
701
361
254
270
152
210
826
724
153
113
705
400
109
111
415
225
112
205
206
811
370
230
216
360
202
200
802
812
401
816
721
601
226
151
352
221
820
220
353
351
810
215
201
110
815];

for i=2:length(Vec1)
	i=i
	[Signal1,Fs1,Bits1]=wavread(['Data:IADS:Sounds.wav:',int2str(Vec2(i)),'.wav']);
	[NPoints1,NChan1]=size(Signal1);
	Norm1=max(max(abs(Signal1)))
	Signal1=Signal1./Norm1;
	for k=1%:length(Vec2) %+1-i
		j=i
		[Signal2,Fs2,Bits2]=wavread(['Data:IADS:Sounds.wav:',int2str(Vec2(j)),'.wav']);
		[NPoints2,NChan2]=size(Signal2);
		Norm2=max(max(abs(Signal2)))
		Signal2=Signal2./Norm2;
		if NPoints2~=NPoints1 | NChan2~=NChan1 | Fs2~=Fs1 | Bits2~=Bits1
			NPoints1=NPoints1
			NPoints2=NPoints2
			NChan1=NChan1
			NChan2=NChan2
			Fs1=Fs1
			Fs2=Fs2
			Bits1=Bits1
			Bits2=Bits2
			pause
			if NPoints2~=NPoints1
				NPoints=min([NPoints2 NPoints1])
				Signal1=Signal1(1:NPoints,:);
				Signal2=Signal2(1:NPoints,:);
			else
				return
			end
		end
		
		for Rel=0.5 %0.2:0.3:0.8
			Signal1Tmp=(1-Rel).*Signal1;
			Signal2Tmp=Rel.*Signal2;
			Signal=Signal1Tmp+Signal2Tmp;
			subplot(3,1,1)
			plot(Signal1Tmp(:,1))
			axis([1 NPoints1 -1 1])
			subplot(3,1,2)
			plot(Signal2Tmp(:,1),'r')
			axis([1 NPoints1 -1 1])
			subplot(3,1,3)
			plot(Signal(:,1),'g')
			axis([1 NPoints1 -1 1])
			pause(.01)
% 			
 			sound(Signal,Fs)
		end
% 		sound(Signal1,Fs)
% 		sound(Signal2,Fs)
	end
end
