% Ronan O'Malley
% September 19th 2005
% upgraded October 4th
% tri_tremolo.m
% M Script that multiplies a low frequency oscillator (LFO) by the sample wave to provide a tremolo effect
% Possibility for extension:
%       -different LFO shapes (triangle, square, combination

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters to vary the effect %
%rate=3;             % freqency in Hz of tremolo wave, generally 3 - 10 Hz (verify this)
%depth=0.5;          % max amplitude of tremelo wave 0-1, is this actually the depth??
%barrier=0.3;        % min level for multiplication by LFO
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

filename='acoustic.wav';


% read the sample waveform
[wave,Fs,bits] = wavread(filename);



% using a sin wave at the moment, in practice is usually a 
% triangle wave or a square wave or a cross between the two
%trem=(depth*sin(2*pi*index*(rate/Fs)))';    % sin(2pi*fa/fs)


% 1e-4 to 1e-3
delta=5e-4;
minf=-0.5;
maxf=0.5;
% create triangle wave LFO
trem=minf:delta:maxf;
while(length(trem) < length(wave) )
    trem=[trem (maxf:-delta:minf)];
    trem=[trem (minf:delta:maxf)];
end

trem = trem(1:length(wave));
plot(trem);

% for each sample
for n=1:length(wave),
    
    % multiply the sample by the current LFO coefficient
    % but only if the LFO is  at a significant level, otherwise it would mute the signal
    %if ((trem(i) > barrier) | (trem(i) < -barrier)) 
    
    
    wave(n)= wave(n).*trem(n);
    
    
    %end
end


% write output
wavwrite(wave,Fs,bits,'out_tremolo.wav');