Using audio input function

I’m having an issue passing the audioIn() function from my ofApp class to a custom ‘myOwnClass’.

When I run my code I get ‘,address=0x0)’ on my line mono[i]=input[i*2]*0.5; because input is NULL

If I check the see if input is NULL before I run this code before that line, the line still goes through and gives me the same error.

Note: I create an ofSoundStream mySoundStream in my ofApp.h and set it up in my ofApp.cpp setup().

    void ofApp::audioIn(float * input, int bufferSize, int nChannels){
              myOwnClassObject.audioIn(input, bufferSize, nChannels);

void myOwnClass::audioIn(float * input, int bufferSize, int nChannels){

        for (int i = 0; i < bufferSize; i++){
            mono[i] = input[i*2]*0.5; //Get audio stream coming in Channel 1

Should it be:

myOwnClassObject.audioIn(* input, bufferSize, nChannels);

Because in the the MyOwnClass your input parameters need a float * (pointer) and from the main app if seems like you’re trying to send input (float) and not *input (pointer)? Not too sure though. But definitely a pointer issue.

Beware of audio, I’ve had issues trying to dereference pointers to manipulate when working with audio as most times it’s a pointer to an array so to dereference it you’ll need to go through a for loop and do *input + i to find the actual array of floats to read the buffers. Not too elegant, imo.

I’ve never tried it before, but I’d think that adding a listener inside the class should work better?

hi @michaelpromeo, forget my previous reply. Got sending audio input to a class working, with no errors.

Uploaded the code with a small little visualization to my dropbox, find it here:

Thank you for the help @ayruos I realized what I was doing wrong from your code! You first setup you ‘myAudioClassObject’ and then ‘ofSoundStreamSetup’ I was doing the opposite so the audioIn function on ‘myAudioClassObject’ would start running and crash my app because the vector mono I have in there was empty!

:slight_smile: glad to have helped!