首页 > 解决方案 > C++ - Convert typedef to non-static method or object creation

问题描述

Hello I am using c++ in my Android project and I am fairly new to it. I have this class called SuperpoweredAndroidAudioIO which has the following constructor parameters.

SuperpoweredAndroidAudioIO(int samplerate, int buffersize, bool enableInput, bool enableOutput, audioProcessingCallback callback, void *clientdata, int inputStreamType = -1, int outputStreamType = -1);

Here audioProcessingCallback is a typedef which is defined in the library like this,

typedef bool (*audioProcessingCallback) (void *clientdata, short int *audioIO, int numberOfFrames, int samplerate);

Now every time I have to create an object of SuperpoweredAndroidAudioIO, I have to pass the static method as the parameter for the audioProcessingCallback like this,


static bool audioProcessing(
        void *__unused clientdata, // custom pointer
        short int *audio,           // buffer of interleaved samples
        int numberOfFrames,         // number of frames to process
        int __unused samplerate     // current sample rate in Hz
) {
     //Some code
     return true;
}

audioIO = new SuperpoweredAndroidAudioIO(
            samplerate,      
            buffersize,      
            true,            
            true,           
            audioProcessing, // audio processing callback function
            NULL,      
            -1,
            SL_ANDROID_STREAM_MEDIA
    );

So my question is that is there any way to remove that static method as an audio processing callback and directly assign a method or object or anything that can work without static. The reason is that if I declare a static method I have to use all the variables inside it as static. So can anyone please help here?

标签: c++java-native-interfacesuperpowered

解决方案


推荐阅读