MATLAB: Making a GUI for playback of wav files

app designerMATLAB

I want to make a GUI were the listener is able to audition two separate sounds (wave files). Something like in the attached image. E.g. 1 = "reference", 2 = "comparison". When the listener hit pushbuton 1, he or she will hear the reference, when hitting pushbotton 2 he or she hear the comparison. Maybe with separate start and stop pusbuttons.
Is it best to you App designer for this?

Best Answer

Marius - you seem to be programmatically creating your GUI and throwing in GUIDE-style callbacks. You need to assign the callbacks to the controls in order for them to fire. For example, to assign a callback to pushbutton1 you could do
pushbutton1 = uicontrol('Style','pushbutton','String','Play','Position',[90 100 50 50], 'Callback', @pushbutton1_Callback);
and then the signature of this callback would be
function pushbutton1_Callback(hObject, eventdata)
Note how handles has been removed since that is a GUIDE structure. It each callback seems to reference a global variable named file_name yet no where do I see this is defined. If you want to reference the audio files that you have already read (Reference_iem_test_0.wav and Variable_iem_test_4_0.wav), then create a main function that creates your GUI and nest the callbacks within it. For example, if you modify your code slightly to
function MyAudioPlayer
f = figure;
fp1 = uipanel('parent',f,'Title','Reference','fontSize',18,'Position',[.170 .50 .200 .200]);
fp2 = uipanel('parent',f,'Title','Comparison', 'fontSize',18,'Position',[.620 .50 .200 .200]);
[y1,Fs1] = audioread('Reference_iem_test_0.wav');
[y2,Fs2] = audioread('Variable_iem_test_4_0.wav');
player1 = audioplayer1(y1,Fs1);
player2 = audioplayer1(y2,Fs2);
uicontrol('Style','pushbutton','String','Play','Position',[90 100 50 50], 'Callback', @pushbutton1_Callback);
uicontrol('Style','pushbutton','String','Stop','Position',[170 100 50 50], 'Callback', @pushbutton2_Callback);
uicontrol('Style','pushbutton','String','Play','Position',[340 100 50 50], 'Callback', @pushbutton3_Callback);
uicontrol('Style','pushbutton','String','Stop','Position',[420 100 50 50], 'Callback', @pushbutton4_Callback);
function pushbutton1_Callback(hObject, eventdata)
% start player1
end
function pushbutton2_Callback(hObject, eventdata)
% stop player1
end
function pushbutton3_Callback(hObject, eventdata)
% start player2
end
function pushbutton4_Callback(hObject, eventdata)
% stop player2
end
end
and save to a file named MyAudioPlayer.m, then you should be able to start and stop the audio players as desired (I've left that code to you). Because the callbacks are nested within the main function, then the callbacks have access to the local variables declared in the main function (i.e. the player1 and player2 objects).