Connexions

You are here: Home » Content » Reading and Writing Audio Files in LabVIEW
Content Actions
Lenses

What is a lens?

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

This content is ...
Affiliated with (?)
This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • This module is included in aLens by: National InstrumentsAs a part of collection:"Musical Signal Processing with LabVIEW -- Programming Techniques for Audio Signal Processing"

    Comments:

    "The modules in this course make extensive use of "screencasts" -- videos captured directly from the computer screen that show LabVIEW in operation, making this a great introduction to using […]"

    Click the "National Instruments" link to see all content affiliated with them.

    National Instruments
Also in these lenses
  • This module is included inLens: richb's DSP resources
    By: Richard BaraniukAs a part of collection:"Musical Signal Processing with LabVIEW -- Programming Techniques for Audio Signal Processing"

    Comments:

    "A great course on LabVIEW based signal processing using music and audio as motivation."

    Click the "richb's DSP" link to see all content selected in this lens.

    richb's DSP
  • This module is included inLens: Digital Signal Processing with NI LabVIEW and the National Instruments Platform
    By: Sam ShearmanAs a part of collection:"Musical Signal Processing with LabVIEW (All Modules)"

    Comments:

    "This online course covers signal processing concepts using music and audio to keep the subject relevant and interesting. Written by Prof. Ed Doering from the Rose-Hulman Institute of Technology, […]"

    Click the "NI Signal Processing" link to see all content selected in this lens.

    NI Signal Processing
Tags

(?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

Reading and Writing Audio Files in LabVIEW

Module by: Ed Doering

Summary: Learn how to use LabVIEW to retrieve an audio signal from a WAV-format file, and how to save an audio signal that you have created to a WAV-format file.

Overview

LabVIEW offers a variety of ways to read and write audio files in WAV format. After completing this module you will be able to use the Simple Read and Simple Write subVIs located in the “Programming | Graphics & Sound | Sound | Files” palette to retrieve an audio signal as a 1-D array from a .wav file, and also to save a 1-D array that represents an audio signal to a .wav file. Additional points covered include scaling your audio signal to have a maximum absolute value of one before saving as an audio file, and how to create a two-channel (stereo) audio file.

Retrieve an Audio Signal from a .wav File

The Sound File Simple Read subVI accepts a filename for an audio file in .wav format and returns a waveform data type. You can read mono or stereo files, and also determine information such as the audio signal’s sampling frequency and its total number of samples.
The following video screencast shows how to use Simple Read to retrieve the audio signal as an array data type that can be used as a signal input for your own VIs. You may want to start LabVIEW now, then follow along to create your own version of the VI pictured below. If so, you will need the two audio files referenced in the screencast: tone-noise.wav and left-right.wav.
lvt_audio_simple-read.html
Figure 1: [video] LabVIEW Techniques: Retrieve an audio signal from a .wav file

Save an Audio Signal to a .wav File

The Sound File Simple Write subVI accepts a signal in waveform data type and a filename and stores the signal as a .wav file. You can set the number of bits per sample (16 is recommended for best fidelity). You must ensure that your signal values lie in the range -1 to +1, otherwise other applications may not be able to read your .wav file properly.
The next video screencast shows how to use Simple Write to save an existing 1-D array that represents an audio signal to a .wav file. The screencast also covers some not-so-obvious data-type transformations required to successfully create your .wav file. You may want to start LabVIEW now, then follow along to create your own version of the VI pictured below. If so, you will need the audio file referenced in the screencast: tone-noise.wav.
lvt_audio_simple-write.html
Figure 2: [video] LabVIEW Techniques: Save an audio signal to a .wav file

Scale Your Audio Before Saving to a .wav File

As mentioned earlier, you must ensure that all of the samples in your signal lie in the range -1 to +1. It is easy to create signals that exceed this range, especially when you add multiple signals together.
The next screencast illustrates how Quick Scale is an easy way to scale your 1-D array such that the maximum absolute value is always one; Quick Scale is located in the “Signal Processing | Sig Operation” palette, and should be used as the last step before converting to the waveform data type.
lvt_audio_simple-write-quickscale.html
Figure 3: [video] LabVIEW Techniques: Scale audio signal to +/- 1 range before saving to a .wav file

Create a Two-Channel (Stereo) .wav File

Creating a stereo .wav file requires that you assemble an array of waveforms, one for the left channel and the other for the right channel. Watch the next screencast video to learn how.
lvt_audio_simple-write-stereo.html
Figure 4: [video] LabVIEW Techniques: Save a stereo (two-channel) audio signal to a .wav file

Comments, questions, feedback, criticisms?

Discussion forum

Send feedback