High CPU usage when running "soundsc" or "play"
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to play simple beep sounds of various lengths and whenever I run "soundsc" or "play" the CPU usage goes high up. Does anybody known why is this the case and if there is anything that can be done to keep the CPU usage low?
Kind regards, Marius
4 个评论
Stephen23
2018-5-9
Hi,
Thanks for your replies.
I am running Windows 7 Professional with Service Pack 1 on a i5-3210M CPU @2.5Ghz (laptop) and Matlab 2018a. I open up Matlab, paste this code in the command window, hit enter and then monitor the CPU usage.
[y,Fs] = audioread('sounds\beep-1378.125Hz-30s.wav');
player = audioplayer(y, Fs);
play(player);
The sound I am playing is a triangle shape stored as a .wav file and is 30 seconds long. The CPU usage is quite high for the whole duration of the sound playing. Once the sound stops the CPU usage goes down.

Kind regards, Marius
采纳的回答
Jan
2018-5-9
编辑:Jan
2018-5-9
My former comment vanished, when your message was moved from the section for answers to the comments. I wrote:
And what do you expect? One of the two cores works for creating the sound. On my i7 with 4 cores/8 threads, playing the sound uses 16% of the processor - to my surprise it is not 12.5%, but at least near to it.
But you are right: Windows can play sounds without blocking a core. See e.g. FEX: jAudio. This allows a buffered output also. Unfortunately it blocks the Matlab session until the sound has been played. I do not understand the methods of this submission, so maybe it is not possible to play the sound non-blocking. But at least jAudio demonstrates, that playing a sound requires just some percent of CPU load.
There are some other submissions in the FileExchange, but their handling is not trivial.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!