Action on close of spectrumAnalyzer() object/windows

조회 수: 6 (최근 30일)
Jonas
Jonas 2022년 12월 8일
편집: Jonas 2022년 12월 13일
Dear community,
at the moment I am preparing for some real time processing on audio recordings. I want to end the inifinite recording loop, when the visualizing window is closed. How can I achieve this, i cannot even find the handle to the plotting window.
so far the loop closes when the window with tunable properties is closed and then the spectrumAnalyzer() window is closed.
Note: this is about a spectrumAnalyzer object, not dsp.spectrumAnalyzer()
Unfortunately i cannot have a look into the first, since it is p-code
deviceReader = audioDeviceReader('NumChannels',2);
% Create scope
specScope = spectrumAnalyzer('SampleRate',deviceReader.SampleRate, ...
'Method','Filter bank', ...
'PlotAsTwoSidedSpectrum',false, ...
'FrequencyScale','Log', ...
'AveragingMethod','Exponential', ...
'ShowLegend',true, ...
'ChannelNames',{'Input channel 1','Output channel 1'}, ...
'YLimits',[-102.67239232318423 -22.46657271946507]);
% just a audio plugin doing some processing
sut = audiopluginexample.SpeechPitchDetector;
setSampleRate(sut,deviceReader.SampleRate);
% Open parameterTuner for interactive tuning during simulation
tuner = parameterTuner(sut);
drawnow
% Stream processing loop
nOverruns = 0;
figs=findall(0,'type','figure'); % end loop if any until here opened window is closed
while all(ishandle(figs))
% Read from input, process, and write to output
[in,novr] = deviceReader();
nOverruns = nOverruns + novr; % Increment the overrun counter
in = in(:,1);
out = process(sut,in);
% Visualize input and output data in scope
%%%%%% This call opens the window with representation, but i cannot
%%%%%% find the handle of this window to include it in the whilw
%%%%%% statement
specScope([in(:,1),out(:,1)]);
% Process parameterTuner callbacks
drawnow limitrate
end
% Clean up
delete(specScope)
release(deviceReader)
release(specScope)

채택된 답변

Jonas
Jonas 2022년 12월 13일
편집: Jonas 2022년 12월 13일
alright, I now got it. we can close and open the scope Window using show(scope) and hide(scope) und we can check if the scope window is hidden (closed) with isVisible(scope)
edit: When using with while(), dont forget a call to drawnow limitrate

추가 답변 (1개)

Jonas
Jonas 2022년 12월 12일
my insight so far:
I have seen, that a new Process is created, and the Window Name has the title "Spectrum Analyzer". we could use that and check via cmd or powershell, if the process exist with the Window TItle I asked for
unfortunately, this causes performance issues, which made me introduce a timer, which makes it check every some seconds
checking via cmd, i Used
[~,b] = system('tasklist /fi "WINDOWTITLE eq Spectrum Analyzer"');
(credit to here)
i then check in the text for the MATLABWindow with
if ~contains(b,'MATLABWindow.exe')
break;
end
using powershell over cmd, I used
system( 'powershell -command "get-process | where-object {$_.mainWindowTitle -like ''Spectrum Analyzer''}"' );
(credit to here and here)
i then check in the text for the MATLABWindow with
if ~contains(b,'MATLABWindow')
break;
end
in summary: it works, but the performance (of the system call) is really poor and not acceptable

카테고리

Help CenterFile Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by