Emania

housle

Dec 9th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.10 KB | None | 0 0
  1. fs = 44000;
  2. T = 1;
  3. t = 0 : 1/fs : T;
  4. t = t(1:fs * T);
  5. f0 = 110;
  6.  
  7. % A = [3615 1111 2081 853 1768 600 714 603 250 98]'; % type 1
  8. % A = [4382 1499 823 695 958 376 317 204 271 124]'; % type 2
  9. A = [44 21 10 8 11 2 1 1 0]'; % type 3
  10. % A = [50 20 4 5 7 5 4 2 2 1]'; % type 4
  11.  
  12.  
  13. attack = 0.2;
  14. decay = 0.3;
  15. sustain_value = 0.8;
  16. release = 0.1;
  17. sustain = 1 - attack - decay - release;
  18.  
  19.  
  20. obalka = t / attack;                                                % attack
  21. obalka(attack * fs : (attack + decay) * fs - 1) = 1 - (sustain_value) .* t(1:decay * fs);
  22. obalka((attack + decay) * fs : end - attack * fs) = sustain_value;                        % sustain
  23. obalka(end - nabeh * fs + 1:end) = fliplr(sustain_value * t(1:fs*nabeh) / nabeh);
  24. obalka = obalka(1:fs * T);
  25.  
  26.  
  27.  
  28. tony = [0 2 4 5 7 9 11 12];
  29. step = 2 ^ (1 / 12);
  30. FV = 2 .* (step .^ tony);
  31. N = length(A);
  32.  
  33. total = [];
  34. for i = 1:8
  35.     F = FV(i) * f0 * [1:N]';
  36.     vibratto = 1 + sin(2 * pi * 10 * t) / 1.2;
  37.     signals =  A .* sawtooth(2 * pi * F .* t);
  38.     signal = vibratto .* obalka .* sum(signals);
  39.     total = [total signal];
  40. end
  41.  
  42. sound(total, fs)
Advertisement
Add Comment
Please, Sign In to add comment