drawnow function in App Designer stops working?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Michael Svejcar
le 18 Mar 2020
Commenté : hagege ruben
le 23 Mar 2020
Hello,
I'm making audio player in Matlab's App Designer for my thesis. However, I got stuck with one issue I got, so I'll describe it here on simple example, where the same issue also happens.
First, in my private properties, I define variables for AudioFileReader and AudioDeviceWriter, so I can access these objects later from callbacks:
afr = dsp.AudioFileReader;
adw = audioDeviceWriter;
Then, I make two state buttons, StateButton1 and StateButton2. When you press one of them, their purpose is meant to change app.afr.Filename to corresponding track (first button is for playing one track, like 01.wav, second button for another track, 02.wav, for example), play the track while the button is pressed (while it's value property equals to 1), and to "unpress" the other button, which is not currently playing. This way, when one button is pressed and it's corresponding audio file is playing and I press the second button, the first button gets "unpressed", second button gets pressed and the audio file corresponding to second button starts playing. When I unpress the button coressponding to the currently playing audio file, it simply stops.
Here is the code of StateButton1ValueChanged callback:
app.StateButton2.Value = 0;
release(app.afr);
release(app.adw);
app.afr.Filename = '01.wav';
app.afr.SamplesPerFrame = 512;
app.adw.SampleRate = app.afr.SampleRate;,
while ~isDone(app.afr) & app.StateButton1.Value == 1
audio = app.afr();
app.adw(audio);
drawnow;
end
And here is practically the same code for StateButton2ValueChanged callback, only with different parameters:
app.StateButton1.Value = 0;
release(app.afr);
release(app.adw);
app.afr.Filename = '02.wav';
app.afr.SamplesPerFrame = 512;
app.adw.SampleRate = app.afr.SampleRate;,
while ~isDone(app.afr) & app.StateButton2.Value == 1
audio = app.afr();
app.adw(audio);
drawnow;
end
It works fine like this for some time, however the problem starts after few changes from track 1 to track 2 and vice versa with these two state buttons. When I click on them alternately to change the currently playing track for like ten times, then it gets stuck and I can't turn off the currently playing track with it's corresponding button, can't change the currently playing track with the second button to the second audio file and the first button even doesn't get unpressed, as it should, when I press the second button to the "pressed" Value = 1 state. Only the track that was playing before the freeze keeps playing.
Now I'm seriously getting clueless, it seems to me like that the "drawnow;" function in each callback stops working after few changes from first callback to the second one and vice versa for some reason, but why? Any ideas? I'll really appreciate any idea or clue why this is happening, as I need to finish my thesis in like two months and this is still such a hurdle for me.
Thank you very much for any response.
0 commentaires
Réponse acceptée
hagege ruben
le 22 Mar 2020
did you try pause(0.001)?
It did work best for me on 2019b
2 commentaires
hagege ruben
le 23 Mar 2020
well maybe you could also add a Busy property to you'r code so that it would skip updating when already working on previous update.
also you should try to make a function out of redundant code, it's a good practice and helps for debugging/maintainance of the code
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!