フィルターのクリア

Control dsp.audiodevicewriter with a toggle switch button

3 ビュー (過去 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
  1 件のコメント
Bastien Lechat
Bastien Lechat 2018 年 1 月 9 日
drawnow() was the missing part ! Thank you so much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by