1

在我的一个回调中,我加载了一个 wav 文件,然后将其绘制在轴上。在另一个回调中,我尝试播放 wav 文件,但它不工作。求大神帮忙,怎么玩??

function btnload_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile('*.wav','Select Data File');
[y,fs] = wavread([pathname filename]);
axes(handles.axes1)
plot(y);
title('ORIGINAL AUDIO SIGNAL');
ylabel('t');
guidata(hObject, handles); %updates the handles




function btnplay1_Callback(hObject, eventdata, handles)
soundsc(y,fs); 
4

1 回答 1

3

如果您需要在 GUIDE 生成的 GUI 中维护应用程序数据handles,一种方法是使用传递给所有回调函数的结构:

function btnload_Callback(hObject, eventdata, handles)
    %# read WAV file
    [filename, pathname] = uigetfile('*.wav','Select Data File');
    [y,fs] = wavread([pathname filename]);

    %# plot wave
    axes(handles.axes1)
    plot(y);
    title('ORIGINAL AUDIO SIGNAL');
    ylabel('t');

    %# save it to handles structure
    handles.y = y;
    handles.fs = fs;
    guidata(hObject, handles);      %# updates the handles
end

function btnplay1_Callback(hObject, eventdata, handles)
    %# retrieve the wave data, and play the sound
    soundsc(handles.y, handles.fs);
end
于 2011-10-30T07:44:12.117 回答