Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Creates a pop up menu allowing the user to select an instrument.
- H=uicontrol('Style','Popup','Position',[550 450 100 50], 'String', ...
- 'Guitar|Clarinet|Trumpet|Tone|Reverb Trumpet|VictoRythm');
- % Determines the value of B based on the instrument. Allows program to
- % chose proper sound.
- pause; B=get(H,'Value');
- %X=wavread('proj3.wav');
- %XX=reshape(X,32768,13,5);
- load('proj3.mat'); % Loads created .mat file.
- XX = XXX; %XXX from project3.mat is copied to XX used in this program
- %Creates our own unique sound. C is the amplitudes of the fundamental
- %frequency and the 5 harmonics. D is the time duration of each note put
- %into the matrix containing all sounds. Additive synthesis is used to
- %create the 13 different notes using the VictoRythm Instrument.
- C=[1548 733.1 479.6 232 123.5 164.9];
- D=0.74303854875;
- F=[392 415.3 440 466.16 493.88 523.25 554.37 587.33 622.25 659.25 ...
- 698.4 739.99 783.99];
- T=[0:1/44100:D];
- for G=1:13
- W(:,G)=C*cos(2*pi*F(G)*[1:6]'*T);
- end
- %Used to patch the high G problem for the clarinet
- count2=1;
- highG=[];
- %creation of possible exported sound
- newsound='sound.wav';
- %Used to play harmonies together.
- ex=exist('L');
- XX(:,:,6)=W; % Stores the sound into the 6 row in the z direction.
- XX1=XX(1:32768,:,B); % Creates a 32768 long matrix containing the sound of
- %the chosen instrument.
- XX1(32669:32768,:)=0; % Sets last 100 notes in the whole note equal to 0.
- XX2=XX(1:32768,:,B);
- XX2(16285:16384,:)=0;
- XX3=XX(1:32768,:,B);
- XX3(8093:8192,:)=0;
- Z = [ ]; % Creates empty matrix to store sound variables.
- E = [ ]; % Matrix variable used when deleting the previous note
- uicontrol('Style','Pushbutton','Position',[100 140 55 55], ...
- 'String','G ','BackgroundColor','white','Callback', ...
- 'a =XX1(1:32768,1);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
- %This ui control creates the whole note for the various notes. Stores the
- %first 32768 samples of the sound. Every third one after this contains the
- %same code, adjusted for each note.
- uicontrol('Style','Pushbutton','Position',[100 195 55 55], ...
- 'String','1/2','BackgroundColor','white','Callback', ...
- 'a =XX2(1:16384,1);sound(a,44100);Z=[Z;a];count2 =count2+2;E=[E 0.5];');
- %This ui control creates the half note for the various notes. Stores the
- %first 16384 samples of the sound. Every third one after this contains the
- %same code, adjusted for each note.
- uicontrol('Style','Pushbutton','Position',[100 250 55 55], ...
- 'String','1/4','BackgroundColor','white','Callback', ...
- 'a =XX3(1:8192 ,1);sound(a,44100);Z=[Z;a];count2 =count2+1;E=[E 0.25];');
- %This ui control creates the quarter note for the various notes. Stores the
- %first 8192 samples of the sound. Every third one after this contains the
- %same code, adjusted for each note.
- uicontrol('Style','Pushbutton','Position',[155 140 55 55],'String', ...
- 'A ','BackgroundColor','white','Callback','a =XX1(1:32768,3);sound(a,44100);Z=[Z;a];count2 =count2+4;E=[E 1];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- 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];');
- % Creates a button called "Delete." Deletes the last note played.
- uicontrol('Style','Pushbutton','Position',[100 75 110 55],'String','Delete','Callback','Z=Z(1:end-E(end)*32768);E=E(1:end-1);');
- % Creates a button called "Playback." Plays what has been stored in the
- % matrix so far.
- uicontrol('Style','Pushbutton','Position',[210 75 110 55],'String','Playback','Callback','sound(Z,44100)')
- % Creates a button called "Reset." Erases the entire matrix.
- uicontrol('Style','Pushbutton','Position',[320 75 110 55],'String','Reset','Callback','close; run project3new.m');
- % Creates a button called "Export". Saves the matrix to a .wav file.
- uicontrol('Style','Pushbutton','Position',[430 75 110 55],'String','Export','Callback','wavwrite(Z,44100,newsound)');
- % Creates a button called "Harmony." Sets another matrix equal to the
- % Z matrix. It then erases everything from the Z matrix, allowing the user
- % to create two matrices to play simulateously.
- uicontrol('Style','Pushbutton','Position',[50 75 50 50],'String','Harmony','Callback','L=Z;Z = [ ];');
- % Creates a button called "end." This button exits out of the matrix,
- % plays the sound of the matrix, and saves the L & Z matrix to the
- % transcriber.
- 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