We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm pretty sure I'm almost there with this script. The sketch runs without any errors and I've got the camera to run, a box to scan through the pixels of the image and a tone to play; but the tone doesn't change in relation to the pixels being scanned which is what i wanted to happen. This code is pretty messy and I'm fairly new to processing so apologies in advance.
Any help would be great, Thanks!
import processing.video.*;
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioOutput out;
SineWave sine;
Capture video;
int location = 0;
int fullSize;
int[] aPixels;
int direction = 1;
boolean onetime= true;
float signal;
void setup() {
String[] cameras = Capture.list();
video = new Capture(this, cameras[0]);
video.start();
fullSize = video.height * video.width;
size(500, 500);
aPixels = new int[width*height];
noFill();
stroke(255);
frameRate(50);
loadPixels();
arrayCopy(pixels, aPixels);
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO);
sine = new SineWave(440, 0.5, out.sampleRate());
sine.portamento(10);
out.addSignal(sine);
}
void draw() {
{
if (signal > width*height-1 ||
signal < 0) {
direction = direction * -1;
}
if (mousePressed) {
if (mouseY > height-1) {
mouseY = height-1;
}
if (mouseY < 0) {
mouseY = 0;
}
signal = mouseY*width+mouseX;
}
else {
signal += (0.33*direction);
}
background(255, 255, 255);
if (video.available() == true) {
video.read();
}
image(video, 0, 0);
if (location == fullSize) {
location = 0;
}
else {
location++;
}
loadPixels();
fill(pixels[location]);
int row = location / width;
int pos = location - (row * width);
updatePixels();
rect(signal%width-5, int(signal/width)-5, 10, 10);
point(signal%width, int(signal/width));
for (int i=0; i<width*height; i++) {
pixels[i] = aPixels[i];
}
float freq = map(brightness(aPixels[int(signal)]), 0, 255, 987.77, 261.63);
sine.setFreq(freq);
float pan = map(pixels[int(signal)], 0, width, -1, 1);
sine.setPan(pan);
}
}
Answers
I got your PM and have had a look at your sketch.
It is not possible to modify your code easily because apart from the untidiness, there are no comments, and much of the code doesn't make sense or appears redundant.
So I have taken your code, chopped out the redundant bits and got it to change frequency based on the underlining brightness of the pixel. It might not do exactly what you want but should form a good starting point.
Thanks so much man, i really appreciate your help :)