function movingfile3 = movingfile3(wavefile, startelev1, startangle2, middleelev1, middleangle2, finishelev1, finishangle2)

% function movingfile = hrtfpanning(wavefile, startelev1, startangle2,finishelev1, finishangle2)
% wavefile is given mono files (tictacs.wav)
% startelev1 is elevation angle from -40 to 90 degrees
% startangle1 is azimuth angle from 0 to 180 degrees
% finishelev2 is also elevation angle from -40 to 90 degrees
% finishangle2 is again, azimuth angle from 0 to 180 degrees

% azimuth angles should be consecutive angles for the movingfile to work
% properly and elevation angle the same


[x] = readhrtf(startelev1,startangle2,'L'); 
[x2] = readhrtf(middleelev1,middleangle2,'L');
[x3] = readhrtf(finishelev1, finishangle2, 'L');
%reads and outputs the HRTFs for the specified angles and channel (ear)
%Returns stereo symmetrical hrtf in first two rows of
% x such that left is first row, right is second row.

x = x'; 
x2 = x2';
x3 = x3';
%values are set in columns instead of rows

convolvedfileL1 = conv(wavefile,x(:,1)); 
convolvedfileL2 = conv(wavefile,x2(:,1));
convolvedfileL3 = conv(wavefile,x3(:,1));
convolvedfileR1 = conv(wavefile,x(:,2));
convolvedfileR2 = conv(wavefile,x2(:,2));
convolvedfileR3 = conv(wavefile,x3(:,2));
% convolves the stereo symmetrical hrtf ouputs for [x] =
% readhrtf(startelev1,startangle2,'L'); and [x2] =
% readhrtf(finishelev1,finishangle2,'L');

lengthfile = length(convolvedfileL1); 
fadeout1 = [linspace(1,0,lengthfile/2), zeros(1,lengthfile/2),0];
fadeout1 = fadeout1';
convolvedfileL1fo = convolvedfileL1.*fadeout1;
convolvedfileR1fo = convolvedfileR1.*fadeout1;
% creates a fadeout effect for the second convolved file

lengthfile = length(convolvedfileL2); 
fadein2 = [linspace(0,1,lengthfile/2), linspace(1,0,lengthfile/2),0];
fadein2 = fadein2';
convolvedfileL2fi = convolvedfileL2.*fadein2;
convolvedfileR2fi = convolvedfileR2.*fadein2;
% creates a fadein effect for the convolved file

lengthfile = length(convolvedfileL3); 
fadeout3 = [ zeros(1,lengthfile/2), linspace(0,1,lengthfile/2),0];
fadeout3 = fadeout3';
convolvedfileL3fo = convolvedfileL3.*fadeout3;
convolvedfileR3fo = convolvedfileR3.*fadeout3;



convolvedfileLmov = convolvedfileL1fo+convolvedfileL2fi+convolvedfileL3fo;
convolvedfileRmov = convolvedfileR1fo+convolvedfileR2fi+convolvedfileR3fo;
movingfile = [convolvedfileLmov, convolvedfileRmov];
movingfile3 = movingfile./max(max(abs(movingfile)));
% convolves fadein and fadeout files for each channel, adds them together,
% and normalizes it
