From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make a boolean tone?

On my VI, I currently have 2 boolean indicators (LEDs).  In addition to these LEDs lighting up, I would like to have audible tones as well.  For example, whenever LED 1 is on, I want to play a 440Hz tone.  Whenever LED 2 is on, I want to play a 880Hz tone.  In my application these two LEDs are mutually exclusive so I don't have to worry about both tones playing simultaneously.
 
Thanks for the help!
0 Kudos
Message 1 of 9
(11,604 Views)
How you do it depends on the structure of your program. Do you have a single loop in which the LEDs are continuously updated? If so you'll need a shift register to keep track of a boolean flag to keep track of whether the sound has played. Then use a case structure that's controlled by the value of the LED and whether the sound has played. If you have an event structure in a while loop you can simply handle the boolean's "Value Change" event and look at its value. If true, play a sound.
0 Kudos
Message 2 of 9
(11,585 Views)

Hmm, I have the first situation, a single loop in which the LEDs are continuously updated.  I am not sure if I'm getting what you're saying though--I want it to continuously be generating the tone, so if the sound has played on one iteration of the loop, it should keep playing on the next iteration if the LED is still lit up.  Also, I guess I don't know anything about how to create sounds.  I tried using the Beep VI with my own frequency and duration, but then it wasn't a continuous tone.  Also, I think it got behind because when the LED turned off, it kept doing its beep beep beep thing.

0 Kudos
Message 3 of 9
(11,577 Views)

Hi,

For the continuous sound generation you can look at Continuous sound output.vi at NI Example Finder

If your booleans are going to be updated continuosly, use them to run above VI as a sub-vi, that will give you something that you like.

Depending on how frecuently you update your booleans probably you´ll get a non-continuous sound, adjustments should be made maybe.

 

0 Kudos
Message 4 of 9
(11,566 Views)
The reason I had suggested using a shift register (or similar mechanism) to keep track if the sound is already playing is so that you do not restart the sound playing when you get into the "true" part of the case to play the sound since you're continously updating the boolean indicator. If the sound generation is done via a subVI (as it most likely would be), calling the VI again will simply restart the sound and it will sound like a Milli Vanilli concert.

Attached is a simple demonstration program (LabVIEW 8.20).

I was unable to find the "Continous Sound Output" example in the Example Finder. There's a "Continuous Sound Input", though.
0 Kudos
Message 5 of 9
(11,522 Views)
Mmm, in my LabView 7.1 installation is under: \examples\sound\sound adv.llb
 
maybe that example is no longer included in 8.20...
 
I´m attaching that example for you
0 Kudos
Message 6 of 9
(11,503 Views)
Thanks very much for these suggestions.  I mostly got them to work--on my PC I can run a modified Continuous Sound Output where I can pause the sound and switch between tones based on my two boolean values.  But when I try to run the app on my Pocket PC it doesn't work.  Just to check, I tried building just the original Continuous Sound Output vi with LabView PDA, but I get no sound at all.  Anyone out there have any ideas why that might be?  I get no warnings or errors, just no sound.  And I know my sound is on.  I have been able to use the Beep.vi to create sound successfully in the past.
 
Thanks!
0 Kudos
Message 7 of 9
(11,480 Views)
How are you trying to play the sound? Have you looked at the shipping example for sound output on a PDA called Play Sound? This might be helpful for you doing the sound output on the PDA.
Nick R
NI
0 Kudos
Message 8 of 9
(11,377 Views)

Thanks to everyone who helped with this.  I finally figured out what the problems were with playing the sounds on my Windows Mobile PDA.  Problem #1 was that the function generator I was using with Continuous Sound Output.vi did not work on the PDA.  Or perhaps it needed to be more completely configured on the PDA than it does on PC.  In any case, when I switched the the Sine Waveform Generator it worked.  The other problem was that the PDA seems to need the data to be converted from Waveform [DBL] to 1D array [U8] to work in the sound VIs.  The PC seems to be much more forgiving about this, because it handles it okay.  For the PDA I first used the GetWaveformComponents, and then converted the Y output to U8 before inputting that into SO Write.

This still doesn't work great, because I haven't figured out how to multithread this sound generation part with my data acquisition part, but at least it's functional enough for the data collection that has to happen this week!

Thanks again!

0 Kudos
Message 9 of 9
(11,023 Views)