Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptp5.js | getPan() Function

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() { 
   
    // 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); 
  


Output:

0 // balanced sound pan

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




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); 


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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments