To register and login, use your Google, Twitter, Facebook, LinkedIn, or OpenID credentials.

This is allowing us to stop most spam registrations. We've deleted most of the spam accounts that got through, and we're closely watching for more.

reson~ (cyclone) with libpd and Android

luongluong Posts: 5
edited January 2013 in Pd Everywhere

[SOLVED]

Hi,

I am trying to use reson~ with libpd on Android.

I got the source code of cyclone [ http://suita.chopin.edu.pl/~czaja/miXed/externs/cyclone.html ] and compiled the source with NDK for the reson~ part, following the makefile of ScenePlayer sample app.

However, my patch does not work (it does on desktop) and I keep getting "error: ... couldn't create" from PdUiDispatcher.

I tried with PdService and with PdBase.addToSearchPath() directly, with same results.

I am using the last version of libpd. From what I could understand, for externals I should only compile them with NDK and libpd should take care of the rest: is that correct?

Anyone here used cyclone with libpd for Android?

Thank you very much,
Luong

Answers

  • NitroooNitrooo Posts: 21

    That's curious. I had the very same issue yesterday with average~ from cyclone. Compiled externals from other libraries are working fine. There must be some kind of incompatibility with the cyclone externals. Eventually I gave up and modified my patches not to use average~. Please, let us know if you find a solution!

  • luongluong Posts: 5

    Thank you for your feedback Nitrooo!

    Although I was hoping for some easy-to-fix error from my side, I'm glad to know I am not alone in this. :-)

    I'll let you know if I find something!

    Meanwhile, I hope that someone else here can help with this problem: I am not a Pure Data expert, so I don't know if I'll be able to get rid reson~ from my patch...

  • kapsykapsy Posts: 30

    Hah, was just about to give the cyclone externals a go...

    Wanted to use the counter external. I'm an external newb but will try anyway, see if I get the same result.

  • kapsykapsy Posts: 30

    Hi Luong, I'm trying to get counter.c compiling but I must be doing something wrong with my Make file, as I can't seem to shake the following errors:

    ++++++++++++++++++++++++++++++++++++++
    $ ndk-build
    /cygdrive/c/android/android-ndk-r8d/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
    SharedLibrary : libcounter.so
    C:/android/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/counter/counter.o: in function counter_dobang:jni/counter.c:104: error: undefined reference to 'loudbug_bug'
    C:/android/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/counter/counter.o: in function counter_new:jni/counter.c:321: error: undefined reference to 'fittermax_get'
    C:/android/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/counter/counter.o: in function counter_setup:jni/counter.c:401: error: undefined reference to 'fitter_setup'
    collect2: ld returned 1 exit status
    /cygdrive/c/android/android-ndk-r8d/build/core/build-binary.mk:397: recipe for target `obj/local/armeabi/libcounter.so' failed
    make: *** [obj/local/armeabi/libcounter.so] Error 1
    ++++++++++++++++++++++++++++++++++++++

    Here is my Android.mk, copied mostly from the scene player app:

    ++++++++++++++++++++++++++++++++++++++

    LOCAL_PATH := $(call my-dir)

    --------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := counter
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src $(LOCAL_PATH)/../../../src_misc/cyclone/shared
    LOCAL_CFLAGS := -DPD
    LOCAL_SRC_FILES := counter.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_SHARED_LIBRARY)

    --------------------------------------------

    ++++++++++++++++++++++++++++++++++++++

    I must be doing something wrong (as I seem to have a habit of doing lately), I un-tared the cyclone source as is to the src_misc/cyclone dir - but by the error messages I'm missing something else - any ideas?

  • NitroooNitrooo Posts: 21
    edited January 2013

    You must provide the linker with the compiled object files which contain the missing references. Basically you have to look for the include directives in the source file of the object that can't be linked (counter.c: "common/loud.h" and "common/fitter.h") and compile the relative implementations (loud.c and fitter.c) as static libraries by using these lines in your Android.mk, one block for each static library:

    -----------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := loud
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_LDFLAGS := -Wl,--export-dynamic
    LOCAL_SRC_FILES := loud.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_STATIC_LIBRARY)

    -----------------------------------

    Then you have to add the references to the static libraries to be used to link your external:

    -----------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := counter
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_LDFLAGS := -Wl,--export-dynamic
    LOCAL_SRC_FILES := counter.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    LOCAL_STATIC_LIBRARIES := loud lib2 lib3
    include $(BUILD_SHARED_LIBRARY)

    -----------------------------------

    The order of the libs in "LOCAL_STATIC_LIBRARIES" matters, so if it doesn't work try changing the order of the entries.

  • kapsykapsy Posts: 30
    edited January 2013

    Thanks for your help Nitrooo. Finally got it going following your advice, and had to move the fitter.c/fitter.h and loud.c/loud.h into /common folder.

    Heres the Android.mk:

    LOCAL_PATH := $(call my-dir)

    -----------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := loud
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_SRC_FILES := common/loud.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_SHARED_LIBRARY)

    -----------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := fitter
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_LDFLAGS := -WI,--export-dynamic
    LOCAL_SRC_FILES := common/fitter.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_SHARED_LIBRARY)

    -----------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := counter
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_LDFLAGS := -WI,--export-dynamic
    LOCAL_SRC_FILES := counter.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    LOCAL_STATIC_LIBRARIES := fitter loud
    include $(BUILD_SHARED_LIBRARY)

    -----------------------------------

    The correct libcounter.so, libfitter.so and libloud.so files were made and appeared in lib folder on my device, but I too get

    01-27 19:29:02.675: D/POST(25521): error: ... couldn't create

    so no go :(

    Not a big deal as I could recreate counter anyway, glad to learn more about packaging externals, but like Luong, theres alot of cool stuff in cyclone that I would too like to use. So keen to hear if anyone can figure this one out.

    Mainly for my own ref, but the git's here if anyones interested:

    https://github.com/Kapsy/CounterExternal1

  • NitroooNitrooo Posts: 21
    edited January 2013

    This is not going to fix the issue, but anyway in general you may want to build the needed libraries as static, so that you don't have to distribute additional .so files: "include $(BUILD_STATIC_LIBRARY)".

  • luongluong Posts: 5
    edited January 2013

    Hi everyone.

    I just nailed this, kind of.

    The problem is that libpd (if I am not wrong) wants your source files under the "jni" folder.
    Without any subfolder.

    So at the beginning, under my Eclipse project, I got something like this:




    [jni]

    [cyclone]

    [shared]

    shared.c

    shared.h

    [common]

    loud.c

    loud.h

    [sickle]

    sic.c

    sic.h

    [sickle]

    reson.c

    Android.mk

    Application.mk




    Because I just copied the source files needed by reson~, directly from the cyclone source tarball, keeping the directory structure.

    With that directory structure, and correctly edited makefiles (copied and edited from the ScenePlayer example, as pointed by the libpd documentation), the NDK compiler compiles everything without any error, creating the various .so files accordingly.

    But then, when the Android app is launched, libpd could not load the reson~ component.

    Now I have changed the directory structure to this:




    [jni]

    shared.c

    shared.h

    loud.c

    loud.h

    sic.c

    sic.h

    reson.c

    Android.mk

    Application.mk




    So everything is directly contained in the jni folder.

    And I manually edited all the #include statements of the .c files so that they does not point at any subdirectory, but to the .h files directly.

    With these changes, reson~ is correctly compiled and loaded in the Android app.

  • NitroooNitrooo Posts: 21

    Great! :-bd

    I'm gonna give a try later!

    Thank you very much!

  • kapsykapsy Posts: 30

    Awesome - gonna try right now! Thanks alot luong! :bz

    Nitrooo - does that mean if I compile the first two libs as static (fitter and loud), that only one .so file would be created?

  • NitroooNitrooo Posts: 21

    Yes, as far as I remember you'd get just the external's .so file.

  • kapsykapsy Posts: 30

    Just answered my own q - thanks, now getting just the one libcounter.so

  • kapsykapsy Posts: 30

    Ok,

    Just tried exactly as you said with the counter external - no sub dirs, all includes and c files in the jni/ folder, edited the counter.c to reflect that too- compiled fine, but... still getting a 'can't create'.

    Tried uninstalling the app, deleting the obj and libs folders and built again just to be sure but still 'can't create'.

    Will give reson~ a go in case I'm doing something wrong.

    PS: updated https://github.com/Kapsy/CounterExternal1 with what I tried with Luongs fix.

  • luongluong Posts: 5
    edited January 2013

    Hi kapsy,

    I have checked your github source code, in particular CounterExternal1Main.java .

    Seems that your problem is that you don't load externals altogether.

    Libpd gives you two ways to do this:

    1) Use a Service, through PdService.

    2) Load them programmatically calling PdBase.addToSearchPath(String path); [This is what PdService does for you, btw]

    So, in CounterExternal1Main.java, add this line before PdAudio.initAudio(22050, 0, 2, 1, true); in your initPd():

    PdBase.addToSearchPath("/data/data/"+getPackageName()+"/lib");

    Note: addToSearchPath() can be used for PD patches externals too (.pd files), not only for "compiled from C" ones.

  • kapsykapsy Posts: 30
    edited January 2013

    Hi luong, thanks for taking the time to check my code. Tried PdBase.addToSearchPath(), and it worked... thanks! ;;)

    Now getting:

    01-29 11:31:57.839: D/POST(2842): float: 1.0

    01-29 11:31:57.839: D/POST(2842): bang

    01-29 11:31:58.871: D/POST(2842): float: 2.0

    01-29 11:31:58.871: D/POST(2842): bang

    01-29 11:31:59.843: D/POST(2842): float: 3.0

    The float outputs are coming from cyclone's counter.

    So, I then assuming the reason I could run freeverb external without PdBase.addToSearchPath() was that I was running Pd as a service, whereas the counter test I wasn't...

    Can't wait to get onto some other cyclone externals.

    Do you have an idea as to why subfolders don't work?

  • luongluong Posts: 5

    Glad to know that it works!

    I don't know why subfolders don't work... :P

  • abeshiusabeshius Posts: 9

    Hello Guys!

    I have been trying to get the svf~ external from the cyclone library working inside my android project but to no avail. I have followed pretty much every step that's highlighted in this thread. Initially I was getting problems with building the external, but then I followed kapsy's github project for the Android.mk file and I could create the libraries in the specific architecture folders. Eventually I managed to get libpd to recognise my external. The following is my logcat output :

    02-05 03:23:28.693: I/PdUiDispatcher(7475): print: /data/data/processing.test.synthcircle/files/./ref/svf~.pd_linux: Cannot load library: load_library(linker.cpp:761): not a valid ELF executable: /data/data/processing.test.synthcircle/files/./ref/svf~.pd_linux
    02-05 03:23:28.693: I/PdUiDispatcher(7475): print:
    02-05 03:23:28.693: I/PdUiDispatcher(7475): print:

    02-05 03:23:28.693: I/PdUiDispatcher(7475): print: svf~
    02-05 03:23:28.693: I/PdUiDispatcher(7475): print:

    02-05 03:23:28.693: I/PdUiDispatcher(7475): print: 500
    02-05 03:23:28.693: I/PdUiDispatcher(7475): print:

    02-05 03:23:28.693: I/PdUiDispatcher(7475): print: 2
    02-05 03:23:28.693: I/PdUiDispatcher(7475): print:
    02-05 03:23:28.693: I/PdUiDispatcher(7475): print: error: ... couldn't create

    I have been using PdService in my code, and I am absolutely at my wits end as to what may be going wrong. I am no expert in building ndk code and this is my first time, but the fact that I did get some sort of an output for svf~ and then error : couldn't create and I am getting no audio output from my app. Please help. It would be greatly appreciated.

  • pbrinkmannpbrinkmann Posts: 686 ✭✭

    Are you using the latest version of Pd for Android? It looks like Pd is trying to load svf~.pd_linux. With the latest revision, the external should be called libsvf_tilde.so.

  • abeshiusabeshius Posts: 9
    edited February 2013

    Hi Peter, thanks for replying. I don't know why its using the svf~.pd_linux.I am using the latest version of pd for android. This is what my Android.mk looks like :

    LOCAL_PATH := $(call my-dir)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := shared
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_SRC_FILES := shared.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_STATIC_LIBRARY)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := loud
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_LDFLAGS := -WI,--export-dynamic
    LOCAL_SRC_FILES := loud.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_STATIC_LIBRARY)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := sic
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_SRC_FILES := sic.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_STATIC_LIBRARY)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := svf_tilde
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_LDFLAGS := -WI,--export-dynamic
    LOCAL_SRC_FILES := svf.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    LOCAL_STATIC_LIBRARIES := shared loud sic
    include $(BUILD_SHARED_LIBRARY)

    ---------------------------------------------------------------

    Initially, I had imported the svf~.pd_linux in my /ref folder where the patch is kept to test out the patch on my computer. I had then removed it, zipped it and let PdService load the patch for my project. This is where the patch is being loaded in the code :

    ...
    protected void loadPatch() throws IOException {
    File dir = getFilesDir();
    IoUtils.extractZipResource(
    getResources().openRawResource(processing.test.synthcircle.R.raw.vnsequencer), dir, true);
    File patchFile = new File(dir, "vnsequencer.pd");
    PdBase.openPatch(patchFile.getAbsolutePath());
    }

    ...

    I know the patch works without the svf~ external. It's only after the inclusion after which it has stopped working. Still getting the error...:couldn't create in logcat.

    Thanks a lot!

  • abeshiusabeshius Posts: 9

    Update :

    I got another external working from another library! I don't know how but it just works :) But the svf~ external in the cyclone library still doesnt work. Can anybody shed any light on this?

  • abeshiusabeshius Posts: 9

    Right. I got another external from the cyclone library working finally. I think I will stick to it as the svf~ is still giving the same error. I'll update it if I finally get it working. Looks like the order of the included static libraries was wrong. I played around with it after looking at the c header files and it seems to be working now! atleast for a couple of externals. Thanks a lot!

  • kapsykapsy Posts: 30

    Hi abeshius. Does that mean you ended up getting svf~ working? I haven't seen the "not a valid ELF executable" error before (having built only 2 externals so far ;) )

  • pbrinkmannpbrinkmann Posts: 686 ✭✭

    By the way, with the new approach to handling externals, you don't have to worry about packaging them anymore. The ndk-build tool will put the binaries in the libs directory, and the installer will automatically pick the right one for each device. Then PdService will add the libs directory to Pd's search path, and after that it's ready to use.

  • abeshiusabeshius Posts: 9

    Hi kapsky. I didn't get the svf~ working for some reason and to be honest I gave up. I used something called lores~ in the same library and that compiled without any error. Looking through the thread and my Android.mk file, I realised that the order was wrong. So in case somebody wands to build something from the /sickle portion of the cyclone library, you can follow this format(please correct me if I am wrong)

    LOCAL_PATH := $(call my-dir)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := shared
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_SRC_FILES := shared.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_STATIC_LIBRARY)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := sic
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_SRC_FILES := sic.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_STATIC_LIBRARY)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := loud
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_SRC_FILES := loud.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    include $(BUILD_STATIC_LIBRARY)

    ---------------------------------------------------------------

    include $(CLEAR_VARS)
    LOCAL_MODULE := lores_tilde
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../pd-for-android/PdCore/jni/libpd/pure-data/src
    LOCAL_CFLAGS := -DPD
    LOCAL_LDFLAGS := -WI,--export-dynamic
    LOCAL_SRC_FILES := lores.c
    LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../../pd-for-android/PdCore/libs/$(TARGET_ARCH_ABI) -lpd
    LOCAL_STATIC_LIBRARIES := shared sic loud include
    include $(BUILD_SHARED_LIBRARY)

    ---------------------------------------------------------------

    In my previous post the order of building the static library for sic and loud were interchanged which is why I was probably getting compilation errors. The compilation of lores~ worked perfectly, and so did the implementation in the app.

  • abeshiusabeshius Posts: 9

    Hi Peter. I am sorry I didn't mean to use the work 'packaging' in that sense. I just meant, zipping it back for my code to extract it. The new implementation is indeed awesome, so thank you so very much for coming up with something as awesome like libpd :)
    No progress with the svf~ however. Atleast not yet. If i get it working and i find out its something silly, I will let you know. Thanks a lot guys!

  • pbrinkmannpbrinkmann Posts: 686 ✭✭
    edited February 2013

    Glad to hear that you're enjoying libpd! About packaging your externals, that's exactly what I meant. With the new approach, you don't even have to zip and extract them anymore. The Android build tools will compile and package and deploy them automatically. If you're using PdService, then your externals will be ready to use as soon as you compile them with ndk-build.

  • kapsykapsy Posts: 30

    Yeah that is pretty cool... I checked out some code for what you have to do to get externals working before the new pd and to be honest - it seemed like more effort than it was worth! abeshius - I'm intrigued, I'm quite keen to give svf~ a go over the next few days - when I find some time I'll let you know how I go.

Sign In or Register to comment.