Example Code

How to Play a WAV File 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.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview
This VI demonstrates how to open a .WAV file, configure a sound output device (Sound Card) and play the WAV file on the device.


Description

The user is able to specify the number of samples to read from the WAV file per iteration which allows for signal processing before writing the data stream to the output device.  The attached example determines the maximum amplitude in the sample set and displays its value on a second graph.


Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Download the attached VI (Play WAV File.vi).
  2. Select a WAV file in the 'WAV file location' control
  3. Run the VI.

 

Additional Information or References

The number 'Samples Per Read' control must be set high enough to ensure the loop can fully execute before the device runs out of data to write.  The minimum acceptable value is around 2000 depending on your system specs.
VI Snippet

287.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.