Sound Labview

Embed Size (px)

Citation preview

  • 7/30/2019 Sound Labview

    1/2

    Reading and Writing Audio Files in LabVIEW

    Module by: Ed Doering. E-mail the authorEdited By:

    Erik Luther, Sam Shearman

    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.

    OverviewLabVIEW offers a variety of ways to read and write audio files in WAVformat. After completing this module you will be able to use the Simple Read andSimple 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 tosave a 1-D array that represents an audio signal to a .wav file. Additional pointscovered include scaling your audio signal to have a maximum absolute value of onebefore saving as an audio file, and how to create a two-channel (stereo) audio file.

    Retrieve an Audio Signal from a .wav FileThe Sound File Simple Read subVIaccepts a filename for an audio file in .wav format and returns a waveform datatype. You can read mono or stereo files, and also determine information such as theaudio signals sampling frequency and its total number of samples.The followingvideo screencast shows how to use Simple Read to retrieve the audio signal as anarray data type that can be used as a signal input for your own VIs. You may wantto start LabVIEW now, then follow along to create your own version of the VIpictured below. If so, you will need the two audio files referenced in the screencast:tone-noise.wav and left-right.wav.Figure 1:

    [video] LabVIEW Techniques: Retrieve an audio signal from a .wav fileFigure 1 (lvt_audio_simple-read.html)

    Save an Audio Signal to a .wav FileThe Sound File Simple Write subVI accepts asignal 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 otherapplications may not be able to read your .wav file properly.The next video

  • 7/30/2019 Sound Labview

    2/2

    screencast shows how to use Simple Write to save an existing 1-D array thatrepresents 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.Figure 2:

    [video] LabVIEW Techniques: Save an audio signal to a .wav file

    Figure 2 (lvt_audio_simple-write.html)

    Scale Your Audio Before Saving to a .wav FileAs mentioned earlier, you mustensure that all of the samples in your signal lie in the range -1 to +1. It is easy tocreate signals that exceed this range, especially when you add multiple signalstogether.The next screencast illustrates how Quick Scale is an easy way to scaleyour 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 thelast step before converting to the waveform data type.Figure 3:

    [video] LabVIEW Techniques: Scale audio signal to +/- 1 range before

    saving to a .wav file

    Figure 3 (lvt_audio_simple-write-quickscale.html)

    Create a Two-Channel (Stereo) .wav FileCreating a stereo .wav file requires thatyou assemble an array of waveforms, one for the left channel and the other for theright channel. Watch the next screencast video to learn how.Figure 4:

    [video] LabVIEW Techniques: Save a stereo (two-channel) audio signal

    to a .wav file

    Figure 4 (lvt_audio_simple-write-stereo.html)