Noise detection to glitch
in
Contributed Library Questions
•
1 year ago
Hi!
Ok, I've made a program with the krister.Ess-library and a movie - which glitches whenever there is noise. My problem is that it is constantly glitching and never "normal". So, if I want the video to glitch "only-when-spoken-to"-ish what should I do?
This is what I got so fare:
import krister.Ess.*;
AudioStream myStream;
AudioInput myInput;
PitchShift myShift;
Amplify myAmplify;
Reverb myReverb;
import processing.video.*;
Movie myMovie;
boolean inputReady=false;
float[] streamBuffer;
boolean toggle=true;
PImage b;
PFont font = createFont("Sans Serif", 36);
void setup() {
//size(256,200);
// start up Ess
Ess.start(this);
// create a new AudioInput (4k buffer)
myInput=new AudioInput(4096);
// create a new AudioStream (4k buffer)
myStream=new AudioStream(myInput.size);
streamBuffer=new float[myInput.size];
// our filters
myShift=new PitchShift(2);
myAmplify=new Amplify(4);
myReverb=new Reverb();
// start
myStream.start();
myInput.start();
frameRate(30);
// billede
size(1000, 1200);
myMovie = new Movie(this, "totoro.mov");
myMovie.play();
//myMovie.speed(1.3);
// myMovie.frameRate(1);
textFont(font);
}
void draw() {
// glitch billede
int interp=(int)max(0,(((millis()-myStream.bufferStartTime)/(float)myStream.duration)*myStream.size));
image(myMovie, 18, 16);
text(myInput.buffer2[interp], 10, 800);
loadPixels();
//if (inputReady)
for (int i=0; i<pixels.length; i++) {
pixels[i] = int(pixels[i] * 2 * (myInput.buffer2[interp] + 1));
}
updatePixels();
//if (inputReady)
//background(0,0,255);
/*
// paint the top white
fill(255);
noStroke();
rect(0,0,width,height/2);
// draw both waveforms
//int interp=(int)max(0,(((millis()-myStream.bufferStartTime)/(float)myStream.duration)*myStream.size));
for (int i=0;i<256;i++) {
float leftp=50;
float rightp=50;
float left=150;
float right=150;
if (i+interp+1<myStream.buffer2.length) {
leftp-=myInput.buffer2[i+interp]*50.0;
rightp-=myInput.buffer2[i+1+interp]*50.0;
left-=myStream.buffer2[i+interp]*50.0;
right-=myStream.buffer2[i+1+interp]*50.0;
}
stroke(0,0,255);
line(i,leftp,i+1,rightp);
stroke(255);
line(i,left,i+1,right);
}*/
}
void audioStreamWrite(AudioStream theStream) {
// block until we have some input
while (!inputReady);
System.arraycopy(streamBuffer,0,myStream.buffer,0,streamBuffer.length);
if (toggle) {
myShift.filter(myStream);
myAmplify.filter(myStream);
} else {
myReverb.filter(myStream);
}
inputReady=false;
}
void audioInputData(AudioInput theInput) {
System.arraycopy(myInput.buffer,0,streamBuffer,0,myInput.size);
inputReady=true;
}
void keyPressed() {
toggle=!toggle;
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
void movieEvent(Movie m) {
m.read();
}
Ok, I've made a program with the krister.Ess-library and a movie - which glitches whenever there is noise. My problem is that it is constantly glitching and never "normal". So, if I want the video to glitch "only-when-spoken-to"-ish what should I do?
This is what I got so fare:
import krister.Ess.*;
AudioStream myStream;
AudioInput myInput;
PitchShift myShift;
Amplify myAmplify;
Reverb myReverb;
import processing.video.*;
Movie myMovie;
boolean inputReady=false;
float[] streamBuffer;
boolean toggle=true;
PImage b;
PFont font = createFont("Sans Serif", 36);
void setup() {
//size(256,200);
// start up Ess
Ess.start(this);
// create a new AudioInput (4k buffer)
myInput=new AudioInput(4096);
// create a new AudioStream (4k buffer)
myStream=new AudioStream(myInput.size);
streamBuffer=new float[myInput.size];
// our filters
myShift=new PitchShift(2);
myAmplify=new Amplify(4);
myReverb=new Reverb();
// start
myStream.start();
myInput.start();
frameRate(30);
// billede
size(1000, 1200);
myMovie = new Movie(this, "totoro.mov");
myMovie.play();
//myMovie.speed(1.3);
// myMovie.frameRate(1);
textFont(font);
}
void draw() {
// glitch billede
int interp=(int)max(0,(((millis()-myStream.bufferStartTime)/(float)myStream.duration)*myStream.size));
image(myMovie, 18, 16);
text(myInput.buffer2[interp], 10, 800);
loadPixels();
//if (inputReady)
for (int i=0; i<pixels.length; i++) {
pixels[i] = int(pixels[i] * 2 * (myInput.buffer2[interp] + 1));
}
updatePixels();
//if (inputReady)
//background(0,0,255);
/*
// paint the top white
fill(255);
noStroke();
rect(0,0,width,height/2);
// draw both waveforms
//int interp=(int)max(0,(((millis()-myStream.bufferStartTime)/(float)myStream.duration)*myStream.size));
for (int i=0;i<256;i++) {
float leftp=50;
float rightp=50;
float left=150;
float right=150;
if (i+interp+1<myStream.buffer2.length) {
leftp-=myInput.buffer2[i+interp]*50.0;
rightp-=myInput.buffer2[i+1+interp]*50.0;
left-=myStream.buffer2[i+interp]*50.0;
right-=myStream.buffer2[i+1+interp]*50.0;
}
stroke(0,0,255);
line(i,leftp,i+1,rightp);
stroke(255);
line(i,left,i+1,right);
}*/
}
void audioStreamWrite(AudioStream theStream) {
// block until we have some input
while (!inputReady);
System.arraycopy(streamBuffer,0,myStream.buffer,0,streamBuffer.length);
if (toggle) {
myShift.filter(myStream);
myAmplify.filter(myStream);
} else {
myReverb.filter(myStream);
}
inputReady=false;
}
void audioInputData(AudioInput theInput) {
System.arraycopy(myInput.buffer,0,streamBuffer,0,myInput.size);
inputReady=true;
}
void keyPressed() {
toggle=!toggle;
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
void movieEvent(Movie m) {
m.read();
}
1