Syphon into my Processing code

edited February 2014 in Library Questions

Hello,

I'm attempting to incorporate my Processing code into Madmapper, and I'm interested in embedding Syphon into my code to make that happen.

However, I was hoping you guys can help me on what section of my code I need to add / modify. I tried modifying my code using references from blogs and forums, but I think the technicality of my code is what needs a more specialized modification.

Thank you in advance!

below is my code:

import ddf.minim.*;

Minim minim;
AudioInput in;
AudioOutput out;
WaveformRenderer waveform;

void setup()
{
  size(1400, 700);

  minim = new Minim(this);
  minim.debugOn();

  // get a line in from Minim, default bit depth is 16
  in = minim.getLineIn(Minim.STEREO, 512);
  out = minim.getLineOut(Minim.STEREO, 512);

  waveform = new WaveformRenderer();
  in.addListener(waveform);


  // adds the signal to the output
  out.addSignal(waveform);
}





class WaveformRenderer implements AudioListener, AudioSignal
{

  private float[] left;
  private float[] right;

  WaveformRenderer()
  {
    //    left = null;
    //    right = null;
  }

  synchronized void samples(float[] samp)
  {
    left = samp;
  }

  synchronized void samples(float[] sampL, float[] sampR)
  {
    left = sampL;
    right = sampR;
  }


  void generate(float[] samp)
  {
    System.arraycopy(right, 0, samp, 0, samp.length);
  }

  // this is a stricly mono signal
  void generate(float[] sampL, float[] sampR)
  {
    if (left!=null && right!=null) {
      System.arraycopy(left, 0, sampL, 0, sampL.length);
      System.arraycopy(right, 0, sampR, 0, sampR.length);
    }
  }
}







void stop()
{
  in.close();
  minim.stop();
  super.stop();
}

// control values
int ringSize = 15; // base ring radius
int ringInc = 15;  // bstep from ring to ring
int ring = ringSize;
int cycles = 0;
int xcycles = 0;
int ycycles = 0;
int yy = 700/4;
int xx =  1400/5;
int cycleLength = 7;

void draw() {
  PImage p = get();
  tint(255);
  image(p, 0, 0, 1400, 700);
  stroke(255);

  strokeWeight(1.0);
  float a = 0;
  float angle = (7*PI) / 700;
  int step = in.bufferSize() / 200;
  // tile the sceen

  // step down yy twice
  // step across xx 4 times
  // sound loop
  for (int i=0; i < in.bufferSize() - step; i+=step) {
    float x = xx + cos(a) * (100 * in.mix.get(i) + ring);//700
    float y = yy + sin(a) * (100 * in.mix.get(i) + ring);// 350
    //println (in.mix.get(i));
    float x2 = xx + cos(a + angle) * (350 * in.mix.get(i+step) + ring);//700
    float y2 = yy + sin(a + angle) * (350 * in.mix.get(i+step) + ring);//350
    line(x, y, x2, y2);
    a += angle;
  } // sound loop
  //println ("xx = "+xx+" yy= "+yy+"cy= " + cycles + " ring = "+ring);

  cycles++;
  // x increment
  if (cycles%cycleLength == 0) {
    ring += ringInc;
    xx += width/5;
    xcycles++;
    //delay(500);
    // y increment
    if (xcycles == 4) {
      xcycles = 0;
      ycycles++;
      xx =  1400/5;
      yy += height/2;
      // reset to start
      if (yy > height) {
        xx = 1400/5;
        yy = 700/4;
        cycles=1;
        xcycles = 0;
        ycycles = 0;
        ring = 15;
      }
    }
  }
}
Tagged:

Answers

  • edited February 2014

    The syphon library comes with examples to show how to send/receive frames. Take a look at those to see what modifications are needed in your code. One quick thing though is that syphon requires either the P2D or P3D renderers in size(), it won't work with the default renderer.

Sign In or Register to comment.