LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Recording audio to wav file using start/stop button

Hello, my name is Sorin and this is my dillema:

 

I am using the PXI-4461 and have two audio sources connected to the two analog inputs. I would like to record the audio to a wav file (one for each channel). I found an example on ni.com (http://zone.ni.com/devzone/cda/epd/p/id/5609) that records one channel, and modified it so it will record two channels. It is attached, and I apologize for my messy coding.

The current vi will record for a specified amount of time, and I am able to playback the audio files. My task is to create a start and stop buttons, so that the recording is not controlled by a fixed time.

 

I've tried changing the timing to use continuous samples, and putting the DAQmx Read.vi in a while loop. From there I've tried simply outputting the data from the while loop, but it seems like it only outputs the last sample, so I added a shift register where the waveform read is appended to the waveform from the previous iteration, and the output seems to look good on the graphical indicator, but then the wav file seems un-playable. I've attached both my original timed dual channel read as well as my attempt at dual channel read with stop button (both are based off of the example mentioned above).

 

I'd appreciate if anyone can help me out or point me in the correct direction. Thank you!

 

--Sorin

0 Kudos
Message 1 of 3
(4,989 Views)

I didn't notice anything really wrong at first glance. I would recommend probing some of the wires. Make sure you're getting the inputs you're expecting from your DAQ functions, make sure they're building up correctly. Make sure the output from the while loop looks right and ultimately you'll at least get which step in the process is creating the problem. If your waveform graph looks good and you're outputting it via the same waveform VI it shouldn't be a problem. You can try using the Sound File Simple Write.vi by it's self without the extra VIs. I feel like that example may be too complex for what you're doing and there are a lot of variables you could eliminate while getting the same effect.  

0 Kudos
Message 2 of 3
(4,966 Views)

Your program structure is not adequate for what you are trying to do.  I would strongly suggest a three loop structure with the following in each:

 

Loop 1 (UI Loop) - Contains an event structure to handle UI events (such as pressing the start and stop buttons or reconfiguring the data acquisition).  Sends commands to the other two loops using queues.

Loop 2 (Data Acquisition Loop) - Contains a task handler / state machine for taking your data.  It will have at least two states (running and stopped) and handle such commands as start, stop, reconfigure, etc.  It will take commands from Loop 1 via queue and pass data to loop 3 via a different queue.

Loop 3 (File I/O Loop) - Contains a task handler / state machine for saving your data files.  It will also have at least two states (running and stopped) and handle such commands as open file, close file, save data, etc.

 

If you are unfamiliar with state machines, task handlers, and producer / consumer loops, read up on those before attempting to implement this.  You can find examples of each of these in the LabVIEW help and on these forums.  For an example application that is very similar to your application, check out this.  It reads sound from the sound card instead of a DAQ device, and analyzes the data instead of storing it, but modification should be relatively simple once you understand how it works (which admittedly is not simple).

 

As a side note, why are you using the example subVIs for saving to WAV instead of the VIs from the LabVIEW palette?  You also may be running into memory issues with trying to save all the data at once.  Saving it in chunks as you get it will take care of this problem.

0 Kudos
Message 3 of 3
(4,958 Views)