Why does dsp.AudioRecorder() uses SO much CPU time?

2 ビュー (過去 30 日間)
Ian Weston
Ian Weston 2016 年 2 月 25 日
コメント済み: Ian Weston 2016 年 3 月 1 日
I've been following the online mathworks tutorial here: streaming signal processing
It all works well and everything is good - However when I look at the task manager while running this code, I can see that matlab is using 35% of my CPU time! This was much higher than i had expected so i removed all the graphing and the filtering code, and just had the audio streaming in and out. when i run the code again it is still taking up 35% CPU time. I have also tried playing around with the other streaming audio functions dsp.AudioFileReader() and dsp.AudioPlayer() and so long as one of these functions is being called, then the CPU time is up at 35%.
My CPU is an Intel I5 running at 4.2Ghz - i have other realtime audio applications that only take 5% CPU to work with realtime audio.
Is there anything that can be done to reduce the overhead of these functions?
I've tried increasing and decreasing the buffer size too - the theory being that a smaller buffer size will mean the dsp.AudioRecorder() function is called more frequently. however it has no effect as the CPU usage remains at 35%. It seems that the functions are spending most of the time in a blocking wait state... and it would be great to get around this as it only leaves 65% CPU time for other processing.
Any help would be gratefully received! Thank you!

回答 (1 件)

Gabriele Bunkheila
Gabriele Bunkheila 2016 年 3 月 1 日
Hi Ian,
Thanks for asking. I work at MathWorks and I thought I'd take a stab at answering your question.
In short – The CPU load measured by the OS tends to be irrelevant for most MATLAB-only use cases.
dsp.AudioRecorder does not really take all that time itself. The CPU utilization that you saw simply indicates that MATLAB is sitting somewhere in your program while nothing else is happening. You noted yourself that removing plotting and filtering didn’t change the CPU utilization. This works both ways – increasing the computational load will generally not increase CPU utilization as long as the code can run in real time.
On the other end, CPU utilization metrics are relevant to use cases where MATLAB runs alongside other time-critical applications on your machine. To better serve those use cases we are considering improvements to our audio I/O capabilities for future MATLAB releases.
I hope this answers your question.
  1 件のコメント
Ian Weston
Ian Weston 2016 年 3 月 1 日
Hi Gabriele,
Many thanks for your answer, that gives me an insight into how matlab works on the inside, and that's really useful. thank you!
In this case, I will be mostly working within MATLAB, and eventually getting my hands dirty with some CUDA. So for the time being I don't see this being an issue, and its a relief to know there is still plenty of CPU time available hidden behind the MATLAB threads.
Many thanks! Ian.


Community Treasure Hunt

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

Start Hunting!

Translated by