record code
in
Programming Questions
•
3 years ago
I'm have some code that draws audio input as dots. It was written to save output as pages of image files (.pdf ) but I want it to save as a movie for as long as the sound runs. I followed instructions from
http://forum.processing.org/topic/record-code
but Quicktime doesn't recognise the .mov file - and I think there is also a problem that the .mov file is written before the sound input ends.
import processing.video.*;
public int pn=0;
public String savename ="wakemovie-"; // << here is the name of the file
MovieMaker mm;
public boolean firstpass = true;
public int frate = 5; // <<-- here is the frameRate
public boolean inc = true; // always set to true this increments each frame
public boolean addmovframe = true; // this is used to save the quictktime video
public boolean dovid =false; //<< toggle this true or false to save pics
public boolean looponce = false; // if you want to just loop once set to true
public boolean snap = true; // toggle this to take a snap of the first frame
void saveget() {
setupvid();
if (dovid) {
if (inc) {
pn++;
}
save(savename+str(pn)+".png");
}
if (addmovframe) {
mm.addFrame();
}
if (looponce) {
noLoop();
exit();
} // Pressing the ESCape , ' key or ~ key will end the capture and the sketch
if (keyPressed ==true && ( key=='`' || key =='~' || key == ESC)) {
mm.finish();
exit();
}
}
void setupvid() {
if (firstpass)
{
mm = new MovieMaker(this, width, height, savename+".mov", frate,
MovieMaker.ANIMATION, MovieMaker.LOSSLESS);
if (snap) {
save("snap"+savename+str(pn)+".png");
}
firstpass = false;
}
}
void loop() {
saveget(); // toggle comment this to save video or run as normal
}
//////////
import krister.Ess.*;
AudioInput myChannel;
FFT myFFT;
void setup() {
size(screen.width,400);
background(255);
// start up Ess
Ess.start(this);
myChannel= new AudioInput();
myChannel.start();
// we want 256 frequency bands, so we pass 512
myFFT=new FFT(512/4);
// normalize the spectrum
myFFT.limits();
myFFT.equalizer(true);
// I want 20 averages
myFFT.averages(20);
}
int counter = 0;
int page_ctr= 0;
boolean REDRAW = false;
void draw() {
if(REDRAW == true) {
page_ctr++;
save("PAGE"+page_ctr+".pdf");
background(255);
REDRAW = false;
loop();
}
// draw frequency bars----------20
for (int i=0; i<20; i++) {
float temp = max(0,myFFT.averages[i]*512);
ellipseMode(CORNER);
fill(100);
float vertdist = 15;
float circgap = 5;
if(temp>(512/8.0)) {
strokeWeight(1);
ellipse(counter,i*vertdist,vertdist-circgap,vertdist-circgap);
}
}
}
public void audioInputData(AudioInput input) {
myFFT.getSpectrum(input);
counter+=20.458; // 20 is the distance that it moves across each pass
if(counter>=width) {
counter = 0;
REDRAW = true;
}
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
http://forum.processing.org/topic/record-code
but Quicktime doesn't recognise the .mov file - and I think there is also a problem that the .mov file is written before the sound input ends.
import processing.video.*;
public int pn=0;
public String savename ="wakemovie-"; // << here is the name of the file
MovieMaker mm;
public boolean firstpass = true;
public int frate = 5; // <<-- here is the frameRate
public boolean inc = true; // always set to true this increments each frame
public boolean addmovframe = true; // this is used to save the quictktime video
public boolean dovid =false; //<< toggle this true or false to save pics
public boolean looponce = false; // if you want to just loop once set to true
public boolean snap = true; // toggle this to take a snap of the first frame
void saveget() {
setupvid();
if (dovid) {
if (inc) {
pn++;
}
save(savename+str(pn)+".png");
}
if (addmovframe) {
mm.addFrame();
}
if (looponce) {
noLoop();
exit();
} // Pressing the ESCape , ' key or ~ key will end the capture and the sketch
if (keyPressed ==true && ( key=='`' || key =='~' || key == ESC)) {
mm.finish();
exit();
}
}
void setupvid() {
if (firstpass)
{
mm = new MovieMaker(this, width, height, savename+".mov", frate,
MovieMaker.ANIMATION, MovieMaker.LOSSLESS);
if (snap) {
save("snap"+savename+str(pn)+".png");
}
firstpass = false;
}
}
void loop() {
saveget(); // toggle comment this to save video or run as normal
}
//////////
import krister.Ess.*;
AudioInput myChannel;
FFT myFFT;
void setup() {
size(screen.width,400);
background(255);
// start up Ess
Ess.start(this);
myChannel= new AudioInput();
myChannel.start();
// we want 256 frequency bands, so we pass 512
myFFT=new FFT(512/4);
// normalize the spectrum
myFFT.limits();
myFFT.equalizer(true);
// I want 20 averages
myFFT.averages(20);
}
int counter = 0;
int page_ctr= 0;
boolean REDRAW = false;
void draw() {
if(REDRAW == true) {
page_ctr++;
save("PAGE"+page_ctr+".pdf");
background(255);
REDRAW = false;
loop();
}
// draw frequency bars----------20
for (int i=0; i<20; i++) {
float temp = max(0,myFFT.averages[i]*512);
ellipseMode(CORNER);
fill(100);
float vertdist = 15;
float circgap = 5;
if(temp>(512/8.0)) {
strokeWeight(1);
ellipse(counter,i*vertdist,vertdist-circgap,vertdist-circgap);
}
}
}
public void audioInputData(AudioInput input) {
myFFT.getSpectrum(input);
counter+=20.458; // 20 is the distance that it moves across each pass
if(counter>=width) {
counter = 0;
REDRAW = true;
}
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
1
