LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up a continuous audio io buffer

Solved!
Go to solution

I am fairly new to Labview and am running into 2 problems that I can't solve. If anyone can help, that would be great.

 

I am trying to create a VI using the sound card that receives an audio input from a sine wave generator (plugged into the mic port), converts that signal into a frequency and uses the frequency to output a sine wave of a slightly higher frequency

 

I started off using the simultaneous IO example VI and modified it to my needs. (see attached VI) I am using Labview 8.5 on a Pentium 4 3.0Ghz PC.

 

I keep getting 2 errors, one is that the tone measurement device measures an Inf signal and refers to the Niquist theorem. I have a sampling rate of 44100Hz and 4410 samples but an input of only 100Hz sine wave. I have coupled the sampling rate and samples at a 10:1 ratio. I'm pretty sure this is wrong. Do you have any better suggestions on designing the buffer?

 

Also, I occasionally receive an error regarding the sound input read.vi "A task must be running to perform this operation"

 

 

 

0 Kudos
Message 1 of 10
(5,795 Views)

On the "Sound Input Configure VI" set the value  number of samples/ch to a value 3-5 times the value used on the "Sound Input Read VI "

On the "Sound Input Configure VI" the number of samples/ch specifies the number of samples per channel in the buffer. This value must be bigger than value used on "Sound Input Read VI " else the buffer will overflow

 But I do not think your project will have any success because of a bug introduced in Labview 8.0, that NI refuse to fix. An to be honest this is disrespectful of NI. But they perhaps fear that people will stop to purchase their DAQ units and use inexpensive sound cards. But this is nonsense.

Well back to bug. The sound output system in Labview do not have any double (or larger) buffer possibilitiesThen the sound buffer is empty the sound will stop, and you will never be able to fill up the buffer the exact time the last sample is played. This will give glitches in the sound recognized as annoying "pops" and "clicks" in the sound output. If we go back to 7.1 the sound output system had  double (or larger) buffer possibilities. Since you are new in this forum your post will be read by an application engineer from NI. I invite this person to comment why the bug has been ignored for so long time. But I guess the request will be ignored like this bug.  

If you are interested I might have some tip for youdo you use XP as OS? 



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 2 of 10
(5,780 Views)

Hi Coq rouge,

 

Thanks for your reply. Yes I'd very much appreciate any tips you have to troubleshoot this. Besides the annoying clicks right now though, I also keep receiving a value of infinity for tone measurement. For my current setup, I am using a sine wave generator right now plugged into the mic port.I measure the sine wave frequency and input it into the sine-generator to generate a slightly higher sine frequency. But for some reason, with this current buffer setup, I keep getting an INF value for tone measurement after a few seconds of running the program.


I am using Microsoft XP Professional with SP2.

 

Actually, coincidentally, the setup I have now is a copy from a post that you did earlier.

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=397480&query.id=274646#M397480

 

I copied the setup of the current buffer from a reply you posted (see link above) In the .png picture, you have the same number of samples per channel value going into both the Sound Input Configure and Sound Input Read VIs.

 

 

I have also tried adding a arithmetic division to the orange line going to the sound input read to decrease the number of samples per channel by 5 times. This would mean that the configure vi has a samples value 5 times greater than the read vi as you suggested. The exact same error still appears though with the INF value returned at the tone measurement.

 

0 Kudos
Message 3 of 10
(5,738 Views)
Solution
Accepted by topic author Alan Tang

In that case I guess I just was lucky. You should do something like I did here http://forums.ni.com/ni/board/message?board.id=170&message.id=399671&query.id=277879#M399671

That way the timing then you read the sound card is not so important. The buffer will prevent dataloss and error. If you get buffer overrun the sound card Task ID will become invalid if I remember correct. Like you I was struggling some with the Labview sound system. But now it works fine. At least the input part.  The output part have I fixed with some work around. One way I have discussed here http://forums.ni.com/ni/board/message?board.id=170&message.id=403131&query.id=279026#M403131 and here . You could also use a free software for the sound output. This is called waveio. You can find it here http://www.zeitnitz.de/Christian/index.php?sel=waveio. It work on XP but I do not know if it works on Vista. With this software you can have up to four output buffers, and the clicks will be gone. Try out how many buffers you need. I think 2 should work fine



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 4 of 10
(5,732 Views)

Hi Coq Rouge,

 

Great that solved the audio buffer problem. Your awesome.

 

I'm still having problems with the tone measurement function which is killing the program. Have you ever encountered this sort of problem?

0 Kudos
Message 5 of 10
(5,713 Views)

Good for you, and that you accepeted your own sulution 😉

By the way which solution did you use for the outpot part. The waveio or the old Labview sound system. Also still no word from NI. I guess they keep ignoring this matter. It is not importent for them



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 6 of 10
(5,709 Views)

Yes.. haha, oops clicked the wrong box.Smiley Tongue

 

I used the regular output solution from labview 8.5 using their Simultaneous IO program.I actually tried the waveIO function before but the record/input function of that VI gives me numbers that are much different from the ones from the Labview Sound read vi's. Using a similar program setup as I am now, WaveIO will give frequencies of 0.002Hz. For example, in the Labview Sound Read vi, the raw data after being read Y ouput values around 0.25-0.30. WaveIO read function ouputs Y values around 600-900. 

 

 

More importantly, I am still having trouble interfacing with my 5Mhz function generator though. Can you shed any light on this? Is my current input method wrong?

 

My current setup is a function generator with its output connected to the mic port. The sound read function reads it for about 2 seconds, then stops and give my program an error.

0 Kudos
Message 7 of 10
(5,694 Views)

Remember that a sound card only are good for output in the audio range 20-20Khz. The input are also AC coupled (that gives the 20Hz lower freq). That is thumb rule. So 5Mhz will not work. The last tip is then using DBL or SGL types as input the max amplitude is 1. I think I have read it some place. But I am not sure. If you get strange result this may be the reason.  

I will also test the waveio in a application soon. I will repport the result.

 



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 8 of 10
(5,688 Views)

The function generator goes up to 5Mhz but I am not using it at 5Mhz. I am using it around 300hz so it should be okay. As well, the tone measurements I am using are actually accurate with my current VI, eg. 300hz on the generator = measured value of 300hz using the tone measurement function.

 

The issue I am having is that as you can see on my VI, the read function is in a While loop. The read function only seems to read it for a few seconds, then it does not read anymore. There must be something configured wrong on this read function.

 

For example, I fooled around with the While loop.

 

Eg1. I removed the loop and the sound input/output clear functions and ran the program using run continuously button. Result? Continuous audio output but with distinct beeps in between BUT read function works perfectly from the generator. The beeps occur whenever the VI restarts itself.

 

Eg2. I extended the while loop to cover the Sound Input/Output Configure functions. Used run program. Result?Continuous audio output with much slighter beeps in between but the read function works perfectly with the function generator.

 

Eg3. I extended the while loop to cover only Sound Input Configure. Used run program. Result? Contininuous audio with slight but annoying clicks or chirps in between. Very continuous audio though and no breaks in sound. See attached for this configuration.So there is no way to get rid of these clicks in Labview 8.5?

0 Kudos
Message 9 of 10
(5,682 Views)

Try this it is the best from labview and waveio. It worked for me. The waveio input is as if the sound had been AD converted-> Take the result and divide it with range/(2^n) there n=number of bits. For a amplitude=1 the range is 1-(-1)= top-bottom

It is somewhat messy wiring but anyway here it is



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 10 of 10
(5,679 Views)