Control dsp.audiodevicewriter with a toggle switch button
3 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I would like to create a toggle button allowing user to chose when to start/stop my noise sample. (I attached a photo)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168559/image.png)
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 件のコメント
採用された回答
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 Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!