gusucode.com > 用ASD一行键,弹奏出钢琴标准音。从左到右音高逐渐升高。 > 用ASD一行键,弹奏出钢琴标准音。从左到右音高逐渐升高。频率可以在playsound文件中自己设置/soundplay/soundplay.m
function varargout = soundplay(varargin) % SOUNDPLAY M-file for soundplay.fig % SOUNDPLAY, by itself, creates a new SOUNDPLAY or raises the existing % singleton*. % % H = SOUNDPLAY returns the handle to a new SOUNDPLAY or the handle to % the existing singleton*. % % SOUNDPLAY('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SOUNDPLAY.M with the given input arguments. % % SOUNDPLAY('Property','Value',...) creates a new SOUNDPLAY or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before soundplay_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to soundplay_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 soundplay % Last Modified by GUIDE v2.5 27-Nov-2010 15:17:25 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @soundplay_OpeningFcn, ... 'gui_OutputFcn', @soundplay_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 soundplay is made visible. function soundplay_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 soundplay (see VARARGIN) % Choose default command line output for soundplay handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes soundplay wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = soundplay_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 key press with focus on figure1 and no controls selected. function figure1_KeyPressFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) hi=get(hObject,'currentcharacter'); switch hi case 'm' playsound(130.81); case 'n' playsound(146.83); case 'b' playsound(164.81); case 'v' playsound(174.61); case 'c' playsound(196); case 'x' playsound(220); case 'z' playsound(246.94); case 'a' playsound(261.63); case 's' playsound(293.67); case 'd' playsound(329.63); case 'f' playsound(349.23); case 'g' playsound(392); case 'h' playsound(440); case 'j' playsound(493.88); case 'k' playsound(523.25); case 'l' playsound(587.33); case ';' playsound(659.26); case 'p' playsound(698.46); case 'o' playsound(783.99); case 'i' playsound(880); case 'u' playsound(987.77); case 'y' playsound(1046.5); otherwise end