LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Input audio into labview then output to speaker

Solved!
Go to solution

Hello working on a project for school but are running into some trouble. This is my first time using labview so I am not very familiar with it. We are trying to build a equalizer using labview. The first thing we wanted to get working was to use the headphone jack output from my phone into NI Elvis II analog inputs then using the analog outputs from NI Elvis II to a amplifier out to a speaker. We used two DAQ assistant modules on our block diagram one set up as a input going to analog input 0 and one set up as an output going to analog output 0 on NI Elvis II. We do get sound output sometimes but it is delayed by like 10 seconds and other times it just throws up error messages or it wont start all together. We got the idea from a website which I will attach below we followed the same settings they used as well but labview can't keep up with. I will attach pictures of our block diagram and settings below let me know if you need anymore information. 

 

https://blog.studica.com/graphic-equalizer-labview-2017

 

Thanks in advance for your help.

Daniel

       

Download All
0 Kudos
Message 1 of 8
(963 Views)

Hi, Daniel.  From your picture of your LabVIEW code, I know you are using Express VIs, but I can't "examine" the code (so I can't tell how you've configured it, nor can I advise you on how to fix it), and I also cannot "test" the code in the "picture".

 

I also cannot tell what version of LabVIEW you are using.  If you're "new" to LabVIEW, you may be using the "latest version", and many of the "old hands" are still running LabVIEW 2019 or 2021.  Are you using a LabVIEW "Project"?  If you'd included the .lvproj file, we could at least know your LabVIEW version.

 

Suggestion:

  1. Create a Folder that contains all of the VIs that are in your Project, including the .lvproj "Project" file, if you are using it.
  2. Close LabVIEW.  Open Windows Explorer.  Find the "Project Folder" with your "project", right click the Folder, and choose "Send to", then "Compressed (zipped) folder".
  3. Attach the resulting .zip file, which now contains your entire Project.  Even if we can't open the VIs, we can at least open the .lvproj file and know something about your LabVIEW situation ...

Bob Schor

0 Kudos
Message 2 of 8
(932 Views)

Hi Bob,

Thanks for getting back to me, I only have access to labview at my school and I won't be back there until Monday. But I have the VI that we were using for our tests which I will attach bellow. Also not sure what version of labview they are using at my school but I can check that on Monday if thats something you need. Thanks in advance for your help.

 

Daniel

 

   

0 Kudos
Message 3 of 8
(893 Views)

Daniel,

 

     Thank you!  You are running LabVIEW 2021 (which, fortunately, I have installed on one of my PCs, so I can open your VI, which consists of two Express VIs (not useful for what you are trying to do), and explain many of the problems you are having.  And it also tells me that you have not learned the "Three Rules of Data Flow" (the programming paradigm that LabVIEW uses).

 

     Here's the basis of Data Flow.  First, there are "things", and "wires".  "Things" include Functions (like "Add" or "Write Text File"), Structures (like a Case statement, a While or For Loop), and VIs (or sub-VIs) that you might write.  "Things" usually have "Inputs" and "Outputs" -- data comes into the "Thing" through its "Inputs" and goes/ out through its "Outputs" (you can have zero or more Inputs or Outputs).  "Wires" carry data, can go into and out of "Structures", and can go from the Output of a "Thing" to the Input of another "Thing".  Got that?

 

     So what are these "Three Rules" (that's what I call what comes next)?

  1. A Structure, Function, or VI (i.e. a "Thing") doesn't start to do anything until all of its Inputs have data present.  I forgot to mention that VIs get their data in and out through their Front Panels, where the inputs are called "Controls" and the Outputs are called "Indicators".
  2. "Things" don't put data on any of their Outputs until the Thing is done with whatever it does (e.g. an Add doesn't give you a sum output until it finishes adding the data presented to its inputs).
  3. If you have multiple "Things" that aren't connected by "Wires" such that data flows from one to the other, you cannot say which one starts (or finishes) first.  You need to treat them as if they run simultaneously, as in "parallel programming".

     So I looked at your first DAQ Assistant, which is reading Voltages.  You have set it up to take Continuous Samples (good, you don't want the data to be "interrupted" between samplings), acquiring 50,000 of them at a frequency of 44.1 kHz.  It is connected by a strange wire, a Dynamic Data wire (which I never use, though, when they were first introduced, I tried them for about two weeks, then swore "never again!") to another DAQ Assistant (I call these the "Dreaded DAQ Assistant", or "DDA" for short) that accepts 10,000 data points and writes them out as a Voltage signal.  I don't know what device you are using, but it appears that the data rate for output might be 1 kHz.

 

     And finally, there's a Stop Button, wired to the Stop input of the first DDA, with its output going to the Stop input of the second DDA, and the final output going to the Stop Control of the While Loop.

 

     So let's talk Data Flow.  Assume you start the program with the Stop button not pushed.  The While Loop starts, the first DDA starts, it collects 50 k samples at 44.1 kHz (which takes 50/44.1 = 1.13 (approx.) seconds, then puts those samples into the Dynamic Data Wire (DDW?).  At this point, DDA #1 can start generating the next batch of 50 k samples.  Meanwhile, DDA #2 accepts 10,000 (or 1/5 of the DDW's content) and starts playing it out at some rate (which might be 1 kHz).  This takes 10 seconds, right?  And that's only 1/5 of the data, so it will take 50 seconds to output the first 1.13 seconds of sampled data.

 

     But we're not done -- there's the Stop button to consider.  We assumed it was not pushed when we started, but let's say you pushed it 1 second after you started this routine running.  Will this value be transferred to the While Loop's Stop Control?  Remember the Third Rule -- everything in the While Loop that is not connected output-to-input runs "simultaneously".  But the only thing that is not so connected is the Stop button, so it runs first, and when it does, it is not pushed.  So it puts "False" on the input to DDA #1, which 1.13" later puts "False" on the output of DDA #1, which puts False on the input of DDA #2, which 50 seconds later puts False on the Stop Control of the While loop, so the Loop tries to run again.  The second time, the Button has been pressed, so after another 1.13 + 50 seconds, the While loop will finally stop.

 

     Some of my timing might be off because I don't know what device you are using, but you see the problem, I hope.  But not to worry -- if you learn a little bit more about LabVIEW, you can sample DVD Audio (44.1 kHz) and play it out through speakers (with a faster D/A converter, like in a Sound Card) without a 50 second "lag".

 

     To get a sense of how to wean yourself from the DDA, do a Web Search for "Learn 10 Functions in NI DAQmx and Handle 80 Percent of Your Data Acquisition Applications".  Ignore Section 1, which talks about the DDA.  I haven't looked at this White Paper recently, but as I recall, it tells you "How To" do things in LabVIEW and in other languages like C and C++ -- pay attention only to the LabVIEW sections.

 

     Here's a little exercise to get you thinking Data Flow and learning the Joy of LabVIEW.

  • Let's stick with the DDA and the DDW for the time being (even though you want to avoid them as soon as you possibly can, which is why I pointed you to the DAQmx White Paper).  Design a While Loop that acquire data at 44.1 kHz, but delivers a data sample every 10 milliseconds.  That's all it does -- it samples continuously, outputting data, which you should bring to the right-hand edge of the While Loop, where it will present itself as an "Output Tunnel" (don't connect this output tunnel to anything).  Put the Stop Button inside this While Loop and wire the Stop output to the Stop Control.
  • When you run it, verify that you can now stop the loop "almost instantly".  Experiment a bit with the Loop speed -- what do you have to do to make the Loop run at 1 Hz (instead, as above, when it runs at 100 Hz)?
  • Imagine, now, you had a second While Loop (placed to the right of the first, "Producing" loop) that could accept the (sound) samples and "play" them at a rate of 44.1 kHz, effectively "Consuming" the data produced by the first loop.  Now look up "Consumer/Producer Design Pattern".

That's all for now.

 

Bob Schor

0 Kudos
Message 4 of 8
(876 Views)
Solution
Accepted by topic author Danwei98

Hi, Daniel.

 

     After a good night's sleep, I re-read your initial post, and this time, I "listened to what you said".  You are clearly asking about processing a sound signal (I can say "I knew that", because I recognized the 44.1 kHz sampling frequency, but my brain wasn't fully functioning).

 

     Forget entirely everything to do with DAQmx, Express VIs, etc. (though it's not a bad idea to read that long post of mine and be sure you understand the concepts I was trying to get across).  You are dealing with sound, a particular type of data that LabVIEW knows and understands.  Open a blank VI, and go to the Block Diagram.  Right-click to bring up the Palettes, and notice one called "Graphics and Sound".  Open that, then open "Sound".

Bob_Schor_0-1682861199843.png

The functions in the "Input" sub-Palette are designed to work with the "Sound In" (or microphone) port on your computer (and sample at 44.1 kHz), the ones in Output are designed to work with your Speakers (and also can handle that data rate), and the one called "Files" is for (well, I'm not going to give it away, I'll let you discover what's inside there for yourself).  Unfortunately, NI made the "Acquire" Express VI output the Waveform data in Dynamic Data format, then has the audacity to tell you in the detailed Help "Returns the data this Express VI acquires from the selected device using the setting you specify in the configuration dialog box.  You can convert this output to a waveform or one-dimensional array of waveforms (one per channel) by using the Convert from Dynamic Data function". 

 

Do you know that LabVIEW ships with lots of Examples?  They may be a little "ahead" of your current experience with LabVIEW, but there are some that may pay to look at and try to understand.  Click on Help, Find Examples, then click the Search tab and enter "sound".  The first 8 will give you some ideas.
 
Bob Schor
0 Kudos
Message 5 of 8
(850 Views)

Hi Bob,

Thanks for all your help, you are very knowledgeable when it comes to labview. I am going to test everything tonight in class I'll let you know tomorrow if it works.

 

Thanks again,

Daniel

0 Kudos
Message 6 of 8
(812 Views)

@Danwei98 wrote:

Hi Bob,

Thanks for all your help, you are very knowledgeable when it comes to labview.


Not so much "knowledgable" as "experienced and still learning".  I had been doing programming in conventional (text) languages (my favorite was Pascal), so had some experience with data structures and code organization, plus a colleague who worked with me to show me the rudiments of LabVIEW.  I was thrown in to maintaining (and eventually completely re-writing) a LabVIEW Real-Time routine in LabVIEW 7, and learned additional tricks (like "hold down the Shift key to make the Arrow keys move LabVIEW Objects around the screen 8-times faster") from our Graduate Students.

 

And when confronted with a function or situation I didn't quite "get", it's so simple to type ^N, spin up a blank VI, and write a tiny Test routine to see how something works.  I also learned about the Examples that Ship with LabVIEW, and in a few cases, I've written (and Posted on the Forums) "Revised" versions of these Examples to try to show how to use certain LabVIEW features.  "Learn by Doing".

 

Bob Schor

0 Kudos
Message 7 of 8
(795 Views)

Indeed I always love learning something new even if it is a struggle at first. I followed your other post step by step and finally got it working it was much simpler than I thought its always a great feeling to finally figure out something you been struggling with for weeks. One of the programming languages I have had the most fun learning is BASIC just started learning it a couple of months ago as sort of a hobbie haven't had much time with it lately but will get back into it this summer. It been great talking with you and thanks again for all your help.

 

Daniel

0 Kudos
Message 8 of 8
(791 Views)