How to execute tanf from math.h?

dsp
faust
math

#1

Hey!

I am trying to port some filters from faust to axoloti and I am having some trouble executing a standard function. What is the correct way to get tanf to work?

Generate code complete
Start compiling patch
Compiling patch... with /Applications/Axoloti.app/Contents/Java/firmware
BDIR = /Users/logsol/Documents/axoloti/build
FIRMWARE = .
RM
APP
! /Users/logsol/Documents/axoloti/build/xpatch.h.gch
. /Applications/axoloti_runtime/platform_osx/arm-none-eabi/include/math.h
. /Applications/axoloti_runtime/platform_osx/lib/gcc/arm-none-eabi/4.9.3/include/stdint.h
. /Applications/axoloti_runtime/platform_osx/arm-none-eabi/include/stdlib.h
LINK
/Users/logsol/Documents/axoloti/build/xpatch.o: In function `PatchProcess(long*, long*)':
xpatch.cpp:(.text+0xc0): undefined reference to `tanf'

In the output log I see that math.h is being included and when I search this file, I do see a reference to tanf in it:

...
/* Single precision versions of ANSI functions.  */

extern float atanf _PARAMS((float));
extern float cosf _PARAMS((float));
extern float sinf _PARAMS((float));
extern float tanf _PARAMS((float));
extern float tanhf _PARAMS((float));
extern float frexpf _PARAMS((float, int *));
extern float modff _PARAMS((float, float *));
extern float ceilf _PARAMS((float));
extern float fabsf _PARAMS((float));
extern float floorf _PARAMS((float));
...

Can anybody shine some light on this? Or maybe I should be using another tangent implementation altogether?

Cheers!


#2

Not sure how to get it working, by importing libraries, but I checked the Faust documentation:

It seems like it's the same as tanh/atan functions, but at signal rate. So if it's not too complicated, maybe you can just replace it with a tanh approximation?

I made a tanh approximation object for axoloti, you can find it in the community library : jaffa/sat/tanh

PS.
Sounds interesting about the filters. Is it something that might be added to the community library? :slight_smile:


#3

Including the header file is not enough. The header file only tells the compiler that such a function exits and not to worry about it, the linker will add it later. But the linker wants to be told explicitly which libraries to pull additional functions from. Usually you'd just add an option ( -lm for the math library) to the command line that starts the compiler, but as the Axoloti software calls the compiler automatically I don't know if it is possible to add such options somewhere.
It's probably easier to just copy'n'paste the source for this function from somewhere into your own code.


#4

Ahh that is why! Makes sense, thanks!

Luckily I found out that tan(x) is equivalent to sin(x) / cos(x) so I am using sinf(x) / cosf(x) as a workaround, which seems to work fine!

Would be interesting to find out though if it is somehow possible to make a patch add such compiler options..

Yes, if I get it to work, I'd be happy to share :slight_smile:


#5

It is an old topic, but let's shed some light on tweaking axoloti firmware.

Firstly, I guess for a tanf function it is better to checkout the dsp/filter.h of the stmlib instead of going with sinx/cosx. https://github.com/pichenettes/stmlib/blob/master/dsp/filter.h
Many functions are left out of the axoloti, this is to preserve space and to remove expensive functions (like tan).

However, if you like going down the rabbit hole :rabbit2:, you can add lot's of stuff (like adding useful arm algorithms, optimizations, dsp algorithms) by tweaking the firmware build. In the firmware folder of your installation you will find a compile_firmware_{platform} file, tweak the Makefile to add stuff to the firmware, run the build script and you should be good to go. I needed this once for some arm related libraries (CMSIS DSP) and for adding USB SysEx support.

Once you compiled the firmware, the Axoloti IDE will notice the changed firmware CRC and asks you to flash your board with the new version. All previously compiled patches need to be recompiled to make them work and obviously your new patches will not be compatible with the 'standard' axoloti software.