% TYPE 'ampmodsGUI' into command window to run.

function varargout = ampmodsGUI(varargin)
% AMPMODSGUI MATLAB code for ampmodsGUI.fig
%      AMPMODSGUI, by itself, creates a new AMPMODSGUI or raises the existing
%      singleton*.
%
%      H = AMPMODSGUI returns the handle to a new AMPMODSGUI or the handle to
%      the existing singleton*.
%
%      AMPMODSGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in AMPMODSGUI.M with the given input arguments.
%
%      AMPMODSGUI('Property','Value',...) creates a new AMPMODSGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ampmodsGUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ampmodsGUI_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 ampmodsGUI

% Last Modified by GUIDE v2.5 05-Jun-2016 23:24:27

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ampmodsGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @ampmodsGUI_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 ampmodsGUI is made visible.
function ampmodsGUI_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 ampmodsGUI (see VARARGIN)

% Choose default command line output for ampmodsGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ampmodsGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ampmodsGUI_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename pathname] = uigetfile({'*.wav'}, 'Select File');
    fullpathname = strcat (pathname, filename);
    [handles.in1, handles.fs] = audioread(fullpathname);
   guidata(handles.process, handles);
   
   

% --- Executes during object creation, after setting all properties.
function pushbutton1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename pathname] = uigetfile({'*.wav'}, 'Select File');
    fullpathname = strcat (pathname, filename);
    [handles.in2,handles.fs2] = audioread(fullpathname);
   guidata(handles.process, handles);


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename pathname] = uigetfile({'*.wav'}, 'Select File');
    fullpathname = strcat (pathname, filename);
    [handles.in3,handles.fs3] = audioread(fullpathname);
  guidata(handles.process, handles);


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename pathname] = uigetfile({'*.wav'}, 'Select File');
    fullpathname = strcat (pathname, filename);
    [handles.in4,handles.fs4] = audioread(fullpathname);
  guidata(handles.process, handles);




function modfreq_Callback(hObject, eventdata, handles)
% hObject    handle to modfreq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of modfreq as text
%        str2double(get(hObject,'String')) returns contents of modfreq as a double


% --- Executes during object creation, after setting all properties.
function modfreq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to modfreq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in Process.
function Process_Callback(hObject, eventdata, handles)
% hObject    handle to Process (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




function xfade_Callback(hObject, eventdata, handles)
% hObject    handle to xfade (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xfade as text
%        str2double(get(hObject,'String')) returns contents of xfade as a double


% --- Executes during object creation, after setting all properties.
function xfade_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xfade (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function multiplier_Callback(hObject, eventdata, handles)
% hObject    handle to multiplier (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of multiplier as text
%        str2double(get(hObject,'String')) returns contents of multiplier as a double


% --- Executes during object creation, after setting all properties.
function multiplier_CreateFcn(hObject, eventdata, handles)
% hObject    handle to multiplier (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function xmodfreq_Callback(hObject, eventdata, handles)
% hObject    handle to xmodfreq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xmodfreq as text
%        str2double(get(hObject,'String')) returns contents of xmodfreq as a double


% --- Executes during object creation, after setting all properties.
function xmodfreq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xmodfreq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function xmoddepth_Callback(hObject, eventdata, handles)
% hObject    handle to xmoddepth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xmoddepth as text
%        str2double(get(hObject,'String')) returns contents of xmoddepth as a double


% --- Executes during object creation, after setting all properties.
function xmoddepth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xmoddepth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function FM_freq_Callback(hObject, eventdata, handles)
% hObject    handle to FM_freq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FM_freq as text
%        str2double(get(hObject,'String')) returns contents of FM_freq as a double


% --- Executes during object creation, after setting all properties.
function FM_freq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FM_freq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




function repeats_Callback(hObject, eventdata, handles)
% hObject    handle to repeats (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of repeats as text
%        str2double(get(hObject,'String')) returns contents of repeats as a double


% --- Executes during object creation, after setting all properties.
function repeats_CreateFcn(hObject, eventdata, handles)
% hObject    handle to repeats (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function FM_depth_Callback(hObject, eventdata, handles)
% hObject    handle to FM_depth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FM_depth as text
%        str2double(get(hObject,'String')) returns contents of FM_depth as a double



% --- Executes during object creation, after setting all properties.
function uipanelL_CreateFcn(hObject, eventdata, handles)
% hObject    handle to uipanelL (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called



function modfreqR_Callback(hObject, eventdata, handles)
% hObject    handle to modfreqR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of modfreqR as text
%        str2double(get(hObject,'String')) returns contents of modfreqR as a double


% --- Executes during object creation, after setting all properties.
function modfreqR_CreateFcn(hObject, eventdata, handles)
% hObject    handle to modfreqR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function xfadeR_Callback(hObject, eventdata, handles)
% hObject    handle to xfadeR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xfadeR as text
%        str2double(get(hObject,'String')) returns contents of xfadeR as a double


% --- Executes during object creation, after setting all properties.
function xfadeR_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xfadeR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function xmodfreqR_Callback(hObject, eventdata, handles)
% hObject    handle to xmodfreqR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xmodfreqR as text
%        str2double(get(hObject,'String')) returns contents of xmodfreqR as a double


% --- Executes during object creation, after setting all properties.
function xmodfreqR_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xmodfreqR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function xmoddepthR_Callback(hObject, eventdata, handles)
% hObject    handle to xmoddepthR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xmoddepthR as text
%        str2double(get(hObject,'String')) returns contents of xmoddepthR as a double


% --- Executes during object creation, after setting all properties.
function xmoddepthR_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xmoddepthR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function FM_freqR_Callback(hObject, eventdata, handles)
% hObject    handle to FM_freqR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FM_freqR as text
%        str2double(get(hObject,'String')) returns contents of FM_freqR as a double


% --- Executes during object creation, after setting all properties.
function FM_freqR_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FM_freqR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end





function option_Callback(hObject, eventdata, handles)
% hObject    handle to option (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of option as text
%        str2double(get(hObject,'String')) returns contents of option as a double


% --- Executes during object creation, after setting all properties.
function option_CreateFcn(hObject, eventdata, handles)
% hObject    handle to option (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function sine1_Callback(hObject, eventdata, handles)
% hObject    handle to sine1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of sine1 as text
%        str2double(get(hObject,'String')) returns contents of sine1 as a double


% --- Executes during object creation, after setting all properties.
function sine1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sine1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function sine2_Callback(hObject, eventdata, handles)
% hObject    handle to sine2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of sine2 as text
%        str2double(get(hObject,'String')) returns contents of sine2 as a double


% --- Executes during object creation, after setting all properties.
function sine2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sine2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function sine3_Callback(hObject, eventdata, handles)
% hObject    handle to sine3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of sine3 as text
%        str2double(get(hObject,'String')) returns contents of sine3 as a double


% --- Executes during object creation, after setting all properties.
function sine3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sine3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function sine4_Callback(hObject, eventdata, handles)
% hObject    handle to sine4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of sine4 as text
%        str2double(get(hObject,'String')) returns contents of sine4 as a double


% --- Executes during object creation, after setting all properties.
function sine4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sine4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in listen.
function listen_Callback(hObject, eventdata, handles)
% hObject    handle to listen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
output = handles.out;
fs = handles.fs;
sound(output,fs)


% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject    handle to save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
output = handles.out;
fs = handles.fs;
    [filename,npath]=uiputfile('.wav','Save sound','new_sound.wav');
    audiowrite(filename,output,fs)


function length_Callback(hObject, eventdata, handles)
% hObject    handle to length (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of length as text
%        str2double(get(hObject,'String')) returns contents of length as a double


% --- Executes during object creation, after setting all properties.
function length_CreateFcn(hObject, eventdata, handles)
% hObject    handle to length (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function sinefs_Callback(hObject, eventdata, handles)
% hObject    handle to sinefs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of sinefs as text
%        str2double(get(hObject,'String')) returns contents of sinefs as a double


% --- Executes during object creation, after setting all properties.
function sinefs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sinefs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function FM_depthR_Callback(hObject, eventdata, handles)
% hObject    handle to FM_depthR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FM_depthR as text
%        str2double(get(hObject,'String')) returns contents of FM_depthR as a double


% --- Executes during object creation, after setting all properties.
function FM_depthR_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FM_depthR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% --- Executes during object creation, after setting all properties.
function FM_depth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FM_depth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



% --- Executes on button press in process.
function process_Callback(hObject, eventdata, handles)
% hObject    handle to process (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

option = str2num(get(handles.option,'string'));
multiplier =str2num(get(handles.multiplier,'string'));
repeats =str2num(get(handles.repeats,'string'));
%left channel variables
modfreq =str2num(get(handles.modfreq,'string'));
xfade =str2num(get(handles.xfade,'string'));
xmodfreq =str2num(get(handles.xmodfreq,'string'));
xmoddepth =str2num(get(handles.xmoddepth,'string'));
FM_freq =str2num(get(handles.FM_freq,'string'));
FM_depth =str2num(get(handles.FM_depth,'string'));

if xmoddepth == 0
    xmod = 0;
else
    xmod=1;
end
%right channel variables
modfreqR =str2num(get(handles.modfreqR,'string'));
xfadeR =str2num(get(handles.xfadeR,'string'));
xmodfreqR =str2num(get(handles.xmodfreqR,'string'));
xmoddepthR =str2num(get(handles.xmoddepthR,'string'));
FM_freqR =str2num(get(handles.FM_freqR,'string'));
FM_depthR =str2num(get(handles.FM_depthR,'string'));
if xmoddepthR == 0
    xmodR = 0;
else
    xmodR=1;
end

% process audio
if option == 0
    in1 = handles.in1;
    in2 = handles.in2;
    in3 = handles.in3;
    in4 = handles.in4;
    fs = handles.fs;
    fsup = fs*multiplier;
    [wave1, wave2, wave3, wave4, maxLen] = process_inputs(in1, in2, in3, in4, fs, repeats, multiplier);
else
    sine1 = str2num(get(handles.sine1,'string'));
    sine2 = str2num(get(handles.sine2,'string'));
    sine3 = str2num(get(handles.sine3,'string'));
    sine4 = str2num(get(handles.sine4,'string'));
    fs = str2num(get(handles.sinefs,'string'));
    length = str2num(get(handles.length,'string'));
    fsup = multiplier*fs;
    maxLen = length*fsup;
    wave1 = sin(2*pi*sine1*(0:1/fsup:((maxLen-1)/fsup)))';
    wave2 = sin(2*pi*sine2*(0:1/fsup:((maxLen-1)/fsup)))';
    wave3 = sin(2*pi*sine3*(0:1/fsup:((maxLen-1)/fsup)))';
    wave4 = sin(2*pi*sine4*(0:1/fsup:((maxLen-1)/fsup)))';
    wave1(:,2)=wave1;
    wave2(:,2)=wave2;
    wave3(:,2)=wave3;
    wave4(:,2)=wave4;
    
end

[mod1, mod2, mod3, mod4] = ampmods_new2(modfreq, xfade, fsup, xmod, xmoddepth, xmodfreq, FM_freq, FM_depth, maxLen);
[mod1(:,2), mod2(:,2), mod3(:,2), mod4(:,2)] = ampmods_new2(modfreqR, xfadeR, fsup, xmodR, xmoddepthR, xmodfreqR, FM_freqR, FM_depthR, maxLen);
disp(size(mod1))
disp(size(wave1))
wave1 = wave1.*mod1;
wave2 = wave2.*mod2;
wave3 = wave3.*mod3;
wave4 = wave4.*mod4;
output = wave1 + wave2 + wave3 + wave4;
% filter audio.
passband = 20000/fsup;
stopband = 22050/fsup;
lpfilt = designfilt('lowpassfir','PassbandFrequency', passband, 'StopbandFrequency',...
    stopband,'PassbandRipple',0.5,'StopbandAttenuation',120,...
    'DesignMethod','kaiserwin');
% fvtool(lpfilt)
output =filter(lpfilt, output);
% figure(1)
% plot(mod1(:,2),'DisplayName','mod1');hold on;plot(mod2(:,2),'DisplayName','mod2');plot(mod3(:,2),'DisplayName','mod3');plot(mod4(:,2),'DisplayName','mod4');plot(wave1(:,2),'DisplayName','wave1');plot(wave2(:,2),'DisplayName','wave2');plot(wave3(:,2),'DisplayName','wave3');plot(wave4(:,2),'DisplayName','wave4');hold off;


%resample to original fs.
out = resample(output, fs, fsup, 10);
out = (out/max(max(abs(out))));
sound(out,fs);
handles.out = out;
handles.fs = fs;
guidata(handles.listen, handles);


% %       See ISPC and COMPUTER.
% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
%     set(hObject,'BackgroundColor','white');
% end
