发布时间 : 星期五 文章数字变声器更新完毕开始阅读
4.4每个控件的程序如下
4.4.1“录音”radiobutton(radiobutton1)
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1 if get(hObject,'Value')
set(handles.pushbutton1,'Enable','on'); set(handles.edit1,'Enable','on'); set(handles.edit2,'Enable','on'); set(handles.radiobutton2,'Value',0); set(handles.pushbutton3,'Enable','off'); else end
4.4.2“打开”radiobutton(radiobutton2)
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if get(hObject,'Value')
set(handles.radiobutton1,'Value',0); set(handles.pushbutton1,'Enable','off'); set(handles.edit1,'Enable','off'); set(handles.edit2,'Enable','off');
set(handles.pushbutton3,'Enable','on'); else end
13 / 24
4.4.3“开始 ”按钮(pushbutton1)
% --- 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) set(hObject,'string','luyinzhong'); pause(0.4);
Fs=str2double(get(handles.edit2,'String')); t=str2double(get(handles.edit1,'String')); ai=analoginput('winsound',0); chane1=addchannel(ai,1); set(ai,'SampleRate',Fs); duration=t;
set(ai,'SamplesPerTrigger',duration*Fs); start(ai); y=0;time=0;
[y,time]=getdata(ai); handles.y=y; handles.Fs=Fs;
guidata(hObject,handles); plot(handles.axes1,handles.y) title(handles.axes1,'shiyutu'); ysize=size(handles.y);
y=fft(handles.y,length(handles.y)); ysize=size(y);
plot(handles.axes2,abs(y)); xlabel(handles.axes2,'pinlv'); ylabel(handles.axes2,'fudu');
title(handles.axes2,'pinlvtexing'); set(hObject,'string','wanbi');
set(handles.pushbutton2,'Enable','on'); 4.4.4“保存”按钮(pushbutton2)
% --- 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) Fs=handles.Fs; fs=Fs;
14 / 24
[filename]=uiputfile({'*.wav','ALL FILES(*.*)'},'wenjianbaocun'); wavwrite(handles.y,fs,filename); 4.4.5“打开音频文件按钮”(pushbutton3)
% --- 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','ALL FILES'},'xuanzeshengyinwenjian'); if isequal([filename pathname],[0,0]) return; end
str=[pathname filename]; [temp Fs]=wavread(str);
handles.y=temp;handles.Fs=Fs; handles.xuanze=2;
guidata(hObject,handles);
set(handles.pushbutton2,'Enable','on'); 4.4.6“原声”按钮(pushbutton5)
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles) % 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) c=handles.Fs; Fs=c;
wavplay(handles.y,Fs);
plot(handles.axes1,handles.y) title(handles.axes1,'shiyutu'); ysize=size(handles.y);
y=fft(handles.y,length(handles.y)); ysize=size(y);
plot(handles.axes2,abs(y(1:ysize/2))); xlabel(handles.axes2,'pinlv'); ylabel(handles.axes2,'fudu');
title(handles.axes2,'pinlvtexing');
15 / 24
4.4.7“女声”按钮(pushbutton7)
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles) % 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) FL = 80; WL = 240; P = 10; s=handles.y;fs=handles.Fs;
s = s/max(s); L = length(s); FN = floor(L/FL)-2;
exc=zeros(L,1); zi_pre = zeros(P,1); s_rec = zeros(L,1); zi_rec = zeros(P,1); exc_syn = zeros(L,1); s_syn = zeros(L,1); last_syn = 0;
zi_syn = zeros(P,1);
exc_syn_t = zeros(L,1); s_syn_t = zeros(L,1); last_syn_t = 0; zi_syn_t = zeros(P,1); hw = hamming(WL); for n = 3:FN
s_w = s(n*FL-WL+1:n*FL).*hw; [A E] = lpc(s_w, P); ? s_f=s((n-1)*FL+1:n*FL); ??
[exc1,zi_pre] = filter(A,1,s_f,zi_pre); exc((n-1)*FL+1:n*FL) = exc1;
[s_rec1,zi_rec] = filter(1,A,exc1,zi_rec); s_rec((n-1)*FL+1:n*FL) = s_rec1; s_Pitch = exc(n*FL-222:n*FL); PT = findpitch(s_Pitch); G = sqrt(E*PT);
tempn_syn = [1:n*FL-last_syn]';
exc_syn1 = zeros(length(tempn_syn),1); exc_syn1(mod(tempn_syn,PT)==0) = G;
exc_syn1 = exc_syn1((n-1)*FL-last_syn+1:n*FL-last_syn); [s_syn1,zi_syn] = filter(1,A,exc_syn1,zi_syn); exc_syn((n-1)*FL+1:n*FL)=exc_syn1;
16 / 24