wavread signal handling problems with music in GUI
Show older comments
*Problem 1: When I press play on my GUI plays the song, but the stop button works and if I close the GUI that is playing the whole program closes and also close the matlab. Problem 2: try everything and I can not plot the signal of the song please I'm not a matlab expert would help with these problems and I need to program other functions. are 5 buttons and axes which shows me the sign of the song. axes (handles.axes1) the main thing I want is work and play and graphics estop I will appreciate any contribution and support.
This is the code I use GUI:*
function openfiles_Callback(hObject, eventdata, handles)
global ruta
global musica
disp('Running')
run = 1;
fs=44100;
bits=16;
ruta=uigetfile('*.wav','Selecciona un archivo wav');
if isequal(ruta,0)
disp('User pressed cancel')
set(handles.openfiles,'Enable','on');
set(handles.play,'Enable','off');
else
disp('User selected ')
set(handles.openfiles,'Enable','on');
set(handles.play,'Enable','on');
[musica fs bits]=wavread(ruta);
set(handles.openfiles,'Enable','on');
end
function mute_Callback(hObject, eventdata, handles)
% hObject handle to mute (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 play.
function play_Callback(hObject, eventdata, handles)
global musica
global ruta
global runn
if isequal(ruta,0)
set(handles.play,'Enable','off');
else
runn=1;
set(handles.stop,'Enable','on');
set(handles.mute,'Enable','on');
set(handles.volumen,'Enable','on');
wavplay(musica,44100);
end
function stop_Callback(hObject, eventdata, handles)
global run;
if (run==0)
set(handles.pushbutton1,'Enable','on');
end
function volumen_Callback(hObject, eventdata, handles)
global runn;
if (runn == 1)
set(handles.stop,'Enable','off');
set(handles.play,'Enable','on');
end
Answers (2)
Walter Roberson
on 5 Oct 2011
0 votes
Is your "global runn" the same as your "global run" ?
There is nothing in the code you show that ever sets run or runn to 0.
There is nothing in the code you show that would stop the sound from playing before it is finished.
How are you closing the GUI such that it triggers your problem #1?
What form of plot were you hoping to use of the music? Note that your music is very likely stereo.
Synchronizing a plot (of some kind) of the signal with the playing of the signal is difficult in MATLAB.
Note: As the user might choose to change directories, it would be a good idea for your uigetfile() to record the directory information along with the path information.
Daniel Shub
on 5 Oct 2011
0 votes
The wavplay function is depreciated. You should look at using audioplayer instead.
1 Comment
Walter Roberson
on 5 Oct 2011
... and if I recall correctly, audioplayer() provides a specific method to stop the playing.
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!