Hi,
I’m working on a simple program that creates polygons out of the audiobuffer data of percussive attacks. I have no idea why, but it keeps crashing.
When it crashes, the computer is completely frozen, i can’t even force quit xcode or my app.
Perhaps there is something obvious that I am missing? I have stripped out all the elements and then put them back one a time. It worked great for a while and then started crashing again.
I get no compiler warnings and nothing from GDB(since it freezes before I can check it)
I am running OF version 0.0062, XCode 3.2.5, OS X 10.6.6 on a 2011 MacBook Pro.
If anyone has moment to browse over my testApp.cpp any comments or suggestions would be greatly appreciated!
Thank you,
Jason
#include “testApp.h”
#include “stdio.h”
const float DEG2RAD = 3.14159/180;
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(0,0,0);
// 0 output channels,
// 2 input channels
// 22050 samples per second
// 256 samples per buffer
// 4 num buffers (latency)
ofSoundStreamSetup(0,2,this, 44100, 256, 4);
left = new float[256];
sumOfSquares = 0;
peakAmp = 0;
peakAmpMax = 0;
//blob variables
r = 40;
a = ofGetWidth() / 2;
b = ofGetHeight() / 2;
scale = 50;
numBlobs = 0;
freeze = false;
}
//--------------------------------------------------------------
void testApp::update()
{
//this prevents more than one blob per percussive attack(well sort of…)
if (peakAmp < 0.0001) freeze = true;
if (peakAmp > 0.001 && freeze) { //make sure we are above the threshold and that we are open to freezing new blobs
if (peakAmp > peakAmpMax) peakAmpMax = peakAmp; //follow the amplitude as it rises
if (peakAmp < peakAmpMax) { //Right after the amplitude hits the maximum, create a new blob
blob newBlob;
for (int i = 0; i < 256; i++) {
float radians = (i / 256.0f * 360.0f) * DEG2RAD;
newBlob.vertices[i][0] = cos(radians) * (r + left[i] * scale) + a;
newBlob.vertices[i][1] = sin(radians) * (r + left[i] * scale) + b;
}
newBlob.red = ofRandom(0, 255);
newBlob.green = ofRandom(0, 255);
newBlob.blue = ofRandom(0, 255);
beatBlobs.push_back(newBlob);
numBlobs++;
freeze = false;
}
}
// if there are more than 10 blobs, erase the first one.
if (numBlobs > 10) {
beatBlobs.pop_front();
numBlobs–;
}
}
void testApp::draw(){
int x, y;
//draw previous blobs
for (list::iterator bb = beatBlobs.begin(); bb != beatBlobs.end(); ++bb) {
ofSetColor(bb->red, bb->green, bb->blue);
ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofBeginShape();
for (int i = 0; i < 256; i++){
ofVertex(bb->vertices[i][0], bb->vertices[i][1]);
}
ofEndShape();
}
//draw current blob
ofSetColor(0x00FFFF);
ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofBeginShape();
for (int i = 0; i < 256; i++){
float radians = (i / 256.0f * 360.0f) * DEG2RAD;
x = cos(radians) * (r + left[i] * scale) + a;
y = sin(radians) * (r + left[i] * scale) + b;
ofVertex(x, y);
}
ofEndShape();
//output data
char reportString[255];
sprintf(reportString, “peakAmp = %f\nframerate: %f\nnum blobs: %i”, peakAmp, ofGetFrameRate(), numBlobs);
ofDrawBitmapString(reportString,80,380);
}
static float adder = 0;
//--------------------------------------------------------------
void testApp::audioReceived (float * input, int bufferSize, int nChannels){
// samples are “interleaved”
sumOfSquares = 0;
for (int i = 0; i < bufferSize; i++){
left[i] = input[i\*2];
sumOfSquares += left[i] * left[i];
}
float rms = sqrt(sumOfSquares) / bufferSize;
peakAmp = 1.414 * rms;
}