function y = twocarbrass(f0, dur, fs)
% Y = TWOCARBRASS(FO, DUR, FS) A two carrier FM brass instrument.
%  FO is the fundamental (sounding) frequency
%  DUR is the note duration in seconds
%  FS is the sampling rate
% 
%  Example use:
%  y = twocarbrass(220, 1, fs);

nT = 0:1/fs:dur-1/fs;
sustarg = 0.7;

% Set amplitude envelopes
A1env = adsr(0.03, 0.02, sustarg, 0.15, dur*fs);
% The relative strength of the formant can be adjusted by changing
% the peak of A2env (which is usually less than that of A1env).
A2env = 0.8*adsr(0.03, 0.02, sustarg, 0.3, dur*fs);                                                    

% Set index of modulation
IMAX = 5;
envI = adsr(0.03, 0.06, sustarg, 0.01, dur*fs);
I1 = IMAX*envI;
I2 = 1.8/IMAX*envI;

% Set frequencies of carriers and modulator
fm = f0;               % modulating frequency
fc1 = f0;              % 1st carrier frequency
ff = 1500;             % formant frequency
fc2 = round(ff/f0)*f0; % 2nd carrier frequency:
                       % keep ff as close as possible to the
                       % desired frequency while remaining an
                       % integer multiple of f0

% FM equations for each carrier
y1 = A1env.*cos(2*pi*fc1.*nT + I1.*cos(2*pi*fm*nT));
y2 = A2env.*cos(2*pi*fc2.*nT + I2.*cos(2*pi*fm*nT));

y = y1+y2;

