# Control volume with Minim Library

**URL:** https://discourse.processing.org/t/control-volume-with-minim-library/21055
**Category:** Libraries
**Created:** [May 19, 2020, 2:05pm UTC](https://discourse.processing.org/t/control-volume-with-minim-library/21055 "2020-05-19T14:05:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)
#### Post date: [May 19, 2020, 2:05pm UTC](https://discourse.processing.org/t/control-volume-with-minim-library/21055/1 "2020-05-19T14:05:47Z")

</div>

Hello,  
I would like to set volume of different audio output with mini library.  
Thanks

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [May 19, 2020, 3:21pm UTC](https://discourse.processing.org/t/control-volume-with-minim-library/21055/2 "2020-05-19T15:21:39Z")

</div>

Hi,

With a minimal search on the [Minim documentation](http://code.compartmental.net/minim/index.html), you have the `setVolume()` function for different classes :

- [AudioInput::setVolume](http://code.compartmental.net/minim/audioinput_method_setvolume.html)
- [AudioOutput::setVolume](http://code.compartmental.net/minim/audiooutput_method_setvolume.html)
- [AudioPlayer::setVolume](http://code.compartmental.net/minim/audioplayer_method_setvolume.html)
- [AudioSample::setVolume](http://code.compartmental.net/minim/audiosample_method_setvolume.html)

---

<div class="post-metadata">

### Author: ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)
#### Post date: [May 31, 2020, 10:50am UTC](https://discourse.processing.org/t/control-volume-with-minim-library/21055/3 "2020-05-31T10:50:49Z")

</div>

Hello.  
I can’t understand the manner to patch modules with each other.  
I would like to control volume of this audio output  
noize.patch( moog ).patch( out );  
Would you please, show me how to set the volume in the example below .  
Thank you.

```auto
// import everything necessary to make sound.
import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
Minim minim;
AudioOutput out;
MoogFilter moog;

// setup is run once at the beginning
void setup()
{
// initialize the drawing window
  size(300, 300);
  
  // initialize the minim and out objects
  minim = new Minim(this);
  out = minim.getLineOut();
  // construct a law pass MoogFilter with a 
  // cutoff frequency of 1200 Hz and a resonance of 0.5
  moog = new MoogFilter( 1200, 0.5 );
  
  // we will filter a white noise source,
  // which will allow us to hear the result of filtering
  Noise noize = new Noise( 0.5f );  

  // send the noise through the filter
  noize.patch( moog ).patch( out );
}

// we'll control the frequency and resonance of the filter
// using the position of the mouse, in typical x-y controller fashion
void mouseMoved()
{
  float freq = constrain( map( mouseX, 0, width, 200, 12000 ), 200, 12000 );
  float rez = constrain( map( mouseY, height, 0, 0, 1 ), 0, 1 );
  
  moog.frequency.setLastValue( freq );
  moog.resonance.setLastValue( rez );
}

void keyPressed()
{
  if ( key == '1' ) moog.type = MoogFilter.Type.LP;
  if ( key == '2' ) moog.type = MoogFilter.Type.HP;
  if ( key == '3' ) moog.type = MoogFilter.Type.BP;
}

// draw is run many times
void draw()
{
  // erase the window to black
  background( 0 );
  // draw using a white stroke
  stroke( 255 );
  // draw the waveforms
  for( int i = 0; i < out.bufferSize() - 1; i++ )
  {
    // find the x position of each buffer value
    float x1 = map( i, 0, out.bufferSize(), 0, width );
    float x2 = map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  } 
  
  text( "Filter type: " + moog.type, 10, 225 );
  text( "Filter cutoff: " + moog.frequency.getLastValue() + " Hz", 10, 245 );
  text( "Filter resonance: " + moog.resonance.getLastValue(), 10, 265 ); 
}

```

---

<div class="post-metadata">

### Author: ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)
#### Post date: [June 3, 2020, 2:56pm UTC](https://discourse.processing.org/t/control-volume-with-minim-library/21055/4 "2020-06-03T14:56:59Z")

</div>

I have seen this but I don’t know how to use it.

void setVolume(float value).

Please, can I have an example.
