09-17-2014 07:25 PM
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.
09-18-2014 01:06 PM
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
09-18-2014 05:44 PM
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
09-19-2014 11:42 AM
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
09-24-2014 09:37 PM
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
09-29-2014 01:00 PM
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
09-29-2014 02:05 PM
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!
09-30-2014 09:53 PM
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.
10-01-2014 10:41 AM
Hi Myriam,
I'm using a float64 array. Is it possible to it with this?
RaziM
10-01-2014 11:25 AM
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