# Get frequencies of sound

**URL:** https://discourse.processing.org/t/get-frequencies-of-sound/14004
**Category:** Libraries
**Created:** [September 15, 2019, 4:33pm UTC](https://discourse.processing.org/t/get-frequencies-of-sound/14004 "2019-09-15T16:33:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Loe159](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@Loe159](https://discourse.processing.org/u/Loe159)
#### Post date: [September 15, 2019, 4:33pm UTC](https://discourse.processing.org/t/get-frequencies-of-sound/14004/1 "2019-09-15T16:33:43Z")

</div>

Hi, to start, sorry for my English but I’m French so I’ll maybe do some mistakes.

I’m totally new on Processing and I’d like to get bass of the song of my PC. To do it, I already found a code wich do a spectrograme of the sound of my PC.

```auto
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim;
AudioInput in;
FFT fft;
int w;

void setup()
{
  size(640, 840);
  minim = new Minim(this);
  in = minim.getLineIn(Minim.STEREO, 512);
  fft = new FFT(in.bufferSize(), in.sampleRate());
  fft.logAverages(60, 7);
  stroke(255);
  w = width/fft.avgSize();
  strokeWeight(w);
  strokeCap(SQUARE);
}

void draw()
{
  background(0);
  fft.forward(in.mix);
  
  for(int i = 0; i < fft.avgSize(); i++) {
    line((i * w) + (w / 2), height, (i * w) + (w / 2), height - fft.getAvg(i) * 4);
    
  }
 
    
}

```

I saw that the 5th, 6th, 7th 8th and 9th columns correspond to the bass of the music :  
[https://gyazo.com/2a58b24018f36c37d207b346ca7fa680](https://gyazo.com/2a58b24018f36c37d207b346ca7fa680)

I would like to know, with my code when there are bass frequencies.

I totally don’t know how to do it;  
Can you help me please ? Thanks a lot 🙂

---

<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: [September 16, 2019, 2:48am UTC](https://discourse.processing.org/t/get-frequencies-of-sound/14004/2 "2019-09-16T02:48:35Z")

</div>

pick that data , add them up and compare them with a limit  
if the limit is hit change the background color

```auto
import ddf.minim.*;
import ddf.minim.analysis.*;
//import ddf.minim.effects.*;
//import ddf.minim.signals.*;
//import ddf.minim.spi.*;
//import ddf.minim.ugens.*;

Minim minim;
AudioInput in;
FFT fft;
int w;
boolean diagp = true;
float bsum=0,blimit=50;

void setup() {
  size(640, 840);
  minim = new Minim(this);
  in = minim.getLineIn(Minim.STEREO, 512);
  fft = new FFT(in.bufferSize(), in.sampleRate());
  fft.logAverages(60, 7);
  stroke(255);
  w = width/fft.avgSize();
  strokeWeight(w);
  strokeCap(SQUARE);
  print("AVG array "+fft.avgSize());// 63
}

void draw() {
  if ( bsum > blimit ) background(200,0,0);
  else background(0);
  fft.forward(in.mix);
  for (int i = 0; i < fft.avgSize(); i++) {
    line((i * w) + (w / 2), height, (i * w) + (w / 2), height - fft.getAvg(i) * 4);
  }
    bsum=0;
    for ( int i = 0; i<5; i++) {
      int p = i+5;
      if ( diagp ) print( " ["+p+"] "+nf(fft.getAvg(p), 0, 2) );
      bsum += fft.getAvg(p);
    }
    if ( diagp ) println();

}

```
