Example Code

Wave File Continuous Write in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.


  • LabVIEW

Code and Documents


This example VI shows how to generate and write sound data to a file in chunks.


While the standard LabVIEW Send Write Wave File.vi writes to disk after the entire data set has been created or acquired, this example will write smaller data chunks continuously to disk as one wave file, decreasing memory usage and execution time. There are four VIs contained within the library: Wave File Continuous Write.vi, Wave File Config.vi, Wave File Write.vi and Wave File Close.vi. The top level VI, Wave File Continuous Write.vi, generates a waveform using the Sine Waveform.vi and feeds it in a for loop. The sampling info, frequency and amplitude controls are used as inputs to Sine Waveform.vi while the Sound Format control is the input of the Wave File Config.vi. This VI prompts the user as to where to create the file and initialize it. The for loop contains the Wave File Write.vi which will take the sine information and typecast it to a string then write it into the file. The VI will check whether the incoming waveform is 8 or 16 bit as well as whether it is mono or stereo and adjust accordingly. Finally, Wave File Close.vi finishes this text file by concatenating into a string the header required for the sound file. It adds this data to the 44 characters left blank by Wave File Config.vi.


  • LabVIEW 2012 (or compatible)

Steps to Implement or Execute Code

  1. Download the attached files to your computer
  2. Open the library "Wave File Continuous Write.llb"
  3. Open the VI "Wave File Continuous Write.vi"
  4. Select the file format and the sampling infoRun the VISelect the path to the TDMS file
  5. Run the VI
  6. Open the TDMS file and observe the logged data


Additional Information or References

VI Block Diagram

Wave File Continuous Write LV2012 NI Verified.png


**This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.