From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with volume control

Solved!
Go to solution
I've looked around the forums and found some pretty complex ways of controlling the volume of a file being played. I'm new to LabView and was wondering if I could get an example/explanation of how to simply control the volume of a sound file via a slider. I tried to use 'Sound Output Set Volume', but couldn't figure out what the 'task ID' should be, or if it was even needed.
0 Kudos
Message 1 of 10
(5,995 Views)
Not sure which examples you've looked at, and what you consider "pretty complex". The task ID is created by the Sound Output Configure VI. If you open the Example Finder (Help->Find Examples) and search for "sound", open the example called "Sound File to Sound Output". It has a volume slider on it. I suspect you can probably use the VI as is.
0 Kudos
Message 2 of 10
(5,987 Views)

The task ID comes from previous sound output functions.
Here's what the general sequence of sound output functions would look like.

sound output.PNG

 

Process:

1) Configure the output device.

2) Set the volume for the device (you can move this step inside the loop if you will be changing the volume during run time)

3) Write data to the output device. You should include some timing logic in this loop as well.

4) When you are finished, stop writing to the device.

Message Edited by Cory K on 07-28-2009 12:10 PM
Cory K
Message 3 of 10
(5,964 Views)
You may also put the volume control in a separate while loop as long as it has a valid task ID. But before you post again you should study the Labview sound examples. Go to the toolbar then help and find examples. Search for sound. If you are stuck in any Labview problem this may be your saver. And it is much quicker than posting a question in this forum 😉 But feel free to post any questions hereif the find example function does not solve your problem 


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 4 of 10
(5,948 Views)

I understand. I had initially looked at that example, but I had hoped that there would be a more simplistic answer to the problem. I've attached a VI of my progress and I have two questions.

 

1. The VI "works", but only once, and then the program will neither end, nor play the file again.

2. One of the .wav files I frequently use plays just fine in another program when I use the 'Play Sound File' VI, but won't work in this program when I use the 'Sound File Read' VI. But I have another .wav file that works fine for both programs.

0 Kudos
Message 5 of 10
(5,932 Views)

rmhughes wrote: 

1. The VI "works", but only once, and then the program will neither end, nor play the file again.


That's because you need to reset where the Sound File Read starts reading the file. This is explained in the Help for that function. By default it reads starting where it left off. Once it gets to the end of the file, there's nothing more to read. You have to reset the counter in your code, and explicitly tell the function to read at an absolute position.

 


2. One of the .wav files I frequently use plays just fine in another program when I use the 'Play Sound File' VI, but won't work in this program when I use the 'Sound File Read' VI. But I have another .wav file that works fine for both programs.

 

The most likely reason is that you are not wiring the sound format output from Sound File Info to Sound Output Configure. There's a reason why it's connected in the example. Did you leave it unconnected for a reason?

 

You also should be wiring the error cluster. 

 

See attached modification, which actually is a copy of the example I pointed out with the modification for the restart of the playing. 

0 Kudos
Message 6 of 10
(5,923 Views)
Solution
Accepted by topic author rmhughes
Noticed that I never attached the mod, but it doesn't matter since I realized that if the wave file is large you will probably want to read it in chunks. Therefore, the above mod should have the Number of Samples control back in there.
Message Edited by smercurio_fc on 07-28-2009 03:20 PM
Message 7 of 10
(5,919 Views)

Thank you for all your help! I've gotten it working, although I still have the issue of one .wav file being able to play and the other cannot.

 

I've attached the two sound files I use frequently. The snare drum works on every program I've tried it on, but the Hank Hill .wav file only works when I use 'Play Sound File' VI. I'm not sure how I could wire it differently since it works for one, but not the other.

0 Kudos
Message 8 of 10
(5,885 Views)
The "Sound File Info" VI returns a value of zero for the bits/sample for that file, which is why you get an error if you try to play it with the example I provided. When I tried to play the Hank Hill sample with the "Play Sound File" VI I heard nothing. It does play with Windows Media Player, though. I'm not an expert on audio formats, so I couldn't tell you what's different between the two files.
0 Kudos
Message 9 of 10
(5,879 Views)
Thank you for all your help!
0 Kudos
Message 10 of 10
(5,875 Views)