Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
17 ratings:
 3.64 out of 5     Rate this Document

How to Use the Sound Output VIs in LabVIEW to Play Wave Files



Primary Software:
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I see that there are sound output VIs in LabVIEW to play wave files, but I can't seem to get them to work. What is the proper way to use these VIs?

Solution:

LabVIEW 7.0 and 7.1

Here is a good way to use the Sound Output VIs to play a wave file:

  1. Use the Snd Read Wave File.vi to read the .wav file. Pass in the path of the file that you want to read. This function is important, because it will pass out the sound format and the stereo and mono data which will be needed in upcoming steps.
  2. Use the SO Config.VI to configure your sound card for the type of wave file that you have just read. Pass the sound format from step 1 into this VI. This VI passes out the task ID.
  3. Use the SO Write.vi to write the data to the sound card. You must pass the mono and stereo data from step 1 into this VI. You may do multiple writes and then play it all at once.
  4. Use the SO Start.vi to start playing the wave data that you wrote to the buffer in step 3.
  5. Use the SO Wait.vi to wait until all sound written to the buffer has been output.
  6. Use the SO Clear.vi to close the sound output device. This is important because it releases any resources the device was using back to the computer.
Attached to this document is a simple VI that follows these six steps. This is a simple example to illustrate how to use the Sound Output VIs. You may also add more advanced features such as SO Volume and SO Pause.

LabVIEW 8.0 and later

An example program that reads and plays a .wav file can be found by using the example finder.  You can access this by selecting Help » Find Examples.  When the NI Example Finder dialog box is displayed select Hardware Input and Output » Sound » Sound File to Sound Output.vi.

You can also navigate to the example by selecting the Search tab on the top left of the window.  In the search box type Sound and press Enter.  The example program is named Sound File to Sound Output.vi.

This program will read a .wav file and play it at the volume you specify.

Related Links:
KnowledgeBase 2EBIKR8E: Troubleshooting Sound VI Error Codes 10003, 10005, 10240, 10402, 10403, 10405, 10408, 10444, 10846

Attachments:


SIMPLE~1.ZIP


Report Date: 12/12/2003
Last Updated: 11/01/2012
Document ID: 34BJ3SFQ

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit