SndObj: Realtime audio input with SndCoreAudio

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,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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,

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. :frowning: I’ve got a copy of Programming Interactivity (great book) but that hasn’t shed any light on my particular problem.

For realtime fft analysis on input channels you should check out the ofxFft extension. Here is a topic about it: http://forum.openframeworks.cc/t/ofxfft:-fftw-±kiss-fft-wrapper/2184/0
Dont forget to also install the KISS library for this. Works quite well for me (although I still have to figure out whats the best way to get a logarithmic scale).

Good luck. :slight_smile:

Yeah, I posted on that one. Maybe I might have learned enough by now to take another look at it. Thanks for reminding me!

Ah, I see… Yeah, I also don’t understand it fully yet, but slowly Im learning it. :slight_smile: