LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate brief tone asynchronously

Solved!
Go to solution

I'm developing a behavioral task on a Windows PC using LabVIEW.  I'm measuring some human reaction times, and am willing to live with Windows' "time uncertainty" (there is nothing else running on this PC, which is not connected to the network, while I'm running this task).

 

As part of the task, I want to play a brief sound (typically 500 msec) using a low (200 Hz), middle (300 Hz), or high (500 Hz) tone.  I modified the Generate Sound example in LabVIEW (8.6) to do this.  However, while the tone is playing, the sub-VI in which it is embedded is "blocked" (throwing off the ability to time what the user is doing, i.e. did he press the right key, and when?).

 

Is there a way to precompute a sound (say 500 msec of a 500 Hz sine wave, sampling rate of 5000 Hz = 2500 points), hand it off to a "sound-player", and come right back?  The sound would then play asynchronously, ending when it "got to the end" of the waveform, and the basic logic of the program would not be "stalled".

 

Alternatively, since my "play a sound" VI does work (even if it "blocks" me temporarily), is there a way to call it asynchronously?  Most of my program is currently running as a Queued State Machine, with one of the states being, for example, "Success" (entered when the subject "does it right").  What I do in this state is generate a "reward message" ("Good Job"), play a "reward tone", and transition to the next state.  I don't want to "stick around" in this state until the tone finishes, hence the need to have it play asynchronously.  [Hmm -- VI server?  Amazing how ideas pop into your head when you are trying to explain to someone else what it is you are trying to do ...].

 

I'm going to try the VI Server idea that just occurred to me.  Any other good suggestions greatly appreciated.

 

Bob Schor

0 Kudos
Message 1 of 3
(2,577 Views)

The sub-VI should not be blocking you.  Or I didn't understand whay you meant by that...

It may be an implementation issue. 

 

Can you post your code so that we can have a look at it?

 

R

0 Kudos
Message 2 of 3
(2,567 Views)
Solution
Accepted by topic author Bob_Schor

Yep, VI Server does the trick!  Of course, you have to call using a VI Invoke Node, which doesn't (easily) let you pass arguments to a Front Panel, but since I just need three tones, I wrote three "tone" VIs (instead of one with controls to set the tone).  To speed things up, in the Initialization state, I go find the RefNums to my three tone VIs and save them in shift registers, so I only need to wire the appropriate RefNum to an Invoke Node and use the Run method to play my beep asynchronously.

 

0 Kudos
Message 3 of 3
(2,563 Views)