show 2 waves and their addition

edited May 2017 in Library Questions

Good morning, I'd like to show two waves that I've created and their addition. So, in the window we'd see 3 waves. Wave 1, Wave2, and the result. I only can see the same wave1 three times. Thanks.

[See comments for code]

Answers

  • edited May 2017

    [source code image deleted, see below]

  • Edit post, highlight code, press Ctrl-o.

    Don't post images of code. Don't code in a serif, proportional spaced font. What are you, a monster? 8)

  • That code looks like you are drawing the same thing 3 times. out.left.get(i), how is that different in the three for loops?

  • Does this help?

    http://code.compartmental.net/minim/oscil_method_getwaveform.html

    I'm hoping that's the waveform for the oscillators. You need to do this for the two waves and use out for the third to give the sum.

  • thanks koogs, I'd like to draw myWave1, myWave2, and the addition of both. Thanks. I'll check your link. Thanks in advance

  • edited May 2017

    Sigh.

  • I'm sorry , Ctrl-O doesn't work in my computer.

  • import ddf.minim.*;
    import ddf.minim.ugens.*;
    import ddf.minim.analysis.*;
    Minim minim;
    Oscil myWave1;
    Oscil myWave2;
    Summer sum;
    AudioOutput out;
    void setup() {
      size (600, 900);
      minim = new Minim(this);
      Summer sum= new Summer();
      myWave1 = new Oscil (1000, 0.5f, Waves.SINE);
      myWave2 = new Oscil (1000, 0.5f, Waves.SINE);
      out = minim.getLineOut();
    
      myWave1.patch (sum);
      myWave2.patch (sum);
      sum.patch(out);
    }
    void draw() {
      background (0);
      stroke(255, 255, 0);
      strokeWeight(1);
      for (int i = 0; i < out.bufferSize() - 1; i++)
      {
        line(i, 20 - out.left.get(i)*50, i+1, 50 - out.left.get(i+1)*50);
        line(i, 120 - out.right.get(i)*50, i+1, 150 - out.right.get(i+1)*50);
      }
      stroke(0, 255, 255);
      for (int i = 0; i < out.bufferSize() - 1; i++) {
        line(i, 220 - out.left.get(i)*50, i+1, 250 - out.left.get(i+1)*50);
        line(i, 320 - out.right.get(i)*50, i+1, 350 - out.right.get(i+1)*50);
      }
    
      stroke(255, 0, 255);
      for (int i = 0; i < out.bufferSize() - 1; i++) {
        line(i, 420 - out.left.get(i)*50, i+1, 450 - out.left.get(i+1)*50);
        line(i, 520 - out.right.get(i)*50, i+1, 550 - out.right.get(i+1)*50);
      }
    }
    
  • edited May 2017 Answer ✓

    waveform() doesn't really cut it - it's only defined between 0 and 1 and it doesn't vary with the frequency (ie if it's a sine wave you'll get exactly 1 repeat of the sine wave)

    stereo doesn't really make sense in your code. i'd ditch it, use mono instead.

    and using different x values for point i and i+1 is also wrong

    line(i, 320 - out.right.get(i)*50, i+1, 350 - out.right.get(i+1)*50);
    

    should be 320 and 320 imo (see the minim examples)

  • thanks a lot

Sign In or Register to comment.