Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

voltage <-> audio samples?

Solved!
Go to solution

Hello all,

 

Perhaps a stupid question, but: if I put a line-out audio signal on the inputs of a NI USB card and then use C++ and NIDAQmx to read the voltages on the inputs (using a DAQmxCreateAIVoltageChan()), are those voltages the equivalents of the actual sound amplitudes? I am interested in the basic theoretical idea, as one who hasn't studied signal processing.

 

Thanks a lot!

--Cristina.

0 Kudos
Message 1 of 7
(3,533 Views)
Solution
Accepted by topic author acgrama

Hi Cristina,

 

Not a stupid question at all--the voltages are indeed the equivalent of the actual sound amplitudes (see the wikipedia article Line Level).  A DAQ card with a ±2V range should be able to accomodate a typical line-out audio signal. 

 

If high performance is a requirement, your best best would be to use a Dynamic Signal Acquisition card.  However, these can be quite costly.  If you're just looking into this for a hobby or school project then a regular DAQ card would probably be suitable.

 

 

Best Regards,

John Passiak
0 Kudos
Message 2 of 7
(3,519 Views)

Thank you for your answer, John! That's exactly what I wanted to confirm.

 

I need this for work in a project where our client wants to acquire audio data using several types of NI cards (NI USB 9229 being the one I have here for testing -- I know it's not the best for this task, but our client will not change their decision to use this model). The problem is, I cannot read proper values, as it seems, at the card's inputs. That was the point of my initial question -- I thought perhaps some other transformation should be done to the read samples before they could be used.

Actual test case:

- audio file containing a sinus at 440Hz being played on the computer

- line out cable from the computer leads to NI USB 9229's inputs

- C++ application reads samples from the NI card

No matter what sampling frequency I use, or how many samples I read, the train of samples is never even vaguely sinusoidal in shape. Funny thing is that when I read values from the card using the Measurement&Automation(MAX) application's "Test Panels", I can see a very clear sinusoid.

0 Kudos
Message 3 of 7
(3,497 Views)

"I read values from the card using the Measurement&Automation(MAX) application's "Test Panels", I can see a very clear sinusoid."

 

If the test panels are giving the correct result then there is probably something inherent to the C++ code that is causing the problem.  If you post the DAQmx portion of the code I'd be happy to take a look.

 

 

Having said this... the 9229 is far from ideal for measuring the line out signal without amplification.  This card has a ±60 V range with 110 mV accuracy.  You might instead consider the 9234.

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 7
(3,482 Views)

Seems like if I use a much lower sampling rate (5000 Hz instead of 5 kHz), I can reconstruct some of the original sound (with some noise in the background, of course). The challenge will be to clean this up as best as possible, however.

 

(Regarding the use of the 9229 -- unfortunately, our clients are adamant about using the 9229, for reasons of their own, so there's no escape there 🙂 We can only try to do our best with this card.)

0 Kudos
Message 5 of 7
(3,456 Views)

And, of course, I meant "5000 Hz instead of 50 kHz" 🙂

0 Kudos
Message 6 of 7
(3,452 Views)

Solved!! Writing here the idea in case anyone stumbles over the thread:

- the audio samples read from the card were double values such as 1.45236, 3.72134, 3.21456, etc.

- the wav file to be written with the read audio values only accepts integers, so we used floor/ceiling functions to cast the read sample values to long values => but this lost the variation existent in the digits after the comma, as everything under 3.5 became 3 and everything over 3.5 became 4, for instance

- Solution: first, we normalised the raw values to the range of values expected by the wav file and cast them to long afterwards. This preserves the variations after the decimal comma and we are able to reproduce very clear sound with the 9229.

 

0 Kudos
Message 7 of 7
(3,445 Views)