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
Stephen23 2018-5-9
Marius Rusu's "Answer" moved here:
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
Marius Rusu
Marius Rusu 2018-5-9
编辑:Marius Rusu 2018-5-9
At some point I received a notification for a comment that was reading "what do you expect". I can't see the comment here on the website but I would add that if I play the same .wav file with windows media player the CPU barely moves (see below print screen). I don't expect the same with Matlab but I was expecting much less CPU usage. Would appreciate any tips on reducing it when playing sounds in Matlab as I need to use sounds in conjunction with continuous processing streams of TCP data and updating various graphs. PS. I already update graphs using the below code which is more efficient than using plot.
set(myAxis,'XData',myXdata,'YData',myYdata);
Kind regards, Marius

请先登录,再进行评论。

采纳的回答

Jan
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 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by