Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.17 KB | None | 0 0
  1. % Creates a pop up menu allowing the user to select an instrument.
  2. H=uicontrol('Style','Popup','Position',[550 450 100 50], 'String', ...
  3. 'Guitar|Clarinet|Trumpet|Tone|Reverb Trumpet|VictoRythm');
  4. % Determines the value of B based on the instrument. Allows program to
  5. % chose proper sound.
  6. pause; B=get(H,'Value');
  7. %X=wavread('proj3.wav');
  8. %XX=reshape(X,32768,13,5);
  9. load('proj3.mat'); % Loads created .mat file.
  10. XX = XXX; %XXX from project3.mat is copied to XX used in this program
  11.  
  12. %Creates our own unique sound. C is the amplitudes of the fundamental
  13. %frequency and the 5 harmonics. D is the time duration of each note put
  14. %into the matrix containing all sounds. Additive synthesis is used to
  15. %create the 13 different notes using the VictoRythm Instrument.
  16. C=[1548 733.1 479.6 232 123.5 164.9];
  17. D=0.74303854875;
  18. F=[392 415.3 440 466.16 493.88 523.25 554.37 587.33 622.25 659.25 ...
  19. 698.4 739.99 783.99];
  20. T=[0:1/44100:D];
  21. for G=1:13
  22. W(:,G)=C*cos(2*pi*F(G)*[1:6]'*T);
  23. end
  24.  
  25. %Used to patch the high G problem for the clarinet
  26. count2=1;
  27. highG=[];
  28.  
  29. %creation of possible exported sound
  30. newsound='sound.wav';
  31.  
  32. %Used to play harmonies together.
  33. ex=exist('L');
  34.  
  35. XX(:,:,6)=W; % Stores the sound into the 6 row in the z direction.
  36. XX1=XX(1:32768,:,B); % Creates a 32768 long matrix containing the sound of
  37. %the chosen instrument.
  38. XX1(32669:32768,:)=0; % Sets last 100 notes in the whole note equal to 0.
  39. XX2=XX(1:32768,:,B);
  40. XX2(16285:16384,:)=0;
  41.  
  42. XX3=XX(1:32768,:,B);
  43. XX3(8093:8192,:)=0;
  44.  
  45. Z = [ ]; % Creates empty matrix to store sound variables.
  46. E = [ ]; % Matrix variable used when deleting the previous note
  47.  
  48.  
  49.  
  50. uicontrol('Style','Pushbutton','Position',[100 140 55 55], ...
  51. 'String','G ','BackgroundColor','white','Callback', ...
  52. 'a =XX1(1:32768,1);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  53. %This ui control creates the whole note for the various notes. Stores the
  54. %first 32768 samples of the sound. Every third one after this contains the
  55. %same code, adjusted for each note.
  56. uicontrol('Style','Pushbutton','Position',[100 195 55 55], ...
  57. 'String','1/2','BackgroundColor','white','Callback', ...
  58. 'a =XX2(1:16384,1);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  59. %This ui control creates the half note for the various notes. Stores the
  60. %first 16384 samples of the sound. Every third one after this contains the
  61. %same code, adjusted for each note.
  62. uicontrol('Style','Pushbutton','Position',[100 250 55 55], ...
  63. 'String','1/4','BackgroundColor','white','Callback', ...
  64. 'a =XX3(1:8192 ,1);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  65. %This ui control creates the quarter note for the various notes. Stores the
  66. %first 8192 samples of the sound. Every third one after this contains the
  67. %same code, adjusted for each note.
  68. uicontrol('Style','Pushbutton','Position',[155 140 55 55],'String', ...
  69. 'A ','BackgroundColor','white','Callback','a =XX1(1:32768,3);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  70. uicontrol('Style','Pushbutton','Position',[155 195 55 55],'String','1/2','BackgroundColor','white','Callback','a =XX2(1:16384,3);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  71. uicontrol('Style','Pushbutton','Position',[155 250 55 55],'String','1/4','BackgroundColor','white','Callback','a =XX3(1:8192 ,3);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  72. uicontrol('Style','Pushbutton','Position',[210 140 55 55],'String','B ','BackgroundColor','white','Callback','a =XX1(1:32768,5);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  73. uicontrol('Style','Pushbutton','Position',[210 195 55 55],'String','1/2','BackgroundColor','white','Callback','a =XX2(1:16384,5);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  74. uicontrol('Style','Pushbutton','Position',[210 250 55 55],'String','1/4','BackgroundColor','white','Callback','a =XX3(1:8192 ,5);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  75. uicontrol('Style','Pushbutton','Position',[265 140 55 55],'String','C ','BackgroundColor','white','Callback','a =XX1(1:32768,6);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  76. uicontrol('Style','Pushbutton','Position',[265 195 55 55],'String','1/2','BackgroundColor','white','Callback','a =XX2(1:16384,6);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  77. uicontrol('Style','Pushbutton','Position',[265 250 55 55],'String','1/4','BackgroundColor','white','Callback','a =XX3(1:8192 ,6);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  78. uicontrol('Style','Pushbutton','Position',[320 140 55 55],'String','D ','BackgroundColor','white','Callback','a =XX1(1:32768,8);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  79. uicontrol('Style','Pushbutton','Position',[320 195 55 55],'String','1/2','BackgroundColor','white','Callback','a =XX2(1:16384,8);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  80. uicontrol('Style','Pushbutton','Position',[320 250 55 55],'String','1/4','BackgroundColor','white','Callback','a =XX3(1:8192 ,8);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  81. uicontrol('Style','Pushbutton','Position',[375 140 55 55],'String','E ','BackgroundColor','white','Callback','a=XX1(1:32768,10);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  82. uicontrol('Style','Pushbutton','Position',[375 195 55 55],'String','1/2','BackgroundColor','white','Callback','a=XX2(1:16384,10);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  83. uicontrol('Style','Pushbutton','Position',[375 250 55 55],'String','1/4','BackgroundColor','white','Callback','a=XX3(1:8192 ,10);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  84. uicontrol('Style','Pushbutton','Position',[430 140 55 55],'String','F ','BackgroundColor','white','Callback','a=XX1(1:32768,11);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  85. uicontrol('Style','Pushbutton','Position',[430 195 55 55],'String','1/2','BackgroundColor','white','Callback','a=XX2(1:16384,11);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  86. uicontrol('Style','Pushbutton','Position',[430 250 55 55],'String','1/4','BackgroundColor','white','Callback','a=XX3(1:8192 ,11);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  87. uicontrol('Style','Pushbutton','Position',[485 140 55 55],'String','G ','BackgroundColor','white','Callback','a=XX1(1:32768,13);sound(a,44100);Z=[Z;a];if(B==2) highG(count2)= 1;end;count2 =count2+4;E=[E 1];');
  88. uicontrol('Style','Pushbutton','Position',[485 195 55 55],'String','1/2','BackgroundColor','white','Callback','a=XX2(1:16384,13);sound(a,44100);Z=[Z;a];if(B==2) highG(count2)= 1;end;count2 =count2+2;E=[E 0.5];');
  89. uicontrol('Style','Pushbutton','Position',[485 250 55 55],'String','1/4','BackgroundColor','white','Callback','a=XX3(1:8192 ,13);sound(a,44100);Z=[Z;a];if(B==2) highG(count2) = 1;end;count2 =count2+1;E=[E 0.25];');
  90. uicontrol('Style','Pushbutton','Position',[127.5 305 55 55],'String','G#','BackgroundColor','black','ForegroundColor','white','Callback','a=XX1(1:32768,2);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  91. uicontrol('Style','Pushbutton','Position',[127.5 360 55 55],'String','1/2','BackgroundColor','black','ForegroundColor','white','Callback','a=XX2(1:16384,2);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  92. uicontrol('Style','Pushbutton','Position',[127.5 415 55 55],'String','1/4','BackgroundColor','black','ForegroundColor','white','Callback','a=XX3(1:8192,2);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  93. uicontrol('Style','Pushbutton','Position',[127.5+55 305 55 55],'String','A#','BackgroundColor','black','ForegroundColor','white','Callback','a=XX1(1:32768,4);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  94. uicontrol('Style','Pushbutton','Position',[127.5+55 360 55 55],'String','1/2','BackgroundColor','black','ForegroundColor','white','Callback','a=XX2(1:16384,4);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  95. uicontrol('Style','Pushbutton','Position',[127.5+55 415 55 55],'String','1/4','BackgroundColor','black','ForegroundColor','white','Callback','a=XX3(1:8192,4);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  96. uicontrol('Style','Pushbutton','Position',[127.5+165 305 55 55],'String','C#','BackgroundColor','black','ForegroundColor','white','Callback','a=XX1(1:32768,7);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  97. uicontrol('Style','Pushbutton','Position',[127.5+165 360 55 55],'String','1/2','BackgroundColor','black','ForegroundColor','white','Callback','a=XX2(1:16384,7);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  98. uicontrol('Style','Pushbutton','Position',[127.5+165 415 55 55],'String','1/4','BackgroundColor','black','ForegroundColor','white','Callback','a=XX3(1:8192,7);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  99. uicontrol('Style','Pushbutton','Position',[127.5+220 305 55 55],'String','D#','BackgroundColor','black','ForegroundColor','white','Callback','a=XX1(1:32768,9);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  100. uicontrol('Style','Pushbutton','Position',[127.5+220 360 55 55],'String','1/2','BackgroundColor','black','ForegroundColor','white','Callback','a=XX2(1:16384,9);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  101. uicontrol('Style','Pushbutton','Position',[127.5+220 415 55 55],'String','1/4','BackgroundColor','black','ForegroundColor','white','Callback','a=XX3(1:8192,9);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  102. uicontrol('Style','Pushbutton','Position',[127.5+330 305 55 55],'String','F#','BackgroundColor','black','ForegroundColor','white','Callback','a=XX1(1:32768,12);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
  103. uicontrol('Style','Pushbutton','Position',[127.5+330 360 55 55],'String','1/2','BackgroundColor','black','ForegroundColor','white','Callback','a=XX2(1:16384,12);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
  104. uicontrol('Style','Pushbutton','Position',[127.5+330 415 55 55],'String','1/4','BackgroundColor','black','ForegroundColor','white','Callback','a=XX3(1:8192,12);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
  105. % Creates a button called "Delete." Deletes the last note played.
  106. uicontrol('Style','Pushbutton','Position',[100 75 110 55],'String','Delete','Callback','Z=Z(1:end-E(end)*32768);E=E(1:end-1);');
  107. % Creates a button called "Playback." Plays what has been stored in the
  108. % matrix so far.
  109. uicontrol('Style','Pushbutton','Position',[210 75 110 55],'String','Playback','Callback','sound(Z,44100)')
  110. % Creates a button called "Reset." Erases the entire matrix.
  111. uicontrol('Style','Pushbutton','Position',[320 75 110 55],'String','Reset','Callback','close; run project3new.m');
  112. % Creates a button called "Export". Saves the matrix to a .wav file.
  113. uicontrol('Style','Pushbutton','Position',[430 75 110 55],'String','Export','Callback','wavwrite(Z,44100,newsound)');
  114. % Creates a button called "Harmony." Sets another matrix equal to the
  115. % Z matrix. It then erases everything from the Z matrix, allowing the user
  116. % to create two matrices to play simulateously.
  117. uicontrol('Style','Pushbutton','Position',[50 75 50 50],'String','Harmony','Callback','L=Z;Z = [ ];');
  118. % Creates a button called "end." This button exits out of the matrix,
  119. % plays the sound of the matrix, and saves the L & Z matrix to the
  120. % transcriber.
  121. uicontrol('Style','Pushbutton','Position',[100 15 440 50],'String','end','BackgroundColor','blue','ForegroundColor','yellow','FontSize',14,'Callback','sound(Z,44100),if (ex~=0);sound(L,44100);end;close');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement