issue with audioplayer/sound functions

Hi all,
I am running an automated test using Matlab. I have two functions, collectData and Analysis and a main script than calls these functions in that order. collectData plays a bunch of wav files using sound (also tried audioplayer) function (non-blocking function call) sequentially, make some measurements while the audio is being played to collect raw data. Analysis function analyses this data to generate results. The issue is that, sometimes Analysis function is called when collectData has not finished its execution completely and then Analysis function complains because it does not have complete data. I am guessing that sound/audioplayer has something to do with this but not sure exactly what. Could someone help me out here?
Thanks in advance, Alok

 Accepted Answer

Do you have return argument for your collectData function? If not, you could add one, for example CompleteFlag=collectData(). The point is, to make sure collectData() is completed. Although, it should be that way even you don't have return argument. It is called in sequence, right? One suggestion, maybe add "pause(SomeSeconds)" after the collectData() calls.

1 Comment

Thanks Fangjun. Actually, in the code, I found a return if the system isn't connected. It is not supposed to lose connection but it turns out that it does and the control returns to the main script. So thats where the root of problem is and not sound/audioplayer function.

Sign in to comment.

More Answers (1)

If you use an audioplayer object p to play the sounds then you could add:
while p.isplaying
end
to the end of collectData or at the beginning of Analysis. If you want to add it to the beginning of Analysis you will need to pass the audioplayer object as an argument.

Products

Community Treasure Hunt

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

Start Hunting!