Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
suri

Junior Member
Registered:
Posts: 12
Reply with quote  #1 
Hi,

I have a wav soundfile that I would like to play in certain scenarios in loops. I tried writing it in several ways and matlab crashes after consistently after I play it 3 times. What am I doing wrong? This is the syntax I have in each loop that calls the sound

 id = mgladdsound('sound.wav');
 mglplaysound(id);
 mglstopsound(id);

TIA!
0
Jaewon

Administrator
Registered:
Posts: 873
Reply with quote  #2 
You are not supposed to call mgl functions directly. Define a SND TaskObject in the conditions file and call toggleobject(). Or use the AudioSound adapter.
0
suri

Junior Member
Registered:
Posts: 12
Reply with quote  #3 
Ahhh.. thank you
0
Jaewon

Administrator
Registered:
Posts: 873
Reply with quote  #4 
Actually it is okay to use mgl functions. I just don't have time to document the functions thoroughly and answer questions about them.

In your case, I don't know how your loop is working, but you are not destroying the sound object that you created. It will cause a memory management issue and crash MATLAB eventually.
0
suri

Junior Member
Registered:
Posts: 12
Reply with quote  #5 
I tried to create and destroy the sound at every if and failed to produce sound
0
Jaewon

Administrator
Registered:
Posts: 873
Reply with quote  #6 
I don't understand what you mean by "every if", but the sound stops when you destroy the object. So you should give it some time. Try inserting pause() before you destroy it.
0
suri

Junior Member
Registered:
Posts: 12
Reply with quote  #7 
Ha! So simple and yet I couldn’t get it. Thank you!
0
Jaewon

Administrator
Registered:
Posts: 873
Reply with quote  #8 
One thing worth to mention. If you create objects directly by calling mgl functions, their information is not stored to the data file and therefore they don't show up during replay.
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.