wavplay stall

5 views (last 30 days)
Jennifer
Jennifer on 22 Oct 2011
I am trying to play two wav files back to back and matlab is stalling randomly between the two calls. On my personal computer which is running 2007a the program works just fine. On my lab computer running 2010a is where is stalls. All files have been transferred and there are no errors in the code.
The code looks something like this
sr =44100;
wavplay (x, sr)
wavplay (y,sr)
I have also tried adding in a print to screen between the two to see if its something with the first wavplay and it will run but stalls at the second wavplay. Any thoughts?

Answers (2)

Wayne King
Wayne King on 23 Oct 2011
Hi, if you replace your wavplay(x,sr) calls with
audioplayer(x,sr)
Does that help?

Jan
Jan on 23 Oct 2011
WAVPLAY and SOUND, which both call PLAYSND, as well as AUDIOPLAYER are very sensitive. I've observed crashs in Matlab 5.3, 6.0. 6.1, 6.5, 7.0, 2008b, 2009a and 2011b in Windows under different conditions. Sometimes just a message box "Cannot register sound window" appears on heavy system load, sometimes Matlab becomes unresponsive. Under 2011b the AUDIOPLAYER has a 1.5 seconds delay before the sound is started in my Windows7 installation. When the AUDIOPLAYER object is created inside a function and started asynchronously, the sound is suppressed completely, if the function has left earlier:
function MyBeep
Wave = [sin(1:.6:400), sin(1:.7:400), sin(1:.4:400)]);
AP = audioplayer(Wave(:), 22050);
play(AP);
% ==> AP is deleted before the sound starts due to delay
The AP object is not deleted, if it stays alive:
function MyBeep
persistent AP
Wave = [sin(1:.6:400), sin(1:.7:400), sin(1:.4:400)]);
AP = audioplayer(Wave(:), 22050);
play(AP);
But now Matlab 6.5 and 2011b crash and create a dump. when the Matlab session is finished. Under 2009b everything works well. This can be solved by a "clear MyBeep" in the finish.m function.
Adding an automatic deletion of the AUDIOPLAYER object inside its StopFcn results in an immediate crash under 2011b, but works under 6.5 and 2009a.
I've tried it very hard to create one function for such a simple asynchronous beeping, which works stable under the different Matlab version. Finally I resigned.
  1 Comment
Wayne King
Wayne King on 23 Oct 2011
Given Jan's comments, do you have the Signal Processing Blockset in R2010b? If so, I think you'll find dsp.AudioFileReader and dsp.AudioPlayer useful. I have not had the problems you report with those System objects.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!