08-16-2021 12:02 PM - edited 08-16-2021 12:02 PM
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?
Solved! Go to Solution.
08-16-2021 12:50 PM
@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.
08-16-2021 01:03 PM
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
08-16-2021
05:30 PM
- last edited on
11-07-2024
06:00 PM
by
Content Cleaner
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.
08-17-2021 12:34 PM
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!