# how to Make sound wave change color according to sound frequency from mic input 

**URL:** https://discourse.processing.org/t/how-to-make-sound-wave-change-color-according-to-sound-frequency-from-mic-input/385
**Category:** Coding Questions
**Created:** [May 25, 2018, 10:16pm UTC](https://discourse.processing.org/t/how-to-make-sound-wave-change-color-according-to-sound-frequency-from-mic-input/385 "2018-05-25T22:16:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![harmony](https://avatars.discourse-cdn.com/v4/letter/h/d2c977/32.png) [@harmony](https://discourse.processing.org/u/harmony)
#### Post date: [May 25, 2018, 10:16pm UTC](https://discourse.processing.org/t/how-to-make-sound-wave-change-color-according-to-sound-frequency-from-mic-input/385/1 "2018-05-25T22:16:32Z")

</div>

hello,

i have a Mic input from minim library, i want to know the value of the sound frequency and make the sound wave change color according to sound input.

i know about fft but all the examples I’ve seen had uploaded song not Mic input and i just don’t know how to apply it, also how am i gonna change the stroke color after i know the value?  
if you can help that’d be great

this is the code i have for now

```auto
import ddf.minim.;
import ddf.minim.analysis.;

Minim minim;
AudioInput in;
FFT fft;

void setup()
{
size(1000,500);

minim = new Minim(this);

// use the getLineIn method of the Minim object to get an AudioInput
in = minim.getLineIn();

fft = new FFT( in.bufferSize(), in.sampleRate() );

}

void draw()
{
//wave color
stroke(0);

// draw the waveforms so we can see what we are monitoring
for(int i = 0; i < in.bufferSize() - 1; i++)
{
line( i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50 );
line( i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50 );
}

}

```

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [May 26, 2018, 5:55pm UTC](https://discourse.processing.org/t/how-to-make-sound-wave-change-color-according-to-sound-frequency-from-mic-input/385/2 "2018-05-26T17:55:05Z")

</div>

I see that you also posted this question [here](http://forum.happycoding.io/t/make-sound-wave-change-color-according-to-sound-frequency-from-mic-input-processing/281). When you post your question to multiple sites, please link between them so we know what help you’ve already received.

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [May 27, 2018, 7:36pm UTC](https://discourse.processing.org/t/how-to-make-sound-wave-change-color-according-to-sound-frequency-from-mic-input/385/3 "2018-05-27T19:36:26Z")

</div>

These examples might work for you. It does not use FFT but it changes the image based on sound amplitude:

> [Interactive video with sound input - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/26401/interactive-video-with-sound-input)  
> [How to control tint of image in Processing with audio output volume - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/17803/how-to-control-tint-of-image-in-processing-with-audio-output-volume)

For FFT using Minim, check: [Minim : : FFT](http://code.compartmental.net/minim/fft_class_fft.html)

FFT and mic here:

> [Turn audio input sound into color - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/19461/turn-audio-input-sound-into-color)  
> [How to manually apply FFT to sound input? - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/11400/how-to-manually-apply-fft-to-sound-input)  
> [Doing an FFT on system audio currently playing with Minim - Processing Forum](https://forum.processing.org/one/topic/doing-an-fft-on-system-audio-currently-playing-with-minim.html)  
> [Get Audio Input with minim? - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/25450/get-audio-input-with-minim)

Now, are you sure you want to use frequency? Do you know the concepts? Working with amplitude could be sufficient and it is easier.

Kf

---

<div class="post-metadata">

### Author: ![PHuzzeyMusic](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@PHuzzeyMusic](https://discourse.processing.org/u/PHuzzeyMusic)
#### Post date: [June 28, 2018, 1:41am UTC](https://discourse.processing.org/t/how-to-make-sound-wave-change-color-according-to-sound-frequency-from-mic-input/385/4 "2018-06-28T01:41:13Z")

</div>

This is my first post, but I hope this is helpful. I spend a ton of my time working in processsing using the sound library and fft. I’ve been meaning to check out minim so this was a good chance for me to jump into it and compare it to the sound library. I modified the original code you posted to make a real simple fft visualization that changes from green to red when that frequency band is loud enough.

```auto
import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioInput in;
FFT fft;

void setup()
{
  size(1000, 500);
  minim = new Minim(this);
  in = minim.getLineIn(1, 1024, 44100);
  fft = new FFT( in.bufferSize(), in.sampleRate() );
}

void draw()
{
  background(0);
  fft.forward(in.mix);
  for (int i = 0; i < fft.specSize(); i++)
  {
    if ( fft.getBand(i) > 5) {
      stroke(0, 200, 0);
    } else {
      stroke(200, 0, 0);
    }
    int linePoint = (int)map(i, 0, fft.specSize(), 0, width);
    line( linePoint, height, linePoint, height - fft.getBand(i) * 5);
  }
}

```

First, when using fft you must constantly monitor it, analyze() in processing.sound and it appears to be forward() in minim. Minim seems to be more flexible in that is not “attached” to the AudioInput object, unlike the processing sound library.  
Second, in my experience using fft the higher indexes aren’t very useful in terms of musical analysis. In this example of breaking the audio signal into 1024 chunks, after about index 210 - 220 (roughly 9000Hz) the frequencies are so high pitch that they are either not in the musical spectrum and eventually out of the spectrum of human hearing.  
I hope this helps and also gets you thinking of more ways to use audio to manipulate visuals.
