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.

hi, @StevenSarns,
how is your project

  • signal generator ( with 20Hz sawtooth sound output? )
  • microphone PC sound card
  • record to file? or looped to processing input
  • scope like processing show

i am currently on a remake of a processing scope
using arduino USB connected analog inputs.
but think that sound frequencies are on the limit of that hardware.

as i lack the hardware ( calibrated signal generator ) even to see that my indicated
frequencies are nearly correct, i think after reading this post , that using a
sound / micro / arduino analog input /
might be a good idea and not need to buy much signal generation hardware,
just play a sound from any PC using ?audacity?


up to now i only have a signal from a other arduino ( DUE has analog output )
where i have no idea what frequency that might be
( can not calibrate one arduino with an other )


but i hope i get the mic input to a arduino working.
but yes, that is total different as your PC soundcard with micro / processing / minim lib / way.

Simple online tone generator for audio range:
https://www.szynalski.com/tone-generator/

:slight_smile:

1 Like