Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Playing a WAV file using the ANSI C functions for NIDAQMx

Hi,

 

I'm sorry if this is the wrong forum for this question, this is my first time here, and also my first time using the Measurement Studio functions.

I'm trying to play a WAV file over the analog channel of the NI PCIe - 6351 using C++ functions.

 

 

I know how to create a task and an Analog output voltage channel using the functions  DAQmxCreateTask and DAQmxCreateAOVoltageChan respectively. I can output a signal with a well defined math function like a sine wave by placing the samples in an array, but I need to play an audio signal which is saved in the WAV format. 

 

Can anybody help me with this please?

Any suggestions/code examples you have will be helpful.

 

Thanks.

 

 

 

 

0 Kudos
Message 1 of 10
(6,675 Views)

Hi RaziM,

 

It sounds like you need to find a way to convert that .WAV file into a 1-D array of data, so that you can output that array to your device using DAQmx functions as you described.  There's a good amount of information about this available online.  I've linked to a few forum posts to get you started:

 

C++ Reading the Data Part of a WAV File: http://stackoverflow.com/questions/13660777/c-reading-the-data-part-of-a-wav-file

Reading WAV File C++/C: http://www.dreamincode.net/forums/topic/334091-reading-wave-file-cc/

 

If you have access to LabVIEW, you could also use the Sound File Read VI to convert a WAV file LabVIEW waveform data, then extract the array from that data.

 

-Myriam

0 Kudos
Message 2 of 10
(6,662 Views)

Thanks Myriam.

 

That sounds like the best way to go about it.

 

Do you happen to know if that is how LabVIEW goes about doing this?

 

 

RaziM

 

0 Kudos
Message 3 of 10
(6,655 Views)

Hi RaziM,

 

If you open up the Sound File Read VI in LabVIEW, it looks like the function is making calls to a LabVIEW DLL called lvsound2.dll.  Unfortunately, I don't have much information other than that, but if you have LabVIEW installed you may be able to call that DLL from Visual Studio.

 

-Myriam

0 Kudos
Message 4 of 10
(6,640 Views)

Hi Myriam,

 

Thanks for your help.

 

For those who may be facing a similar problem you have to go about implementing what Myriam suggested.

Using an existing library like libsnd may be a good idea; it has functions that let you extract data from the WAV file without having to parse it.

 

 

Razi M

 

 

0 Kudos
Message 5 of 10
(6,591 Views)

Hi,

 

I noticed that the output waveform is actually of a higher frequency than the actual wav file.  Can somebody tell me how I can set the frequency of a simple waveform using the NIDAQmx library in C/C++?

 

Thanks.

 

RaziM

0 Kudos
Message 6 of 10
(6,550 Views)

 

Below is an image of the two waveforms. The pink waveform is the actual audio file and the green (I'm sorry i don't know what the color is actually called, but I'm sure you'll be able to tell) is the one played out of the analog output. The Sine wave is supposed to be 1KHz. Hope this helps understand my question better.

Thanks!

 

 

tek00002.png

0 Kudos
Message 7 of 10
(6,546 Views)

Hey RaziM,

 

Are you using the Waveform data type to output your data?  A waveform is composed of three parts: the initial time (t0), the time between each sample (dt), and the data (Y) values.  If this is what you're using, you should be able to change the dt component of the waveform to change the frequency of the signal.  

0 Kudos
Message 8 of 10
(6,532 Views)

Hi Myriam,

 

I'm using a float64 array. Is it possible to it with this?

 

 

RaziM

0 Kudos
Message 9 of 10
(6,522 Views)

The function DAQmxSetAOFuncGenFreq  is listed in the ANSI C function reference. Do you have any examples for the usage of this function?

 

I've tried using it, and it seems to make no difference in the output waveform.

 

Thanks.

 

RaziM

 

0 Kudos
Message 10 of 10
(6,518 Views)