signal&system

410687002

電機二 曹育銘

outline:


outline:

load 4 songs

play, pause, resume, stop

loud version low version fast version

slow version upsidedown(-y) reverse version

plot left signal

plot right signal

code:

function varargout = untitled(varargin)

% UNTITLED MATLAB code for untitled.fig

% UNTITLED, by itself, creates a new UNTITLED or raises the existing

% singleton*.

%

% H = UNTITLED returns the handle to a new UNTITLED or the handle to

% the existing singleton*.

%

% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in UNTITLED.M with the given input arguments.

%

% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before untitled_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to untitled_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 untitled


% Last Modified by GUIDE v2.5 10-May-2019 13:49:41


% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @untitled_OpeningFcn, ...

'gui_OutputFcn', @untitled_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 untitled is made visible.

function untitled_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 untitled (see VARARGIN)


% Choose default command line output for untitled

handles.output = hObject;


% Update handles structure

guidata(hObject, handles);


% UIWAIT makes untitled wait for user response (see UIRESUME)

% uiwait(handles.figure1);



% --- Outputs from this function are returned to the command line.

function varargout = untitled_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)



% --- Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)

y = handles.y;

fs = handles.fs;

playerObj=audioplayer(y,fs) ;

play(playerObj);

time=(1:length(y))/fs;

handles.playerObj=playerObj;

guidata(hObject, handles);

left=y(:,1);

right=y(:,2);

plot(handles.axes1,time, left);

plot(handles.axes3,time, right);

% 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)



% --- Executes on selection change in listbox1.

function listbox1_Callback(hObject, eventdata, handles)

% hObject handle to listbox1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)


% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array

% contents{get(hObject,'Value')} returns selected item from listbox1



% --- Executes during object creation, after setting all properties.

function listbox1_CreateFcn(hObject, eventdata, handles)

% hObject handle to listbox1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called


% Hint: listbox 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



% --- If Enable == 'on', executes on mouse press in 5 pixel border.

% --- Otherwise, executes on mouse press in 5 pixel border or over listbox1.

function listbox1_ButtonDownFcn(hObject, eventdata, handles)

% hObject handle to listbox1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on selection change in popupmenu1.

function popupmenu1_Callback(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)


% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array

% contents{get(hObject,'Value')} returns selected item from popupmenu1



% --- Executes during object creation, after setting all properties.

function popupmenu1_CreateFcn(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called


% Hint: popupmenu 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 pushbutton4.

function pushbutton4_Callback(hObject, eventdata, handles)

[y, fs]=audioread('C:\Users\eric8\Desktop\1.mp3');

handles.y = y;

guidata(hObject, handles);

handles.fs = fs;

guidata(hObject, handles);

playerObj = audioplayer(y,fs);

handles.playerObj = playerObj;

guidata(hObject, 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)



% --- Executes on button press in pushbutton5.

function pushbutton5_Callback(hObject, eventdata, handles)

playerObj=handles.playerObj;

stop(playerObj);

% hObject handle to pushbutton5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton6.

function pushbutton6_Callback(hObject, eventdata, handles)

playerObj=handles.playerObj;

pause(playerObj);

% hObject handle to pushbutton6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton7.

function pushbutton7_Callback(hObject, eventdata, handles)

playerObj=handles.playerObj;

resume(playerObj);

% hObject handle to pushbutton7 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton8.

function pushbutton8_Callback(hObject, eventdata, handles)

y = handles.y;

fs = handles.fs;

playerObj=audioplayer(8*y,fs) ;

play(playerObj);

time=(1:length(8*y))/fs;

%plot(handles.axes1,time,8*y);

handles.playerObj=playerObj;

guidata(hObject, handles);

left=8*y(:,1);

right=8*y(:,2);

plot(handles.axes1,time, left);

plot(handles.axes3,time, right);


% hObject handle to pushbutton8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton9.

function pushbutton9_Callback(hObject, eventdata, handles)

y = handles.y;

fs = handles.fs;

playerObj=audioplayer(0.2*y,fs) ;

play(playerObj);

time=(1:length(0.2*y))/fs;

%plot(handles.axes1,time,0.2*y);

handles.playerObj=playerObj;

guidata(hObject, handles);

left=0.2*y(:,1);

right=0.2*y(:,2);

plot(handles.axes1,time, left);

plot(handles.axes3,time, right);

% hObject handle to pushbutton9 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton10.

function pushbutton10_Callback(hObject, eventdata, handles)

y = handles.y;

fs = handles.fs;

playerObj=audioplayer(y,1.25*fs) ;

time=(1:length(y))/1.25*fs;

%plot(handles.axes1,time,y);

play(playerObj);

handles.playerObj=playerObj;

guidata(hObject, handles);

left=y(:,1);

right=y(:,2);

plot(handles.axes1,time, left);

plot(handles.axes3,time, right);

% hObject handle to pushbutton10 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton11.

function pushbutton11_Callback(hObject, eventdata, handles)

y = handles.y;

fs = handles.fs;

playerObj=audioplayer(y,0.8*fs) ;

%playerObj.SampleRate=0.5*fs ;

time=(1:length(y))/0.8*fs;

%plot(handles.axes1,time,y);

play(playerObj);

handles.playerObj=playerObj;

guidata(hObject, handles);

left=y(:,1); % 抽取第 1 声道

right=y(:,2); % 抽取第 2 声道

plot(handles.axes1,time, left);

plot(handles.axes3,time, right);

% hObject handle to pushbutton11 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton12.

function pushbutton12_Callback(hObject, eventdata, handles)

y = handles.y;

fs = handles.fs;

playerObj=audioplayer(-y,fs) ;

%left=y(:,1);

%right=y(:,2);

%subplot(2,1,1), plot((1:length(left))/fs, left);

%subplot(2,1,2), plot((1:length(right))/fs, right);

time=(1:length(-y))/fs;

%plot(handles.axes1,time,-y);

play(playerObj);

handles.playerObj=playerObj;

guidata(hObject, handles);

left=-y(:,1);

right=-y(:,2);

plot(handles.axes1,time, left);

plot(handles.axes3,time, right);

% hObject handle to pushbutton12 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton13.

function pushbutton13_Callback(hObject, eventdata, handles)

y = handles.y;

fs = handles.fs;

playerObj=audioplayer(flipud(y), fs) ;

time=(1:length(flipud(y)))/fs;

%plot(handles.axes1,time,flipud(y));

play(playerObj);

handles.playerObj=playerObj;

guidata(hObject, handles);

left=y(:,1);

right=y(:,2);

plot(handles.axes1,time, flipud(left));

plot(handles.axes3,time, flipud(right));

% hObject handle to pushbutton13 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton14.

function pushbutton14_Callback(hObject, eventdata, handles)

[y, fs]=audioread('C:\Users\eric8\Desktop\2.mp3');

handles.y = y;

guidata(hObject, handles);

handles.fs = fs;

guidata(hObject, handles);

playerObj = audioplayer(y,fs);

handles.playerObj = playerObj;

guidata(hObject, handles);

% hObject handle to pushbutton14 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton15.

function pushbutton15_Callback(hObject, eventdata, handles)

[y, fs]=audioread('C:\Users\eric8\Desktop\4.mp3');

handles.y = y;

guidata(hObject, handles);

handles.fs = fs;

guidata(hObject, handles);

playerObj = audioplayer(y,fs);

handles.playerObj = playerObj;

guidata(hObject, handles);

% hObject handle to pushbutton15 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on button press in pushbutton16.

function pushbutton16_Callback(hObject, eventdata, handles)

[y, fs]=audioread('C:\Users\eric8\Desktop\3.mp3');

handles.y = y;

guidata(hObject, handles);

handles.fs = fs;

guidata(hObject, handles);

playerObj = audioplayer(y,fs);

handles.playerObj = playerObj;

guidata(hObject, handles);

% hObject handle to pushbutton16 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)



% --- Executes on slider movement.

function slider5_Callback(hObject, eventdata, handles)


% hObject handle to slider5 (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,'Value') returns position of slider

% get(hObject,'Min') and get(hObject,'Max') to determine range of slider



% --- Executes during object creation, after setting all properties.

function slider5_CreateFcn(hObject, eventdata, handles)

% hObject handle to slider5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called


% Hint: slider controls usually have a light gray background.

if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor',[.9 .9 .9]);

end


DEMO

https://youtu.be/P56DbqCa15Q