Minim Frequency Variable
in
Core Library Questions
•
2 years ago
What I want:
average video brightness to influence oscillator frequency.
Problem:
float freq = pixelBrightness;
sine.setFreq(pixelBrightness);
-will not overwrite:-
float pixelBrightness = 0;
Result:
Frequency stays 0, unless I manually change that value. But it should be effected by the "pixelBrightness"
- import ddf.minim.*;
- import ddf.minim.signals.*;
- import processing.video.*;
- Minim minim;
- AudioOutput out;
- SineWave sine;
- float pixelBrightness = 0;
- Capture video;
- void setup()
- {
- size(640, 480, P3D);
- minim = new Minim(this);
- // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
- out = minim.getLineOut(Minim.STEREO);
- // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
- sine = new SineWave(440, 0.5, out.sampleRate());
- // set the portamento speed on the oscillator to 200 milliseconds
- sine.portamento(100);
- // add the oscillator to the line out
- out.addSignal(sine);
- // with portamento on the frequency will change smoothly
- float freq = pixelBrightness;
- sine.setFreq(pixelBrightness);
- video = new Capture(this, width, height, 30);
- }
- void draw() {
- if (video.available()) {
- video.read();
- image(video, 0, 0, width, height); // webcam activeren
- int brightestX = 0; // X helderste pixel
- int brightestY = 0; // Y helderste pixel
- float brightestValue = 0;
- // zoek naar helderste pixel
- video.loadPixels();
- int index = 0;
- for (int y = 0; y < video.height; y++) {
- for (int x = 0; x < video.width; x++) {
- // Kleur pixel
- int pixelValue = video.pixels[index];
- // Helderheid pixel
- pixelBrightness = brightness(pixelValue);
- float prevPixelBrightness = 0;
- float pixelAverage = (pixelBrightness / prevPixelBrightness);
- prevPixelBrightness = pixelBrightness;
- index++;
- if (index == video.width || index == video.height){
- println("Brightness and hertz " + pixelBrightness);
- }
- }
- }
- }
- }
Thanks in advance for solving my noob question!
Thom
1