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.

filter_none

edit
close

play_arrow

link
brightness_4
code

var sound; 
var gtpan; 
   
function preload() { 
   
    // Initialize sound 
    sound = loadSound("song.mp3"); 
   
function setup() { 
         
    // Playing the preloaded sound 
    sound.play(); 
  
    //Checking paused or not 
    var gtpan = sound.getPan(); 
    console.log(gtpan); 
  

chevron_right


Output:

0 // balanced sound pan

Example : With pan() function will calling getPan() function.

filter_none

edit
close

play_arrow

link
brightness_4
code

var sound; 
var gtpan; 
   
function preload() { 
   
    // Initialize sound 
    sound = loadSound("song.mp3"); 
   
function setup() { 
         
    // Playing the preloaded sound 
    sound.play(); 
  
    //using pan function
    sound.pan(-1,5);
  
    //Checking pan position  
    var gtpan = sound.getPan(); 
    console.log(gtpan); 
      
    //using pan function
    sound.pan(1, 10);
  
    //Checking pan position  
    var gtpan = sound.getPan(); 
    console.log(gtpan); 

chevron_right


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

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.