We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm working on a very bare bones oscilloscope program using the minim library:
import ddf.minim.*;
Minim minim;
AudioInput in;
color white;
void setup()
{
size(512, 100, P2D);
white = color(255);
colorMode(HSB,100);
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.STEREO, 512);
background(0);
}
void draw()
{
background(0);
// draw the waveforms
for(int i = 0; i < in.bufferSize() - 1; i++)
{
stroke((1+in.left.get(i))*50,100,100);
line(i, 50 + in.left.get(i)*50, i, 50 + in.left.get(i+1)*50);
}
}
void stop()
{
in.close();
minim.stop();
super.stop();
}
My question is, how do I make the waveform trigger/stabilize like an actual oscilloscope? I'm trying to figure that out so I can make the waveform stay at a certain spot so it doesn't jump around. Basically keep the waveform stable at all times.
Thanks for your help.
Answers
You need to manage your
in.bufferSize()
as it has the current data to display. You could create a container made of time-amplitude pair values. Then, one way is to trigger on the leading edge or falling edge of a signal. This can be easily accomplish using a threshold applied to your values. When you find a signal going above the threshold, then you display that position at the center of the screen and the other values should be shifted up or down accordingly.There is an oscilloscope library in case you don't know about it.
Kf
I do know about the library, but I'm trying to make it bare bones as I said. I tried making an if statement where when in.left is rising it resets the waveform buffer but that did nothing. I don't really know how to make the position at the center of the screen. I don't know how I can reset the waveform buffer. I tried that if statement and then it would make i = 0 but that didn't do anything either. I'd be nice if you could point me in the right direction with example code. Thanks.
Doing something like this requires to know about the nature of your data, and exactly how you envision your trigger to work. Here I have implemented the concept based on leading edge crossing. White line is based line. Blue line is the current threshold definition. The data from minim is in a range of -1..+1. When displaying, I multiply this data by a normalization factor which I defined as height/2. I set my threshold to 0.4 based on observations from the
printInfo()
function in my code below. Green line shows the data points.The concept is this. If the wave crosses the threshold, capture this crossing point. Set this crossing point as the center of the display (across the sketch width) which means all the data is shifted either to the left or to the right. Because the display width is 512 and the data buffer is 512, if the data is shifted with respect to the leading edge crossing, then it is natural that either the left end or right end will have no data... these data bins were set to zero (Notice this is because I copy the original data to a temporal array before I reset those containers to zero).
I removed the hsb color definition, added an inversion on the y axis, and instead of calling
background()
, I am using a fill with alpha to slowly erased my sketch content. So this creates an effect of memory on the display where you can see that previous waves are attenuated and removed after few iterations, and not immediately in the case you callbackground()
function.As in an oscilloscope, I work with the time-amplitude domain. However, the examples of the minim is based on a buffer that provides amplitude only, no time information. Then What I do is that I take the index of the array and I set them to be my time. The amplitude from minim is used as my amplitude data, so I get two internal arrays: time and amplitude which store the data to display.
Kf
//REFERENCE: https://forum.processing.org/two/discussion/28074/how-to-add-a-trigger-to-an-oscilloscope-program#latest // //Title: Oscilloscope trigger based on the leading edge. //Author: Kfrajer, July 15, 2018
There also is a new forum