Hey guys. I’m rather new to C++ programming, and I’m having a little trouble. I’m trying to generate some realtime graphics with SndObj. I tried working it out with ofxSndObj, but I couldn’t figure out how to connect startSystemInOut to the FFT function. So I’ve tried using SndObj directly.
testApp.cpp
#include "testApp.h"
#include "stdio.h"
//--------------------------------------------------------------
void testApp::setup(){
ofSetWindowTitle("template project");
ofSetFrameRate(60);
audio.SetInput(&io, 1);
window.SetParam(2500);
analysis.SetWindow(&window);
analysis.SetInput(&audio);
}
//--------------------------------------------------------------
void testApp::update(){
cout << "UPDATING...\n\n";
io.Read();
audio.DoProcess();
analysis.DoProcess();
cout << "SndIO:\t" << io.ErrorMessage() << "\n"
<< "SndIn:\t" << audio.ErrorMessage() << "\n"
<< "FFT:\t" << analysis.ErrorMessage() << "\n";
int i = 0;
int len = analysis.GetFFTSize();
cout << "FFT length:\t" << len << "\n\n";
cout << "Analising:\t";
while(i < len) {
fft[i] = analysis.Output(i);
i++;
cout << fft[i] << ", ";
}
}
//--------------------------------------------------------------
void testApp::draw(){
ofNoFill();
int i;
for (i = DEF_FFTSIZE; i > 0 ; i--) {
ofCircle(300, 300, fft[i]/(i*2));
}
}
testApp.h
#ifndef _TEST_APP
#define _TEST_APP
#define MACOSX
#include "ofMain.h"
#include "ofxSndObj.h"
#include "AudioDefs.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
SndCoreAudio io;
SndIn audio;
HammingTable window;
FFT analysis;
float fft[1024];
};
#endif
Program outputs this:
UPDATING…
SndIO: No error
SndIn: No error.
FFT: No error
FFT length: 1024
Analising: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0, -0, 0,
There are no errors when it compiles, but nothing happens when the program runs. I couldn’t find a pre-built version of SndObj, so I’m just using it through ofxSndObj. After stumbling around google, I tried building the library on my own, but I really couldn’t figure it out. I’m using XCode on Snow Leopard.
I feel relatively stupid right now - could someone help me? I’ve tried my best on google, as I’m sure somebody’s done this before, but I can’t find anything that helps. I’ve got a copy of Programming Interactivity (great book) but that hasn’t shed any light on my particular problem.