Slow framerate with Syphon - trial and error coding!
in
Contributed Library Questions
•
6 months ago
I've just spent longer than I'd care to admit hacking the
Adavision Adalight sketch to work with the
Syphon library
The original Adalight sketch captures the screen (or parts of it) and sends it to an led array via Arduino.
I modified the sketch so that I could send the whole screen to my 32 x 16 array and it worked at around 22 fps.
I thought the screen capture was probably a bottleneck so I thought I'll use the syphon framework and send a 32x16 image via syphon to this sketch from a vjing app.
So.....eventually (I wasn't really a Processing user until earlier today) .......I have achieved this but the framerate is lower than it was with the screen capture at about 15 fps! I can accept that going from the GL world back to the CPU isn't the smartest/quickest thing to do but surely with such a tiny amount of data it doesn't clog things up that much?
Here is the relevant part of the code which is largely copied and pasted. Only the bits relating to the pixels array are really mine. Can anyone see any obvious mistakes?
Thanks
// PER_FRAME PROCESSING ------------------------------------------------------
void draw () {
int d, i, j, o, c, weight, rb, g, sum, deficit, s2;
int[] pxls, offs;
if (client.available()) {
S_img = client.getImage(S_img,false); // load the pixels array with the updated image info (slow)
image(S_img, 0, 0, width, height);
}
weight = 257 - fade; // 'Weighting factor' for new frame vs. old
j = 6; // Serial led data follows header / magic word
loadPixels();
for(i=0; i<leds.length; i++) { // For each LED...
color ipix=pixels[i];
// Blend new pixel value with the value from the prior frame
ledColor[i][0] = (short)((((ipix >> 16) & 0xff) * weight +
prevColor[i][0] * fade) >> 8);
ledColor[i][1] = (short)(((( ipix >> 8) & 0xff) * weight +
prevColor[i][1] * fade) >> 8);
ledColor[i][2] = (short)((((ipix) & 0xff) * weight +
prevColor[i][2] * fade) >> 8);
// Boost pixels that fall below the minimum brightness
sum = ledColor[i][0] + ledColor[i][1] + ledColor[i][2];
if(sum < minBrightness) {
if(sum == 0) { // To avoid divide-by-zero
deficit = minBrightness / 3; // Spread equally to R,G,B
ledColor[i][0] += deficit;
ledColor[i][1] += deficit;
ledColor[i][2] += deficit;
} else {
deficit = minBrightness - sum;
s2 = sum * 2;
// Spread the "brightness deficit" back into R,G,B in proportion to
// their individual contribition to that deficit. Rather than simply
// boosting all pixels at the low end, this allows deep (but saturated)
// colors to stay saturated...they don't "pink out."
ledColor[i][0] += deficit * (sum - ledColor[i][0]) / s2;
ledColor[i][1] += deficit * (sum - ledColor[i][1]) / s2;
ledColor[i][2] += deficit * (sum - ledColor[i][2]) / s2;
}
}
// Apply gamma curve and place in serial output buffer
serialData[j++] = gamma[ledColor[i][0]][0];
serialData[j++] = gamma[ledColor[i][1]][1];
serialData[j++] = gamma[ledColor[i][2]][2];
if(port != null) port.write(serialData); // Issue data to Arduino
println(frameRate); // How are we doing?
// Copy LED color data to prior frame array for next pass
arraycopy(ledColor, 0, prevColor, 0, ledColor.length);
}
}
1