Digitize Audio Input

Hello All, Thanks in advance for any insights. I am very new to Processing. My project is to create an oscilloscope-like presentation of the signal on the MIC input of my desktop computer. The test waveform is a 20 Hz sawtooth wave generated by an external signal generator.

1 - the externally generated signal is being acquired correctly by the PC audio hardware as evidenced by a correct display using the example code in the minim getLineIn example.
2- my code generates the desired display when executed using the “test();” fake input generator function.
3 - when the “test()” call is commented out, I get an unintelligible image (see below)

I suspect that using a buffer size of 1 is the root of my problem (minim might normalize the data).

? - is there a simpler way to get a digitized sample of the MIC in?
? - am I missing something about the way getLineIn works?

import ddf.minim.*;
Minim minim;
AudioInput in;

void setup()
{
  size(1000, 200);
  minim = new Minim(this);
  in = minim.getLineIn(Minim.MONO,1);  // getLineIn(int type, int bufferSize, float sampleRate)
  background(0);
  stroke(255);
  frameRate(1000);                    // draw()/sec
}

int x;
int lastX=0;
float y;
float lastY=0;

void draw()
{
  x++;
  if(x>width) {
    x=0;
    lastX=0;
    background(0);
    stroke(255);
  }
  y = in.left.get(0);
  test();
  line(lastX,100+(lastY*100),x,100+(y*100));
  lastY=y;
  lastX=x;
}

void test() {
  float xx = x%50;
  y = xx/50 - .5;
}
1 Like

Please format your code when posting.
Try to cut and paste your current code into Processing and you will see why.

When you “cut and paste” this from Processing (formatted code):

line(lastX,100+(lastY*100),x,100+(y*100));

This is what we see (unformatted code):
line(lastX,100+(lastY100),x,100+(y100));

Just highlight your code and click on the </> button in the editor.

:slight_smile:

Thanks - I wondered how to do that.

import ddf.minim.*;
Minim minim;
AudioInput in;

void setup()
{
  size(1000, 200);
  minim = new Minim(this);
  in = minim.getLineIn(Minim.MONO,1);  // getLineIn(int type, int bufferSize, float sampleRate)
  background(0);
  stroke(255);
  frameRate(1000);                    // draw()/sec
}

int x;
int lastX=0;
float y;
float lastY=0;

void draw()
{
  x++;
  if(x>width) {
    x=0;
    lastX=0;
    background(0);
    stroke(255);
  }
  y = in.left.get(0);
//  test();
  line(lastX,100+(lastY*100),x,100+(y*100));
  lastY=y;
  lastX=x;
}

void test() {
  float xx = x%50;
  y = xx/50 - .5;
}

Look at the “examples” that come with the minim library.

:slight_smile:

Thanks, but…
The example you suggested fills a buffer, then plays the buffer. I am trying to get a single data point (buffer size of one) and plot that point. I am looking for a solution to the problem of acquiring a single data point.

Possibly relevant: an example of a minim oscilloscope.