Low Framerate with syphon and serial.

Hey guys, Im very new to processing, and Im trying to control LPD8806 led strips with processing. I started with adalight sketch and tweaked it a little, but I cant understand why the strips cant run faster than 10-15fps. Any thoughts?

This is the code Im using in processing:

import codeanticode.syphon.*;
import processing.serial.*;

static final short fade = 75;
static final short lenght = 340;

byte[]           serialData  = new byte[6 + lenght * 3];
short[][]        ledColor    = new short[lenght][3],
                 prevColor   = new short[lenght][3];
byte[][]         gamma       = new byte[256][3];

PImage S_img;
SyphonClient client;
Serial port;

public void setup() {
  size(lenght, 1, P2D);

  int    i;

  port = new Serial(this, Serial.list()[2], 115200);
  client = new SyphonClient(this, "Quartz Composer");

  background(0);

  serialData[0] = 'A';                              // Magic word
  serialData[1] = 'd';
  serialData[2] = 'a';
  serialData[3] = (byte)((lenght - 1) >> 8);   // LED count high byte
  serialData[4] = (byte)((lenght - 1) & 0xff); // LED count low byte
  serialData[5] = (byte)(serialData[3] ^ serialData[4] ^ 0x55); // Checksum

  for(i=0; i<256; i++) {
    gamma[i][0] = (byte)(pow((float)i, 2.8));
    gamma[i][1] = (byte)(pow((float)i, 2.8));
    gamma[i][2] = (byte)(pow((float)i, 2.8));
  }
}
Serial openPort() {
  String[] ports;
  ports = Serial.list();
  return new Serial(this, ports[0], 115200);
}

void draw () {

  int i, j, weight;

   {
    //S_img = client.getGraphics(S_img);
    S_img = client.getImage(S_img, false); // does not load the pixels array (faster)
    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

  for(i=0; i<lenght; i++) {  // For each LED...
    loadPixels();
    color ipix=pixels[i];
    { 
    ledColor[i][1]  = (short)((((ipix >> 16) & 0xff) * weight + prevColor[i][0] * fade) >> 8);
    ledColor[i][2]  = (short)((((ipix >> 8) & 0xff) * weight + prevColor[i][1] * fade) >> 8);
    ledColor[i][0]  = (short)((((ipix) & 0xff) * weight + prevColor[i][2] * fade) >> 8);                          
    }                        
    // Apply gamma curve and place in serial output buffer
    serialData[j++] = gamma[ledColor[i][1]][1];
    serialData[j++] = gamma[ledColor[i][2]][2];
    serialData[j++] = gamma[ledColor[i][0]][0];
  } 
    println(frameRate); // How are we doing?
    port.write(serialData); // Issue data to Arduino
}

Thanks!

Answers

  • First thing coming to mind: don't call loadPixel() for each pixel! You can move it out of the loop.

  • Hey PhiLho! I've tried that but I get some weird results. The fps of the screen with the loadpixels outside the loop its something like 60fps but the ledstrip goes terrible slow. With the loadpixels inside the loop it runs at about 15fps but the ledstrip goes smoother. weird

Sign In or Register to comment.