Cabbage Logo
Back to Cabbage Site

CsoundUnity Package (UPM) development

I’m having a look at the Csound for Android code.
I found something that is not so clear to me.
In the native interface (csndJNI.java) there are two different methods of the GetSpoutSample, and just one of the SetSpinSample.
This is what I found at line 342:

public final static native float csoundGetSpoutSample(long jarg1, int jarg2, int jarg3);

and line 813:

    public final static native float Csound_GetSpoutSample(long jarg1, Csound jarg1_, int jarg2, int jarg3);

while for the SetSpinSample there is just a native method, at line 340:

public final static native void csoundSetSpinSample(long jarg1, int jarg2, int jarg3, float jarg4);

This makes me a bit confused. What’s the difference between these native methods?

In Csound.java there is the implementation for GetSpoutSample, line 583:

public float GetSpoutSample(int frame, int channel) {
    return csndJNI.Csound_GetSpoutSample(swigCPtr, this, frame, channel);
}

There I can also see an implementation for AddSpinSample, but not for SetSpinSample.
I’ll have to add the SetSpinSample method to do some tests for the crash we have in CsoundUnity when targeting Android.
Maybe I should ask on Slack?

EDIT:
I just read that Csound.java, csndJNI.java and all the referenced code are generated using SWIG.
I don’t know how it works :thinking:

I’ve no experience with SWIG either. Are you on the Csound slack channel? Might be good to reach out to Steven there. He said he would help if we can’t figure it out. I’m away for a few days, so I can’t give it much time to this right now. Please keep me posted though, I’m interested to learn more.

Yes I’m on the Csound Slack channel.
I posted an issue on Github, maybe I’ll link that on the chat.

Hi @giovannibedetti, did you reach out to Steven on the slack dev channel? Was he able to offer any advise?

Hi @rorywalsh!
I opened an issue on Github but got no answer yet.


Maybe I wasn’t clear enough?
I’ll do some other tests today!

I think you were clear enough, but I find the slack channel is far more responsive.

Ok I’ll post the issue there, which channel is best? #dev?

I think #dev is best for this type of question. You might ping Steven in your question too. I’m not sure how busy he is with other things at the moment, but he your best bet!

Ok great!
I’ll just double check if what I wrote is true and then drop him a line on #dev.
I’ll keep you posted.
BTW I did some tests with the new UIElements, the performance is for sure better (no spikes at all even with lots of sliders), but basically all the editor part must be rewritten (again :sweat_smile:).
The interesting thing is that the existing controls can still be used and mixed with XML code (as an IMGUIContainer).
All the styling and binding is detached from the structure, which is great.
I’ll take it as an exercise for the future :nerd_face:
I have a couple of spare weeks to work on this, hope I’ll get far enough!

Given the speed at which you have got through everything else, I assume you will fly though this! If you need anyone to do some donkey work let me know :wink:

I hope so! But this time it’s something totally new for me, and there’s not a lot of examples and code out there to be inspired from.
I’ll let you know how it goes!

I created a test Activity on Android and I get no crash calling GetSpoutSample or AddSpinSample.
:thinking:
I’ll ask on #dev :sweat_smile:

Ok I got an answer:

vlazzarini commented 2 minutes ago

Yes, there is no SetSpinSample in the Csound API, so you have to use AddSpinSample.

I’ll try and see what happens on Unity!

Tried changing SetSpinSample with AddSpinSample, but the crash is related with GetOutputSample (that’s calling the native csoundGetSpoutSample):

Crash log

2020-07-14 17:09:25.532 3105-3139/com.Csound.CsoundUnityPackage_DevelopmentProject E/CRASH: other thread is trapped; signum = 11

--------- beginning of crash

2020-07-14 17:09:25.535 3105-3139/com.Csound.CsoundUnityPackage_DevelopmentProject E/AndroidRuntime: FATAL EXCEPTION: UnityMain
Process: com.Csound.CsoundUnityPackage_DevelopmentProject, PID: 3105
java.lang.Error: FATAL EXCEPTION [UnityMain]
Unity version : 2019.3.9f1
Device model : samsung SM-J730F
Device fingerprint: samsung/j7y17ltexx/j7y17lte:7.0/NRD90M/J730FXXU1AQI5:user/release-keys

Caused by: java.lang.Error: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Version '2019.3.9f1 (e6e740a1c473)', Build type 'Development', Scripting Backend 'mono', CPU 'armeabi-v7a'
Build fingerprint: 'samsung/j7y17ltexx/j7y17lte:7.0/NRD90M/J730FXXU1AQI5:user/release-keys'
Revision: '7'
ABI: 'arm'
Timestamp: 2020-07-14 17:09:24+0100
pid: 3105, tid: 4509, name: Audio Mixer Thr  >>> com.Csound.CsoundUnityPackage_DevelopmentProject <<<
uid: 10237
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Cause: null pointer dereference
    r0  00000000  r1  00000000  r2  00001e2c  r3  00000002
    r4  00000000  r5  cef5af70  r6  00000000  r7  00000000
    r8  00000000  r9  cc6669c0  r10 cc6e9570  r11 c737e478
    ip  c5a72340  sp  c737e348  lr  c5a72390  pc  c026015a

backtrace:
      #00 pc 001ca15a  /data/app/com.Csound.CsoundUnityPackage_DevelopmentProject-2/lib/arm/libcsoundandroid.so (csoundGetSpoutSample+14) (BuildId: 2a9cb8e8297b697cdf82f7cf85f873f20ac88815)
      #01 pc 0000638e  <anonymous:c5a6c000>

managed backtrace:
      #00 (wrapper managed-to-native) csoundcsharp.Csound6/NativeMethods:csoundGetSpoutSample (intptr,int,int)
      #01 CsoundUnityBridge:GetSpoutSample (int,int) </Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnityBridge.cs:470>
      #02 CsoundUnity:GetOutputSample (int,int) </Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnity.cs:731>
      #03 CsoundUnity:ProcessBlock (single[],int) </Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnity.cs:1446>
      #04 CsoundUnity:OnAudioFilterRead (single[],int) </Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnity.cs:1404>
      #05 (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object_int (object,intptr,intptr,intptr)

    at libcsoundandroid.csoundGetSpoutSample(csoundGetSpoutSample:14)
    at csoundcsharp.Csound6.NativeMethods.csoundGetSpoutSample (intptr,int,int)(Native Method)
    at CsoundUnityBridge.GetSpoutSample (int,int)(/Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnityBridge.cs:470)
    at CsoundUnity.GetOutputSample (int,int)(/Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnity.cs:731)
    at CsoundUnity.ProcessBlock (single[],int)(/Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnity.cs:1446)
    at CsoundUnity.OnAudioFilterRead (single[],int)(/Users/gb/Desktop/WORKS_&_STUFF/CSOUND/GIT/CsoundUnityPackage/CsoundUnityPackage_DevelopmentProject/Packages/CsoundUnity/Runtime/CsoundUnity.cs:1404)
    at <Module>.runtime_invoke_void__this___object_int (object,intptr,intptr,intptr)(Native Method)

I just posted to that github page now, there is a csoundSetSpinSample method? I asked Victor to add it a while back. He has clearly forgot :laughing:


And if it wasn’t available, how the hell are we using it in our CsoundUnity code :rofl:

I tried using the AddSpinSample method and it works in the same way (in Editor, so I assume also in desktop builds).
The crash on Android comes from the GetOutputSample method. I tested this method on Csound for Android and I get no crash!
Maybe the libs for Android we’re using are not updated to the last version. :thinking:

Can we not just use the same libs that you use when you test for Android?

Yes already tried, didn’t work… let me try again because I don’t remember if I got a dll not found or the same crash

Just tried replacing the libs, Dll not found…

#0 0xcffd008f (libunity.so) GetStacktrace(int) 0x26
#1 0xd0be83b3 (libunity.so) DebugStringToFile(DebugStringToFileData const&) 0x106
#2 0xd05484c1 (libunity.so) DebugLogHandler::Internal_Log(LogType, LogOption, core::basic_strin
2020-07-14 20:32:32.460 22808-22832/com.Csound.CsoundUnityPackage_DevelopmentProject E/Unity: DllNotFoundException: csoundandroid
at (wrapper managed-to-native) csoundcsharp.Csound6+NativeMethods.csoundSetGlobalEnv(string,string)

I have to understand how Hector created libnative.so!

Have you been in touch with him before? I can reach out to him via email if you like. He’s the key to all of this :joy: