The setVolume() function is an inbuilt function in p5.js library. This function is used to control the volume of the played audio on the web. This function has a range of between (0.0) which means total silence to (1.0) which means full volume. This volume also can be controllable by a slider var by dividing that in different ranges.
setVolume( volume, rampTime, timeFromNow )
Note: All the sound-related functions only work when the sound library is included in the head section of the index.html file.
Parameter: This function accept three parameters as mentioned above and described below.
- volume: This parameter holds a float number that defines the volume of the playback.
- rampTime: This parameter holds an integer value of time in the second format after that the sound will be fade. It is optional.
- timeFromNow: This parameter holds an integer value of time in the second format after that define event will happen.
Example 1: In this example, we set the fixed volume in the code which is 0.5.
Example 2: In this example, we will create a slide that will help the user to increase the volume by 0.2, and the starting volume is set to 0.2.
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Supported Browsers: The browsers are supported by p5.js setVolume() function are listed below:
- Google Chrome
- Internet Explorer
- How to get the function name inside a function in PHP ?
- p5.js | nfs() Function
- D3.js | d3.hcl() Function
- PHP | ord() Function
- PHP | Ds\Set contains() Function
- PHP | dir() Function
- D3.js | d3.max() function
- PHP | exp() Function
- CSS | hsl() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Set add() Function
- PHP | Ds\Set last() Function
- CSS | rgb() Function
- PHP | Ds\Set first() Function
- p5.js | box() Function
- D3.js | d3.min() function
- p5.js | nf() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.