04-03-2011 02:41 PM
I have a boolean button controlling a case structure within a while loop so that a sound is played when the button is pressed. Is it possible to modify the VI so the function within the case structure restarts when the button is pressed before the sound finishes being played? Currently the button can only be pressed once the sound has finished being generated.
Thanks in advance
04-05-2011 10:46 AM
Hi Jnaumann,
You can try two possible solutions:
1) Place your play waveform VI outside of your case structure. This will also force you to wire something into the false case of your case structure.
2) Right click on your button in your front panel and choose to change the Mechanical Action of it. This determines how LabVIEW reads your pressing of the button.
Please let me know if you have any more questions on this.
Regards,
04-06-2011 08:26 AM
Hiand thanks for your help.
For some reason the forum asked me to create a new profile.
I have tried both of your suggestions. Using the first suggestion I managed to make the VI release the button but the case structure still had to finish before being able to trigger the sound again. With the second suggestion an error was produced because the number of samples must be greatert than zero since (Iassume) it will be trying to play a waveform for the blank case.
I suppose I could create a single sample of zero voltage for the false case but this seems a bit clumsy.
I have another query regarding this VI. When listening to the sound produced it appears as if the amplitude has no effect on the volume of the sound being played back. Do you have any ideas why this might be?
Thanks again
Jack
04-06-2011 08:53 AM
Hi Jack,
In each iteration of your while loop your Button will be read once and then a decision made based on that. With your current loop, you have to wait until the full waveform is played before you can iterate it again. You will need to change your architecture if you need something else to happen. A good method of understanding what is happening in your VI is to put Highlight Execution on and watch what happens when you run the program.
The reason why you can’t change the amplitude is because Play Waveform is an Express VI. This means it is a higher level VI which makes it easier to program but it doesn’t give you the flexibility of low level VIs. If you want to have control over all these aspects (and even possibly solve your first problem) you should consider using the low level VIs. You can find these in Functions Palette >> Programming>> Graphics & Sound >> Sound >> Output
I hope this helps.
Regards,
04-06-2011 09:03 AM
I would suggest opening the Example Finder (Help -> Find Examples) and searching for "sound". Open the example "Sound File to Sound Output". That example shows playing a sound in pieces, allowing to stop it at any time. You can easily adapt the example to do what you want.
04-06-2011 09:56 AM - edited 04-06-2011 10:03 AM
Jack,
If I understand your issue correctly you want multiple instances of "Play Waveform.vi" running concurently. The express vi is configured for re-enterant execution so you only need a method of launcing the function and continuing on.
The example below shows one way to get this type of behaviour. the shown event case opens a referance to Delay.vi found here This function is just a common wait with error handeling vi but is useful for demonstration that I can run more than 1 instance at the same time.
run the vi. and press Play as fast as you can. The timestamps in Array show that Delay.vi is called without blocking since they are less than 2 seconds apart
For your purposes: you'll need to convert the Play Waveform express vi to a normal vi and select its path in the open referance and build and pass in the waveform "Data"
A little more on that 0x08
the help for the open ref function have great info on how LabVIEW works wtith that option
"Prepare for reentrant run. Reserves the target VI so it cannot be edited and if the target VI is reentrant, allocates a dedicated parallel data space for this VI reference. If the target VI is not reentrant, this function returns an error. When you release the VI reference, LabVIEW unreserves the reentrant target VI and deallocates a parallel data space. Use this option with the Run VI method to run multiple instances of a reentrant VI simultaneously. If you target a reentrant VI and do not use this option, this function returns a reference to the VI without allocating a parallel data space for the VI reference. When you do not use this option, multiple calls to this function for a reentrant VI return references to the same VI with the same data space, and this function does not clone the VI. Refer to the examples\viserver\runvi.llb for examples of using this option."
Good Luck