-
Notifications
You must be signed in to change notification settings - Fork 9
/
tremolo.m
executable file
·39 lines (32 loc) · 1.1 KB
/
tremolo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function [ out ] = tremolo( in, fs, rate, depth, lag, LFO )
%TREMOLO simulates a guitar tremolo stomp box
% IN - input guitar vector
% FS - sampling rate of IN
% RATE - frequency of LFO
% DEPTH - amplitude of modulating LFO
% LAG - stereo lag in msec
% LFO - low frequency oscillator - sin, tri, or squ
dbstop if error
% depth 0 to 1 (amplitude 0 to 1)
% rate 0.05 to 5 Hz
lagSamples=ceil(lag/1000*fs); %converts ms of lag to # samples
n = (1:length(in))';
argWaveLeft = 2*pi*rate/fs * n;
argWaveRight = 2*pi*rate/fs * (n+lagSamples);
% delay implemented as phase difference of the right channel with respect
% to the left
switch LFO
case{'squ','square'}
wave_left = depth*square(argWaveLeft);
wave_right = depth*square(argWaveRight);
case{'tri','triangle'}
wave_left = depth*sawtooth(argWaveLeft,.5);
wave_right = depth*sawtooth(argWaveRight,.5);
case{'sin','sine'}
wave_left = depth*sin(argWaveLeft);
wave_right = depth*sin(argWaveRight);
end
left = in.*(1+wave_left);
right = in.*(1+wave_right);
out=[left,right]; % creating a stereo output
end