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


#1

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

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

}

#2

I see that you also posted this question here. When you post your question to multiple sites, please link between them so we know what help you’ve already received.


#3

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

https://forum.processing.org/two/discussion/26401/interactive-video-with-sound-input
https://forum.processing.org/two/discussion/17803/how-to-control-tint-of-image-in-processing-with-audio-output-volume

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

FFT and mic here:

https://forum.processing.org/two/discussion/19461/turn-audio-input-sound-into-color
https://forum.processing.org/two/discussion/11400/how-to-manually-apply-fft-to-sound-input
https://forum.processing.org/one/topic/doing-an-fft-on-system-audio-currently-playing-with-minim.html
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


#4

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.

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.