also this one http://puredata.info/docs/developer/Libdir, if it is not included in the above list?

No particular preference myself, the few externals I built (mrpeach, zexy, abl_link~) just seemed to work out of the box with their makefiles on Bela, as long as I could figure out what the right parameter for make was (e.g.: PDINCLUDEDIR=/usr/local/include/libpd/ vs PD_INCLUDE=/usr/local/include/libpd/). Oh I also compiled all the externals that come with Pd-l2ork, so perhaps have a look at how those are handled.

    giuliomoro
    for now Ive gone with pd-lib-builder, seems to have most targets (e.g. iOS) and works well enough.
    saying that, Im sure I could easily move to others if required.

    got an external building on macOS, now off to test it with PD on bela

    make sure you specify some Cortex-A8 specific optimizations, such as:
    O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize and - if you use gcc- : --fast-math

      ok, I have this now working nicely with pd-lib-builder...

      it already has detection for RPI2 etc, so basically all I need to do was detect it was 'bela', the best i could think of was to look at release. so here are the simple changes I made... (diff , so + means added line)

      giuliomoro , do you think there is a better way to detect bela?
      Ive created a fork of pd-lib-builder, if we have an agreed approach then I can issue a PR to add bela as a target

      changes made to pd-lib-builder
      pd-lib-builder/Makefile.pdlibbuilder

       # Beagle, Udoo, RPi2 etc.
       ifeq ($(machine), armv7l)
      +release := $(shell uname -r)
      +ifeq (`$(findstring $`(release), 3.8.13xenomai-bone41), $(release))
      +  $(info bela build)
      +  arch.c.flags = -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize --fast-math
      +else
         arch.c.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard
       endif
      +endif

      then you can compile with this, to build and install it into the correct place for bela to pick it up.

      make PDINCLUDEDIR=/usr/local/include/libpd/  PDLIBDIR=~/Bela/projects/pd-externals install

      BTW... ive just noticed... if I'm powered off USB (connected to computer etc) its extremely noisy (unbearable), yet perfectly ok, if its power via 5v jack, normal?

      Side note: not quite sure what the best approach for building externals for windows is...pd_lib_builder (& others) seem to use MinGW, which whilst they work, appear to mean you need to have MinGW installed/setup to use the external... since the generated dll is dependent on it. not really an issue for me, not really a big windows user 🙂

        thetechnobear giuliomoro , do you think there is a better way to detect bela?

        Not sure.

        Truth is, there is nothing special about Bela in the way you build externals (except if you want to use POSIX wrappers for Xenomai, but that is a different story), so the compiler flags I suggested above are good for any Cortex-A8. In fact, the Pi2 has 4 Cortex-A8 cores, so the same flags should work fine for it as well.

        Perhaps try to grep /proc/cpuinfo

        processor	: 0
        model name	: ARMv7 Processor rev 2 (v7l)
        BogoMIPS	: 993.47
        Features	: swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls
        CPU implementer	: 0x41
        CPU architecture: 7
        CPU variant	: 0x3
        CPU part	: 0xc08
        CPU revision	: 2
        
        Hardware	: Generic AM33XX (Flattened Device Tree)
        Revision	: 0000
        Serial		: 0000000000000000

        If you find things like neon in there, this will be good indicators that you would need -mfpu=neon, and probably --fast-math. Note: using -mfpu=neon is needed to actually use the Neon fpu because otherwise the compiler would tend to use the vfpv3, for most stuff, as the latter is IEEE754-compliant, while Neon is not. But we tend not to care about denormals and/or signed NANs when doing audio, so we are happy with the faster, non-compliant Neon. Similarly. -ffast-math tells the compiler to feel free to use non-compliant unit and operation re-ordering. Note: I just found out that -ffast-math is actually supported by clang. I guess--fast-math, which I was using earlier, was just a legacy gcc option? Bottom line: you can use -ffast-math regardless of the compiler.

        However, grepping for neon is not enough for -mtune=cortex-a8. In practice, I am not even sure -mtune=cortex-a8 is needed when compiling natively. You can check running gcc with --verbose without -mtune if -mtune=cortex-a8 is implied. If that is implied, it would also be interesting to see how gcc detects that.

        -ftree-vectorize is good for any architecture which has a SIMD unit (that is: probably all architectures that you would build Pd externals for, these days). It does not seem to be implied by -O3, but also I do not understand the difference between this and -free-loop-vectorize. More here.

        -mfloat=hard is system dependent but I am not sure how you would detect it. Again, probably the presence of neon or vfp would make you think that there is a floating point unit and that -mfloat=hard, because it would be silly - and slower - to run soft-float. Again, this can probably be omitted when compiling natively, and again you can check with --verbose.

        Last, if from cpuinfo you get

        Hardware	: Generic AM33XX (Flattened Device Tree)

        there is a pretty good chance you are on a BeagleBone, and if you get that, plus something from uname -a | grep -i xeno, then you most likely are on Bela.

        Forgot to mention:
        sometimes a great performance booster on the Cortex A8 can be achieved using single precision constants. This is because expressions like

        float b = 1;
        float a = 0.5 * b;

        the second line will do something along the lines of:

        • notice that 0.5 is a double constant
        • extend b to a double and to a full 64-bit precision double multiplication
        • narrow down the result to a float and store it into a

        double operation on the A8 are supported only on the vfp, therefore the multiplication above would never run on the Neon unit.
        If you write the code, you could fix it by adding an f to the floating point constant:

        float b = 1;
        float a = 0.5f * b;

        or type-casting the constant it or assigning it to a variable before using it (best is to type cast to something like sample_t which is also appropriately typedefined elsewhere in the code.
        Instead of changing the source code, a low-hanging fruit is the solution of telling gcc: -fsingle-precision-constant (unsupported by clang). However, this may lead to potential precision issues where the programmer actually wanted to store a double precision constant, as it would turn ALL floating point constants to single-precision (including those assigned to a double variable). Therefore, the program

        #include <stdio.h>
        
        void main(void)
        {
            float a = 99.99999999;
            double b = 99.9999999;
            printf("a: %.20f,\nb: %.20f\n", a, b);
        }

        would produce:
        without -fsingle-precision-constant

        a: 100.00000000000000000000,
        b: 99.99999990000000593682

        with -fsingle-precision-constant

        a: 100.00000000000000000000,
        b: 100.00000000000000000000

        Whether this is a problem or not, is very much dependent on the codebase, so I would advise against adding it to the compiler flags by default.

        23 days later

        Hi All,

        Novice questions. Even reading this thread I am unsure about what is going on.

        So some quick questions -

        1/ I have been to patch storage and I would like to use The Soundhack plugins on my Bela. Is this possible? I see source code is provided
        2/ I see some of them are compiled for Organelle does that mean they can be put on Bela? Moreover can Organelle patches be used on Bela?
        3/If all that is possible where do I start learning about compiling patches on Bela, that will explain what is going on.

        I know I am trying to run before I can walk but the Organelle folks have it great and I want some of the fun and make my own interface!!

        Thanks for your time.

        Best
        S

        I am not sure what architecture the Organelle runs on. Is it x86 or ARM?
        If it's ARM, then possibly Pd externals compiled for it may run on Bela, as long as they have been compiled against the same version of PureData.
        In practice, I would suggest you compile your own. It is normally straightforward, but it could be painful.

        Most externals come with a Makefile or any other script to build them. If you are lucky they will also have some documentation. You would normally:

        • copy the folder to Bela
        • have a look at the Makefile. There should be a variable called something like PDINCLUDEDIR or PD_INCLUDE (see examples above). When you invoke make you need to define that variable on the command line so that it points to the folder where the libpd headers are. In the case of Bela, this is /usr/local/include/libpd/.
        • from a terminal, cd into the folder and type something like make PDINCLUDEDIR=/usr/local/include/libpd/ (or replace PDINCLUDEDIR with the appropriate variable requested by your Makefile.
        • hopefully this will work and you will get a file called externalaname.pd_linux. If you do, then copy that over to /root/Bela/projects/pd-externals/ and you can then start using it in your patches.
        • if the make fails, that will commonly be because of a missing dependency. The documentation that comes with the external should be able to get you through the dependencies, so try to fix that, rinse and repeat

        If you find any issues with the above, let us know and we can probably get you through if you are stuck. Also, the examples above in this page should help you.

        Regarding Organelle patches being used on Bela, that really depends on how they are written. I have seen they have some way to access their buttons and pots which is different from ours, so you may have to edit them to be able to control them from Bela.
        However, as long as you have the needed externals, they should work, provided you do the above changes for controlling them.

        Organelle is arm, so externals will work... but as the discussion between @giuliomoro and I above, they may not be optimised for bela.

        Ive recently acquired an Organelle, so for patches/externals I'm working on, I'm planning to do Bela builds/versions, and also making a 'bela mother patch' that will be compatible with Organelle, using 4 analog pots, encoder and an oled display... this might seem odd (as I have an organelle), but it would give me something like Organelle but has very low latency, also of course, I can then do extended versions with more analog pots etc.

          Ok thanks that is heartening and something to get my teeth into. The control side of the hacking is not too much of a problem, it is more the compiling and getting any externals to work.
          thetechnobear Will you be sharing the oled display and pots info as I would love something similar. For now I will get about getting these patches working...

          Thanks again for your time.
          Best. S

            thetechnobear

            So how is the Organelle? I have been thinking if getting one as they look so cute, it's just the price that us a little galling. Is the quality up to the price?

              AndyCap I'm enjoying it more than I expected... the form factor is very enjoyable, and there some interesting patches out there.
              Given Ive got Bela and Axoloti - I was concerned it would be a bit too similar, but the immediacy of its interface (and its limitations) has actually been quite inspiring.... I've got a lot of ideas for it still brewing 🙂
              Quality seems good so far. Yeah, Id agree its quite pricey, but it is made in small volumes - so its probably a bit unfair to judge it merely on 'price of components'.

              as I said, I'm also looking forward to partnering it up with Bela/Axoloti, I think they will be nice companions.

              a couple of things id wish on an 'organelle v2', would be
              - the 4 pots should also be endless encoders... makes much more sense with the oled
              - battery power 🙂

              Smuff sure once I finally get around to building it fully - the main thing I keep stumbling over with Bela though, is sorting out some kind of enclosure/mounting - every time I try, I end up binning it and starting again!
              ( I guess, why I like the fact Organelle was already finished 😉)

                thetechnobear

                Thanks for all the info, I think I may have to get one. I do like the look of them.

                8 days later

                thetechnobear I would like some kind of CV connections as well as your suggestions especially the rotary encoders. That is why I am hanging on hoping for the Bela CV module. This is all good I still have a way to go understanding PD patches in Bela but that is my issue. Good luck on making yours...

                7 months later

                Hi,

                I've been trying to compile an external to use with the Bela. The instructions I've been able to parse from above don't seem to work, first of all because there doesn't seem to a libpd file in the include directory:

                alt text

                Is there a new process for this? I haven't been able to find anything else recent in the forum about making externals on the board.

                Thanks,
                Colin

                Yeah sorry the include folder is now in /usr/local/include/libpd

                I updated the posts above to reflect this.

                  so if you are cross-compiling, you will need to copy those files from the board on to your computer (or mount the filesystem remotely)

                  I'm trying to build the external on the Bela, so no cross compiling. Just looking for a proper Makefile now.

                  5 days later

                  giuliomoro
                  I have an external that seems to have compiled ok, but doesn't seem to be functioning properly on the Bela. It works fine on all other systems - I've tested it on OSX, Windows 10, and Ubuntu. For some reason, I can't get proper values when I run it on the Bela. I'm wondering if I could send you the files and have you double check them. I totally understand if this is a pain, though. In case it's not and you have a spare moment... The object does a cross correlation on two audio signals and writes the result to an array (first outlet), as well as provides the index from the center of the array (second outlet), and gives the peak value (third outlet). The first two inlets are for the audio signal, and the third is for a calibration input (which doesn't seem to be working, hence the expr~ object). Here is a link to all the necessary files to compile and run if you do have the inclination: https://www.dropbox.com/s/g5wtmicokn1r1xg/xcorr.zip?dl=0

                  Thanks!
                  Colin

                  Hi Colin,
                  the difference between platforms could be due to the fact that on Bela Pd's internal blocksize is 16, while in Pd it defaults to 64. Your code does an FFT of the size of the incoming buffer, so maybe mayer_reallfft() does not like an FFT of size 16?

                  Note that you cannot change this parameter at runtime: you would need to recompile libpd editing

                  #define DEFDACBLKSIZE 16

                  to

                  #define DEFDACBLKSIZE 64

                  in

                  libpd/pure-data/src/s_stuff.h

                  To recompile libpd:

                  git clone https://github.com/BelaPlatform/libpd.git
                  git submodule init
                  git submodule update --recursive
                  .... do your change to pure-data/src/s_stuff.h
                  make -f Makefile-Bela
                  make -f Makefile-Bela install

                  PS: I like the comments to the Pd API in your xcorr~.cfile: very instructive.

                  EDIT: using https for git clone