p5.js | getPan() Function
The getPan() function is an inbuilt function of p5.sound library that display the pan() function effect. This function print the stereo pan position of the audio. This function can also be applicable without the pan() function.
Syntax:
getPan()
Note: All the sound-related functions only work when the sound library is included in the head section of the index.html file.
Parameters: This function does not accept any parameter.
Return Values: This function return the stereo pan position of the playing audio. integer in minus form means left side more powerful sound and integer in plus form means right side more powerful.
Below examples illustrates the p5.getPan() function in JavaScript:
Example 1: Without pan() function will calling getPan() function.
var sound;
var gtpan;
function preload() {
sound = loadSound( "song.mp3" );
}
function setup() {
sound.play();
var gtpan = sound.getPan();
console.log(gtpan);
}
|
Output:
0 // balanced sound pan
Example : With pan() function will calling getPan() function.
var sound;
var gtpan;
function preload() {
sound = loadSound( "song.mp3" );
}
function setup() {
sound.play();
sound.pan(-1,5);
var gtpan = sound.getPan();
console.log(gtpan);
sound.pan(1, 10);
var gtpan = sound.getPan();
console.log(gtpan);
}
|
Output:
-1
1
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Supported Browsers: The browsers supported by p5.getPan() function are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Last Updated :
17 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...