LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using SO Write to play a continuous waveform using PC sound card. (Circular Buffers?))

How can I play a continuous, repeating waveform using SO VI's (that isn't choppy)? I gather that I need to buffer the waveform, and I see examples using AO VI's, but how do you buffer using SO Write? What are Circular Buffers and might I use this technique to solve my problem?

Windows ME
Dell Inspiron 5000e
LabView 6i
0 Kudos
Message 1 of 6
(4,113 Views)
MGS,

From what I can tell about the waveform playing utilities, they are unable to do what you are asking for. About the only thing I can come up with for you is to make the waveform you wish to play as long as possible, and just start and stop play as necessary.

Perhaps someone at NI can come up with a different solution, but as far as I know, that's it.

Good luck
Message 2 of 6
(4,113 Views)
Hello,

There is no way to generate a true continuous repeating waveform with the Sound VIs in their current form. The best thing you can do at this point is that which was already suggested...send in a large data array into the SO Write function. I have attached a sample VI written by another NI Engineer that demonstrates this.

I believe R&D is aware that continuous buffered output is a desired customer feature in the Sound VIs. Perhaps we will see this functionality in a future version of LabVIEW.

Good luck, and have a pleasant day.

Sincerely,
Darren N.
NI Applications Engineer
0 Kudos
Message 3 of 6
(4,113 Views)
Hi MGS!

MGS writes:

> How can I play a continuous, repeating waveform using SO VI's (that
> isn't choppy)? I gather that I need to buffer the waveform, and I see
> examples using AO VI's, but how do you buffer using SO Write? What
> are Circular Buffers and might I use this technique to solve my
> problem?
>

I've tried to do the same, i.e. synthesize a wave for continuous,
non-choppy output, and have some un-solved problems.

A buffer is sent to SO Write, which is then transfered to the device
driver and the sound output hardware. The problem is how to refill the
buffer that is sent SO Write, before the internal buffers of SO Write
and/or the device driver or hardware empties their buffer, which would
result in silence. We need a warning that the buff
er is almost empty,
so that more samples can be constructed. I've found no way to do that
using LabView 5.1.

However, we now how fast samples are consumed, so they can be produced
at the same rate, or perhaps a little faster. If they are produced
much faster, the memory will fill up, but if the difference is small,
the program can run for quite a while. It was a year ago, or so, that
I did this, so I don't remember the details.

A circular buffer can be used in a multi-thread producer-consumer
program. I've done it in C and C++, from some tutorial I found on
threads, or maybe it was from the OSS (open sound system) for
Linux. It is a buffer with a write position and a read position. The
addresses wraps around, so it works a bit like a conveyor belt. The
writer must check that the buffer is non-full, and the reader that it
is non-empty. I'm not sure how to implement it i LabView, or if it's needed.


--
Helge Stenstrom
h.stenstrom@ieee.org
0 Kudos
Message 4 of 6
(4,113 Views)
I don’t know if your application can accept this, but a workaround might be saving to file and call Windows’ PlaySound to do the job.
0 Kudos
Message 5 of 6
(4,113 Views)
Sorry I'm coming in late on this - but none of the other answers I see have mentioned this technique:
If you have a 'SO write' call inside a while loop, and want to keep generating output without starving or overrunning the output buffer, you can set up a simultaneous 'SI Read' process within the loop. As long as input and output sampling rates are the same, the SI process will pace the loop. You can discard the input samples if you don't need them.
I used this quite successfully to do a soundcard-based realtime audio processing VI, just as an experiment. It does pitch inversion around a user-adjustable center frequency (the "poor man's" speech scrambler). In the example, I generate as many sine samples as I have SI samples, then multiply the arr
ays. You could use a similar technique to generate the next N samples from your waveform.

Hope this helps. I've attached the VI, which was last saved in LV5.1.1...

Regards,
Dave
David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 6 of 6
(4,113 Views)