function varargout = playAudio(varargin)
% PLAYAUDIO M-file for playAudio.fig
% PLAYAUDIO, by itself, creates a new PLAYAUDIO or raises the existing
% singleton*.
%
% H = PLAYAUDIO returns the handle to a new PLAYAUDIO or the handle to
% the existing singleton*.
%
% PLAYAUDIO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PLAYAUDIO.M with the given input arguments.
%
% PLAYAUDIO('Property','Value',...) creates a new PLAYAUDIO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before playAudio_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to playAudio_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 playAudio
% Last Modified by GUIDE v2.5 11-Nov-2008 17:50:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @playAudio_OpeningFcn, ...
'gui_OutputFcn', @playAudio_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 playAudio is made visible.
function playAudio_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 playAudio (see VARARGIN)
% move GUI to the center of the screen
movegui(hObject,'center');
% set the position and size of the icon to display
axespos = getpixelposition(handles.axes1);
imgdata = imread('music', 'jpg');
imgsize = size(imgdata);
axespos(3) = imgsize(2);
axespos(4) = imgsize(1);
setpixelposition(handles.axes1, axespos);
image(imgdata);
set(handles.axes1, 'Visible', 'off');
% set(handles.samplerate, 'String', '8192');
% set(handles.node, 'String', '0.000123');
% Choose default command line output for playAudio
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes playAudio wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = playAudio_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)
warningstate = warning;
warning off;
sample = handles.sample;
node = handles.node;
a=sin(2*pi*440*(0:node:0.5));
b=sin(2*pi*493.88*(0:node:0.5));
cs=sin(2*pi*554.37*(0:node:0.5));
d=sin(2*pi*587.33*(0:node:0.5));
e=sin(2*pi*659.26*(0:node:0.5));
fs=sin(2*pi*739.99*(0:node:0.5));
line1=[a,a,e,e,fs,fs,e,e,];
line2=[d,d,cs,cs,b,b,a,a,];
line3=[e,e,d,d,cs,cs,b,b];
song=[line1,line2,line3,line3,line1,line2];
wavwrite(song,'ff.wav');
pause(.01);
y = wavread('ff.wav');
Fs = sample;
sound(y,Fs);
warning(warningstate);
function node_Callback(hObject, eventdata, handles)
% hObject handle to node (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 node as text
% str2double(get(hObject,'String')) returns contents of node as a double
handles.node = str2double(get(hObject,'string'));
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function node_CreateFcn(hObject, eventdata, handles)
% hObject handle to node (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 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)
warningstate = warning;
warning off;
sample = handles.sample;
node = handles.node;
a=sin(2*pi*440*(0:node:0.5));
b=sin(2*pi*493.88*(0:node:0.5));
cs=sin(2*pi*554.37*(0:node:0.5));
d=sin(2*pi*587.33*(0:node:0.5));
e=sin(2*pi*659.26*(0:node:0.5));
fs=sin(2*pi*739.99*(0:node:0.5));
line1=[a,a,e,e,fs,fs,e,e,];
line2=[d,d,cs,cs,b,b,a,a,];
line3=[e,e,d,d,cs,cs,b,b];
song=[line1,line2,line3,line3,line1,line2];
wavwrite(song,'ff.wav');
warning(warningstate);
% Update handles structure
guidata(hObject, handles);
function samplerate_Callback(hObject, eventdata, handles)
% hObject handle to samplerate (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 samplerate as text
% str2double(get(hObject,'String')) returns contents of samplerate as a double
handles.sample = str2double(get(hObject,'string'));
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function samplerate_CreateFcn(hObject, eventdata, handles)
% hObject handle to samplerate (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