function [vibrato_ammodL vibrato_ammodR rotary_speaker] = rotaryspeaker( modfreq, width, fc)
%x = wav file, fs = signal frequency, modfreq = modulation frequency, width = width of vibrato, fc = carrier frequency
%rotaryspeaker - creating the effect of rotating speaker horns.

%   Using vibrato and amplitude modulation, creates the effect of a sound being sent to rotating speaker horns

%importing wave file and frequency of file use
[x,fs] = wavread('smoothpiano');%Wav file can be replaced with any other wav file in the folder 'Trombone' and 'anechoic_choir'.  
%modfreq (2 is a good number)
%width (0.001 is a good number)
%fc (2 is a good number)

%left side vibrato
ya_alt=0;
Delay=width; % basic delay of input sample in sec
DELAY=round(Delay*fs); % basic delay in # samples
WIDTH=round(width*fs); % modulation width in # samples
if WIDTH>DELAY 
  error('delay greater than basic delay !!!');
  return;
end

MODFREQ=modfreq/fs; % modulation frequency in # samples
LEN=length(x);        % # of samples in WAV-file
L=2+DELAY+WIDTH*2;    % length of the entire delay  
Delayline=zeros(L,1); % memory allocation for delay
yL=zeros(size(x));% memory allocation for output vector
for n=1:(LEN-1)
   M=MODFREQ;
   MOD=sin(M*2*pi*n); 
   TAP=1+DELAY+WIDTH*MOD;
   i=floor(TAP);
   frac=TAP-i;
   Delayline=[x(n);Delayline(1:L-1)]; 
   
   %---Allpass Interpolation------------------------------
   yL(n,1)=(Delayline(i+1)+(1-frac)*Delayline(i)-(1-frac)*ya_alt);  
   ya_alt=yL(n,1);
end   
   

%Amplitude modulation left side
%Creating amplitude modulation of the singal after the vibrato is added
n = length(yL);
c = (1:n) / fs;
c = 2 * pi * fc * c;
ampmodL = sin(c);
ampmodL = ampmodL';

vibrato_ammodL = yL .* ampmodL;
    
%Right side vibrato
ya_alt=0;
Delay=width; % basic delay of input sample in sec
DELAY=round(Delay*fs); % basic delay in # samples
WIDTH=round(width*fs); % modulation width in # samples
if WIDTH>DELAY 
  error('delay greater than basic delay !!!');
  return;
end
MODFREQ=modfreq/fs; % modulation frequency in # samples
LEN=length(x);        % # of samples in WAV-file
L=2+DELAY+WIDTH*2;    % length of the entire delay  
Delayline=zeros(L,1); % memory allocation for delay
yR=zeros(size(x));     % memory allocation for output vector
for n=1:(LEN-1)
   M=MODFREQ;
   MOD=-sin(M*2*pi*n); % Inverting sin wave of right signal
   TAP=1+DELAY+WIDTH*MOD;
   i=floor(TAP);
   frac=TAP-i;
   Delayline=[x(n);Delayline(1:L-1)]; 
   
   %---Allpass Interpolation------------------------------
   yR(n,1)=(Delayline(i+1)+(1-frac)*Delayline(i)-(1-frac)*ya_alt);  
   ya_alt=yR(n,1);
end
%Amplitude modulation left side
%Creating amplitude modulation of the singal after the vibrato is added
ampmodR = ampmodL .* -1;%inverting amplitude modulation of right signal

vibrato_ammodR = yR .* ampmodR;

rotary_speaker = [(vibrato_ammodR.*0.7)+vibrato_ammodL , (vibrato_ammodL.*0.7)+vibrato_ammodR];%create rotating stereo image
  
rotary_speaker = rotary_speaker./max(max(abs(rotary_speaker))); % normailise function

wavwrite(rotary_speaker, fs, 'rotating_speaker_effect.wav'); %

sound(rotary_speaker, fs); %play sound
end

