• PUDN用户
    了解作者
  • matlab
    开发工具
  • 10KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 25
    下载次数
  • 2012-04-20 22:53
    上传日期
通过一个单一的合成器实现众多乐器和音效的控制。我们要做的工作就是通过一定的方法合成一段不少于30秒的音乐,并流畅播放。设计中主要采用音调幅度调制的方式再现乐曲。
musichecheng.rar
  • musichecheng
  • computermusic.fig
    4.8KB
  • computermusic.m
    23.9KB
内容介绍
function varargout = computermusic(varargin) % COMPUTERMUSIC M-file for computermusic.fig % COMPUTERMUSIC, by itself, creates a new COMPUTERMUSIC or raises the existing % singleton*. % % H = COMPUTERMUSIC returns the handle to a new COMPUTERMUSIC or the handle to % the existing singleton*. % % COMPUTERMUSIC('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in COMPUTERMUSIC.M with the given input arguments. % % COMPUTERMUSIC('Property','Value',...) creates a new COMPUTERMUSIC or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before computermusic_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to computermusic_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help computermusic % Last Modified by GUIDE v2.5 13-Jan-2010 18:44:54 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @computermusic_OpeningFcn, ... 'gui_OutputFcn', @computermusic_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before computermusic is made visible. function computermusic_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to computermusic (see VARARGIN) % Choose default command line output for computermusic handles.output = hObject; ao = analogoutput('winsound'); %建立硬件对象 handles.ao=ao; addchannel(handles.ao,[1]); % Update handles structure guidata(hObject, handles); % UIWAIT makes computermusic wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = computermusic_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in playmusic. function playmusic_Callback(hObject, eventdata, handles) % hObject handle to playmusic (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) val=get(handles.xuanzegequ,'value'); omg = zeros(64,1); t = [0:6.25e-5:8]'; for k = -29:34 %按十二平均律计算每个音调的频率 if k==-27 | k==-24| k==-20 | k==-17|k==-13 | k==-10 | k==-6 | k==-3 |k==1 | k==4 | k==8 | k==11 | k==15 |k==18 | k==22 | k==25 |k==29 | k==32 omg(k+30) = omg(k+29)*2^(1/12); elseif k == -29 omg(k+30) = 55*2*pi;%中央c=261.63 else omg(k+30) = omg(k+29)*2^(2/12); end end spe=str2num(get(handles.speeds,'string')); shape = zeros(length(t),8); %shape为一个4列的矩阵,每一列代表一种包络,由短到长 for k = 1:8 if(k==1) shape(t<=0.2,k) = 5*t(t<=0.2); shape(t>0.2&t<=0.3)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=0.7,k)=-2*t(t>0.3&t<=0.7)+k+0.4; end if(k==2) shape(t<=0.2,k)=5*t(t<=0.2); shape(t>0.2&t<=0.3,k)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=0.8,k)=0.8; shape(t>0.8&t<=1.2,k)=-2*t(t>0.8&t<=1.2)+k+0.4; end if(k==3) shape(t<=0.2,k)=5*t(t<=0.2); shape(t>0.2&t<=0.3,k)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=1.3,k)=0.8; shape(t>1.3&t<=1.7,k)=-2*t(t>1.3&t<=1.7)+k+0.4; end if(k==4) shape(t<=0.2,k)=5*t(t<=0.2); shape(t>0.2&t<=0.3,k)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=1.8,k)=0.8; shape(t>1.8&t<=2.2,k)=-2*t(t>1.8&t<=2.2)+k+0.4; end if(k==5) shape(t<=0.2,k)=5*t(t<=0.2); shape(t>0.2&t<=0.3,k)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=2.3,k)=0.8; shape(t>2.3&t<=2.7,k)=-2*t(t>2.3&t<=2.7)+k+0.4; end if(k==6) shape(t<=0.2,k)=5*t(t<=0.2); shape(t>0.2&t<=0.3,k)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=2.8,k)=0.8; shape(t>2.8&t<=3.2,k)=-2*t(t>2.8&t<=3.2)+k+0.4; end if(k==7) shape(t<=0.2,k)=5*t(t<=0.2); shape(t>0.2&t<=0.3,k)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=3.3,k)=0.8; shape(t>3.3&t<=3.7,k)=-2*t(t>3.3&t<=3.7)+k+0.4; end if(k==8) shape(t<=0.2,k)=5*t(t<=0.2); shape(t>0.2&t<=0.3,k)=-2*t(t>0.2&t<=0.3)+1.4; shape(t>0.3&t<=3.8,k)=0.8; shape(t>3.8&t<=4.2,k)=-2*t(t>3.8&t<=4.2)+k+0.4; end end shape_flute = zeros(length(t),8); %shape_flute为一个8列的矩阵,每一列代表一种包络,由短到长 for k = 1:8 if(k==1) shape_flute(t<=0.3,k) = exp(t(t<=0.3)*2.310491)-1; shape_flute(t>0.3&t<=0.5375,k) = 1; shape_flute(t>0.5375&t<=0.625,k) = -11.428571*t(t>0.5375&t<=0.625)+7.142857; end if(k==2) shape_flute(t<=0.6,k) = exp(t(t<=0.6)*1.155245)-1; shape_flute(t>=0.6&t<=1.075,k) = 1; shape_flute(t>1.075&t<=1.25,k) = -5.714286*t(t>1.075&t<=1.25) + 7.142857; end if(k==3) shape_flute(t<=0.8625,k) = exp(t(t<=0.8625)*0.803649)-1; shape_flute(t>0.8625&t<=1.6125,k) = 1; shape_flute(t>1.6125&t<=1.875,k) = -3.809524*t(t>1.6125&t<=1.875)+ 7.142857; end if(k==4) shape_flute(t<=1.15,k) = exp(t(t<=1.15)*0.602737)-1; shape_flute(t>1.15&t<=2.15,k) = 1; shape_flute(t>2.15&t<=2.5,k) = -2.857143*t(t>2.15&t<=2.5)+ 7.142857; end if(k==5) shape_flute(t<=1.4375,k) = exp(t(t<=1.4375)*0.482189)-1; shape_flute(t>1.4375&t<=2.6875,k) = 1; shape_flute(t>2.6875&t<=3.125,k) = -2.285714*t(t>2.6875&t<=3.125)+7.142875; end if(k==6) shape_flute(t<=1.725,k) = exp(t(t<=1.725)*0.404757)-1; shape_flute(t>1.725&t<=3.225,k) = 1; shape_flute(t>3.225&t<=3.75,k) = -1.904761*t(t>3.225&t<=3.75)+7.142875; end if(k==7) shape_flute(t<=2.0125,k) = exp(t(t<=2.0125)*0.344421)-1; shape_flute(t>2.0125&t<=3.7625,k) = 1; shape_flute(t>3.7625&t<=4.375,k) = -1.632653*t(t>3.7625&t<=4.375)+7.1428751; end if(k==8) shape_flute(t<=2.3,k) = exp(t(t<=2.3)*0.301368)-1; shape_flute(t>2.3&t<=4.3,k) = 1; shape_flute(t>4.3&t<=5,k) = -1.428571*t(t>4.3&t<=5) + 7.1428571; end end shape_guitar = zeros(length(t),8); %shape_guitar为一个4列的矩阵,每一列代表一种包络,由短到长,guitar for k = 1:8 if(k==1) shape_guitar(t<=0.0075,k) = 133.3333*t(t<=0.0075); shape_guitar(t>0.0075&t<=0.25,k) = -2.8866*t(t>0.0075&t<=0.25)+1.02165; shape_guitar(t>0.25&t<=0.5,k) = -0.77835*t(t>0.25&t<=0.5)+0.49459; shape_guitar(t>0.5&t<=0.7,k) = -0.5*t(t>0.5&t<=0.7)+0.35; end if(k==2) shape_guitar(t<=0.015,k) = 66.66665*t(t<=0.015); shape_guitar(t>0.015&t<=0.5,k) = -1.4433*t(t>0.015&t<=0.5)+1.02165; shape_guitar(t>0.5&t<=1,k) = -0.389175*t(t>0.5&t<=1)+0.49459; shape_guitar(t>1&t<=1.4,k) = -0.25*t(t>1&t<=1.4)+0.35; end if(k==3) shape_guitar(t<=0.0225,k) = 44.444444*t(t<=0.0225); shape_guitar(t>0.0225&t<=0.75,k) = -0.9622*t(t>0.0225&t<=0.75)+1.02165; shape_guitar(t>0.75&t<=1.5,k) = -0.25945*t(t>0.75&t<=1.
评论
    相关推荐