Example Code

Programatically Create Multi-Channel WAV Audio Files

Code and Documents

Attachment

Overview

This VI programatically creates anywhere from one to eight (7.1) channels of audio data for a WAV file at a specified frequency, sampling rate, bit rate and duration.  An example application could be to use to create test tones.

 

Description

This VI leverages the built-in Sine Waveform.vi to generate one or more waveforms at a specified frequency, phase and duration.  It then uses another built-in function, Sound File Write Simple.vi to generate a WAV file.  Also included is some extra coding to generate a descriptive filename based on the settings chosen by the user.  Additionally, it performs a check of that file name to help prevent accidentally overwriting it.  Note that values provided in the configuration controls are based off industry standards, but you could also modify the code to work with other settings.  Although the Channel Configuration control has all 8 channels exposed, only the number of channels specified by the 'Audio Channels' control will actually be written.  Finally, this VI simply produces a fixed frequency and phase for each channel, but you could use similar techniques to build up a multi-channel WAV file with other data.

Steps to Implement or Execute Code

  1. Choose a destination directory.  Note that the filename will be automatically generated based on the settings chosen.
  2. Configure Audio Channels, Audio Bit Depth, Audio Sampling Rate, Audio Duration and Channel Configuration.
  3. Run the VI
  4. Open the resulting WAV file in your favorite media player and listen.

Requirements

Software

LabVIEW 2011 or later

Hardware

(optional) Sound card to listen to WAV file

Additional Images or Video

Front Panel.png

VI Snippet

Block Diagram.png

Paul Davidson
National Instruments
Product Owner - ni.com Chat

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

Contributors