NI Home > Community > NI Discussion Forums
Reply
Member
The_Prisoner(No.6)
Posts: 8
0 Kudos
Accepted Solution

Continuous Saving from DAQmx to a WAV File

I am trying to save a waveform that was recorded by a DAQmx device into a .wav file.  I have found two sample vi's that I used to start with.

 

Sound Input to File.vi

This vi saves the waveforms from a microphone input to a .wav file.  The nice thing about this vi is it has no limit on how long you can record.

 

SVXMPL_WAV Record (DAQmx).vi

The vi saves the waveforms from the DAQmx input to a .wav file.  The nice thing about this vi is it shows how to get the waveform through the DAQmx device, but you can only record for just over 1 minute.

 

 

DAQmx Input to File.vi

This was my attempt at combining the best things of the above vi's, but it doesn't work and I don't know why.  I'm hoping somebody can tell me where I went wrong and/or how to improve my vi.

 

Thanks

Number 6

Member
Anthony_F
Posts: 195
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

Hi Prisoner,

 

When you try to acquire more than a few minutes of data are you getting an error message that states the requested memory could not be allocated?

This error appears because the program tries to all acquire data in a single DAQmx read call (1 channel N sample).  You will need to instead, modify the program such that you call DAQmx read multiple times so you can use a smaller buffer size.  The best way to change this would be to implement a producer/consumer loop where the producer queues all the samples and the consumer dequeues them and feeds them to the Sound Write Waveform VI. 

 

 

Application Design Patterns: Producer/Consumer

http://zone.ni.com/devzone/cda/tut/p/id/3023

 

Producer/Consumer pattern 

https://decibel.ni.com/content/docs/DOC-8962

Anthony F.
Product Marketing Engineer
National Instruments
Member
The_Prisoner(No.6)
Posts: 8
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

The error message that I am getting is similar, but not quite an out of memory error:

 

Error -50005 occurred at DAQmx Input to File.vi

Possible reason(s):

NI Platform Services:  The specified data width is not supported or cannot be transferred on the bus. The operation could not be completed as specified.

Task Name: _unnamedTask<0>

 

This error message happens right after the program tries to execute the DAQmx Read (Analog Wfm 1Chan NSamp).vi.

 

Would your solution solve this problem as well?

Member
Anthony_F
Posts: 195
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

From your original post it sounds like creating a producer/consumer loop will help you.  What is the acquisition duration you are using?  Do you receive this message when using a smaller value like 1 second?

 

 

Anthony F.
Product Marketing Engineer
National Instruments
Member
The_Prisoner(No.6)
Posts: 8
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

[ Edited ]

This happens the very first time the DAQmx Read (Analog Wfm 1Chan NSamp).vi tries to execute.  It doesn't matter what sample duration I try to use.

 

Number 6

Member
Anthony_F
Posts: 195
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

What device are you using to acquire data?  It looked like you were using a myDAQ in one of the VIs, is this correct?

 

I have acquired data with a myDAQ here and it works fine.  Check your settings against mine

Anthony F.
Product Marketing Engineer
National Instruments
Member
The_Prisoner(No.6)
Posts: 8
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

[ Edited ]

Thank you for showing me that the SVXMPL_WAV Recorder (DAQmx).vi works fine.  I can run that vi with the myDAQ device as well and it works with pretty much any values that I want to put in it.

 

The problem is with the DAQmx Input to File.vi that I wrote. The vi is included in my first post.

 

Number 6

Member
Anthony_F
Posts: 195
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

It looks like you have a numeric constant of 2147483647 going to the samples per channel VI,  what are you trying to do with this constant?

Anthony F.
Product Marketing Engineer
National Instruments
Member
Anthony_F
Posts: 195

Re: Continuous Saving from DAQmx to a WAV File

If you remove the numeric constant, and adjust your max and min values to +/-1 volts your VI seems to work correctly.  The +/-1 volt limitation is defined in the detailed help of the sound file write VI.

Anthony F.
Product Marketing Engineer
National Instruments
Member
The_Prisoner(No.6)
Posts: 8
0 Kudos

Re: Continuous Saving from DAQmx to a WAV File

Yes that works and seems to solve the problem.  Thank you.  I did have to connect the Number of Samples/ch input to the Sample Clock instead of the numeric constant that I had in order to prevent a different error message.

 

I can see that the producer/consumer solution would be more elegant than my method, however I have attached my solution in case anyone else ever wants to look at it.

 

Number 6