# Processing stereo volume control using sound library

**URL:** <https://discourse.processing.org/t/processing-stereo-volume-control-using-sound-library/9950>\
**Category:** Libraries\
**Created:** [April 4, 2019, 4:41am UTC](https://discourse.processing.org/t/processing-stereo-volume-control-using-sound-library/9950 "2019-04-04T04:41:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujoymisc](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@sujoymisc](https://discourse.processing.org/u/sujoymisc)\
**Post date:** [April 4, 2019, 4:41am UTC](https://discourse.processing.org/t/processing-stereo-volume-control-using-sound-library/9950/1 "2019-04-04T04:41:53Z")

</div>

I want to control PC stereo volume control, the following code is doing the same but both the channels are taking the save volume gain.

Q: How do I change the volume of individual channels?

Processing Code:

```auto
import processing.sound.*;
SoundFile file;
Sound s;
float val = 0.0;
float phase = 1.0;

void setup() {
  size(640, 360);
  background(0);
    
  // Load a soundfile from the /data folder of the sketch and play it back
  file = new SoundFile(this, "song.mp3");
  file.play();
  
  s = new Sound(this);
}      

void draw() {
  s.volume(val);
  val = val + (phase*0.001);
  
  if (val > 1.0){
    phase = -1.0;
  }
  else if (val < 0.0){
    phase = 1.0;
  }
  delay(1);
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 6, 2019, 2:43am UTC](https://discourse.processing.org/t/processing-stereo-volume-control-using-sound-library/9950/2 "2019-04-06T02:43:25Z")

</div>

processing SOUND lib might not have that feature now,  
but check on MINIM  
[http://code.compartmental.net/minim/audioinput\_method\_setpan.html](http://code.compartmental.net/minim/audioinput_method_setpan.html)  
also find:  
/ Files / Examples / Contributed Libraries / Minim / Synthesis / panExample /

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 6, 2019, 3:37am UTC](https://discourse.processing.org/t/processing-stereo-volume-control-using-sound-library/9950/3 "2019-04-06T03:37:47Z")

</div>

I agree that minim is the way to go for stereo.

For the Processing Sound library, according to the reference (untested), _if_ your sound is mono, you can set the stereo ratio with pan:

[https://processing.org/reference/libraries/sound/SoundFile\_pan\_.html](https://processing.org/reference/libraries/sound/SoundFile_pan_.html)

---

<div class="post-metadata">

**Author:** ![sujoymisc](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@sujoymisc](https://discourse.processing.org/u/sujoymisc)\
**Post date:** [April 7, 2019, 4:19pm UTC](https://discourse.processing.org/t/processing-stereo-volume-control-using-sound-library/9950/4 "2019-04-07T16:19:20Z")

</div>

Thanks, good suggestion, Its working for me.

---

<div class="post-metadata">

**Author:** ![sujoymisc](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@sujoymisc](https://discourse.processing.org/u/sujoymisc)\
**Post date:** [April 7, 2019, 4:19pm UTC](https://discourse.processing.org/t/processing-stereo-volume-control-using-sound-library/9950/5 "2019-04-07T16:19:51Z")

</div>

Thanks its good suggestion.
