Control dsp.audiodevicewriter with a toggle switch button
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bastien Lechat
am 8 Jan. 2018
Kommentiert: Bastien Lechat
am 9 Jan. 2018
Hello,
I would like to create a toggle button allowing user to chose when to start/stop my noise sample. (I attached a photo)

value of "stop" is '1' and value of "Play" is '2'
It starts correctly, but I can't stop the sound. I am using the app designer. Here is my code:
function replayone(app,event)
value = app.Switch.Value;
afr = dsp.AudioFileReader([app.dir '/audio_track/track' num2str(app.index) '.wav']);
Fs = afr.SampleRate;
adw = audioDeviceWriter('SampleRate', Fs);
app.counter = 0;
while ~isDone(afr)
audioIn = afr();
if app.counter == 0
click = ones([1,length(audioIn)])*0.3;
else
click = zeros*(1:length(audioIn));
end
t = (app.counter + 1 : app.counter + size(audioIn, 1));
app.counter = t(end);
audioout = [audioIn click'];
event.Source
if event.Value == '1'
break
end
adw(audioout);
end
delete(adw), delete(afr)
end
I have been trying quite a few condition, however it looks like when it enters in the loop "while ~isdone" it doesn't check the value of the toggle button anymore. I also have tried with 'switch' and different case but didn't resolve it. Thank you
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 8 Jan. 2018
The event queue will not be checked until a drawnow() or pause() or a figure() or a uiwait() or waitfor() .
Furthermore, the event parameter will not be updated because the function is not being invoked a second time. Instead of checking event.Value, you need to check app.Switch.Value
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Install Products finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!