LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a program to play a sound

All I need to do is make a program to play a sound bit whn it is a bove a certain limit and then stop when it is below that limit. It needs to continoulsy run. 

 

I was able to get this to work by just putting a play file with a path in a case structure but it would not play the whole sound file. I now have a program that I found that will play the whole sound file but it plays the whole sound before stopping. I need it to play and as soon as it goes below the limit it needs to stop. Then if it goes above the limit again, play from the begining of the sound bit.

 

I have a slider to test the program right now, it will later be replaced with a DAQ assistant, I just need to make a proof-of-concept program first. I attached the program. Please help as much as you can, I am still fairly new to LabVIEW. Thanks!

 

-Jake

0 Kudos
Message 1 of 14
(5,050 Views)

How are you running your VI?  I don't see any while loop that allows your code to repeat.  (Please don't tell me you are using the Run Continuously button)

 

Why are you using those sound VI's buried in a library rather than the ones located on the Graphics & Sound >> Sound palette?

 

Your sound will go until the end because you have a Sound Wait VI in there.  What you need to do is monitor your control in a loop, if the comparison goes from False to True (which you can track the boolean with a shift register) then you initiate a Sound Start.  If it goes from True to False, then you can execute with a Sound Stop.  If it is False to False, then do nothing.  If it is True to True, use the Sound Info function to determine if the sound has completed and restart it if necessary, otherwise do nothing.

Message 2 of 14
(5,041 Views)

You need to change your approach. The case structure cannot finish until all code inside it finishes. You need to put the sound file playing in a separate loop that you can control by means of a trigger. I would suggest looking over the examples that ship with LabVIEW. A good one to look at is the "Sound Player" example. That starts the playing of the sound file, but you can stop it at any time by pressing the Stop button. In your case you wouldn't use an event structure since your stop will be some other trigger (like a notification, a queue element, or even a local variable if you program it correctly).

 

Good luck, and post back if you have additional questions.

 

 

EDIT: Created while Ravens Fan was posting his response.

Message 3 of 14
(5,037 Views)

Ok well First @Ravens fan, yes I did have a while loop I just didn't save it so it didn't show up, either way I was still having problems. 

 

I uploaded a new program that I made, I tried to study the 'Sound player' example and this is what I came up with. My teachers have been teaching me case structures, so I do not know much about event structures, so I tried to translate it the best I could.

 

The problems I now have is the boolean stuff. The shift register is now boolean because that it the input, I probably need to change that somehow...which would fix the broken wire coming from the sound output info. Also, I have a feeling the path and 'play sound' need to be outside the case structure, but am not sure how to wire it. 

 

Thanks for all your help so far!

 

0 Kudos
Message 4 of 14
(5,032 Views)

Which labview version do you use. That example you posted is from the Labview 7 period. Nothing wrong in using that setup in newer versions of Labview.



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 5 of 14
(5,027 Views)

You need to move your comparison into the while loop.  Right now you are only making the comparison once right when your VI starts and never again.

 

The shift register is to remember the boolean value from the comparison at the last loop iteration.  You have a broken wire because you wired the task ID integer wire to it.

 

Use the value from the shift register and the value from the comparison (which goes to the right hand side shift register) to do some boolean comparisons,  if old value is False AND new value is True, start the task.  If old value is True and new value is False, stop the task.

0 Kudos
Message 6 of 14
(5,026 Views)

 

Use the value from the shift register and the value from the comparison (which goes to the right hand side shift register) to do some boolean comparisons,  if old value is False AND new value is True, start the task.  If old value is True and new value is False, stop the task.


So are you saying to get rid of the case structure and just do straight comparisons?

0 Kudos
Message 7 of 14
(5,023 Views)

LabVIEW 2010....it says Version 10.0....it just came with a MyDAQ

0 Kudos
Message 8 of 14
(5,022 Views)

No. You need the case structure.

0 Kudos
Message 9 of 14
(5,014 Views)

OK not sure I completely understand what to do when it comes to comparisons, but this is what I have right now. Attached also is a picture of the error with the task id, not sure what to do with that. I have tried numerous things to fix it with no luck. Sorry about being so confused, like I said..I'm fairly new to labview.

 

So i think this is what im telling the program to do, when true play the sound file (input grater than 0). When false stop sound. SOund option then sees if it is playing, it lights an led, if not then ____ (not sure what to do there. I think at this point i want it to go into the shift register no matter if it is playing or not, but that is a boolean line and wont go into the shift register.

 

 

Download All
0 Kudos
Message 10 of 14
(5,001 Views)