High CPU usage when running "soundsc" or "play"

조회 수: 1 (최근 30일)
Marius Rusu
Marius Rusu 2018년 5월 8일
편집: Jan 2018년 5월 9일
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개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by