Example Code

Generating a .wav File on Analog Output Channel Using DAQmx

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.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview:

Demonstrates the use of the DAQmx functions to generate audio loaded from a .wav file.

Descriptions:

This code is written in LabVIEW 2012. The .wav file audio information is divided by 255 to scale the unsigned 8 bit number to be in the range of 0 to 1.  
This is based on the assumption that 0-1V is a good range for your speaker input.
Take note of the voltage generated and ensure that it falls within the specified range of your Data Acquisition device
For example, if connect the analog output to a speaker, ensure that the voltage falls within the acceptable voltage range of the speaker to avoid causing damage.

Steps to Implement:

1. Select the desired device and channel number.
2. Enter the path to your 8-bit mono WAV file.
3. Enter the update rate for your Analog Output(AO) channel.  This should equal the rate of your WAV file.
4. Wire your speakers to the Analog Output channel
5. Run it.
6. The program will continue to loop the WAV file waveform on the AO channel until you click the stop button.

 

Requirements:

NI LabVIEW 2012 or compatible
NI DAQmx 15.5.1 or compatible.

 

2017-04-20_13-11-29.jpg

 

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