matlab 코딩 해석점요.. 급해요 빠르게좀..ㅠㅠ부탁드릴께요
안녕하세요...
저는 대학교에 다니는 공학도 입니다..
matlab을 처음 배우는데요... 프로젝트 발표를 하는데..
멧렙으로 음악연주하기를 하고싶어서 소스를 구했는데요..
해석이 안됩니다. 다른사람들도 이해할수 있게 해석을 해야 하는데.
제가 만든 코딩이 아니라서 어떻게 설명해야 되고
뭔지도 잘 모르겟습니다.
그래서 해석좀 부탁드립ㄴ디ㅏ.
2. playtone
function x = playtune(str,cf,cb)
% Play musical tune.
% [x] = playtune(str,[cf],[cb])
%
% Notation:
% [CDEFGAB] keys, 5 full octaves
% [12345678] key/rest duration,
% with the default [1] semiquaver, [2] quaver, [4] crochet and [8] minim
% [#] sharp / [b] flat / [.] rest / [^] raise octave / [_] lower octave
%
% Examples:
% C major -- playtune('^2CDEFGAB^C_BAGFEDC');
% F major -- playtune('^2FGABb^CDEFEDC_BbAGF');
% B minor (harmonic) -- playtune('^2B^C#DEF#GA#BA#GF#EDC#_B');
% F# minor (melodic) -- playtune('^2F#G#AB^C#D#E#F#EDC#_BAG#F#');
% Doe-a-deer -- playtune('^^6C2D6E2C4EC8E6D2EFFED8F.');
%
% Advanced features:
% CF is a (N,2) matrix where the first column contains the frequency and
% the second column the corresponding scaling coefficient. The simplest
% choice of CF would be cf = [1 1] which generates a pure sine wave. The
% default CF is cf = [1 1; 1.001 0.33; 1.002 0.2; 0.999 0.33; 0.998 0.2]
% which generates a tone resembling the flute.
% CB is a (1,9) vector containing the duration of that particular symbol (1-9).
%
% v2.0, Alan Tan (weechiat@gmail.com)
if nargin < 2 | isempty(cf), cf = [1 1; 1.001 0.33; 1.002 0.2; 0.999 0.33; 0.998 0.2]; end
if nargin < 3 | isempty(cb), cb = [1:9]; end
% Set constants.
Fc = 65.4064;
Fs = 2^13;
Ts = 1/Fs;
Td = 0.1;
c1 = 2*pi*Fc;
c2 = 2.^([0:60]/12);
% Convert string to score.
d = -ones(1,length(str));
d(find(str == 'C')) = 0;
d(find(str == 'D')) = 2;
d(find(str == 'E')) = 4;
d(find(str == 'F')) = 5;
d(find(str == 'G')) = 7;
d(find(str == 'A')) = 9;
d(find(str == 'B')) = 11;
d(find(str == '^')) = 0;
d(find(str == '_')) = 0;
d(find(str == '.')) = 0;
u1 = find(str == 'b');
d(u1-1) = d(u1-1)-1;
u2 = find(str == '#');
d(u2-1) = d(u2-1)+1;
str([u1,u2]) = [];
d([u1,u2]) = [];
% Construct vector.
x = [];
oc = 1;
Tu = Td;
t = [Ts:Ts:Tu];
L = length(t);
th = zeros(size(cf,1),1);
for k = 1:length(str)
if d(k) == -1
Tu = cb(str(k)-48)*Td;
t = [Ts:Ts:Tu];
L = length(t);
else
switch str(k),
case '^', oc = oc+12;
case '_', oc = oc-12;
case '.', x(end+L) = 0;
otherwise
wt = c1*c2(oc+d(k))*t;
x(end+(1:L)) = transpose(cf(:,2))*sin(cf(:,1)*wt+th(:,ones(1,L)));
th = rem(cf(:,1)*wt(end)+th,2*pi);
end
end
end
% Set output.
if ~nargout
soundsc(x,Fs);
clear x;
end
--------------------------------------------------------------
이것인데요...
어떻게 만들어 졋는지 너무 궁금합니다.
cf나 cb soundsc u 값등이 어디서 나왔으며 어떻게 어떻게 만들고 해석해서 설명해야 할지 알고싶습니다..
이것을 다른 사람한테 설명해야 하는데..
도와주세요..
전반적인해석좀 부탁 드립니다
전반 적인 해석이요!.... ㅠㅠ 감사합니다.
댓글 달기