Cabbage Logo
Back to Cabbage Site

Cabbage FMOD Android .so support

Respectively it crashes after the same messages up here, so it’s probably the same error.
I misinterpretated this earlier and went on too quickly…
I can just assume that’s pretty much impossible to determine what’s happening here based on this infos…

You mean the desktop version crashes after some time, or is that rock solid?

Nono that’s android. The desktop version works flawlessly.
Those messages appear in the android monitoring tool which comes with the sdk.

Can you try this after you call csound = new AndroidCsound()

csound->setOpenSlCallbacks();

TBH, I’m not sure it’s even needed any more. The last time I used Csound on Android was quite some time ago.

Unfortunately no change… it keeps crashing exactly at a certain time.

I also tried to append -+rtmidi =NULL -M0 -m0d after -n -d which made the app crash on scene load.

I also tried commenting out the score part of the csound file which has no effect.

You’re csdText CsOptions should just have -n -d for now. That’s the safest thing. Hmm. Can you add this code to your .cpp file. This is a complete hail Mary pass, but who knows!

#include <android/log.h>

extern "C" {
    extern int androidplayopen_(CSOUND *csound, const csRtAudioParams *parm);
    extern int androidrecopen_(CSOUND *csound, const csRtAudioParams *parm);
    extern void androidrtplay_(CSOUND *csound, const MYFLT *buffer, int nbytes);
    extern int androidrtrecord_(CSOUND *csound, MYFLT *buffer, int nbytes);
    extern void androidrtclose_(CSOUND *csound);

    static void androidMessageCallback(CSOUND*, int attr, const char *format, va_list valist)
    {
        char message[1024];
        //vsnprintf(message, 1024, format, valist);
        //__android_log_print(ANDROID_LOG_INFO,"AndroidCsound",message);
    }
}


void AndroidCsound::setOpenSlCallbacks()
{

    __android_log_print(ANDROID_LOG_INFO,"AndroidCsound","setOpenSlCallbacks");

    if(csoundQueryGlobalVariable(csound,"::async::") == NULL)
        if (this->CreateGlobalVariable("::async::", sizeof(int)) == 0)
        {
            int *p = ((int *)csoundQueryGlobalVariable(csound,"::async::"));
            *p = asyncProcess;
            __android_log_print(ANDROID_LOG_INFO,"AndroidCsound","==set callbacks");
            csoundSetPlayopenCallback(csound, androidplayopen_);
            csoundSetRecopenCallback(csound, androidrecopen_);
            csoundSetRtplayCallback(csound, androidrtplay_);
            csoundSetRtrecordCallback(csound, androidrtrecord_);
            csoundSetRtcloseCallback(csound, androidrtclose_);
            csoundSetMessageCallback(csound, androidMessageCallback);
            __android_log_print(ANDROID_LOG_INFO,"AndroidCsound","==callbacks set");
        }

    if(csoundQueryGlobalVariable(csound,"::paused::") == NULL)
    {
        if (this->CreateGlobalVariable("::paused::", sizeof(int)) == 0)
        {
            int *p = ((int *)csoundQueryGlobalVariable(csound,"::paused::"));
            *p = 0;
        }
    }


};

int AndroidCsound::SetGlobalEnv(const char* name, const char* variable)
{
    return csoundSetGlobalEnv(name, variable);
}

void AndroidCsound::Pause(bool pause)
{
    int *p = ((int *)csoundQueryGlobalVariable(csound,"::paused::"));
    *p = pause ?  1  : 0;
}

unsigned long AndroidCsound::getStreamTime()
{
    return *((__uint64_t*) csoundQueryGlobalVariable(csound,"::streamtime::"));
}

I was having a space between =NULL, after that it worked but removed it again.

But unfortunately linker error:
liblog.so: error adding symbols: DSO missing from command line

Ok, I guess you can remove the calls to _android_log… :thinking?

Mh, yes this works, but there are no additional debug logs as far as I see.
Where would I be able to retrieve those callbacks from androidcsound?

Is this any help? It seems like getting the output log would be very helpful in this instance…

You mean it builds, but still doesn’t produce any audio?

Yes sorry, it builds with excluding the _android_log. (without audio and with crash)

I also came across this post, but I’ll look at it a bit further.

Solved it with including -llib. It builds now fine with the logs included but in the monitor I still don’t see any additional logging…

Can you add breakpoints to your source code to see where the crash happens? Add one to the line where you compile Csound and step from there. It should give us the location of the crash. I suspect it might be in the process function…

I tried finding out about breakpoints. As I have no idea how to debug on quest with visual studio, the breakpoints there have no use i believe. (I tried it anyways with no effect). I saw the possibility to create an interrupt via code but I couldn’t recreate it.

I commented out where compile csound is called and just returned fmod ok in FMOD_RESULT F_CALLBACK FMOD_Csound_dspcreate(FMOD_DSP_STATE* dsp_state), which obviously doesn’t work and just crashes the app on scene load.
I have to stop for today now too, but eventually will try to continue finding a solution.

Right. We’ll have to old-school this! Comment out:

	csoundInput = csoundGetSpin(csound);
	csoundOutput = csoundGetSpout(csound);

and

csoundInput[chans + position] = *inbuffer++;
*outbuffer++ = csoundOutput[chans + position];

Then rebuild and try again.

This still crashes after ~10 seconds.

comment out

csoundPerformKsmps(csound);

Still the same.

And if you remove all calls to the Csound library? We need to determine if this is an issue with Csound or not…