function outsound = panorama(monosound,initial_angle,final_angle)
%Summary of panorama function
% 
%Takes mono signal and turns it into a panning stereo signal for the length
%of the wave (from initial angle to final angle)
%monosound is the input signal
%initial_angle in degrees -90 is right 90 is left 0 is centre
%final_angle in degrees -90 is right 90 is left 0 is centre
%Employs chunkymovie function to break up wave into parts for processing
monosound=monosound';
chunksize=10000;
overlap=50;
numChunks = round(length(monosound) / (chunksize*(1-(overlap/100))));
wavelength = length(monosound);
if initial_angle < final_angle
    angle_increment = (final_angle - initial_angle)/numChunks * pi/180; %in radians
else
    angle_increment = -(initial_angle - final_angle)/numChunks * pi/180; %in radians
end
angle = initial_angle *pi/180; %in radians
y = zeros(length(monosound),2);%Matches duration
y=y';

for i=0:numChunks-1
    chunkstart = round((i * chunksize + 1)-(chunksize*i*(overlap/100)));
    chunkend = chunkstart + chunksize;
    if chunkend > wavelength; 
        chunkend = wavelength;
    end
    A = [cos(angle),sin(angle);-sin(angle),cos(angle)];
    x = [monosound(chunkstart:chunkend);...
        monosound(chunkstart:chunkend)];
    window = hann(length(monosound(chunkstart:chunkend)));
    window = [window'; window'];
    x = x.*window;
    z=A*x;
    for j=1:2
    i=1;
        for k=chunkstart:chunkend
            y(j,k)=y(j,k)+z(j,i);
            i=i+1;
        end
    end
    angle = angle + angle_increment;
end;
y=y./max(max(abs(y)));%Normalises signal
outsound=y';

end

