function varargout = Gui1_6(varargin)
% GUI1_6 MATLAB code for Gui1_6.fig
% GUI1_6, by itself, creates a new GUI1_6 or raises the existing
% singleton*.
%
% H = GUI1_6 returns the handle to a new GUI1_6 or the handle to
% the existing singleton*.
%
% GUI1_6('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI1_6.M with the given input arguments.
%
% GUI1_6('Property','Value',...) creates a new GUI1_6 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Gui1_6_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Gui1_6_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 Gui1_6
% Last Modified by GUIDE v2.5 22-Sep-2020 22:43:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gui1_6_OpeningFcn, ...
'gui_OutputFcn', @Gui1_6_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 Gui1_6 is made visible.
function Gui1_6_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 Gui1_6 (see VARARGIN)
% Choose default command line output for Gui1_6
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.slider1,'value',0);
% UIWAIT makes Gui1_6 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gui1_6_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)
global h; h=handles;
global mytimer;
start(mytimer);
global m;
global pyr;
m=0;
global m1; global m2;
m1=1;m2=0;
global abc;
global Fs;
Fs=44100;
global pyr;
[pyr,Fs]=audioread(abc);
sound(pyr,Fs); %声音回放
%n=length(pyr);
% pyr1=fft(pyr,n);
% A1=abs(pyr1)/(n/2);
% f=linspace(0,Fs/2,n/2);
% plot(handles.axes3,f,A1(1:n/2));
% --- 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)
global abc;
global Fs;
global pyr;
Fs=44100;
[FileName,PathName] = uigetfile('*.mp3','Select the audio-file');
abc=fullfile(PathName,FileName);
set(handles.edit1,'String',abc);
[pyr,Fs]=audioread(abc);%声音读取
plot(handles.axes1,pyr);
%显示音频的时间;
global t;global num;
t=length(pyr(:,1))/Fs;
num=length(pyr(:,1));
t1=sprintf('%.1f',t);
set(handles.edit4,'string',t1);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global abc;
global Fs;
global num;
a=100*get(handles.slider1,'value');
%s2=sprintf('%.1f',a); set(handles.edit3,'String',s2);
%v2 = str2double(s2);
v2=a;
v2=round(v2);
num1=round(num);
if(v2<=10)
v2=20;
m4=round(num1*v2/100);
m3=round(num1*(v2-10)/100);
else
m4=round(num1*v2/100);
m3=round(num1*(v2-10)/100);
end
sample=[m3,m4];
[pyr3,Fs]=audioread(abc,sample);
plot(handles.axes2,pyr3);
%播放频谱
n=length(pyr3);
pyr4=fft(pyr3,n);
A1=abs(pyr4)/(n/2);
f=linspace(0,Fs/2,n/2);
plot(handles.axes3,f,A1(1:n/2));
% 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 slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (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
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
global mytimer;
mytimer = timer('StartDelay',0, 'Period',0.1,'TasksToExecute',10000,'ExecutionMode', 'fixedRate');
mytimer.TimerFcn ={@my_callback_fcn};
function my_callback_fcn(obj,event)
global Fs;
global m;
global h;
global mytimer;
%global pyr;
global t;
%a=size(pyr,1); %先矩阵运算,在用结果另起一行,计算分开写!!!
%a=length(pyr(:,1))/fs %求音乐的时间
t=round(t);%a/Fs;%音乐时间
period=0.1;
n1=t/period;%移动次数
dn=1/n1;%slider每一次移动的值
m=m+dn;
%设置滚动条的位置
if(m>=1)
m=1;
stop(mytimer);
set(h.slider1,'value',m);
m=0;
set(h.slider1,'value',m);
else
set(h.slider1,'value',m);
end
%波形随时间变动
global abc;
global m1;global m2;
global num;
dm=round(num/n1);%每一次选取区域的变动指;
m2=m2+dm;
if(m2>=num)
m2=num;
m1=m2-dm;
end
sample=[m1,m2];
m1=m2;
[pyr1,Fs]=audioread(abc,sample);
plot(h.axes2,pyr1);
%播放频谱
n=length(pyr1);
pyr2=fft(pyr1,n);
A1=abs(pyr2)/round(n/2);
f=linspace(0,Fs/2,round(n/2));
plot(h.axes3,f,A1(1:round(n/2)));
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB