How can I remain the drawn boxes?

#1

Hi, All.

I have made Spectrogram of mp3 files.

But, in draw() method, drawn boxes are not remained.
How can I remain the drawn boxes ?

//--------------------------------------------------------------
void ofApp::setup(){
dog.load("/Users/mun/Desktop/woman.mp3");
j=0;
ofBackground(55);
}
//--------------------------------------------------------------
void ofApp::update(){
// by taking maximums, as peaks and then smoothing downward
float * val = ofSoundGetSpectrum(nBandsToGet);
for (int i = 0;i < nBandsToGet; i++){
// let the smoothed value sink to zero:
fftSmoothed[i] *= 0.96f;

	// take the max, either the smoothed or the incoming:
	if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
}

}
//--------------------------------------------------------------
void ofApp::draw(){
float width = (float)(512) / nBandsToGet;
//
for (int i = 0;i < nBandsToGet; i++){
col= fftSmoothed[i]*125000;
if(col>255) col=255;
ofSetColor(col);
ofDrawRectangle(j, i, 1, 1);
}
j+=1;
if(j > 512) j=0;
}

Thanks.

#2

Maybe https://openframeworks.cc//documentation/graphics/ofGraphics/#!show_ofSetBackgroundAuto ?

#3

You have to create an ofFbo and draw to it, it will keep everything unless you explicitly erase it. Then you can use fbo.draw() to put its content on your window. There are a few tutorials on OF docs.

1 Like