#include "ofxFmodSoundPlayer.h"
FMOD_RESULT F_CALLBACK analyzerCallback(FMOD_DSP_STATE *dsp_state,
float *inbuffer, float *outbuffer,
unsigned int length, int inchannels,
int outchannels)
{
// pass the data along
memcpy(outbuffer, inbuffer, sizeof(float)* length * outchannels);
////////// Here you have acess the raw audio data from the sound file
//////////
void *userdata = NULL;
FMOD_DSP_GetUserData(dsp_state->instance, &userdata);
ofxFmodSoundPlayer *player = (ofxFmodSoundPlayer *)userdata;
// now you can access your instnce of your ofxFmodSondPlayer instance
return FMOD_OK;
}
ofxFmodSoundPlayer::ofxFmodSoundPlayer(){
// FIXME: I'd love to setup the analyer callback here, but somehow FMOD doesnt allow me to do so... :-(
}
void ofxFmodSoundPlayer::play(){
ofFmodSoundPlayer::play();
// Setup - insert our own callback into FMOD graph
FMOD_SYSTEM *system;
FMOD_RESULT result = FMOD_Sound_GetSystemObject(sound, &system);
ERRCHECK(result);
FMOD_DSP_DESCRIPTION dsp_description;
memset(&dsp_description, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dsp_description.name, "Audio Analyzer DSP");
dsp_description.channels = 0;
dsp_description.read = analyzerCallback;
dsp_description.userdata = this;
result = FMOD_System_CreateDSP(system, &dsp_description, &analyzer);
ERRCHECK(result);
// Create DSP
result = FMOD_Channel_AddDSP(channel, analyzer, 0);
ERRCHECK(result);
}
void ERRCHECK(FMOD_RESULT result){
if (result != FMOD_OK){
fprintf(stderr, "FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}