LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop delay while generating sound

Solved!
Go to solution

Hi folks,

I've been trying to integrate the "Generate sound.vi" example into another project of mine, one that needs to run as fast as possible.

When doing this, however, I noticed that my program was being slowed to about 10 ms/loop; it seems this delay is also present in the example file.

I've tried changing the sample rate, number of samples/channel, and the timeout terminal on the "Sound Output Write vi" to no avail. I'm fine with delaying the signal initially/having poor latency, but my while loop needs to run faster. Any ideas?

0 Kudos
Message 1 of 5
(1,770 Views)

@mpfreeman wrote:

Hi folks,

I've been trying to integrate the "Generate sound.vi" example into another project of mine, one that needs to run as fast as possible.

When doing this, however, I noticed that my program was being slowed to about 10 ms/loop; it seems this delay is also present in the example file.

I've tried changing the sample rate, number of samples/channel, and the timeout terminal on the "Sound Output Write vi" to no avail. I'm fine with delaying the signal initially/having poor latency, but my while loop needs to run faster. Any ideas?


Talking about code that you don't show us doesn't help us help you 99% of the time.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 5
(1,754 Views)
Solution
Accepted by topic author mpfreeman

The Sound Output Write VI goes away and writes the sound you have configured, that sound consists of 5000 samples at 44K samples /second, that would take 113mS, that is why the loop time is about 10mS. If you want to be doing other things at a faster rate you need two (or more loops) Can you explain what you are trying to achieve

Message 3 of 5
(1,742 Views)

I don't really know the definition of "as fast as possible". Typically a reproducible, hardware independent rate is much more important than some leadfooted code. Else the behavior changes whenever you use a different computer.

 

Why exactly does the sound generation need to be in the same loop? Can't you run it in a parallel loop? What is the architecture and design pattern of the Vi in your project?

 

To make the code a bit more lightweight, get rid of the express VI and dynamic data. You can substitute e.g. sine waveform from the signal generation palette.

0 Kudos
Message 4 of 5
(1,710 Views)

Ah, that makes sense, thank you!

 

I'm making a haptic pen control a scanning tunneling microscope (with a force depending on tunneling current), and I also wanted a sound to change frequency depending on the tunneling current. The haptic pen needed to be running faster than human response time to avoid weird feedback issues, so significant lag in my loop made it unusable.

 

I was under the impression that parallel loops wouldn't work because I needed data from one loop, but by writing the tunneling current to a global variable I was able to get it working.

 

The frequency still changes in discrete steps because of the delay, which is slightly annoying, but it's good enough for me.

 

Thanks again! 

0 Kudos
Message 5 of 5
(1,674 Views)