function varargout = GUI(varargin) % GUI MATLAB code for GUI.fig % GUI, by itself, creates a new GUI or raises the existing % singleton*. % % H = GUI returns the handle to a new GUI or the handle to % the existing singleton*. % % GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI.M with the given input arguments. % % GUI('Property','Value',...) creates a new GUI or raises % the existing singleton*. Starting from the left, property value pairs are % applied to the GUI before GUI_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to GUI_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 GUI % Last Modified by GUIDE v2.5 11-Nov-2013 21:44:09 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @GUI_OpeningFcn, ... 'gui_OutputFcn', @GUI_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 function GUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); initialize_gui(hObject, handles, false); function varargout = GUI_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function time_Callback(hObject, eventdata, handles) time = str2double(get(hObject, 'String')); if isnan(time) set(hObject, 'String', 0); errordlg('Input must be a number','Error'); end handles.metricdata.time = time; guidata(hObject,handles) function time_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function device_menu_Callback(hObject, eventdata, handles) function device_menu_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Fs_menu_Callback(hObject, eventdata, handles) function Fs_menu_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function start_Callback(hObject, ~, handles) time_max = handles.metricdata.time; list=get(handles.Fs_menu,'String'); val=get(handles.Fs_menu,'Value'); Fs = str2double(list{val}); state8 = get(handles.bit8,'Value'); state16 = get(handles.bit16,'Value'); state24 = get(handles.bit24,'Value'); if state8 == 1 bits=8; elseif state16 == 1 bits=16; elseif state24 == 1 bits=24; end dev_number=get(handles.device_menu,'Value')-2; [rec,txt]=signal_rec( Fs, time_max, bits, dev_number ); set(handles.savedata_button,'Enable','on') set(handles.savetxt_button,'Enable','on') handles.rec = rec; handles.txt = txt; guidata(hObject,handles) function reset_Callback(hObject, eventdata, handles) initialize_gui(gcbf, handles, true); function savedata_button_Callback(hObject, eventdata, handles) savedata = handles.rec; [file,path] = uiputfile('*.dat','Save as'); Name = fullfile(path,file); if path==0, return; end save(Name,'savedata','-ascii'); function savetxt_button_Callback(hObject, eventdata, handles) txt = handles.txt; [file,path] = uiputfile('*.txt','Save as'); Name = fullfile(path,file); if path==0, return; end text_file = fopen(Name,'w'); txt = txt.'; fprintf(text_file,'%s%s\r\n%s%s\r\n%s%s\r\n',txt{:}); fclose(text_file); function initialize_gui(fig_handle, handles, isreset) if isfield(handles, 'metricdata') && ~isreset return; end handles.metricdata.time = 10; devnum=audiodevinfo(1); set(handles.savedata_button,'Enable','off') set(handles.savetxt_button,'Enable','off') strArray = java_array('java.lang.String', (devnum+1) ); strArray(1) = java.lang.String('System default'); for i=0:(devnum-1), strArray(i+2) = java.lang.String(audiodevinfo(1,i)); end set(handles.device_menu, 'String', cell(strArray)); set(handles.bit16, 'Value', 1); set(handles.time, 'String', handles.metricdata.time); set(handles.Fs_menu, 'Value', 4); set(handles.device_menu, 'Value', 1); guidata(handles.figure1, handles);