Hi, I’m a beginner in programming and got this code, it draws a line of the audio input as time goes by. Is it possible that when the line is formed till the end of the screen it stays still and then starts again underneath this line. so it will be a pattern? I hope my question is clear. Thanks in advance for the help.
/**
* Grab audio from the microphone input and draw a circle whose size
* is determined by how loud the audio input is.
*/
import processing.sound.*;
import processing.svg.*;
boolean record;
AudioIn input;
Amplitude loudness;
int streamSize = 1500;
float[] sensorHist = new float[streamSize]; //history data to show
void setup() {
size(1500, 500);
background(255);
// Create an Audio input and grab the 1st channel
input = new AudioIn(this, 0);
// Begin capturing the audio input
input.start();
// start() activates audio capture so that you can use it as
// the input to live sound analysis, but it does NOT cause the
// captured audio to be played back to you. if you also want the
// microphone input to be played back to you, call
// input.play();
// instead (be careful with your speaker volume, you might produce
// painful audio feedback. best to first try it out wearing headphones!)
// Create a new Amplitude analyzer
loudness = new Amplitude(this);
// Patch the input to the volume analyzer
loudness.input(input);
}
void draw() {
if (record) {
beginRecord (SVG, "frame-####.svg");
}
// Adjust the volume of the audio input based on mouse position
float inputLevel = map(mouseY, 0, height, 1.0, 0.0);
input.amp(inputLevel);
// loudness.analyze() return a value between 0 and 1. To adjust
// the scaling and mapping of an ellipse we scale from 0 to 0.5
float volume = loudness.analyze();
appendArray(sensorHist, map(volume, 0, 0.5, 0, 500)); //store the data to history (for visualization)
background(255);
noFill();
stroke(0);
beginShape();
for (int n=0; n<sensorHist.length; n++) {
float h = sensorHist[n];
vertex(n, h);
}
if (record) {
endRecord();
record = false;
}
endShape();
}
void mousePressed() {
record = true;
}
//Append a value to a float[] array.
float[] appendArray (float[] _array, float _val) {
float[] array = _array;
float[] tempArray = new float[_array.length-1];
arrayCopy(array, tempArray, tempArray.length);
array[0] = _val;
arrayCopy(tempArray, 0, array, 1, tempArray.length);
return array;
}