This is probably easy for alot of you....
Basically this program is supposed to take Midi data input (the value 0 - 127) and apply it the get a specific frequency range of audio drawn to the screen.
I've been able to manually type the value such as '5' and then '200' to notice that it is working. 5 picks up the lower end while 200 is higher frequency white noise type.
However, now when I've patched some code to let my midi input change the frequency band... it doesn't show the real-time change. The value within the for loop just stays at 90.
I'm sure it's some rule i'm not aware of to change a value within' a for loop. Here is the bit.
int value = 90;
myBus.sendControllerChange(channel, number, value);
....
....
for(int i = 0; i < fft.specSize(); i++)
{
// draw the line for frequency band i, scaling it up a bit so we can see it
line( i, height, i, height - fft.getFreq(value) );
println("VALUE: " + value);
}
}
And here is the code:
Any help is much appreciated!
Thanks.
Basically this program is supposed to take Midi data input (the value 0 - 127) and apply it the get a specific frequency range of audio drawn to the screen.
I've been able to manually type the value such as '5' and then '200' to notice that it is working. 5 picks up the lower end while 200 is higher frequency white noise type.
However, now when I've patched some code to let my midi input change the frequency band... it doesn't show the real-time change. The value within the for loop just stays at 90.
I'm sure it's some rule i'm not aware of to change a value within' a for loop. Here is the bit.
int value = 90;
myBus.sendControllerChange(channel, number, value);
....
....
for(int i = 0; i < fft.specSize(); i++)
{
// draw the line for frequency band i, scaling it up a bit so we can see it
line( i, height, i, height - fft.getFreq(value) );
println("VALUE: " + value);
}
}
And here is the code:
- /**
* This sketch demonstrates how to use an FFT to analyze
* the audio being generated by an AudioPlayer.
* <p>
* FFT stands for Fast Fourier Transform, which is a
* method of analyzing audio that allows you to visualize
* the frequency content of a signal. You've seen
* visualizations like this before in music players
* and car stereos.
*/
import ddf.minim.analysis.*;
import ddf.minim.*;
import themidibus.*;
MidiBus myBus; // The MidiBus
Minim minim;
AudioInput in;
FFT fft;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
MidiBus.list();
myBus = new MidiBus(this, 0, 3); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
// specify that we want the audio buffers of the AudioPlayer
// to be 1024 samples long because our FFT needs to have
// a power-of-two buffer size and this is a good size.
in = minim.getLineIn(Minim.STEREO, 1024);
// loop the file indefinitely
//jingle.loop();
// create an FFT object that has a time-domain buffer
// the same size as jingle's sample buffer
// note that this needs to be a power of two
// and that it means the size of the spectrum will be half as large.
fft = new FFT( in.bufferSize(), in.sampleRate() );
}
void draw()
{
background(0);
stroke(255);
int channel = 0;
int pitch = 64;
int velocity = 127;
myBus.sendNoteOn(channel, pitch, velocity);
myBus.sendNoteOff(channel, pitch, velocity);
int number = 0;
int value = 90;
myBus.sendControllerChange(channel, number, value);
// perform a forward FFT on the samples in jingle's mix buffer,
// which contains the mix of both the left and right channels of the file
fft.forward( in.mix );
for(int i = 0; i < fft.specSize(); i++)
{
// draw the line for frequency band i, scaling it up a bit so we can see it
line( i, height, i, height - fft.getFreq(value) );
println("VALUE: " + value);
}
}
void noteOn(int channel, int pitch, int velocity) {
// Receive a noteOn
println();
println("Note On:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
void noteOff(int channel, int pitch, int velocity) {
// Receive a noteOff
println();
println("Note Off:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
void controllerChange(int channel, int number, int value) {
// Receive a controllerChange
println();
println("Controller Change:");
println("--------");
println("Channel:"+channel);
println("Number:"+number);
println("Value:"+value);
}
Any help is much appreciated!
Thanks.
1