Control dsp.audiodevicewriter with a toggle switch button

조회 수: 5 (최근 30일)
Bastien Lechat
Bastien Lechat 2018년 1월 8일
댓글: Bastien Lechat 2018년 1월 9일
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

채택된 답변

Walter Roberson
Walter Roberson 2018년 1월 8일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Install Products에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by