diff --git a/.gitignore b/.gitignore
index 21b780e5..efa9bc45 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
*.pro.user
build/
+.idea/
+*.iml
\ No newline at end of file
diff --git a/README.md b/README.md
index 03012061..0440cf49 100644
--- a/README.md
+++ b/README.md
@@ -320,7 +320,7 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
Tim Schneeberger (ThePBone)
- 7094 words
+ 7284 words
@@ -341,7 +341,14 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
Katie Frogs (KatieFrogs)
- 2670 words
+ 2848 words
+ |
+
+
+
+ catvinyl
+
+ 2352 words
|
@@ -355,7 +362,7 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
NullPointerException (seqfault)
- 1106 words
+ 1151 words
|
@@ -364,6 +371,8 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
373 words
|
+
+
@@ -371,8 +380,13 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
240 words
|
-
-
+
+
+
+ AnClark Liu (AnClark)
+
+ 173 words
+ |
@@ -387,6 +401,13 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
114 words
|
+
+
+
+ James Fung (james34602)
+
+ 72 words
+ |
@@ -408,6 +429,8 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
13 words
|
+
+
diff --git a/libjamesdsp/libjamesdsp.pro b/libjamesdsp/libjamesdsp.pro
index b89150cc..2d050509 100644
--- a/libjamesdsp/libjamesdsp.pro
+++ b/libjamesdsp/libjamesdsp.pro
@@ -10,6 +10,8 @@ QMAKE_CFLAGS += -std=gnu11 -O2
CONFIG += warn_off # Disable warnings for library
+DEBUG_ASAN: CONFIG += sanitizer sanitize_address
+
# Enable liveprog logging redirection
DEFINES += CUSTOM_CMD
@@ -55,7 +57,22 @@ HEADERS += \
$$BASEPATH/jdsp_header.h \
EELStdOutExtension.h \
PrintfStdOutExtension.h \
- JdspImpResToolbox.h
+ JdspImpResToolbox.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxpre.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxxsrc/xcomplex.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxxsrc/xreal.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/doc/xcomplex.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/doc/xreal.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/hpaconf.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/mp/const07.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/mp/const11.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/mp/const15.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/mp/const19.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/mp/const23.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/mp/const27.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/mp/const31.h \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xpre.h \
+ $$BASEPATH/Effects/info.h
SOURCES += \
$$BASEPATH/Effects/arbEqConv.c \
@@ -105,7 +122,45 @@ SOURCES += \
EELStdOutExtension.c \
PrintfStdOutExtension.c \
JdspImpResToolbox.c \
- subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/multimodalEQ.c
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/atox.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/constant.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxaop.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxbasic.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxconstant.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxconvf.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxexp.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxhypb.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxidiv.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxpow.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxprcmp.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/cxtrig.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/hpaconf.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/prcxpr.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/print.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/prxpr.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/sfmod.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/shift.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xadd.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xchcof.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xdiv.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xevtch.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xexp.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xfmod.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xfrac.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xhypb.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xivhypb.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xivtrg.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xlog.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xmul.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xneg.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xprcmp.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xpwr.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xsigerr.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xsqrt.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xtodbl.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xtoflt.c \
+ $$BASEPATH/Effects/eel2/numericSys/HPFloat/xtrig.c \
+ $$BASEPATH/Effects/multimodalEQ.c
unix {
isEmpty(LIBDIR) {
diff --git a/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj b/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj
index 48449f46..b641fffb 100644
--- a/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj
+++ b/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj
@@ -38,7 +38,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -50,8 +90,8 @@
-
+
@@ -83,14 +123,17 @@
+
+
+
-
+
@@ -103,33 +146,33 @@
{0B79F137-4D4B-448F-95FF-2E6D56BE770B}
Win32Proj
JamesDSPLib
- 10.0.19041.0
+ 10.0
JamesDSPLib
Application
true
- v141
+ v142
MultiByte
Application
false
- v141
+ v142
true
MultiByte
Application
true
- v141
+ v142
MultiByte
Application
false
- v141
+ v142
true
MultiByte
diff --git a/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj.filters b/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj.filters
index d742efd2..7569d18c 100644
--- a/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj.filters
+++ b/libjamesdsp/subtree/Main/CLI/JamesDSPLib.vcxproj.filters
@@ -44,9 +44,6 @@
jdsp\Effects
-
- jdsp\Effects
-
jdsp\Effects
@@ -134,6 +131,129 @@
jdsp\Effects\eel2\numericSys\SolveLinearSystem
+
+ jdsp\Effects
+
+
+ jdsp\Effects\eel2\numericSys\libsamplerate
+
+
+ jdsp\Effects\eel2\numericSys\FilterDesign
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
@@ -160,6 +280,9 @@
{120faa8f-8a0e-42a8-86c4-bfe62ab09b72}
+
+ {8a0ba327-7ca9-4821-9afb-ef3d7eca4812}
+
@@ -249,11 +372,20 @@
jdsp\Effects\eel2\numericSys\libsamplerate
-
- jdsp\Effects\eel2\numericSys\libsamplerate
-
jdsp\Effects\eel2\numericSys\SolveLinearSystem
+
+ jdsp\Effects
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
+
+ jdsp\Effects\eel2\numericSys\HPFloat
+
\ No newline at end of file
diff --git a/libjamesdsp/subtree/Main/CLI/desktop.ini b/libjamesdsp/subtree/Main/CLI/desktop.ini
deleted file mode 100644
index d957fd18..00000000
--- a/libjamesdsp/subtree/Main/CLI/desktop.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[ViewState]
-Mode=
-Vid=
-FolderType=Generic
diff --git a/libjamesdsp/subtree/Main/CLI/hpfloat.eel b/libjamesdsp/subtree/Main/CLI/hpfloat.eel
new file mode 100644
index 00000000..ff66de86
--- /dev/null
+++ b/libjamesdsp/subtree/Main/CLI/hpfloat.eel
@@ -0,0 +1,94 @@
+desc: Hadamard Variable Delay Array
+
+@init
+// Constants
+printf("hZero: %F\n", $hZero);
+printf("hOne: %F\n", $hOne);
+printf("hTwo: %F\n", $hTwo);
+printf("hTen: %F\n", $hTen);
+printf("hPinf: %F\n", $hPinf);
+printf("hMinf: %F\n", $hMinf);
+printf("hNaN: %F\n", $hNaN);
+printf("hPi: %F\n", $hPi);
+printf("hPi2: %F\n", $hPi2);
+printf("hPi4: %F\n", $hPi4);
+printf("hEe: %F\n", $hEe);
+printf("hSqrt2: %F\n", $hSqrt2);
+printf("hLn2: %F\n", $hLn2);
+printf("hLn10: %F\n", $hLn10);
+printf("hLog2_e: %F\n", $hLog2_e);
+printf("hLog2_10: %F\n", $hLog2_10);
+printf("hLog2_e: %F\n", $hLog2_e);
+printf("HPA_MIN: %F\n", $HPA_MIN);
+printf("HPA_MAX: %F\n", $HPA_MAX);
+// Arithmetic
+num256b_1 = xFloatS("0.4121114214214945995439191");
+num256b_2 = xFloatF(-4.1456);
+str1 = xF2str(num256b_2);
+flt1 = xF2f32(num256b_1);
+printf("Load from string 1: %F\nLoad from string 2: %s\nConvert back to float32: %f\n", num256b_1, str1, flt1);
+
+var1 = xAdd(num256b_1, num256b_2);
+var2 = xSub(num256b_1, num256b_2);
+var3 = xMul(num256b_1, num256b_2);
+var4 = xDiv(num256b_1, num256b_2);
+var5 = xclone(num256b_1);
+printf("Add(var1): %F\nSub(var2): %F\nMul(var3): %F\nDiv(var4): %F\nCloned variable: %F\n", var1, var2, var3, var4, var5);
+
+var6 = xsin(var1);
+var7 = xcos(var2);
+var8 = xtan(var3);
+var9 = xasin(var1);
+var10 = xacos(xfrac(var2));
+var11 = xatan(var3);
+var12 = xsinh(var1);
+var13 = xcosh(var2);
+var14 = xtanh(var3);
+var15 = xasinh(var1);
+var16 = xacosh(var2);
+var17 = xatanh(xfrac(var3));
+var18 = xatan2(xFloatS("-0.8"), xFloatS("2.7"));
+printf("sin(var1): %F\n", var6);
+printf("cos(var2): %F\n", var7);
+printf("tan(var3): %F\n", var8);
+printf("asin(var1): %F\n", var9);
+printf("acos(xfrac(var2)): %F\n", var10);
+printf("atan(var3): %F\n", var11);
+printf("sinh(var1): %F\n", var12);
+printf("cosh(var2): %F\n", var13);
+printf("tanh(var3): %F\n", var14);
+printf("asinh(var1): %F\n", var15);
+printf("acosh(var2): %F\n", var16);
+printf("atanh(frac(var3)): %F\n", var17);
+printf("xatan2(-0.8, 2.7): %F\n", var18);
+var19 = xround(xFloatS("-10.8"));
+var20 = xceil(xFloatS("-10.8"));
+var21 = xfloor(xFloatS("-10.8"));
+var22 = xtrunc(xFloatS("-10.8"));
+var23 = xfix(xFloatS("-10.8"));
+var24 = xfrac(xFloatS("80.84125"));
+printf("round(-10.8): %F\nceil(-10.8): %F\nfloor(-10.8): %F\ntrunc(-10.8): %F\nfix(-10.8): %F\nfrac(-10.8): %F\n", var19, var20, var21, var22, var23, var24);
+var25 = xNegation(var17);
+printf("-var17 = %F\n", var25);
+var26 = xsqrt(xabs(var22));
+var27 = xexp(var22);
+printf("sqrt(abs(var22)) = %F\n", var26);
+
+logic1 = xequal(var5, num256b_1);
+logic2 = xequal(var5, var20);
+printf("Is var5 == num256b_1 -> %d\n", logic1);
+printf("Is var5 == var20 -> %d\n", logic2);
+printf("Is var6 <= var7 -> %d\n", xlessequal(var6, var7));
+printf("Is var6 < var7 -> %d\n", xless(var6, var7));
+printf("Is var18 >= var17 -> %d\n", xgreaterequal(var18, var17));
+printf("Is var17 > var18 -> %d\n", xgreater(var17, var18));
+
+printf("exp(0.421) = %F\n", xexp(xFloatS("2.214")));
+printf("exp2(0.421) = %F\n", xexp2(xFloatS("2.214")));
+printf("exp10(0.421) = %F\n", xexp10(xFloatS("2.214")));
+printf("log(0.221) = %F\n", xlog(xFloatS("2.214")));
+printf("log2(0.221) = %F\n", xlog2(xFloatS("2.214")));
+printf("log10(0.221) = %F\n", xlog10(xFloatS("2.214")));
+printf("pow(12.54, 16.45) = %F\n", xpow(xFloatS("12.54"), xFloatS("16.45")));
+printf("intpow(12.54, 280) = %F\n", xintpow(xFloatS("12.54"), 290));
+@sample
diff --git a/libjamesdsp/subtree/Main/CLI/main.c b/libjamesdsp/subtree/Main/CLI/main.c
index e262622b..6c12850a 100644
--- a/libjamesdsp/subtree/Main/CLI/main.c
+++ b/libjamesdsp/subtree/Main/CLI/main.c
@@ -5,31 +5,8 @@
#include
#include "../libjamesdsp/jni/jamesdsp/jdsp/jdsp_header.h"
#include "../libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/dr_wav.h"
-// Windows
-#ifdef _WIN32
-#include
-#include
-////////////////////////////////////////////////////////////////////
-// Performance timer
-double get_wall_time()
-{
- LARGE_INTEGER time, freq;
- if (!QueryPerformanceFrequency(&freq))
- return 0;
- if (!QueryPerformanceCounter(&time))
- return 0;
- return (double)time.QuadPart / freq.QuadPart;
-}
-double get_cpu_time()
-{
- FILETIME a, b, c, d;
- if (GetProcessTimes(GetCurrentProcess(), &a, &b, &c, &d) != 0)
- return (double)(d.dwLowDateTime | ((unsigned long long)d.dwHighDateTime << 32)) * 0.0000001;
- else
- return 0;
-}
#include
-char* openTextFile(char *fileSelectorPath)
+char *openTextFile(char *fileSelectorPath)
{
char *buffer = 0;
long length;
@@ -39,7 +16,7 @@ char* openTextFile(char *fileSelectorPath)
fseek(textFile, 0, SEEK_END);
length = ftell(textFile);
fseek(textFile, 0, SEEK_SET);
- buffer = (char*)malloc(length + 1);
+ buffer = (char *)malloc(length + 1);
if (buffer)
fread(buffer, 1, length, textFile);
fclose(textFile);
@@ -48,10 +25,10 @@ char* openTextFile(char *fileSelectorPath)
return buffer;
}
extern void JamesDSPOfflineResampling(float const *in, float *out, size_t lenIn, size_t lenOut, int channels, double src_ratio);
-float* FileSelecterPopupWavFileWin32(char *fileSelectorPath, double targetFs, unsigned int *channels, size_t *totalPCMFrameCount)
+float *FileSelecterPopupWavFileWin32(char *fileSelectorPath, double targetFs, unsigned int *channels, size_t *totalPCMFrameCount)
{
unsigned int fs;
- float* pSampleData = drwav_open_file_and_read_pcm_frames_f32(fileSelectorPath, channels, &fs, totalPCMFrameCount, 0);
+ float *pSampleData = drwav_open_file_and_read_pcm_frames_f32(fileSelectorPath, channels, &fs, totalPCMFrameCount, 0);
if (pSampleData == NULL)
{
printf("Error opening and reading WAV file");
@@ -72,47 +49,13 @@ float* FileSelecterPopupWavFileWin32(char *fileSelectorPath, double targetFs, un
}
double ratio = targetFs / (double)fs;
int compressedLen = (int)ceil(*totalPCMFrameCount * ratio);
- float *tmpBuf = (float*)malloc(compressedLen * *channels * sizeof(float));
+ float *tmpBuf = (float *)malloc(compressedLen * *channels * sizeof(float));
memset(tmpBuf, 0, compressedLen * *channels * sizeof(float));
JamesDSPOfflineResampling(pSampleData, tmpBuf, *totalPCMFrameCount, compressedLen, *channels, ratio);
*totalPCMFrameCount = compressedLen;
free(pSampleData);
return tmpBuf;
}
-#else
-#include
-#include
-double get_wall_time()
-{
- struct timeval time;
- if (gettimeofday(&time, NULL))
- return 0;
- return (double)time.tv_sec + (double)time.tv_usec * .000001;
-}
-double get_cpu_time()
-{
- return (double)clock() / CLOCKS_PER_SEC;
-}
-#endif
-////////////////////////////////////////////////////////////////////
-char *inputString(FILE* fp, size_t size)
-{
- //The size is extended by the input with the value of the provisional
- char *str;
- int ch;
- size_t len = 0;
- str = realloc(NULL, sizeof(char)*size);//size is start size
- if (!str)return str;
- while (EOF != (ch = fgetc(fp)) && ch != '\n') {
- str[len++] = ch;
- if (len == size) {
- str = realloc(str, sizeof(char)*(size += 16));
- if (!str)return str;
- }
- }
- str[len++] = '\0';
- return realloc(str, sizeof(char)*len);
-}
char *basename(char const *path)
{
#ifdef _MSC_VER
@@ -133,10 +76,10 @@ typedef struct
float paramFloat;
} threadTest;
/* this function is run by the second thread */
-float* loadWaveFile(double targetFs, unsigned int *channels, size_t *totalPCMFrameCount)
+float *loadWaveFile(double targetFs, unsigned int *channels, size_t *totalPCMFrameCount)
{
unsigned int fs;
- float* pSampleData = drwav_open_file_and_read_pcm_frames_f32("EqResponse.wav", channels, &fs, totalPCMFrameCount, 0);
+ float *pSampleData = drwav_open_file_and_read_pcm_frames_f32("EqResponse.wav", channels, &fs, totalPCMFrameCount, 0);
if (pSampleData == NULL)
{
printf("Error opening and reading WAV file");
@@ -157,7 +100,7 @@ float* loadWaveFile(double targetFs, unsigned int *channels, size_t *totalPCMFra
}
double ratio = targetFs / (double)fs;
int compressedLen = (int)ceil(*totalPCMFrameCount * ratio);
- float *tmpBuf = (float*)malloc(compressedLen * *channels * sizeof(float));
+ float *tmpBuf = (float *)malloc(compressedLen * *channels * sizeof(float));
memset(tmpBuf, 0, compressedLen * *channels * sizeof(float));
JamesDSPOfflineResampling(pSampleData, tmpBuf, *totalPCMFrameCount, compressedLen, *channels, ratio);
*totalPCMFrameCount = compressedLen;
@@ -168,29 +111,70 @@ void *inc_x(void *x_void_ptr)
{
threadTest *x_ptr = (threadTest *)x_void_ptr;
JamesDSPLib *jdsp = x_ptr->dspPtr;
-// jdsp->crossfeedForceRefresh = 1;
-// CrossfeedChangeMode(jdsp, 3);
+ // jdsp->crossfeedForceRefresh = 1;
+ // CrossfeedChangeMode(jdsp, 3);
int impulseChannels;
size_t impFrameCount;
float *impulseResponse = loadWaveFile(jdsp->fs, &impulseChannels, &impFrameCount);
- Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount);
+ Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount, 1);
free(impulseResponse);
Convolver1DEnable(jdsp);
pthread_exit(NULL);
return NULL;
}
-FILE *tele = 0;
-FILE *tele2 = 0;
-// We support only .wav file as JDSP buffer testing and processing
-#define FILENAME "137777fs.wav"
+double freqTh[NUMPTS] = { 25.0, 40.0, 63.0, 100.0, 160.0, 250.0, 400.0, 630.0, 1000.0, 1600.0, 2500.0, 4000.0, 6300.0, 10000.0, 16000.0 };
+double gainsTh[NUMPTS] = { 5.0, -1.0, -4, -1, 2.1, 0.0, 0.0, 0.7, -10.7, 0.0, 0.0, 0.0, 0.0, 0.8, 8.0 };
+int idxN, readCountN;
+/*void *inc_eq(void *x_void_ptr)
+{
+ threadTest *x_ptr = (threadTest *)x_void_ptr;
+ JamesDSPLib *jdsp = x_ptr->dspPtr;
+ int ii = 0;
+ while (1)
+ {
+ if (idxN <= ii)
+ continue;
+ ii = idxN;
+ if (idxN > 0 && idxN < 500)
+ {
+ gainsTh[5] += 0.48;
+ if (gainsTh[5] > 64)
+ gainsTh[5] = 64;
+ MultimodalEqualizerAxisInterpolation(jdsp, 0, 5, freqTh, gainsTh);
+ }
+ else if (idxN >= 500)
+ {
+ gainsTh[5] -= 0.4;
+ if (gainsTh[5] < -64)
+ gainsTh[5] = -64;
+ gainsTh[10] -= 0.1;
+ if (gainsTh[10] < -64)
+ gainsTh[10] = -64;
+ MultimodalEqualizerAxisInterpolation(jdsp, 0, 5, freqTh, gainsTh);
+ }
+ if (idxN >= readCountN - 1)
+ break;
+ }
+ pthread_exit(NULL);
+ return NULL;
+}*/
+#define FILENAME "mus.wav"
+static inline float float_from_i32(int32_t ival)
+{
+ static const float scale = 1. / (float)(1UL << 31);
+ return ival * scale;
+}
+int32_t clamp24_from_float(float f);
int main()
{
+ char oldPath[MAX_PATH];
+ GetCurrentDirectory(MAX_PATH, oldPath);
char *text = 0;
int i;
unsigned int channels;
unsigned int sampleRate;
drwav_uint64 totalPCMFrameCount;
- float* pSampleData = drwav_open_file_and_read_pcm_frames_f32(FILENAME, &channels, &sampleRate, &totalPCMFrameCount, 0);
+ float *pSampleData = drwav_open_file_and_read_pcm_frames_f32(FILENAME, &channels, &sampleRate, &totalPCMFrameCount, 0);
if (pSampleData == NULL)
{
printf("Error opening and reading WAV file");
@@ -210,36 +194,36 @@ int main()
return -1;
}
char *filename = basename(FILENAME);
- int frameCountBest = 512;
+ int frameCountBest = 1024;
printf("[Status] Precomputing...\n");
- double wall0 = get_wall_time();
- double cpu0 = get_cpu_time();
JamesDSPGlobalMemoryAllocation();
- JamesDSPLib *jdsp = (JamesDSPLib*)malloc(sizeof(JamesDSPLib));
+ JamesDSPLib *jdsp = (JamesDSPLib *)malloc(sizeof(JamesDSPLib));
memset(jdsp, 0, sizeof(JamesDSPLib));
- JamesDSPInit(jdsp, frameCountBest - 30, sampleRate);
- JamesDSPSetSampleRate(jdsp, (float)sampleRate, 0);
- //JamesDSPSetPostGain(jdsp, -3.0);
+ JamesDSPInit(jdsp, 77, sampleRate);
+ JLimiterSetCoefficients(jdsp, 0.0, 100);
// Parameters
// DRC
- //CompressorSetParam(jdsp, 30.0, 200.0, 800.0);
- //CompressorEnable(jdsp);
+ double freqDRC[NUMPTS_DRS] = { 95.0, 200.0, 400.0, 800.0, 1600.0, 3400.0, 7500.0 };
+ double gainsDRC[NUMPTS_DRS] = { 1.0, 0.9, 0.2, 0.0, 0.0, 0.8, 1.0 };
+ for (i = 0; i < NUMPTS_DRS; i++)
+ gainsDRC[i] = -1.0;
+ CompressorSetParam(jdsp, 0.8, 4, 1, 1);
+ CompressorSetGain(jdsp, freqDRC, gainsDRC, 1);
+ CompressorEnable(jdsp, 1);
// Bass boost
- //tele = fopen("aa.txt", "wb");
- //tele2 = fopen("bb.txt", "wb");
- BassBoostSetParam(jdsp, 10.0f);
- BassBoostEnable(jdsp);
+ //BassBoostSetParam(jdsp, 10.0f);
+ //BassBoostEnable(jdsp);
// Reverb
-// Reverb_SetParam(jdsp, 4);
-// ReverbEnable(jdsp);
+ //Reverb_SetParam(jdsp, 4);
+ //ReverbEnable(jdsp);
// Stereo enhancement
- //StereoEnhancementSetParam(jdsp, 0.5f);
+ //StereoEnhancementSetParam(jdsp, 0.9f);
//StereoEnhancementEnable(jdsp);
// Vacuum tube
- //VacuumTubeEnable(jdsp);
//VacuumTubeSetGain(jdsp, 8.0);
+ //VacuumTubeEnable(jdsp);
// Live programmable DSP
- /*text = openTextFile("C:\\Users\\JamesHighPerformance\\Documents\\EELPrograms\\stftCentreCut.eel");
+ /*text = openTextFile("hadamVerb.eel");
if (text)
{
LiveProgStringParser(jdsp, text);
@@ -265,112 +249,326 @@ int main()
DDCStringParser(jdsp, text);
free(text);
}
- DDCEnable(jdsp);*/
+ DDCEnable(jdsp, 1);*/
// Crossfeed
- //CrossfeedChangeMode(jdsp, 5);
- //CrossfeedChangeMode(jdsp, 3);
- //CrossfeedEnable(jdsp);
+ /*CrossfeedChangeMode(jdsp, 5);
+ CrossfeedChangeMode(jdsp, 3);
+ CrossfeedEnable(jdsp, 1);*/
// Convolver
- /*int impulseChannels;
+ int impulseChannels;
size_t impFrameCount;
//
- float *impulseResponse = FileSelecterPopupWavFileWin32("DormSpks.wav", jdsp->fs, &impulseChannels, &impFrameCount);
- Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount);
- free(impulseResponse);
- //
- impulseResponse = FileSelecterPopupWavFileWin32("EqResponse.wav", jdsp->fs, &impulseChannels, &impFrameCount);
- Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount);
- free(impulseResponse);
+ /*float *impulseResponse = FileSelecterPopupWavFileWin32("longReverb.wav", jdsp->fs, &impulseChannels, &impFrameCount);
+ Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount, 1);
+ free(impulseResponse);*/
//
- impulseResponse = FileSelecterPopupWavFileWin32("reverb james.wav", jdsp->fs, &impulseChannels, &impFrameCount);
- Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount);
+ /*impulseResponse = FileSelecterPopupWavFileWin32("EqResponse.wav", jdsp->fs, &impulseChannels, &impFrameCount);
+ Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount, 1);
free(impulseResponse);
//
- Convolver1DEnable(jdsp);*/
+ impulseResponse = FileSelecterPopupWavFileWin32("408.wav", jdsp->fs, &impulseChannels, &impFrameCount);
+ Convolver1DLoadImpulseResponse(jdsp, impulseResponse, impulseChannels, impFrameCount, 1);
+ free(impulseResponse);*/
+ //Convolver1DEnable(jdsp);
// Arbitrary magnitude response
-// ArbitraryResponseEqualizerStringParser(jdsp, "IE80Cal: 10 -6.1681; 10.3 -6.31; 10.6247 -6.339; 10.7171 -6.2821; 10.8103 -6.396; 10.9043 -6.396; 10.9991 -6.51; 11.0947 -6.51; 11.1912 -6.51; 11.2885 -6.51; 11.3866 -6.6239; 11.4856 -6.6239; 11.5855 -6.6239; 11.6862 -6.7379; 11.7878 -6.7379; 11.8903 -6.7379; 11.9937 -6.7379; 12.098 -6.8519; 12.2032 -6.8519; 12.3093 -6.8519; 12.4163 -6.9658; 12.5243 -6.9658; 12.6332 -6.9658; 12.743 -6.9658; 12.8538 -7.0798; 12.9656 -7.0798; 13.0783 -7.0798; 13.192 -7.1937; 13.3067 -7.1937; 13.4224 -7.1937; 13.5391 -7.1937; 13.6568 -7.3077; 13.7756 -7.3077; 13.8953 -7.3077; 14.0162 -7.4217; 14.138 -7.4217; 14.2609 -7.4217; 14.3849 -7.4217; 14.51 -7.5356; 14.6362 -7.5356; 14.7634 -7.5356; 14.8918 -7.6496; 15.0213 -7.6496; 15.1519 -7.6496; 15.2836 -7.6496; 15.4165 -7.7635; 15.5505 -7.7635; 15.6857 -7.7635; 15.8221 -7.8775; 15.9597 -7.8775; 16.0985 -7.8775; 16.2384 -7.8775; 16.3796 -7.9915; 16.522 -7.9915; 16.6657 -7.9915; 16.8106 -8.1054; 16.9568 -8.1054; 17.1042 -8.1054; 17.2529 -8.1054; 17.4029 -8.2194; 17.5542 -8.2194; 17.7068 -8.2194; 17.8608 -8.2194; 18.0161 -8.3333; 18.1727 -8.4473; 18.3307 -8.4473; 18.4901 -8.4473; 18.6509 -8.4473; 18.8131 -8.4473; 18.9766 -8.5613; 19.1416 -8.5613; 19.308 -8.5613; 19.4759 -8.5613; 19.6453 -8.5613; 19.8161 -8.5613; 19.9884 -8.6752; 20.1622 -8.6752; 20.3375 -8.6752; 20.5143 -8.7892; 20.6926 -8.7892; 20.8726 -8.7892; 21.054 -8.7892; 21.2371 -8.9031; 21.4217 -8.9031; 21.608 -8.9031; 21.7959 -8.9031; 21.9854 -8.9031; 22.1765 -9.0171; 22.3694 -9.0171; 22.5639 -9.0171; 22.76 -9.0171; 22.9579 -9.1311; 23.1575 -9.1311; 23.3589 -9.1311; 23.562 -9.1311; 23.7668 -9.1311; 23.9735 -9.245; 24.1819 -9.245; 24.3922 -9.245; 24.6043 -9.359; 24.8182 -9.359; 25.034 -9.359; 25.2516 -9.359; 25.4712 -9.4729; 25.6927 -9.4729; 25.916 -9.4729; 26.1414 -9.4729; 26.3687 -9.4729; 26.5979 -9.5869; 26.8292 -9.5869; 27.0625 -9.5869; 27.2978 -9.5869; 27.5351 -9.7009; 27.7745 -9.7009; 28.016 -9.7009; 28.2596 -9.7009; 28.5053 -9.7009; 28.7531 -9.7009; 29.0031 -9.7009; 29.2553 -9.8148; 29.5097 -9.8148; 29.7662 -9.9288; 30.0251 -9.9288; 30.2861 -9.9288; 30.5494 -9.9288; 30.8151 -9.9288; 31.083 -9.9288; 31.3532 -9.9288; 31.6258 -10.0427; 31.9008 -10.0427; 32.1782 -10.0427; 32.458 -10.0427; 32.7402 -10.0427; 33.0248 -10.1567; 33.312 -10.1567; 33.6016 -10.1567; 33.8938 -10.1567; 34.1885 -10.1567; 34.4857 -10.2707; 34.7856 -10.2707; 35.088 -10.2707; 35.3931 -10.2707; 35.7008 -10.3846; 36.0112 -10.3846; 36.3243 -10.3846; 36.6402 -10.3846; 36.9587 -10.3846; 37.2801 -10.3846; 37.6042 -10.3846; 37.9312 -10.4986; 38.261 -10.4986; 38.5936 -10.4986; 38.9292 -10.4986; 39.2677 -10.4986; 39.6091 -10.4986; 39.9535 -10.4986; 40.3008 -10.6125; 40.6512 -10.6125; 41.0047 -10.6125; 41.3612 -10.6125; 41.7208 -10.6125; 42.0836 -10.7265; 42.4495 -10.7265; 42.8186 -10.7265; 43.1909 -10.7265; 43.5664 -10.7265; 43.9452 -10.7265; 44.3273 -10.7265; 44.7127 -10.8405; 45.1014 -10.8405; 45.4936 -10.8405; 45.8891 -10.8405; 46.2881 -10.8405; 46.6906 -10.8405; 47.0965 -10.8405; 47.506 -10.9544; 47.9191 -10.9544; 48.3357 -10.9544; 48.756 -10.9544; 49.1799 -10.9544; 49.6075 -10.9544; 50.0388 -10.9544; 50.4739 -10.9544; 50.9127 -10.9544; 51.3554 -11.0684; 51.8019 -11.0684; 52.2523 -11.0684; 52.7066 -11.0684; 53.1649 -11.0684; 53.6272 -11.0684; 54.0934 -11.0684; 54.5637 -11.0684; 55.0382 -11.0684; 55.5167 -11.1823; 55.9994 -11.1823; 56.4863 -11.1823; 56.9774 -11.1823; 57.4728 -11.1823; 57.9725 -11.1823; 58.4766 -11.1823; 58.985 -11.1823; 59.4979 -11.1823; 60.0152 -11.1823; 60.537 -11.1823; 61.0633 -11.1823; 61.5943 -11.2963; 62.1298 -11.2963; 62.67 -11.2963; 63.2149 -11.2963; 63.7645 -11.2963; 64.3189 -11.2963; 64.8782 -11.2963; 65.4422 -11.2963; 66.0112 -11.2963; 66.5852 -11.2963; 67.1641 -11.2963; 67.7481 -11.2963; 68.3371 -11.2963; 68.9313 -11.2963; 69.5306 -11.4103; 70.1352 -11.4103; 70.745 -11.4103; 71.3601 -11.4103; 71.9805 -11.4103; 72.6064 -11.4103; 73.2377 -11.4103; 73.8744 -11.4103; 74.5168 -11.4103; 75.1647 -11.4103; 75.8182 -11.4103; 76.4774 -11.4103; 77.1423 -11.4103; 77.8131 -11.4103; 78.4896 -11.4103; 79.1721 -11.4103; 79.8604 -11.4103; 80.5548 -11.4103; 81.2552 -11.4103; 81.9617 -11.4103; 82.6743 -11.4103; 83.3931 -11.4103; 84.1182 -11.4103; 84.8496 -11.4103; 85.5873 -11.4103; 86.3315 -11.4103; 87.0821 -11.4103; 87.8392 -11.4103; 88.603 -11.5242; 89.3733 -11.5242; 90.1504 -11.5242; 90.9342 -11.5242; 91.7249 -11.5242; 92.5224 -11.5242; 93.3268 -11.5242; 94.1383 -11.5242; 94.9568 -11.5242; 95.7824 -11.5242; 96.6152 -11.5242; 97.4552 -11.5242; 98.3026 -11.5242; 99.1573 -11.5242; 100.019 -11.4103; 100.889 -11.4103; 101.766 -11.4103; 102.651 -11.4103; 103.544 -11.4103; 104.444 -11.4103; 105.352 -11.4103; 106.268 -11.4103; 107.192 -11.4103; 108.124 -11.4103; 109.064 -11.4103; 110.012 -11.4103; 110.969 -11.4103; 111.934 -11.4103; 112.907 -11.4103; 113.889 -11.4103; 114.879 -11.4103; 115.878 -11.4103; 116.885 -11.4103; 117.901 -11.4103; 118.926 -11.4103; 119.961 -11.4103; 121.004 -11.4103; 122.056 -11.4103; 123.117 -11.4103; 124.187 -11.4103; 125.267 -11.4103; 126.356 -11.4103; 127.455 -11.4103; 128.563 -11.2963; 129.681 -11.2963; 130.808 -11.2963; 131.946 -11.2963; 133.093 -11.2963; 134.25 -11.2963; 135.417 -11.2963; 136.595 -11.2963; 137.782 -11.2963; 138.98 -11.2963; 140.189 -11.2963; 141.408 -11.2963; 142.637 -11.2963; 143.877 -11.2963; 145.128 -11.1823; 146.39 -11.1823; 147.663 -11.1823; 148.947 -11.1823; 150.242 -11.1823; 151.548 -11.1823; 152.866 -11.1823; 154.195 -11.1823; 155.536 -11.1823; 156.888 -11.1823; 158.252 -11.0684; 159.628 -11.0684; 161.016 -11.0684; 162.416 -11.0684; 163.828 -11.0684; 165.252 -11.0684; 166.689 -11.0684; 168.139 -11.0684; 169.6 -11.0684; 171.075 -10.9544; 172.562 -10.9544; 174.063 -10.9544; 175.576 -10.9544; 177.103 -10.9544; 178.643 -10.9544; 180.196 -10.9544; 181.763 -10.8405; 183.343 -10.8405; 184.937 -10.8405; 186.545 -10.8405; 188.167 -10.8405; 189.803 -10.8405; 191.453 -10.8405; 193.118 -10.7265; 194.797 -10.7265; 196.491 -10.7265; 198.199 -10.7265; 199.922 -10.7265; 201.661 -10.7265; 203.414 -10.7265; 205.183 -10.6125; 206.967 -10.6125; 208.766 -10.6125; 210.581 -10.6125; 212.412 -10.6125; 214.259 -10.4986; 216.122 -10.4986; 218.001 -10.4986; 219.897 -10.4986; 221.808 -10.4986; 223.737 -10.4986; 225.682 -10.4986; 227.645 -10.4986; 229.624 -10.3846; 231.62 -10.3846; 233.634 -10.3846; 235.666 -10.3846; 237.715 -10.3846; 239.781 -10.2707; 241.866 -10.2707; 243.969 -10.2707; 246.09 -10.2707; 248.23 -10.2707; 250.388 -10.1567; 252.565 -10.1567; 254.761 -10.1567; 256.976 -10.1567; 259.211 -10.0427; 261.464 -10.0427; 263.738 -10.0427; 266.031 -10.0427; 268.344 -10.0427; 270.677 -9.9288; 273.031 -9.9288; 275.404 -9.9288; 277.799 -9.9288; 280.214 -9.9288; 282.651 -9.8148; 285.108 -9.8148; 287.587 -9.8148; 290.088 -9.8148; 292.61 -9.7009; 295.154 -9.7009; 297.72 -9.7009; 300.309 -9.5869; 302.92 -9.5869; 305.554 -9.5869; 308.21 -9.5869; 310.89 -9.5869; 313.593 -9.5869; 316.32 -9.4729; 319.07 -9.4729; 321.844 -9.4729; 324.643 -9.359; 327.465 -9.359; 330.312 -9.359; 333.184 -9.359; 336.081 -9.245; 339.003 -9.245; 341.951 -9.245; 344.924 -9.1311; 347.923 -9.1311; 350.948 -9.1311; 354 -9.1311; 357.077 -9.0171; 360.182 -9.0171; 363.314 -9.0171; 366.473 -8.9031; 369.659 -8.9031; 372.873 -8.9031; 376.115 -8.9031; 379.385 -8.7892; 382.684 -8.7892; 386.011 -8.7892; 389.367 -8.7892; 392.753 -8.7892; 396.168 -8.6752; 399.612 -8.6752; 403.087 -8.6752; 406.591 -8.5613; 410.127 -8.5613; 413.692 -8.5613; 417.289 -8.5613; 420.918 -8.5613; 424.577 -8.5613; 428.269 -8.4473; 431.992 -8.4473; 435.748 -8.4473; 439.537 -8.4473; 443.359 -8.4473; 447.214 -8.3333; 451.102 -8.3333; 455.024 -8.3333; 458.98 -8.3333; 462.971 -8.2194; 466.996 -8.2194; 471.057 -8.2194; 475.152 -8.2194; 479.284 -8.2194; 483.451 -8.1054; 487.654 -8.1054; 491.894 -8.1054; 496.171 -7.9915; 500.485 -7.9915; 504.837 -7.9915; 509.226 -7.9915; 513.654 -7.8775; 518.12 -7.8775; 522.625 -7.8775; 527.169 -7.7635; 531.752 -7.7635; 536.376 -7.7635; 541.039 -7.7635; 545.743 -7.6496; 550.488 -7.6496; 555.275 -7.6496; 560.103 -7.5356; 564.973 -7.5356; 569.885 -7.5356; 574.84 -7.5356; 579.838 -7.4217; 584.879 -7.4217; 589.965 -7.4217; 595.094 -7.4217; 600.268 -7.3077; 605.487 -7.3077; 610.752 -7.3077; 616.062 -7.1937; 621.418 -7.1937; 626.822 -7.1937; 632.272 -7.1937; 637.769 -7.1937; 643.314 -7.0798; 648.907 -7.0798; 654.549 -7.0798; 660.241 -7.0798; 665.981 -6.9658; 671.772 -6.9658; 677.612 -6.9658; 683.504 -6.9658; 689.447 -6.9658; 695.441 -6.8519; 701.488 -6.8519; 707.587 -6.8519; 713.739 -6.8519; 719.945 -6.8519; 726.205 -6.7379; 732.519 -6.7379; 738.888 -6.7379; 745.312 -6.7379; 751.792 -6.7379; 758.329 -6.7379; 764.922 -6.7379; 771.573 -6.6239; 778.282 -6.6239; 785.049 -6.6239; 791.874 -6.6239; 798.759 -6.6239; 805.704 -6.6239; 812.71 -6.6239; 819.776 -6.6239; 826.903 -6.6239; 834.093 -6.51; 841.345 -6.51; 848.66 -6.51; 856.039 -6.51; 863.482 -6.51; 870.99 -6.51; 878.563 -6.51; 886.202 -6.51; 893.907 -6.51; 901.679 -6.51; 909.519 -6.51; 917.427 -6.51; 925.403 -6.51; 933.449 -6.51; 941.565 -6.51; 949.752 -6.51; 958.01 -6.51; 966.339 -6.51; 974.741 -6.51; 983.216 -6.51; 991.765 -6.51; 1000.39 -6.396; 1009.09 -6.396; 1017.86 -6.396; 1026.71 -6.396; 1035.64 -6.396; 1044.64 -6.396; 1053.72 -6.396; 1062.89 -6.396; 1072.13 -6.396; 1081.45 -6.51; 1090.85 -6.51; 1100.34 -6.51; 1109.9 -6.51; 1119.55 -6.6239; 1129.29 -6.6239; 1139.11 -6.6239; 1149.01 -6.7379; 1159 -6.7379; 1169.08 -6.7379; 1179.24 -6.7379; 1189.5 -6.8519; 1199.84 -6.8519; 1210.27 -6.8519; 1220.79 -6.9658; 1231.41 -6.9658; 1242.11 -6.9658; 1252.91 -6.9658; 1263.81 -7.0798; 1274.8 -7.0798; 1285.88 -7.1937; 1297.06 -7.1937; 1308.34 -7.1937; 1319.71 -7.3077; 1331.19 -7.3077; 1342.76 -7.4217; 1354.44 -7.4217; 1366.21 -7.4217; 1378.09 -7.5356; 1390.07 -7.5356; 1402.16 -7.6496; 1414.35 -7.6496; 1426.65 -7.7635; 1439.05 -7.7635; 1451.56 -7.7635; 1464.19 -7.8775; 1476.92 -7.8775; 1489.76 -7.9915; 1502.71 -7.9915; 1515.78 -7.9915; 1528.95 -7.9915; 1542.25 -8.1054; 1555.66 -8.2194; 1569.18 -8.2194; 1582.83 -8.2194; 1596.59 -8.2194; 1610.47 -8.3333; 1624.47 -8.3333; 1638.6 -8.3333; 1652.84 -8.3333; 1667.22 -8.4473; 1681.71 -8.5613; 1696.33 -8.5613; 1711.08 -8.5613; 1725.96 -8.5613; 1740.97 -8.6752; 1756.1 -8.6752; 1771.37 -8.6752; 1786.77 -8.7892; 1802.31 -8.7892; 1817.98 -8.7892; 1833.79 -8.7892; 1849.73 -8.9031; 1865.81 -8.9031; 1882.04 -8.9031; 1898.4 -9.0171; 1914.9 -9.0171; 1931.55 -9.1311; 1948.35 -9.1311; 1965.29 -9.1311; 1982.38 -9.1311; 1999.61 -9.245; 2017 -9.245; 2034.54 -9.245; 2052.22 -9.359; 2070.07 -9.359; 2088.07 -9.4729; 2106.22 -9.4729; 2124.53 -9.5869; 2143.01 -9.5869; 2161.64 -9.5869; 2180.43 -9.7009; 2199.39 -9.7009; 2218.51 -9.7009; 2237.8 -9.7009; 2257.26 -9.8148; 2276.89 -9.8148; 2296.68 -9.9288; 2316.65 -9.9288; 2336.79 -9.9288; 2357.11 -10.0427; 2377.61 -10.0427; 2398.28 -10.1567; 2419.13 -10.1567; 2440.16 -10.1567; 2461.38 -10.2707; 2482.78 -10.2707; 2504.37 -10.2707; 2526.14 -10.2707; 2548.11 -10.3846; 2570.26 -10.3846; 2592.61 -10.4986; 2615.15 -10.4986; 2637.89 -10.4986; 2660.83 -10.6125; 2683.96 -10.6125; 2707.3 -10.6125; 2730.84 -10.6125; 2754.58 -10.7265; 2778.53 -10.7265; 2802.69 -10.7265; 2827.06 -10.8405; 2851.64 -10.8405; 2876.43 -10.8405; 2901.44 -10.8405; 2926.67 -10.8405; 2952.11 -10.9544; 2977.78 -10.9544; 3003.67 -10.9544; 3029.79 -10.9544; 3056.13 -10.9544; 3082.7 -10.9544; 3109.5 -11.0684; 3136.54 -11.0684; 3163.81 -11.0684; 3191.32 -11.0684; 3219.07 -11.0684; 3247.06 -11.0684; 3275.29 -11.0684; 3303.77 -11.0684; 3332.49 -11.0684; 3361.47 -11.0684; 3390.69 -11.0684; 3420.17 -11.0684; 3449.91 -11.0684; 3479.91 -11.0684; 3510.16 -11.0684; 3540.68 -11.0684; 3571.47 -11.1823; 3602.52 -11.1823; 3633.84 -11.1823; 3665.44 -11.1823; 3697.31 -11.1823; 3729.45 -11.1823; 3761.88 -11.1823; 3794.59 -11.1823; 3827.58 -11.1823; 3860.86 -11.1823; 3894.43 -11.1823; 3928.29 -11.1823; 3962.44 -11.0684; 3996.9 -11.0684; 4031.65 -11.0684; 4066.7 -10.9544; 4102.06 -10.9544; 4137.73 -10.8405; 4173.7 -10.8405; 4209.99 -10.7265; 4246.6 -10.6125; 4283.52 -10.4986; 4320.76 -10.3276; 4358.33 -10.1567; 4396.22 -9.9858; 4434.45 -9.9288; 4473 -9.7578; 4511.89 -9.5869; 4551.12 -9.359; 4590.69 -9.1311; 4630.61 -8.9031; 4670.87 -8.7322; 4711.48 -8.5043; 4752.45 -8.3903; 4793.77 -8.1624; 4835.45 -8.0484; 4877.49 -7.8205; 4919.9 -7.7635; 4962.68 -7.6496; 5005.82 -7.5356; 5049.35 -7.4217; 5093.25 -7.4217; 5137.53 -7.3077; 5182.2 -7.1937; 5227.26 -7.1937; 5272.71 -7.0798; 5318.55 -7.0798; 5364.8 -7.0798; 5411.44 -7.0798; 5458.49 -7.1937; 5505.95 -7.1937; 5553.82 -7.1937; 5602.11 -7.3077; 5650.82 -7.3077; 5699.95 -7.4217; 5749.51 -7.4217; 5799.5 -7.5356; 5849.93 -7.6496; 5900.79 -7.7635; 5952.1 -7.8775; 6003.85 -7.8775; 6056.05 -7.9915; 6108.7 -7.9915; 6161.82 -7.9915; 6215.39 -7.9915; 6269.43 -7.9915; 6323.94 -7.9915; 6378.93 -7.9915; 6434.39 -7.8775; 6490.33 -7.8775; 6546.76 -7.7635; 6603.69 -7.6496; 6661.1 -7.4786; 6719.02 -7.3077; 6777.44 -7.1937; 6836.37 -7.0798; 6895.81 -6.9658; 6955.76 -6.7949; 7016.24 -6.6239; 7077.24 -6.453; 7138.78 -6.2251; 7200.85 -6.1681; 7263.46 -6.0541; 7326.61 -5.9402; 7390.31 -5.8262; 7454.57 -5.7123; 7519.38 -5.5983; 7584.76 -5.4843; 7650.71 -5.3704; 7717.23 -5.2564; 7784.33 -5.1425; 7852.01 -5.0285; 7920.28 -5.0285; 7989.14 -4.91453; 8058.61 -4.91453; 8128.67 -4.80057; 8199.35 -4.80057; 8270.64 -4.80057; 8342.55 -4.80057; 8415.08 -4.80057; 8488.25 -4.80057; 8562.05 -4.80057; 8636.5 -4.91453; 8711.59 -5.0285; 8787.33 -5.0285; 8863.73 -5.1425; 8940.8 -5.2564; 9018.54 -5.3704; 9096.95 -5.4843; 9176.05 -5.7123; 9255.83 -5.9402; 9336.31 -6.2251; 9417.48 -6.51; 9499.36 -6.7379; 9581.96 -6.9658; 9665.27 -7.1937; 9749.3 -7.4217; 9834.07 -7.5926; 9919.57 -7.7635; 10005.8 -7.5926; 10092.8 -7.4786; 10180.6 -7.1368; 10269.1 -6.7949; 10358.4 -6.2821; 10448.4 -5.7692; 10539.3 -5.1994; 10630.9 -4.80057; 10723.4 -4.45869; 10816.6 -4.23077; 10910.6 -4.00285; 11005.5 -3.83191; 11101.2 -3.77493; 11197.7 -3.66097; 11295.1 -3.54701; 11393.3 -3.54701; 11492.3 -3.66097; 11592.3 -3.66097; 11693 -3.77493; 11794.7 -3.83191; 11897.3 -4.00285; 12000.7 -4.11681; 12105 -4.11681; 12210.3 -4.23077; 12316.5 -4.23077; 12423.5 -4.11681; 12531.6 -4.11681; 12640.5 -3.94587; 12750.4 -3.77493; 12861.3 -3.66097; 12973.1 -3.54701; 13085.9 -3.54701; 13199.7 -3.43305; 13314.5 -3.43305; 13430.2 -3.43305; 13547 -3.43305; 13664.8 -3.43305; 13783.6 -3.54701; 13903.4 -3.60399; 14024.3 -3.71795; 14146.3 -3.94587; 14269.2 -4.23077; 14393.3 -4.57265; 14518.5 -5.0285; 14644.7 -5.4843; 14772 -5.9402; 14900.5 -6.453; 15030 -6.9088; 15160.7 -7.3077; 15292.5 -7.1937; 15425.5 -6.6809; 15559.6 -5.9972; 15694.9 -5.3134; 15831.3 -4.57265; 15969 -3.94587; 16107.8 -3.26211; 16247.9 -2.63533; 16389.2 -2.06553; 16531.7 -1.55271; 16675.4 -1.15385; 16820.4 -0.86895; 16966.6 -0.58405; 17114.1 -0.35613; 17262.9 -0.12821; 17413 0.09972; 17564.4 0.32764; 17717.2 0.4416; 17871.2 0.55556; 18026.6 0.55556; 18183.3 0.55556; 18341.4 0.55556; 18500.9 0.38462; 18661.7 0.1567; 18824 -0.12821; 18987.7 -0.47009; 19152.8 -0.86895; 19319.3 -1.26781; 19487.3 -1.72365; 19656.7 -2.23647; 19827.6 -2.63533; 20000 -2.92023; 20173.9 -2.57835; 20349.3 -2.12251; 20526.2 -1.43875; 20704.7 -0.69801; 20884.7 0.21368; 21066.3 1.06838; 21249.5 1.80912; 21434.2 2.49288; 21620.6 2.94872; 21808.6 3.34758; 21998.2 3.68946; 22189.5 4.03134; 22382.4 4.31624; 22577 4.60114; 22773.3 4.82906; 22971.3 4.88604; 23171 5; 23372.5 5; 23780.7 4.88604");
-// ArbitraryResponseEqualizerStringParser(jdsp, "cce2: 5000.0 3.0; 2000.0 0.0; 0.0 -100.0; 100.0 -20, 400.0; 0;");
-// jdsp->arbMagForceRefresh = 1; // For testing purpose
-// ArbitraryResponseEqualizerEnable(jdsp);
+ /*ArbitraryResponseEqualizerStringParser(jdsp, "IE80Cal: 10 -6.1681; 10.3 -6.31; 10.6247 -6.339; 10.7171 -6.2821; 10.8103 -6.396; 10.9043 -6.396; 10.9991 -6.51; 11.0947 -6.51; 11.1912 -6.51; 11.2885 -6.51; 11.3866 -6.6239; 11.4856 -6.6239; 11.5855 -6.6239; 11.6862 -6.7379; 11.7878 -6.7379; 11.8903 -6.7379; 11.9937 -6.7379; 12.098 -6.8519; 12.2032 -6.8519; 12.3093 -6.8519; 12.4163 -6.9658; 12.5243 -6.9658; 12.6332 -6.9658; 12.743 -6.9658; 12.8538 -7.0798; 12.9656 -7.0798; 13.0783 -7.0798; 13.192 -7.1937; 13.3067 -7.1937; 13.4224 -7.1937; 13.5391 -7.1937; 13.6568 -7.3077; 13.7756 -7.3077; 13.8953 -7.3077; 14.0162 -7.4217; 14.138 -7.4217; 14.2609 -7.4217; 14.3849 -7.4217; 14.51 -7.5356; 14.6362 -7.5356; 14.7634 -7.5356; 14.8918 -7.6496; 15.0213 -7.6496; 15.1519 -7.6496; 15.2836 -7.6496; 15.4165 -7.7635; 15.5505 -7.7635; 15.6857 -7.7635; 15.8221 -7.8775; 15.9597 -7.8775; 16.0985 -7.8775; 16.2384 -7.8775; 16.3796 -7.9915; 16.522 -7.9915; 16.6657 -7.9915; 16.8106 -8.1054; 16.9568 -8.1054; 17.1042 -8.1054; 17.2529 -8.1054; 17.4029 -8.2194; 17.5542 -8.2194; 17.7068 -8.2194; 17.8608 -8.2194; 18.0161 -8.3333; 18.1727 -8.4473; 18.3307 -8.4473; 18.4901 -8.4473; 18.6509 -8.4473; 18.8131 -8.4473; 18.9766 -8.5613; 19.1416 -8.5613; 19.308 -8.5613; 19.4759 -8.5613; 19.6453 -8.5613; 19.8161 -8.5613; 19.9884 -8.6752; 20.1622 -8.6752; 20.3375 -8.6752; 20.5143 -8.7892; 20.6926 -8.7892; 20.8726 -8.7892; 21.054 -8.7892; 21.2371 -8.9031; 21.4217 -8.9031; 21.608 -8.9031; 21.7959 -8.9031; 21.9854 -8.9031; 22.1765 -9.0171; 22.3694 -9.0171; 22.5639 -9.0171; 22.76 -9.0171; 22.9579 -9.1311; 23.1575 -9.1311; 23.3589 -9.1311; 23.562 -9.1311; 23.7668 -9.1311; 23.9735 -9.245; 24.1819 -9.245; 24.3922 -9.245; 24.6043 -9.359; 24.8182 -9.359; 25.034 -9.359; 25.2516 -9.359; 25.4712 -9.4729; 25.6927 -9.4729; 25.916 -9.4729; 26.1414 -9.4729; 26.3687 -9.4729; 26.5979 -9.5869; 26.8292 -9.5869; 27.0625 -9.5869; 27.2978 -9.5869; 27.5351 -9.7009; 27.7745 -9.7009; 28.016 -9.7009; 28.2596 -9.7009; 28.5053 -9.7009; 28.7531 -9.7009; 29.0031 -9.7009; 29.2553 -9.8148; 29.5097 -9.8148; 29.7662 -9.9288; 30.0251 -9.9288; 30.2861 -9.9288; 30.5494 -9.9288; 30.8151 -9.9288; 31.083 -9.9288; 31.3532 -9.9288; 31.6258 -10.0427; 31.9008 -10.0427; 32.1782 -10.0427; 32.458 -10.0427; 32.7402 -10.0427; 33.0248 -10.1567; 33.312 -10.1567; 33.6016 -10.1567; 33.8938 -10.1567; 34.1885 -10.1567; 34.4857 -10.2707; 34.7856 -10.2707; 35.088 -10.2707; 35.3931 -10.2707; 35.7008 -10.3846; 36.0112 -10.3846; 36.3243 -10.3846; 36.6402 -10.3846; 36.9587 -10.3846; 37.2801 -10.3846; 37.6042 -10.3846; 37.9312 -10.4986; 38.261 -10.4986; 38.5936 -10.4986; 38.9292 -10.4986; 39.2677 -10.4986; 39.6091 -10.4986; 39.9535 -10.4986; 40.3008 -10.6125; 40.6512 -10.6125; 41.0047 -10.6125; 41.3612 -10.6125; 41.7208 -10.6125; 42.0836 -10.7265; 42.4495 -10.7265; 42.8186 -10.7265; 43.1909 -10.7265; 43.5664 -10.7265; 43.9452 -10.7265; 44.3273 -10.7265; 44.7127 -10.8405; 45.1014 -10.8405; 45.4936 -10.8405; 45.8891 -10.8405; 46.2881 -10.8405; 46.6906 -10.8405; 47.0965 -10.8405; 47.506 -10.9544; 47.9191 -10.9544; 48.3357 -10.9544; 48.756 -10.9544; 49.1799 -10.9544; 49.6075 -10.9544; 50.0388 -10.9544; 50.4739 -10.9544; 50.9127 -10.9544; 51.3554 -11.0684; 51.8019 -11.0684; 52.2523 -11.0684; 52.7066 -11.0684; 53.1649 -11.0684; 53.6272 -11.0684; 54.0934 -11.0684; 54.5637 -11.0684; 55.0382 -11.0684; 55.5167 -11.1823; 55.9994 -11.1823; 56.4863 -11.1823; 56.9774 -11.1823; 57.4728 -11.1823; 57.9725 -11.1823; 58.4766 -11.1823; 58.985 -11.1823; 59.4979 -11.1823; 60.0152 -11.1823; 60.537 -11.1823; 61.0633 -11.1823; 61.5943 -11.2963; 62.1298 -11.2963; 62.67 -11.2963; 63.2149 -11.2963; 63.7645 -11.2963; 64.3189 -11.2963; 64.8782 -11.2963; 65.4422 -11.2963; 66.0112 -11.2963; 66.5852 -11.2963; 67.1641 -11.2963; 67.7481 -11.2963; 68.3371 -11.2963; 68.9313 -11.2963; 69.5306 -11.4103; 70.1352 -11.4103; 70.745 -11.4103; 71.3601 -11.4103; 71.9805 -11.4103; 72.6064 -11.4103; 73.2377 -11.4103; 73.8744 -11.4103; 74.5168 -11.4103; 75.1647 -11.4103; 75.8182 -11.4103; 76.4774 -11.4103; 77.1423 -11.4103; 77.8131 -11.4103; 78.4896 -11.4103; 79.1721 -11.4103; 79.8604 -11.4103; 80.5548 -11.4103; 81.2552 -11.4103; 81.9617 -11.4103; 82.6743 -11.4103; 83.3931 -11.4103; 84.1182 -11.4103; 84.8496 -11.4103; 85.5873 -11.4103; 86.3315 -11.4103; 87.0821 -11.4103; 87.8392 -11.4103; 88.603 -11.5242; 89.3733 -11.5242; 90.1504 -11.5242; 90.9342 -11.5242; 91.7249 -11.5242; 92.5224 -11.5242; 93.3268 -11.5242; 94.1383 -11.5242; 94.9568 -11.5242; 95.7824 -11.5242; 96.6152 -11.5242; 97.4552 -11.5242; 98.3026 -11.5242; 99.1573 -11.5242; 100.019 -11.4103; 100.889 -11.4103; 101.766 -11.4103; 102.651 -11.4103; 103.544 -11.4103; 104.444 -11.4103; 105.352 -11.4103; 106.268 -11.4103; 107.192 -11.4103; 108.124 -11.4103; 109.064 -11.4103; 110.012 -11.4103; 110.969 -11.4103; 111.934 -11.4103; 112.907 -11.4103; 113.889 -11.4103; 114.879 -11.4103; 115.878 -11.4103; 116.885 -11.4103; 117.901 -11.4103; 118.926 -11.4103; 119.961 -11.4103; 121.004 -11.4103; 122.056 -11.4103; 123.117 -11.4103; 124.187 -11.4103; 125.267 -11.4103; 126.356 -11.4103; 127.455 -11.4103; 128.563 -11.2963; 129.681 -11.2963; 130.808 -11.2963; 131.946 -11.2963; 133.093 -11.2963; 134.25 -11.2963; 135.417 -11.2963; 136.595 -11.2963; 137.782 -11.2963; 138.98 -11.2963; 140.189 -11.2963; 141.408 -11.2963; 142.637 -11.2963; 143.877 -11.2963; 145.128 -11.1823; 146.39 -11.1823; 147.663 -11.1823; 148.947 -11.1823; 150.242 -11.1823; 151.548 -11.1823; 152.866 -11.1823; 154.195 -11.1823; 155.536 -11.1823; 156.888 -11.1823; 158.252 -11.0684; 159.628 -11.0684; 161.016 -11.0684; 162.416 -11.0684; 163.828 -11.0684; 165.252 -11.0684; 166.689 -11.0684; 168.139 -11.0684; 169.6 -11.0684; 171.075 -10.9544; 172.562 -10.9544; 174.063 -10.9544; 175.576 -10.9544; 177.103 -10.9544; 178.643 -10.9544; 180.196 -10.9544; 181.763 -10.8405; 183.343 -10.8405; 184.937 -10.8405; 186.545 -10.8405; 188.167 -10.8405; 189.803 -10.8405; 191.453 -10.8405; 193.118 -10.7265; 194.797 -10.7265; 196.491 -10.7265; 198.199 -10.7265; 199.922 -10.7265; 201.661 -10.7265; 203.414 -10.7265; 205.183 -10.6125; 206.967 -10.6125; 208.766 -10.6125; 210.581 -10.6125; 212.412 -10.6125; 214.259 -10.4986; 216.122 -10.4986; 218.001 -10.4986; 219.897 -10.4986; 221.808 -10.4986; 223.737 -10.4986; 225.682 -10.4986; 227.645 -10.4986; 229.624 -10.3846; 231.62 -10.3846; 233.634 -10.3846; 235.666 -10.3846; 237.715 -10.3846; 239.781 -10.2707; 241.866 -10.2707; 243.969 -10.2707; 246.09 -10.2707; 248.23 -10.2707; 250.388 -10.1567; 252.565 -10.1567; 254.761 -10.1567; 256.976 -10.1567; 259.211 -10.0427; 261.464 -10.0427; 263.738 -10.0427; 266.031 -10.0427; 268.344 -10.0427; 270.677 -9.9288; 273.031 -9.9288; 275.404 -9.9288; 277.799 -9.9288; 280.214 -9.9288; 282.651 -9.8148; 285.108 -9.8148; 287.587 -9.8148; 290.088 -9.8148; 292.61 -9.7009; 295.154 -9.7009; 297.72 -9.7009; 300.309 -9.5869; 302.92 -9.5869; 305.554 -9.5869; 308.21 -9.5869; 310.89 -9.5869; 313.593 -9.5869; 316.32 -9.4729; 319.07 -9.4729; 321.844 -9.4729; 324.643 -9.359; 327.465 -9.359; 330.312 -9.359; 333.184 -9.359; 336.081 -9.245; 339.003 -9.245; 341.951 -9.245; 344.924 -9.1311; 347.923 -9.1311; 350.948 -9.1311; 354 -9.1311; 357.077 -9.0171; 360.182 -9.0171; 363.314 -9.0171; 366.473 -8.9031; 369.659 -8.9031; 372.873 -8.9031; 376.115 -8.9031; 379.385 -8.7892; 382.684 -8.7892; 386.011 -8.7892; 389.367 -8.7892; 392.753 -8.7892; 396.168 -8.6752; 399.612 -8.6752; 403.087 -8.6752; 406.591 -8.5613; 410.127 -8.5613; 413.692 -8.5613; 417.289 -8.5613; 420.918 -8.5613; 424.577 -8.5613; 428.269 -8.4473; 431.992 -8.4473; 435.748 -8.4473; 439.537 -8.4473; 443.359 -8.4473; 447.214 -8.3333; 451.102 -8.3333; 455.024 -8.3333; 458.98 -8.3333; 462.971 -8.2194; 466.996 -8.2194; 471.057 -8.2194; 475.152 -8.2194; 479.284 -8.2194; 483.451 -8.1054; 487.654 -8.1054; 491.894 -8.1054; 496.171 -7.9915; 500.485 -7.9915; 504.837 -7.9915; 509.226 -7.9915; 513.654 -7.8775; 518.12 -7.8775; 522.625 -7.8775; 527.169 -7.7635; 531.752 -7.7635; 536.376 -7.7635; 541.039 -7.7635; 545.743 -7.6496; 550.488 -7.6496; 555.275 -7.6496; 560.103 -7.5356; 564.973 -7.5356; 569.885 -7.5356; 574.84 -7.5356; 579.838 -7.4217; 584.879 -7.4217; 589.965 -7.4217; 595.094 -7.4217; 600.268 -7.3077; 605.487 -7.3077; 610.752 -7.3077; 616.062 -7.1937; 621.418 -7.1937; 626.822 -7.1937; 632.272 -7.1937; 637.769 -7.1937; 643.314 -7.0798; 648.907 -7.0798; 654.549 -7.0798; 660.241 -7.0798; 665.981 -6.9658; 671.772 -6.9658; 677.612 -6.9658; 683.504 -6.9658; 689.447 -6.9658; 695.441 -6.8519; 701.488 -6.8519; 707.587 -6.8519; 713.739 -6.8519; 719.945 -6.8519; 726.205 -6.7379; 732.519 -6.7379; 738.888 -6.7379; 745.312 -6.7379; 751.792 -6.7379; 758.329 -6.7379; 764.922 -6.7379; 771.573 -6.6239; 778.282 -6.6239; 785.049 -6.6239; 791.874 -6.6239; 798.759 -6.6239; 805.704 -6.6239; 812.71 -6.6239; 819.776 -6.6239; 826.903 -6.6239; 834.093 -6.51; 841.345 -6.51; 848.66 -6.51; 856.039 -6.51; 863.482 -6.51; 870.99 -6.51; 878.563 -6.51; 886.202 -6.51; 893.907 -6.51; 901.679 -6.51; 909.519 -6.51; 917.427 -6.51; 925.403 -6.51; 933.449 -6.51; 941.565 -6.51; 949.752 -6.51; 958.01 -6.51; 966.339 -6.51; 974.741 -6.51; 983.216 -6.51; 991.765 -6.51; 1000.39 -6.396; 1009.09 -6.396; 1017.86 -6.396; 1026.71 -6.396; 1035.64 -6.396; 1044.64 -6.396; 1053.72 -6.396; 1062.89 -6.396; 1072.13 -6.396; 1081.45 -6.51; 1090.85 -6.51; 1100.34 -6.51; 1109.9 -6.51; 1119.55 -6.6239; 1129.29 -6.6239; 1139.11 -6.6239; 1149.01 -6.7379; 1159 -6.7379; 1169.08 -6.7379; 1179.24 -6.7379; 1189.5 -6.8519; 1199.84 -6.8519; 1210.27 -6.8519; 1220.79 -6.9658; 1231.41 -6.9658; 1242.11 -6.9658; 1252.91 -6.9658; 1263.81 -7.0798; 1274.8 -7.0798; 1285.88 -7.1937; 1297.06 -7.1937; 1308.34 -7.1937; 1319.71 -7.3077; 1331.19 -7.3077; 1342.76 -7.4217; 1354.44 -7.4217; 1366.21 -7.4217; 1378.09 -7.5356; 1390.07 -7.5356; 1402.16 -7.6496; 1414.35 -7.6496; 1426.65 -7.7635; 1439.05 -7.7635; 1451.56 -7.7635; 1464.19 -7.8775; 1476.92 -7.8775; 1489.76 -7.9915; 1502.71 -7.9915; 1515.78 -7.9915; 1528.95 -7.9915; 1542.25 -8.1054; 1555.66 -8.2194; 1569.18 -8.2194; 1582.83 -8.2194; 1596.59 -8.2194; 1610.47 -8.3333; 1624.47 -8.3333; 1638.6 -8.3333; 1652.84 -8.3333; 1667.22 -8.4473; 1681.71 -8.5613; 1696.33 -8.5613; 1711.08 -8.5613; 1725.96 -8.5613; 1740.97 -8.6752; 1756.1 -8.6752; 1771.37 -8.6752; 1786.77 -8.7892; 1802.31 -8.7892; 1817.98 -8.7892; 1833.79 -8.7892; 1849.73 -8.9031; 1865.81 -8.9031; 1882.04 -8.9031; 1898.4 -9.0171; 1914.9 -9.0171; 1931.55 -9.1311; 1948.35 -9.1311; 1965.29 -9.1311; 1982.38 -9.1311; 1999.61 -9.245; 2017 -9.245; 2034.54 -9.245; 2052.22 -9.359; 2070.07 -9.359; 2088.07 -9.4729; 2106.22 -9.4729; 2124.53 -9.5869; 2143.01 -9.5869; 2161.64 -9.5869; 2180.43 -9.7009; 2199.39 -9.7009; 2218.51 -9.7009; 2237.8 -9.7009; 2257.26 -9.8148; 2276.89 -9.8148; 2296.68 -9.9288; 2316.65 -9.9288; 2336.79 -9.9288; 2357.11 -10.0427; 2377.61 -10.0427; 2398.28 -10.1567; 2419.13 -10.1567; 2440.16 -10.1567; 2461.38 -10.2707; 2482.78 -10.2707; 2504.37 -10.2707; 2526.14 -10.2707; 2548.11 -10.3846; 2570.26 -10.3846; 2592.61 -10.4986; 2615.15 -10.4986; 2637.89 -10.4986; 2660.83 -10.6125; 2683.96 -10.6125; 2707.3 -10.6125; 2730.84 -10.6125; 2754.58 -10.7265; 2778.53 -10.7265; 2802.69 -10.7265; 2827.06 -10.8405; 2851.64 -10.8405; 2876.43 -10.8405; 2901.44 -10.8405; 2926.67 -10.8405; 2952.11 -10.9544; 2977.78 -10.9544; 3003.67 -10.9544; 3029.79 -10.9544; 3056.13 -10.9544; 3082.7 -10.9544; 3109.5 -11.0684; 3136.54 -11.0684; 3163.81 -11.0684; 3191.32 -11.0684; 3219.07 -11.0684; 3247.06 -11.0684; 3275.29 -11.0684; 3303.77 -11.0684; 3332.49 -11.0684; 3361.47 -11.0684; 3390.69 -11.0684; 3420.17 -11.0684; 3449.91 -11.0684; 3479.91 -11.0684; 3510.16 -11.0684; 3540.68 -11.0684; 3571.47 -11.1823; 3602.52 -11.1823; 3633.84 -11.1823; 3665.44 -11.1823; 3697.31 -11.1823; 3729.45 -11.1823; 3761.88 -11.1823; 3794.59 -11.1823; 3827.58 -11.1823; 3860.86 -11.1823; 3894.43 -11.1823; 3928.29 -11.1823; 3962.44 -11.0684; 3996.9 -11.0684; 4031.65 -11.0684; 4066.7 -10.9544; 4102.06 -10.9544; 4137.73 -10.8405; 4173.7 -10.8405; 4209.99 -10.7265; 4246.6 -10.6125; 4283.52 -10.4986; 4320.76 -10.3276; 4358.33 -10.1567; 4396.22 -9.9858; 4434.45 -9.9288; 4473 -9.7578; 4511.89 -9.5869; 4551.12 -9.359; 4590.69 -9.1311; 4630.61 -8.9031; 4670.87 -8.7322; 4711.48 -8.5043; 4752.45 -8.3903; 4793.77 -8.1624; 4835.45 -8.0484; 4877.49 -7.8205; 4919.9 -7.7635; 4962.68 -7.6496; 5005.82 -7.5356; 5049.35 -7.4217; 5093.25 -7.4217; 5137.53 -7.3077; 5182.2 -7.1937; 5227.26 -7.1937; 5272.71 -7.0798; 5318.55 -7.0798; 5364.8 -7.0798; 5411.44 -7.0798; 5458.49 -7.1937; 5505.95 -7.1937; 5553.82 -7.1937; 5602.11 -7.3077; 5650.82 -7.3077; 5699.95 -7.4217; 5749.51 -7.4217; 5799.5 -7.5356; 5849.93 -7.6496; 5900.79 -7.7635; 5952.1 -7.8775; 6003.85 -7.8775; 6056.05 -7.9915; 6108.7 -7.9915; 6161.82 -7.9915; 6215.39 -7.9915; 6269.43 -7.9915; 6323.94 -7.9915; 6378.93 -7.9915; 6434.39 -7.8775; 6490.33 -7.8775; 6546.76 -7.7635; 6603.69 -7.6496; 6661.1 -7.4786; 6719.02 -7.3077; 6777.44 -7.1937; 6836.37 -7.0798; 6895.81 -6.9658; 6955.76 -6.7949; 7016.24 -6.6239; 7077.24 -6.453; 7138.78 -6.2251; 7200.85 -6.1681; 7263.46 -6.0541; 7326.61 -5.9402; 7390.31 -5.8262; 7454.57 -5.7123; 7519.38 -5.5983; 7584.76 -5.4843; 7650.71 -5.3704; 7717.23 -5.2564; 7784.33 -5.1425; 7852.01 -5.0285; 7920.28 -5.0285; 7989.14 -4.91453; 8058.61 -4.91453; 8128.67 -4.80057; 8199.35 -4.80057; 8270.64 -4.80057; 8342.55 -4.80057; 8415.08 -4.80057; 8488.25 -4.80057; 8562.05 -4.80057; 8636.5 -4.91453; 8711.59 -5.0285; 8787.33 -5.0285; 8863.73 -5.1425; 8940.8 -5.2564; 9018.54 -5.3704; 9096.95 -5.4843; 9176.05 -5.7123; 9255.83 -5.9402; 9336.31 -6.2251; 9417.48 -6.51; 9499.36 -6.7379; 9581.96 -6.9658; 9665.27 -7.1937; 9749.3 -7.4217; 9834.07 -7.5926; 9919.57 -7.7635; 10005.8 -7.5926; 10092.8 -7.4786; 10180.6 -7.1368; 10269.1 -6.7949; 10358.4 -6.2821; 10448.4 -5.7692; 10539.3 -5.1994; 10630.9 -4.80057; 10723.4 -4.45869; 10816.6 -4.23077; 10910.6 -4.00285; 11005.5 -3.83191; 11101.2 -3.77493; 11197.7 -3.66097; 11295.1 -3.54701; 11393.3 -3.54701; 11492.3 -3.66097; 11592.3 -3.66097; 11693 -3.77493; 11794.7 -3.83191; 11897.3 -4.00285; 12000.7 -4.11681; 12105 -4.11681; 12210.3 -4.23077; 12316.5 -4.23077; 12423.5 -4.11681; 12531.6 -4.11681; 12640.5 -3.94587; 12750.4 -3.77493; 12861.3 -3.66097; 12973.1 -3.54701; 13085.9 -3.54701; 13199.7 -3.43305; 13314.5 -3.43305; 13430.2 -3.43305; 13547 -3.43305; 13664.8 -3.43305; 13783.6 -3.54701; 13903.4 -3.60399; 14024.3 -3.71795; 14146.3 -3.94587; 14269.2 -4.23077; 14393.3 -4.57265; 14518.5 -5.0285; 14644.7 -5.4843; 14772 -5.9402; 14900.5 -6.453; 15030 -6.9088; 15160.7 -7.3077; 15292.5 -7.1937; 15425.5 -6.6809; 15559.6 -5.9972; 15694.9 -5.3134; 15831.3 -4.57265; 15969 -3.94587; 16107.8 -3.26211; 16247.9 -2.63533; 16389.2 -2.06553; 16531.7 -1.55271; 16675.4 -1.15385; 16820.4 -0.86895; 16966.6 -0.58405; 17114.1 -0.35613; 17262.9 -0.12821; 17413 0.09972; 17564.4 0.32764; 17717.2 0.4416; 17871.2 0.55556; 18026.6 0.55556; 18183.3 0.55556; 18341.4 0.55556; 18500.9 0.38462; 18661.7 0.1567; 18824 -0.12821; 18987.7 -0.47009; 19152.8 -0.86895; 19319.3 -1.26781; 19487.3 -1.72365; 19656.7 -2.23647; 19827.6 -2.63533; 20000 -2.92023; 20173.9 -2.57835; 20349.3 -2.12251; 20526.2 -1.43875; 20704.7 -0.69801; 20884.7 0.21368; 21066.3 1.06838; 21249.5 1.80912; 21434.2 2.49288; 21620.6 2.94872; 21808.6 3.34758; 21998.2 3.68946; 22189.5 4.03134; 22382.4 4.31624; 22577 4.60114; 22773.3 4.82906; 22971.3 4.88604; 23171 5; 23372.5 5; 23780.7 4.88604");
+ ArbitraryResponseEqualizerEnable(jdsp, 1);*/
// FIR Equalizer
- /*double freq[NUMPTS] = { 25.0, 40.0, 63.0, 100.0, 160.0, 250.0, 400.0, 630.0, 1000.0, 1600.0, 2500.0, 4000.0, 6300.0, 10000.0, 16000.0 };
- double gain[NUMPTS] = { 5.0, -1.0, -4, -1, 2.1, 0.0, 0.0, 0.7, -10.7, 0.0, 0.0, 0.0, 0.0, 0.8, 8.0 };
- //double gain[NUMPTS] = { 0.0, 5.0, 0.0 };
- FIREqualizerAxisInterpolation(jdsp, 0, 0, freq, gain);
- jdsp->equalizerForceRefresh = 1; // For testing purpose
- FIREqualizerEnable(jdsp);*/
- double wall1 = get_wall_time();
- double cpu1 = get_cpu_time();
- printf("[Info] Precomputation of filters take:\n[Info] %lf sec Wall time, %lf sec CPU time\n", wall1 - wall0, cpu1 - cpu0);
- printf("[Info] Samples: %I64d, Channels: %d\n[Status] Allocating buffer\n", totalPCMFrameCount, channels);
- wall0 = get_wall_time();
- cpu0 = get_cpu_time();
+ double freq[NUMPTS] = { 25.0, 40.0, 63.0, 100.0, 160.0, 250.0, 400.0, 630.0, 1000.0, 1600.0, 2500.0, 4000.0, 6300.0, 10000.0, 16000.0 };
+ double gains[NUMPTS] = { 5.0, -1.0, -4, -1, 2.1, 0.0, 0.0, 0.7, -10.7, 0.0, 0.0, 0.0, 0.0, 0.8, 8.0 };
+ //double gains[NUMPTS] = { 0.0, 5.0, 0.0 };
+ //MultimodalEqualizerAxisInterpolation(jdsp, 0, 0, freq, gains);
+ MultimodalEqualizerAxisInterpolation(jdsp, 0, 5, freq, gains);
+ MultimodalEqualizerEnable(jdsp, 1);
+ JamesDSPSetSampleRate(jdsp, (float)sampleRate, 1);
int readcount = (unsigned int)ceil((float)totalPCMFrameCount / (float)frameCountBest);
int finalSize = frameCountBest * readcount;
float *splittedBuffer[2];
- splittedBuffer[0] = (float*)calloc(finalSize, sizeof(float));
- splittedBuffer[1] = (float*)calloc(finalSize, sizeof(float));
+ splittedBuffer[0] = (float *)calloc(finalSize, sizeof(float));
+ splittedBuffer[1] = (float *)calloc(finalSize, sizeof(float));
channel_splitFloat(pSampleData, (unsigned int)totalPCMFrameCount, splittedBuffer, channels);
if (channels == 1)
memcpy(splittedBuffer[1], splittedBuffer[0], finalSize * sizeof(float));
free(pSampleData);
+ void *dt1 = 0, *dt2 = 0;
+ void *yt1 = 0, *yt2 = 0;
+ const char simulateMultiplexing = 0;
+ const char simulateDatatype = 4;
+ if (simulateDatatype == 4) // Pack24
+ {
+ dt1 = malloc(frameCountBest * 3 * 2);
+ dt2 = ((char *)dt1) + frameCountBest * 3;
+ yt1 = malloc(frameCountBest * 3 * 2);
+ yt2 = ((char *)yt1) + frameCountBest * 3;
+ }
+ else if (simulateDatatype == 3 || simulateDatatype == 2) // 8_24 / 32
+ {
+ dt1 = malloc(frameCountBest * sizeof(int32_t) * 2);
+ dt2 = ((char *)dt1) + frameCountBest * sizeof(int32_t);
+ yt1 = malloc(frameCountBest * sizeof(int32_t) * 2);
+ yt2 = ((char *)yt1) + frameCountBest * sizeof(int32_t);
+ }
+ else if (simulateDatatype == 1) // 16
+ {
+ dt1 = malloc(frameCountBest * sizeof(int16_t) * 2);
+ dt2 = ((char *)dt1) + frameCountBest * sizeof(int16_t);
+ yt1 = malloc(frameCountBest * sizeof(int16_t) * 2);
+ yt2 = ((char *)yt1) + frameCountBest * sizeof(int16_t);
+ }
+ else if (simulateDatatype == 0) // float
+ {
+ dt1 = malloc(frameCountBest * sizeof(float) * 2);
+ dt2 = ((char *)dt1) + frameCountBest * sizeof(float);
+ yt1 = malloc(frameCountBest * sizeof(float) * 2);
+ yt2 = ((char *)yt1) + frameCountBest * sizeof(float);
+ }
int targetChannels = 2;
- float **outBuffer = (float**)malloc(targetChannels * sizeof(float*));
+ float **outBuffer = (float **)malloc(targetChannels * sizeof(float *));
for (i = 0; i < targetChannels; i++)
- outBuffer[i] = (float*)calloc(finalSize, sizeof(float));
+ outBuffer[i] = (float *)calloc(finalSize, sizeof(float));
printf("[Info] Processing...\n");
pthread_t inc_x_thread;
threadTest dataThread;
dataThread.dspPtr = jdsp;
- //MovingAverage ma;
- //InitMovingAverage(&ma, 512);
+ readCountN = readcount;
+ //pthread_create(&inc_x_thread, NULL, inc_eq, &dataThread);
for (i = 0; i < readcount; i++)
{
+ idxN = i;
unsigned int pointerOffset = frameCountBest * i;
float *ptrInLeft = splittedBuffer[0] + pointerOffset;
float *ptrInRight = splittedBuffer[1] + pointerOffset;
float *outl = outBuffer[0] + pointerOffset;
float *outr = outBuffer[1] + pointerOffset;
- if (i > 800 && i < 802)
+ if (i == 400)
{
- // Remove below comment for changing convolution impulse response in runtime
+ //CompressorSetParam(jdsp, 0.8, 4, 2, 1);
//pthread_create(&inc_x_thread, NULL, inc_x, &dataThread);
+ //ArbitraryResponseEqualizerStringParser(jdsp, "cce2: 5000.0 3.0; 2000.0 0.0; 0.0 -100.0; 100.0 -20, 400.0; 0;");
+ }
+ if (i > 50 && i < 400)
+ {
+ gains[5] += 0.09;
+ MultimodalEqualizerAxisInterpolation(jdsp, 0, 0, freq, gains);
+ }
+ else if (i >= 400)
+ {
+ gains[5] -= 0.3;
+ gains[10] -= 0.1;
+ MultimodalEqualizerAxisInterpolation(jdsp, 0, 0, freq, gains);
+ }
+ /*if (i == 200)
+ {
+ text = openTextFile("stftCentreCut.eel");
+ if (text)
+ {
+ LiveProgStringParser(jdsp, text);
+ free(text);
+ }
}
- // Remove below comment for changing EQ setting in runtime
- /*if (i > 700 && i < 900)
+ if (i == 300)
{
- gain[5] += 0.25;
- FIREqualizerAxisInterpolation(jdsp, 0, 0, freq, gain);
+ text = openTextFile("fftConvolutionHRTF1.eel");
+ if (text)
+ {
+ LiveProgStringParser(jdsp, text);
+ free(text);
+ }
}
- else if (i >= 900)
+ if (i == 600)
{
- gain[5] -= 0.25;
- FIREqualizerAxisInterpolation(jdsp, 0, 1, freq, gain);
+ text = openTextFile("autopeakfilter.eel");
+ if (text)
+ {
+ LiveProgStringParser(jdsp, text);
+ free(text);
+ }
+ }
+ if (i == 800)
+ {
+ text = openTextFile("stftDenoise.eel");
+ if (text)
+ {
+ LiveProgStringParser(jdsp, text);
+ free(text);
+ }
+ }
+ if (i == 1000)
+ {
+ text = openTextFile("fftConvolution2x4x2.eel");
+ if (text)
+ {
+ LiveProgStringParser(jdsp, text);
+ free(text);
+ }
}*/
- jdsp->processFloatDeinterleaved(jdsp, ptrInLeft, ptrInRight, outl, outr, frameCountBest);
+ if (!simulateMultiplexing)
+ {
+ if (simulateDatatype == 4)
+ {
+ uint8_t *casted1 = dt1;
+ uint8_t *casted2 = dt2;
+ uint8_t *ycasted1 = yt1;
+ uint8_t *ycasted2 = yt2;
+ static const float scale = 1.0f / (float)(1UL << 31);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ jdsp->p24_from_i32(clamp24_from_float(ptrInLeft[j]), casted1 + j * 3);
+ jdsp->p24_from_i32(clamp24_from_float(ptrInRight[j]), casted2 + j * 3);
+ }
+ jdsp->processInt24PackedDeinterleaved(jdsp, casted1, casted2, ycasted1, ycasted2, frameCountBest);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ outl[j] = (float)jdsp->i32_from_p24(ycasted1 + j * 3) * scale;
+ outr[j] = (float)jdsp->i32_from_p24(ycasted2 + j * 3) * scale;
+ }
+ }
+ else if (simulateDatatype == 3 || simulateDatatype == 2)
+ {
+ int32_t *casted1 = dt1;
+ int32_t *casted2 = dt2;
+ int32_t *ycasted1 = yt1;
+ int32_t *ycasted2 = yt2;
+ float scale;
+ if (simulateDatatype == 3)
+ scale = 1.0 / (float)(1 << 23);
+ else
+ scale = 1.0 / (float)(1 << 31);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ casted1[j] = ptrInLeft[j] / scale;
+ casted2[j] = ptrInRight[j] / scale;
+ }
+ if (simulateDatatype == 3)
+ jdsp->processInt8_24Deinterleaved(jdsp, casted1, casted2, ycasted1, ycasted2, frameCountBest);
+ else
+ jdsp->processInt32Deinterleaved(jdsp, casted1, casted2, ycasted1, ycasted2, frameCountBest);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ outl[j] = (float)ycasted1[j] * scale;
+ outr[j] = (float)ycasted2[j] * scale;
+ }
+ }
+ else if (simulateDatatype == 1)
+ {
+ int16_t *casted1 = dt1;
+ int16_t *casted2 = dt2;
+ int16_t *ycasted1 = yt1;
+ int16_t *ycasted2 = yt2;
+ float scale;
+ scale = 1.0 / (float)(1 << 15);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ casted1[j] = ptrInLeft[j] / scale;
+ casted2[j] = ptrInRight[j] / scale;
+ }
+ jdsp->processInt16Deinterleaved(jdsp, casted1, casted2, ycasted1, ycasted2, frameCountBest);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ outl[j] = (float)ycasted1[j] * scale;
+ outr[j] = (float)ycasted2[j] * scale;
+ }
+ }
+ else
+ jdsp->processFloatDeinterleaved(jdsp, ptrInLeft, ptrInRight, outl, outr, frameCountBest);
+ }
+ else
+ {
+ if (simulateDatatype == 4)
+ {
+ uint8_t *casted = dt1;
+ uint8_t *ycasted = yt1;
+ static const float scale = 1.0f / (float)(1UL << 31);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ jdsp->p24_from_i32(clamp24_from_float(ptrInLeft[j]), casted + (j << 1) * 3);
+ jdsp->p24_from_i32(clamp24_from_float(ptrInRight[j]), casted + ((j << 1) + 1) * 3);
+ }
+ jdsp->processInt24PackedMultiplexd(jdsp, casted, ycasted, frameCountBest);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ outl[j] = (float)jdsp->i32_from_p24(ycasted + (j << 1) * 3) * scale;
+ outr[j] = (float)jdsp->i32_from_p24(ycasted + ((j << 1) + 1) * 3) * scale;
+ }
+ }
+ else if (simulateDatatype == 3 || simulateDatatype == 2)
+ {
+ int32_t *casted = dt1;
+ int32_t *ycasted = yt1;
+ float scale;
+ if (simulateDatatype == 3)
+ scale = 1.0 / (float)(1 << 23);
+ else
+ scale = 1.0 / (float)(1 << 31);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ casted[j << 1] = ptrInLeft[j] / scale;
+ casted[(j << 1) + 1] = ptrInRight[j] / scale;
+ }
+ if (simulateDatatype == 3)
+ jdsp->processInt8_24Multiplexd(jdsp, casted, ycasted, frameCountBest);
+ else
+ jdsp->processInt32Multiplexd(jdsp, casted, ycasted, frameCountBest);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ outl[j] = (float)ycasted[j << 1] * scale;
+ outr[j] = (float)ycasted[(j << 1) + 1] * scale;
+ }
+ }
+ else if (simulateDatatype == 1)
+ {
+ int16_t *casted = dt1;
+ int16_t *ycasted = yt1;
+ float scale;
+ scale = 1.0 / (float)(1 << 15);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ casted[j << 1] = ptrInLeft[j] / scale;
+ casted[(j << 1) + 1] = ptrInRight[j] / scale;
+ }
+ jdsp->processInt16Multiplexd(jdsp, casted, ycasted, frameCountBest);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ outl[j] = (float)ycasted[j << 1] * scale;
+ outr[j] = (float)ycasted[(j << 1) + 1] * scale;
+ }
+ }
+ else
+ {
+ float *casted = dt1;
+ float *ycasted = yt1;
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ casted[j << 1] = ptrInLeft[j];
+ casted[(j << 1) + 1] = ptrInRight[j];
+ }
+ jdsp->processFloatMultiplexd(jdsp, casted, ycasted, frameCountBest);
+ for (int j = 0; j < frameCountBest; j++)
+ {
+ outl[j] = ycasted[j << 1];
+ outr[j] = ycasted[(j << 1) + 1];
+ }
+ }
+ }
}
- if (tele)
- fclose(tele);
- if (tele2)
- fclose(tele2);
- wall1 = get_wall_time();
- cpu1 = get_cpu_time();
- printf("[Info] Audio samples processing take:\n[Info] %lf sec Wall time, %lf sec CPU time\n", wall1 - wall0, cpu1 - cpu0);
+ free(dt1);
+ free(yt1);
JamesDSPFree(jdsp);
JamesDSPGlobalMemoryDeallocation();
free(jdsp);
free(splittedBuffer[0]);
free(splittedBuffer[1]);
unsigned int totalFrames = finalSize * targetChannels;
- float *sndBuf = (float*)calloc(totalFrames, sizeof(float));
+ float *sndBuf = (float *)calloc(totalFrames, sizeof(float));
channel_joinFloat(outBuffer, targetChannels, sndBuf, finalSize);
for (i = 0; i < targetChannels; i++)
free(outBuffer[i]);
free(outBuffer);
size_t bufsz = snprintf(NULL, 0, "%s_Processed.wav", filename);
- char *filenameNew = (char*)malloc(bufsz + 1);
+ char *filenameNew = (char *)malloc(bufsz + 1);
snprintf(filenameNew, bufsz + 1, "%s_Processed.wav", filename);
free(filename);
+ SetCurrentDirectory(oldPath);
drwav pWav;
drwav_data_format format;
format.container = drwav_container_riff;
diff --git a/libjamesdsp/subtree/Main/CLI/mus.wav b/libjamesdsp/subtree/Main/CLI/mus.wav
new file mode 100644
index 00000000..919290ef
Binary files /dev/null and b/libjamesdsp/subtree/Main/CLI/mus.wav differ
diff --git a/libjamesdsp/subtree/Main/DSPManager/AndroidManifest.xml b/libjamesdsp/subtree/Main/DSPManager/AndroidManifest.xml
index ae67445c..4bef7cf1 100644
--- a/libjamesdsp/subtree/Main/DSPManager/AndroidManifest.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/AndroidManifest.xml
@@ -11,6 +11,7 @@
+** Copyright (c) 2002-2021, Erik de Castro Lopo
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
-** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
+** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
#ifndef COMMON_H_INCLUDED
#define COMMON_H_INCLUDED
-#ifdef HAVE_STDINT_H
#include
-#elif (SIZEOF_INT == 4)
-typedef int int32_t ;
-#elif (SIZEOF_LONG == 4)
-typedef long int32_t ;
+#ifdef HAVE_STDBOOL_H
+#include
+#endif
+
+#if defined(__x86_64__) || defined(_M_X64)
+# define HAVE_SSE2_INTRINSICS
+#elif defined(ENABLE_SSE2_LRINT) && (defined(_M_IX86) || defined(__i386__))
+# if defined(_MSC_VER)
+# define HAVE_SSE2_INTRINSICS
+# elif defined(__clang__)
+# ifdef __SSE2__
+# define HAVE_SSE2_INTRINSICS
+# elif (__has_attribute(target))
+# define HAVE_SSE2_INTRINSICS
+# define USE_TARGET_ATTRIBUTE
+# endif
+# elif defined(__GNUC__)
+# ifdef __SSE2__
+# define HAVE_SSE2_INTRINSICS
+# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))
+# define HAVE_SSE2_INTRINSICS
+# define USE_TARGET_ATTRIBUTE
+# endif
+# endif
+#endif
+
+#ifdef HAVE_SSE2_INTRINSICS
+#ifdef HAVE_IMMINTRIN_H
+#include
+#else
+#include
+#endif
+#endif /* HAVE_SSE2_INTRINSICS */
+
+#include
+
+#ifdef HAVE_VISIBILITY
+ #define LIBSAMPLERATE_DLL_PRIVATE __attribute__ ((visibility ("hidden")))
+#elif defined (__APPLE__)
+ #define LIBSAMPLERATE_DLL_PRIVATE __private_extern__
+#else
+ #define LIBSAMPLERATE_DLL_PRIVATE
#endif
#define SRC_MAX_RATIO 256
@@ -22,10 +59,14 @@ typedef long int32_t ;
#define SRC_MIN_RATIO_DIFF (1e-20)
+#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
-#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
#define OFFSETOF(type,member) ((int) (&((type*) 0)->member))
#define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
@@ -48,19 +89,22 @@ typedef long int32_t ;
# define WARN_UNUSED
#endif
-
#include "samplerate.h"
enum
{ SRC_FALSE = 0,
SRC_TRUE = 1,
+} ;
- SRC_MODE_PROCESS = 555,
- SRC_MODE_CALLBACK = 556
+enum SRC_MODE
+{
+ SRC_MODE_PROCESS = 0,
+ SRC_MODE_CALLBACK = 1
} ;
-enum
-{ SRC_ERR_NO_ERROR = 0,
+typedef enum SRC_ERROR
+{
+ SRC_ERR_NO_ERROR = 0,
SRC_ERR_MALLOC_FAILED,
SRC_ERR_BAD_STATE,
@@ -87,43 +131,94 @@ enum
/* This must be the last error number. */
SRC_ERR_MAX_ERROR
-} ;
+} SRC_ERROR ;
-typedef struct SRC_PRIVATE_tag
-{ double last_ratio, last_position ;
+typedef struct SRC_STATE_VT_tag
+{
+ /* Varispeed process function. */
+ SRC_ERROR (*vari_process) (SRC_STATE *state, SRC_DATA *data) ;
- int error ;
- int channels ;
+ /* Constant speed process function. */
+ SRC_ERROR (*const_process) (SRC_STATE *state, SRC_DATA *data) ;
- /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
- int mode ;
+ /* State reset. */
+ void (*reset) (SRC_STATE *state) ;
- /* Pointer to data to converter specific data. */
- void *private_data ;
+ /* State clone. */
+ SRC_STATE *(*copy) (SRC_STATE *state) ;
- /* Varispeed process function. */
- int (*vari_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
+ /* State close. */
+ void (*close) (SRC_STATE *state) ;
+} SRC_STATE_VT ;
- /* Constant speed process function. */
- int (*const_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
+struct SRC_STATE_tag
+{
+ SRC_STATE_VT *vt ;
- /* State reset. */
- void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
+ double last_ratio, last_position ;
+
+ SRC_ERROR error ;
+ int channels ;
+
+ /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
+ enum SRC_MODE mode ;
/* Data specific to SRC_MODE_CALLBACK. */
src_callback_t callback_func ;
void *user_callback_data ;
long saved_frames ;
const float *saved_data ;
-} SRC_PRIVATE ;
-int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
+ /* Pointer to data to converter specific data. */
+ void *private_data ;
+} ;
+
+/* In src_sinc.c */
+const char* sinc_get_name (int src_enum) ;
+const char* sinc_get_description (int src_enum) ;
+
+SRC_STATE *sinc_state_new (int converter_type, int channels, SRC_ERROR *error) ;
/* In src_linear.c */
const char* linear_get_name (int src_enum) ;
const char* linear_get_description (int src_enum) ;
-int linear_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
+SRC_STATE *linear_state_new (int channels, SRC_ERROR *error) ;
+
+/*----------------------------------------------------------
+** SIMD optimized math functions.
+*/
+
+#ifdef HAVE_SSE2_INTRINSICS
+static inline int
+#ifdef USE_TARGET_ATTRIBUTE
+__attribute__((target("sse2")))
+#endif
+psf_lrintf (float x)
+{
+ return _mm_cvtss_si32 (_mm_load_ss (&x)) ;
+}
+static inline int
+#ifdef USE_TARGET_ATTRIBUTE
+__attribute__((target("sse2")))
+#endif
+psf_lrint (double x)
+{
+ return _mm_cvtsd_si32 (_mm_load_sd (&x)) ;
+}
+
+#else
+
+static inline int psf_lrintf (float x)
+{
+ return lrintf (x) ;
+} /* psf_lrintf */
+
+static inline int psf_lrint (double x)
+{
+ return lrint (x) ;
+} /* psf_lrint */
+#endif
/*----------------------------------------------------------
** Common static inline functions.
@@ -133,7 +228,7 @@ static inline double
fmod_one (double x)
{ double res ;
- res = x - lrint (x) ;
+ res = x - psf_lrint (x) ;
if (res < 0.0)
return res + 1.0 ;
diff --git a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/config.h b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/config.h
deleted file mode 100644
index df079cb8..00000000
--- a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/config.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/* src/config.h. Generated from config.h.in by configure. */
-/* src/config.h.in. Generated from configure.ac by autoheader. */
-
-/* Set to 1 if the compile is GNU GCC. */
-#define COMPILER_IS_GCC 1
-
-/* Target processor clips on negative float to int conversion. */
-#define CPU_CLIPS_NEGATIVE 1
-
-/* Target processor clips on positive float to int conversion. */
-#define CPU_CLIPS_POSITIVE 0
-
-/* Target processor is big endian. */
-#define CPU_IS_BIG_ENDIAN 0
-
-/* Target processor is little endian. */
-#define CPU_IS_LITTLE_ENDIAN 1
-
-/* Major version of GCC or 3 otherwise. */
-#define GCC_MAJOR_VERSION 4
-
-/* Define to 1 if you have the `alarm' function. */
-#define HAVE_ALARM 1
-
-/* Define to 1 if you have the `calloc' function. */
-#define HAVE_CALLOC 1
-
-/* Define to 1 if you have the `ceil' function. */
-#define HAVE_CEIL 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_DLFCN_H 1
-
-/* Set to 1 if you have libfftw3. */
-#define HAVE_FFTW3 1
-
-/* Define to 1 if you have the `floor' function. */
-#define HAVE_FLOOR 1
-
-/* Define to 1 if you have the `fmod' function. */
-#define HAVE_FMOD 1
-
-/* Define to 1 if you have the `free' function. */
-#define HAVE_FREE 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_INTTYPES_H 1
-
-/* Define to 1 if you have the `m' library (-lm). */
-#define HAVE_LIBM 1
-
-/* Define if you have C99's lrint function. */
-#define HAVE_LRINT 1
-
-/* Define if you have C99's lrintf function. */
-#define HAVE_LRINTF 1
-
-/* Define to 1 if you have the `malloc' function. */
-#define HAVE_MALLOC 1
-
-/* Define to 1 if you have the `memcpy' function. */
-#define HAVE_MEMCPY 1
-
-/* Define to 1 if you have the `memmove' function. */
-#define HAVE_MEMMOVE 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define if you have signal SIGALRM. */
-#define HAVE_SIGALRM 1
-
-/* Define to 1 if you have the `signal' function. */
-#define HAVE_SIGNAL 1
-
-/* Set to 1 if you have libsndfile. */
-#define HAVE_SNDFILE 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_STDINT_H 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_STRING_H 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_SYS_TIMES_H 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define to 1 if you have the header file. */
-#define HAVE_UNISTD_H 1
-
-/* Set to 1 if compiling for Win32 */
-#define OS_IS_WIN32 0
-
-/* Name of package */
-#define PACKAGE "libsamplerate"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT ""
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME ""
-
-/* Define to the full name and version of this package. */
-#define PACKAGE_STRING ""
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME ""
-
-/* Define to the version of this package. */
-#define PACKAGE_VERSION ""
-
-/* The size of `double', as computed by sizeof. */
-#define SIZEOF_DOUBLE 8
-
-/* The size of `float', as computed by sizeof. */
-#define SIZEOF_FLOAT 4
-
-/* The size of `int', as computed by sizeof. */
-#define SIZEOF_INT 4
-
-/* The size of `long', as computed by sizeof. */
-#define SIZEOF_LONG 4
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Version number of package */
-#define VERSION "0.1.3"
diff --git a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/float_cast.h b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/float_cast.h
deleted file mode 100644
index 0318427e..00000000
--- a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/float_cast.h
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
-** Copyright (c) 2001-2016, Erik de Castro Lopo
-** All rights reserved.
-**
-** This code is released under 2-clause BSD license. Please see the
-** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
-*/
-
-/* Version 1.5 */
-
-#ifndef FLOAT_CAST_HEADER
-#define FLOAT_CAST_HEADER
-
-/*============================================================================
-** On Intel Pentium processors (especially PIII and probably P4), converting
-** from float to int is very slow. To meet the C specs, the code produced by
-** most C compilers targeting Pentium needs to change the FPU rounding mode
-** before the float to int conversion is performed.
-**
-** Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
-** is this flushing of the pipeline which is so slow.
-**
-** Fortunately the ISO C99 specifications define the functions lrint, lrintf,
-** llrint and llrintf which fix this problem as a side effect.
-**
-** On Unix-like systems, the configure process should have detected the
-** presence of these functions. If they weren't found we have to replace them
-** here with a standard C cast.
-*/
-
-/*
-** The C99 prototypes for lrint and lrintf are as follows:
-**
-** long int lrintf (float x) ;
-** long int lrint (double x) ;
-*/
-
-#include "config.h"
-
-/*
-** The presence of the required functions are detected during the configure
-** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
-** the config.h file.
-*/
-
-#define HAVE_LRINT_REPLACEMENT 0
-
-#if (HAVE_LRINT && HAVE_LRINTF)
-
- /*
- ** These defines enable functionality introduced with the 1999 ISO C
- ** standard. They must be defined before the inclusion of math.h to
- ** engage them. If optimisation is enabled, these functions will be
- ** inlined. With optimisation switched off, you have to link in the
- ** maths library using -lm.
- */
-
- #define _ISOC9X_SOURCE 1
- #define _ISOC99_SOURCE 1
-
- #define __USE_ISOC9X 1
- #define __USE_ISOC99 1
-
- #include
-
-#elif (defined (__CYGWIN__))
-
- #include
-
- #undef HAVE_LRINT_REPLACEMENT
- #define HAVE_LRINT_REPLACEMENT 1
-
- #undef lrint
- #undef lrintf
-
- #define lrint double2int
- #define lrintf float2int
-
- /*
- ** The native CYGWIN lrint and lrintf functions are buggy:
- ** http://sourceware.org/ml/cygwin/2005-06/msg00153.html
- ** http://sourceware.org/ml/cygwin/2005-09/msg00047.html
- ** and slow.
- ** These functions (pulled from the Public Domain MinGW math.h header)
- ** replace the native versions.
- */
-
- static inline long double2int (double in)
- { long retval ;
-
- __asm__ __volatile__
- ( "fistpl %0"
- : "=m" (retval)
- : "t" (in)
- : "st"
- ) ;
-
- return retval ;
- } /* double2int */
-
- static inline long float2int (float in)
- { long retval ;
-
- __asm__ __volatile__
- ( "fistpl %0"
- : "=m" (retval)
- : "t" (in)
- : "st"
- ) ;
-
- return retval ;
- } /* float2int */
-
-#elif (defined (WIN64) || defined(_WIN64))
-
- /* Win64 section should be places before Win32 one, because
- ** most likely both WIN32 and WIN64 will be defined in 64-bit case.
- */
-
- #include
-
- /* Win64 doesn't seem to have these functions, nor inline assembly.
- ** Therefore implement inline versions of these functions here.
- */
- #include
- #include
-
- __inline long int
- lrint(double flt)
- {
- return _mm_cvtsd_si32(_mm_load_sd(&flt));
- }
-
- __inline long int
- lrintf(float flt)
- {
- return _mm_cvtss_si32(_mm_load_ss(&flt));
- }
-
-#elif (defined (WIN32) || defined (_WIN32))
-
- #undef HAVE_LRINT_REPLACEMENT
- #define HAVE_LRINT_REPLACEMENT 1
-
- #include
-
- /*
- ** Win32 doesn't seem to have these functions.
- ** Therefore implement inline versions of these functions here.
- */
-
- __inline long int
- lrint (double flt)
- { int intgr ;
-
- _asm
- { fld flt
- fistp intgr
- } ;
-
- return intgr ;
- }
-
- __inline long int
- lrintf (float flt)
- { int intgr ;
-
- _asm
- { fld flt
- fistp intgr
- } ;
-
- return intgr ;
- }
-
-#elif (defined (__MWERKS__) && defined (macintosh))
-
- /* This MacOS 9 solution was provided by Stephane Letz */
-
- #undef HAVE_LRINT_REPLACEMENT
- #define HAVE_LRINT_REPLACEMENT 1
- #include
-
- #undef lrint
- #undef lrintf
-
- #define lrint double2int
- #define lrintf float2int
-
- inline int
- float2int (register float in)
- { long res [2] ;
-
- asm
- { fctiw in, in
- stfd in, res
- }
- return res [1] ;
- } /* float2int */
-
- inline int
- double2int (register double in)
- { long res [2] ;
-
- asm
- { fctiw in, in
- stfd in, res
- }
- return res [1] ;
- } /* double2int */
-
-#elif (defined (__MACH__) && defined (__APPLE__))
-
- /* For Apple MacOSX. */
-
- #undef HAVE_LRINT_REPLACEMENT
- #define HAVE_LRINT_REPLACEMENT 1
- #include
-
- #undef lrint
- #undef lrintf
-
- #define lrint double2int
- #define lrintf float2int
-
- inline static long
- float2int (register float in)
- { int res [2] ;
-
- __asm__ __volatile__
- ( "fctiw %1, %1\n\t"
- "stfd %1, %0"
- : "=m" (res) /* Output */
- : "f" (in) /* Input */
- : "memory"
- ) ;
-
- return res [1] ;
- } /* lrintf */
-
- inline static long
- double2int (register double in)
- { int res [2] ;
-
- __asm__ __volatile__
- ( "fctiw %1, %1\n\t"
- "stfd %1, %0"
- : "=m" (res) /* Output */
- : "f" (in) /* Input */
- : "memory"
- ) ;
-
- return res [1] ;
- } /* lrint */
-
-#else
- #ifndef __sgi
- #warning "Don't have the functions lrint() and lrintf()."
- #warning "Replacing these functions with a standard C cast."
- #endif
-
- #include
-
- #define lrint(dbl) ((long) (dbl))
- #define lrintf(flt) ((long) (flt))
-
-#endif
-
-
-#endif /* FLOAT_CAST_HEADER */
-
diff --git a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.c b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.c
index bef019dc..9cf46ed6 100644
--- a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.c
+++ b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.c
@@ -3,59 +3,53 @@
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
-** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
+** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include
#include
#include
-
-#include "config.h"
+#include
#include "samplerate.h"
-#include "float_cast.h"
#include "common.h"
-static int psrc_set_converter (SRC_PRIVATE *psrc, int converter_type) ;
+static SRC_STATE *psrc_set_converter (int converter_type, int channels, int *error) ;
SRC_STATE *
src_new (int converter_type, int channels, int *error)
-{ SRC_PRIVATE *psrc ;
+{
+ return psrc_set_converter (converter_type, channels, error) ;
+} /* src_new */
+SRC_STATE*
+src_clone (SRC_STATE* orig, int *error)
+{
+ if (!orig)
+ {
+ if (error)
+ *error = SRC_ERR_BAD_STATE ;
+ return NULL ;
+ }
if (error)
*error = SRC_ERR_NO_ERROR ;
- if (channels < 1)
- { if (error)
- *error = SRC_ERR_BAD_CHANNEL_COUNT ;
- return NULL ;
- } ;
-
- if ((psrc = calloc (1, sizeof (*psrc))) == NULL)
- { if (error)
+ SRC_STATE *state = orig->vt->copy (orig) ;
+ if (!state)
+ if (error)
*error = SRC_ERR_MALLOC_FAILED ;
- return NULL ;
- } ;
- psrc->channels = channels ;
- psrc->mode = SRC_MODE_PROCESS ;
-
- if (psrc_set_converter (psrc, converter_type) != SRC_ERR_NO_ERROR)
- { if (error)
- *error = SRC_ERR_BAD_CONVERTER ;
- free (psrc) ;
- psrc = NULL ;
- } ;
-
- src_reset ((SRC_STATE*) psrc) ;
-
- return (SRC_STATE*) psrc ;
-} /* src_new */
+ return state ;
+}
SRC_STATE*
src_callback_new (src_callback_t func, int converter_type, int channels, int *error, void* cb_data)
-{ SRC_STATE *src_state ;
+{ SRC_STATE *state ;
if (func == NULL)
{ if (error)
@@ -66,46 +60,36 @@ src_callback_new (src_callback_t func, int converter_type, int channels, int *er
if (error != NULL)
*error = 0 ;
- if ((src_state = src_new (converter_type, channels, error)) == NULL)
+ if ((state = src_new (converter_type, channels, error)) == NULL)
return NULL ;
- src_reset (src_state) ;
+ src_reset (state) ;
- ((SRC_PRIVATE*) src_state)->mode = SRC_MODE_CALLBACK ;
- ((SRC_PRIVATE*) src_state)->callback_func = func ;
- ((SRC_PRIVATE*) src_state)->user_callback_data = cb_data ;
+ state->mode = SRC_MODE_CALLBACK ;
+ state->callback_func = func ;
+ state->user_callback_data = cb_data ;
- return src_state ;
+ return state ;
} /* src_callback_new */
SRC_STATE *
src_delete (SRC_STATE *state)
-{ SRC_PRIVATE *psrc ;
-
- psrc = (SRC_PRIVATE*) state ;
- if (psrc)
- { if (psrc->private_data)
- free (psrc->private_data) ;
- memset (psrc, 0, sizeof (SRC_PRIVATE)) ;
- free (psrc) ;
- } ;
+{
+ if (state)
+ state->vt->close (state) ;
return NULL ;
} /* src_state */
int
src_process (SRC_STATE *state, SRC_DATA *data)
-{ SRC_PRIVATE *psrc ;
+{
int error ;
- psrc = (SRC_PRIVATE*) state ;
-
- if (psrc == NULL)
+ if (state == NULL)
return SRC_ERR_BAD_STATE ;
- if (psrc->vari_process == NULL || psrc->const_process == NULL)
- return SRC_ERR_BAD_PROC_PTR ;
- if (psrc->mode != SRC_MODE_PROCESS)
+ if (state->mode != SRC_MODE_PROCESS)
return SRC_ERR_BAD_MODE ;
/* Check for valid SRC_DATA first. */
@@ -113,7 +97,8 @@ src_process (SRC_STATE *state, SRC_DATA *data)
return SRC_ERR_BAD_DATA ;
/* And that data_in and data_out are valid. */
- if (data->data_in == NULL || data->data_out == NULL)
+ if ((data->data_in == NULL && data->input_frames > 0)
+ || (data->data_out == NULL && data->output_frames > 0))
return SRC_ERR_BAD_DATA_PTR ;
/* Check src_ratio is in range. */
@@ -126,13 +111,13 @@ src_process (SRC_STATE *state, SRC_DATA *data)
data->output_frames = 0 ;
if (data->data_in < data->data_out)
- { if (data->data_in + data->input_frames * psrc->channels > data->data_out)
+ { if (data->data_in + data->input_frames * state->channels > data->data_out)
{ /*-printf ("\n\ndata_in: %p data_out: %p\n",
(void*) (data->data_in + data->input_frames * psrc->channels), (void*) data->data_out) ;-*/
return SRC_ERR_DATA_OVERLAP ;
} ;
}
- else if (data->data_out + data->output_frames * psrc->channels > data->data_in)
+ else if (data->data_out + data->output_frames * state->channels > data->data_in)
{ /*-printf ("\n\ndata_in : %p ouput frames: %ld data_out: %p\n", (void*) data->data_in, data->output_frames, (void*) data->data_out) ;
printf ("data_out: %p (%p) data_in: %p\n", (void*) data->data_out,
@@ -145,21 +130,21 @@ src_process (SRC_STATE *state, SRC_DATA *data)
data->output_frames_gen = 0 ;
/* Special case for when last_ratio has not been set. */
- if (psrc->last_ratio < (1.0 / SRC_MAX_RATIO))
- psrc->last_ratio = data->src_ratio ;
+ if (state->last_ratio < (1.0 / SRC_MAX_RATIO))
+ state->last_ratio = data->src_ratio ;
/* Now process. */
- if (fabs (psrc->last_ratio - data->src_ratio) < 1e-15)
- error = psrc->const_process (psrc, data) ;
+ if (fabs (state->last_ratio - data->src_ratio) < 1e-15)
+ error = state->vt->const_process (state, data) ;
else
- error = psrc->vari_process (psrc, data) ;
+ error = state->vt->vari_process (state, data) ;
return error ;
} /* src_process */
long
src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
-{ SRC_PRIVATE *psrc ;
+{
SRC_DATA src_data ;
long output_frames_gen ;
@@ -171,15 +156,13 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
if (frames <= 0)
return 0 ;
- psrc = (SRC_PRIVATE*) state ;
-
- if (psrc->mode != SRC_MODE_CALLBACK)
- { psrc->error = SRC_ERR_BAD_MODE ;
+ if (state->mode != SRC_MODE_CALLBACK)
+ { state->error = SRC_ERR_BAD_MODE ;
return 0 ;
} ;
- if (psrc->callback_func == NULL)
- { psrc->error = SRC_ERR_NULL_CALLBACK ;
+ if (state->callback_func == NULL)
+ { state->error = SRC_ERR_NULL_CALLBACK ;
return 0 ;
} ;
@@ -187,7 +170,7 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
/* Check src_ratio is in range. */
if (is_bad_src_ratio (src_ratio))
- { psrc->error = SRC_ERR_BAD_SRC_RATIO ;
+ { state->error = SRC_ERR_BAD_SRC_RATIO ;
return 0 ;
} ;
@@ -196,8 +179,8 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
src_data.data_out = data ;
src_data.output_frames = frames ;
- src_data.data_in = psrc->saved_data ;
- src_data.input_frames = psrc->saved_frames ;
+ src_data.data_in = state->saved_data ;
+ src_data.input_frames = state->saved_frames ;
output_frames_gen = 0 ;
while (output_frames_gen < frames)
@@ -209,7 +192,7 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
if (src_data.input_frames == 0)
{ float *ptr = dummy ;
- src_data.input_frames = psrc->callback_func (psrc->user_callback_data, &ptr) ;
+ src_data.input_frames = state->callback_func (state->user_callback_data, &ptr) ;
src_data.data_in = ptr ;
if (src_data.input_frames == 0)
@@ -221,17 +204,17 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
** to SRC_MODE_PROCESS first and when we return set it back to
** SRC_MODE_CALLBACK.
*/
- psrc->mode = SRC_MODE_PROCESS ;
+ state->mode = SRC_MODE_PROCESS ;
error = src_process (state, &src_data) ;
- psrc->mode = SRC_MODE_CALLBACK ;
+ state->mode = SRC_MODE_CALLBACK ;
if (error != 0)
break ;
- src_data.data_in += src_data.input_frames_used * psrc->channels ;
+ src_data.data_in += src_data.input_frames_used * state->channels ;
src_data.input_frames -= src_data.input_frames_used ;
- src_data.data_out += src_data.output_frames_gen * psrc->channels ;
+ src_data.data_out += src_data.output_frames_gen * state->channels ;
src_data.output_frames -= src_data.output_frames_gen ;
output_frames_gen += src_data.output_frames_gen ;
@@ -240,12 +223,12 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
break ;
} ;
- psrc->saved_data = src_data.data_in ;
- psrc->saved_frames = src_data.input_frames ;
+ state->saved_data = src_data.data_in ;
+ state->saved_frames = src_data.input_frames ;
if (error != 0)
- { psrc->error = error ;
- return 0 ;
+ { state->error = (SRC_ERROR) error ;
+ return 0 ;
} ;
return output_frames_gen ;
@@ -256,58 +239,74 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
int
src_set_ratio (SRC_STATE *state, double new_ratio)
-{ SRC_PRIVATE *psrc ;
-
- psrc = (SRC_PRIVATE*) state ;
-
- if (psrc == NULL)
+{
+ if (state == NULL)
return SRC_ERR_BAD_STATE ;
- if (psrc->vari_process == NULL || psrc->const_process == NULL)
- return SRC_ERR_BAD_PROC_PTR ;
if (is_bad_src_ratio (new_ratio))
return SRC_ERR_BAD_SRC_RATIO ;
- psrc->last_ratio = new_ratio ;
+ state->last_ratio = new_ratio ;
return SRC_ERR_NO_ERROR ;
} /* src_set_ratio */
int
src_get_channels (SRC_STATE *state)
-{ SRC_PRIVATE *psrc ;
-
- psrc = (SRC_PRIVATE*) state ;
-
- if (psrc == NULL)
- return SRC_ERR_BAD_STATE ;
- if (psrc->vari_process == NULL || psrc->const_process == NULL)
- return SRC_ERR_BAD_PROC_PTR ;
+{
+ if (state == NULL)
+ return -SRC_ERR_BAD_STATE ;
- return psrc->channels ;
+ return state->channels ;
} /* src_get_channels */
int
src_reset (SRC_STATE *state)
-{ SRC_PRIVATE *psrc ;
-
- if ((psrc = (SRC_PRIVATE*) state) == NULL)
+{
+ if (state == NULL)
return SRC_ERR_BAD_STATE ;
- if (psrc->reset != NULL)
- psrc->reset (psrc) ;
+ state->vt->reset (state) ;
- psrc->last_position = 0.0 ;
- psrc->last_ratio = 0.0 ;
+ state->last_position = 0.0 ;
+ state->last_ratio = 0.0 ;
- psrc->saved_data = NULL ;
- psrc->saved_frames = 0 ;
+ state->saved_data = NULL ;
+ state->saved_frames = 0 ;
- psrc->error = SRC_ERR_NO_ERROR ;
+ state->error = SRC_ERR_NO_ERROR ;
return SRC_ERR_NO_ERROR ;
} /* src_reset */
+/*==============================================================================
+** Control functions.
+*/
+
+const char *
+src_get_name (int converter_type)
+{ const char *desc ;
+
+ if ((desc = sinc_get_name (converter_type)) != NULL)
+ return desc ;
+ if ((desc = linear_get_name (converter_type)) != NULL)
+ return desc ;
+
+ return NULL ;
+} /* src_get_name */
+
+const char *
+src_get_description (int converter_type)
+{ const char *desc ;
+
+ if ((desc = sinc_get_description (converter_type)) != NULL)
+ return desc ;
+ if ((desc = linear_get_description (converter_type)) != NULL)
+ return desc ;
+
+ return NULL ;
+} /* src_get_description */
+
int
src_is_valid_ratio (double ratio)
{
@@ -317,6 +316,79 @@ src_is_valid_ratio (double ratio)
return SRC_TRUE ;
} /* src_is_valid_ratio */
+/*==============================================================================
+** Error reporting functions.
+*/
+
+int
+src_error (SRC_STATE *state)
+{ if (state)
+ return state->error ;
+ return SRC_ERR_NO_ERROR ;
+} /* src_error */
+
+const char*
+src_strerror (int error)
+{
+ switch (error)
+ { case SRC_ERR_NO_ERROR :
+ return "No error." ;
+ case SRC_ERR_MALLOC_FAILED :
+ return "Malloc failed." ;
+ case SRC_ERR_BAD_STATE :
+ return "SRC_STATE pointer is NULL." ;
+ case SRC_ERR_BAD_DATA :
+ return "SRC_DATA pointer is NULL." ;
+ case SRC_ERR_BAD_DATA_PTR :
+ return "SRC_DATA->data_out or SRC_DATA->data_in is NULL." ;
+ case SRC_ERR_NO_PRIVATE :
+ return "Internal error. No private data." ;
+
+ case SRC_ERR_BAD_SRC_RATIO :
+ return "SRC ratio outside [1/" SRC_MAX_RATIO_STR ", " SRC_MAX_RATIO_STR "] range." ;
+
+ case SRC_ERR_BAD_SINC_STATE :
+ return "src_process() called without reset after end_of_input." ;
+ case SRC_ERR_BAD_PROC_PTR :
+ return "Internal error. No process pointer." ;
+ case SRC_ERR_SHIFT_BITS :
+ return "Internal error. SHIFT_BITS too large." ;
+ case SRC_ERR_FILTER_LEN :
+ return "Internal error. Filter length too large." ;
+ case SRC_ERR_BAD_CONVERTER :
+ return "Bad converter number." ;
+ case SRC_ERR_BAD_CHANNEL_COUNT :
+ return "Channel count must be >= 1." ;
+ case SRC_ERR_SINC_BAD_BUFFER_LEN :
+ return "Internal error. Bad buffer length. Please report this." ;
+ case SRC_ERR_SIZE_INCOMPATIBILITY :
+ return "Internal error. Input data / internal buffer size difference. Please report this." ;
+ case SRC_ERR_BAD_PRIV_PTR :
+ return "Internal error. Private pointer is NULL. Please report this." ;
+ case SRC_ERR_DATA_OVERLAP :
+ return "Input and output data arrays overlap." ;
+ case SRC_ERR_BAD_CALLBACK :
+ return "Supplied callback function pointer is NULL." ;
+ case SRC_ERR_BAD_MODE :
+ return "Calling mode differs from initialisation mode (ie process v callback)." ;
+ case SRC_ERR_NULL_CALLBACK :
+ return "Callback function pointer is NULL in src_callback_read ()." ;
+ case SRC_ERR_NO_VARIABLE_RATIO :
+ return "This converter only allows constant conversion ratios." ;
+ case SRC_ERR_SINC_PREPARE_DATA_BAD_LEN :
+ return "Internal error : Bad length in prepare_data ()." ;
+ case SRC_ERR_BAD_INTERNAL_STATE :
+ return "Error : Someone is trampling on my internal state." ;
+
+ case SRC_ERR_MAX_ERROR :
+ return "Placeholder. No error defined for this error number." ;
+
+ default : break ;
+ }
+
+ return NULL ;
+} /* src_strerror */
+
/*==============================================================================
** Simple interface for performing a single conversion from input buffer to
** output buffer at a fixed conversion ratio.
@@ -339,19 +411,96 @@ src_simple (SRC_DATA *src_data, int converter, int channels)
return error ;
} /* src_simple */
+void
+src_short_to_float_array (const short *in, float *out, int len)
+{
+ for (int i = 0 ; i < len ; i++)
+ { out [i] = (float) (in [i] / (1.0 * 0x8000)) ;
+ } ;
+
+ return ;
+} /* src_short_to_float_array */
+
+void
+src_float_to_short_array (const float *in, short *out, int len)
+{
+ for (int i = 0 ; i < len ; i++)
+ { float scaled_value ;
+ scaled_value = in [i] * 32768.f ;
+ if (scaled_value >= 32767.f)
+ out [i] = 32767 ;
+ else if (scaled_value <= -32768.f)
+ out [i] = -32768 ;
+ else
+ out [i] = (short) (psf_lrintf (scaled_value)) ;
+ }
+} /* src_float_to_short_array */
+
+void
+src_int_to_float_array (const int *in, float *out, int len)
+{
+ for (int i = 0 ; i < len ; i++)
+ { out [i] = (float) (in [i] / (8.0 * 0x10000000)) ;
+ } ;
+
+ return ;
+} /* src_int_to_float_array */
+
+void
+src_float_to_int_array (const float *in, int *out, int len)
+{ double scaled_value ;
+
+ for (int i = 0 ; i < len ; i++)
+ { scaled_value = in [i] * (8.0 * 0x10000000) ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { out [i] = 0x7fffffff ;
+ continue ;
+ } ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { out [i] = -1 - 0x7fffffff ;
+ continue ;
+ } ;
+#endif
+ out [i] = (int) psf_lrint (scaled_value) ;
+ } ;
+
+} /* src_float_to_int_array */
+
/*==============================================================================
** Private functions.
*/
-static int
-psrc_set_converter (SRC_PRIVATE *psrc, int converter_type)
+static SRC_STATE *
+psrc_set_converter (int converter_type, int channels, int *error)
{
- if (sinc_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
- return SRC_ERR_NO_ERROR ;
+ SRC_ERROR temp_error;
+ SRC_STATE *state ;
+ switch (converter_type)
+ {
+ case SRC_SINC_BEST_QUALITY :
+ state = sinc_state_new (converter_type, channels, &temp_error) ;
+ break ;
+ case SRC_SINC_MEDIUM_QUALITY :
+ state = sinc_state_new (converter_type, channels, &temp_error) ;
+ break ;
+ case SRC_SINC_FASTEST :
+ state = sinc_state_new (converter_type, channels, &temp_error) ;
+ break ;
+ case SRC_LINEAR :
+ state = linear_state_new (channels, &temp_error) ;
+ break ;
+ default :
+ temp_error = SRC_ERR_BAD_CONVERTER ;
+ state = NULL ;
+ break ;
+ }
- if (linear_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
- return SRC_ERR_NO_ERROR ;
+ if (error)
+ *error = (int) temp_error ;
- return SRC_ERR_BAD_CONVERTER ;
+ return state ;
} /* psrc_set_converter */
diff --git a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.h b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.h
index 9dc10045..767c753b 100644
--- a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.h
+++ b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/samplerate.h
@@ -3,12 +3,12 @@
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
-** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
+** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
/*
** API documentation is available here:
-** http://www.mega-nerd.com/SRC/api.html
+** http://libsndfile.github.io/libsamplerate/api.html
*/
#ifndef SAMPLERATE_H
@@ -25,7 +25,7 @@ typedef struct SRC_STATE_tag SRC_STATE ;
/* SRC_DATA is used to pass data to src_simple() and src_process(). */
typedef struct
{ const float *data_in ;
- float *data_out ;
+ float *data_out ;
long input_frames, output_frames ;
long input_frames_used, output_frames_gen ;
@@ -54,6 +54,12 @@ typedef long (*src_callback_t) (void *cb_data, float **data) ;
SRC_STATE* src_new (int converter_type, int channels, int *error) ;
+/*
+** Clone a handle : return an anonymous pointer to a new converter
+** containing the same internal state as orig. Error returned in *error.
+*/
+SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
+
/*
** Initilisation for callback based API : return an anonymous pointer to the
** internal state of the converter. Choose a converter from the enums below.
@@ -94,6 +100,18 @@ long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *
int src_simple (SRC_DATA *data, int converter_type, int channels) ;
+/*
+** This library contains a number of different sample rate converters,
+** numbered 0 through N.
+**
+** Return a string giving either a name or a more full description of each
+** sample rate converter or NULL if no sample rate converter exists for
+** the given value. The converters are sequentially numbered from 0 to N.
+*/
+
+const char *src_get_name (int converter_type) ;
+const char *src_get_description (int converter_type) ;
+
/*
** Set a new SRC ratio. This allows step responses
** in the conversion ratio.
@@ -125,6 +143,17 @@ int src_reset (SRC_STATE *state) ;
int src_is_valid_ratio (double ratio) ;
+/*
+** Return an error number.
+*/
+
+int src_error (SRC_STATE *state) ;
+
+/*
+** Convert the error number into a string.
+*/
+const char* src_strerror (int error) ;
+
/*
** The following enums can be used to set the interpolator type
** using the function src_set_converter().
@@ -132,10 +161,26 @@ int src_is_valid_ratio (double ratio) ;
enum
{
- SRC_SINC_MEDIUM_QUALITY = 0,
- SRC_LINEAR = 1,
+ SRC_SINC_BEST_QUALITY = 0,
+ SRC_SINC_MEDIUM_QUALITY = 1,
+ SRC_SINC_FASTEST = 2,
+ SRC_LINEAR = 3,
} ;
+/*
+** Extra helper functions for converting from short to float and
+** back again.
+*/
+
+void src_short_to_float_array (const short *in, float *out, int len) ;
+void src_float_to_short_array (const float *in, short *out, int len) ;
+
+void src_int_to_float_array (const int *in, float *out, int len) ;
+void src_float_to_int_array (const float *in, int *out, int len) ;
+
+
+void precompute_lpfcoeff();
+void clean_lpfcoeff();
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
diff --git a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_linear.c b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_linear.c
index c239a085..4ddd7b45 100644
--- a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_linear.c
+++ b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_linear.c
@@ -1,21 +1,27 @@
/*
-** Copyright (c) 2002-2016, Erik de Castro Lopo
+** Copyright (c) 2002-2021, Erik de Castro Lopo
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
-** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
+** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include
#include
#include
#include
+#include
-#include "config.h"
-#include "float_cast.h"
#include "common.h"
-static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
-static void linear_reset (SRC_PRIVATE *psrc) ;
+static SRC_ERROR linear_vari_process (SRC_STATE *state, SRC_DATA *data) ;
+static void linear_reset (SRC_STATE *state) ;
+static SRC_STATE *linear_copy (SRC_STATE *state) ;
+static void linear_close (SRC_STATE *state) ;
/*========================================================================================
*/
@@ -26,18 +32,26 @@ static void linear_reset (SRC_PRIVATE *psrc) ;
typedef struct
{ int linear_magic_marker ;
- int channels ;
- int reset ;
+ int dirty ;
long in_count, in_used ;
long out_count, out_gen ;
- float last_value [1] ;
+ float *last_value ;
} LINEAR_DATA ;
+static SRC_STATE_VT linear_state_vt =
+{
+ linear_vari_process,
+ linear_vari_process,
+ linear_reset,
+ linear_copy,
+ linear_close
+} ;
+
/*----------------------------------------------------------------------------------------
*/
-static int
-linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+static SRC_ERROR
+linear_vari_process (SRC_STATE *state, SRC_DATA *data)
{ LINEAR_DATA *priv ;
double src_ratio, input_index, rem ;
int ch ;
@@ -45,41 +59,41 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
if (data->input_frames <= 0)
return SRC_ERR_NO_ERROR ;
- if (psrc->private_data == NULL)
+ if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
- priv = (LINEAR_DATA*) psrc->private_data ;
+ priv = (LINEAR_DATA*) state->private_data ;
- if (priv->reset)
+ if (!priv->dirty)
{ /* If we have just been reset, set the last_value data. */
- for (ch = 0 ; ch < priv->channels ; ch++)
+ for (ch = 0 ; ch < state->channels ; ch++)
priv->last_value [ch] = data->data_in [ch] ;
- priv->reset = 0 ;
+ priv->dirty = 1 ;
} ;
- priv->in_count = data->input_frames * priv->channels ;
- priv->out_count = data->output_frames * priv->channels ;
+ priv->in_count = data->input_frames * state->channels ;
+ priv->out_count = data->output_frames * state->channels ;
priv->in_used = priv->out_gen = 0 ;
- src_ratio = psrc->last_ratio ;
+ src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
- input_index = psrc->last_position ;
+ input_index = state->last_position ;
/* Calculate samples before first sample in input array. */
while (input_index < 1.0 && priv->out_gen < priv->out_count)
{
- if (priv->in_used + priv->channels * (1.0 + input_index) >= priv->in_count)
+ if (priv->in_used + state->channels * (1.0 + input_index) >= priv->in_count)
break ;
- if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
- src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
+ if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
+ src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
- for (ch = 0 ; ch < priv->channels ; ch++)
+ for (ch = 0 ; ch < state->channels ; ch++)
{ data->data_out [priv->out_gen] = (float) (priv->last_value [ch] + input_index *
- (data->data_in [ch] - priv->last_value [ch])) ;
+ ((double) data->data_in [ch] - priv->last_value [ch])) ;
priv->out_gen ++ ;
} ;
@@ -88,23 +102,25 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
} ;
rem = fmod_one (input_index) ;
- priv->in_used += priv->channels * lrint (input_index - rem) ;
+ priv->in_used += state->channels * psf_lrint (input_index - rem) ;
input_index = rem ;
/* Main processing loop. */
- while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index < priv->in_count)
+ while (priv->out_gen < priv->out_count && priv->in_used + state->channels * input_index < priv->in_count)
{
- if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
- src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
+ if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
+ src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
- if (SRC_DEBUG && priv->in_used < priv->channels && input_index < 1.0)
- { printf ("Whoops!!!! in_used : %ld channels : %d input_index : %f\n", priv->in_used, priv->channels, input_index) ;
+#if SRC_DEBUG
+ if (priv->in_used < state->channels && input_index < 1.0)
+ { printf ("Whoops!!!! in_used : %ld channels : %d input_index : %f\n", priv->in_used, state->channels, input_index) ;
exit (1) ;
} ;
+#endif
- for (ch = 0 ; ch < priv->channels ; ch++)
- { data->data_out [priv->out_gen] = (float) (data->data_in [priv->in_used - priv->channels + ch] + input_index *
- (data->data_in [priv->in_used + ch] - data->data_in [priv->in_used - priv->channels + ch])) ;
+ for (ch = 0 ; ch < state->channels ; ch++)
+ { data->data_out [priv->out_gen] = (float) (data->data_in [priv->in_used - state->channels + ch] + input_index *
+ ((double) data->data_in [priv->in_used + ch] - data->data_in [priv->in_used - state->channels + ch])) ;
priv->out_gen ++ ;
} ;
@@ -112,26 +128,26 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
- priv->in_used += priv->channels * lrint (input_index - rem) ;
+ priv->in_used += state->channels * psf_lrint (input_index - rem) ;
input_index = rem ;
} ;
if (priv->in_used > priv->in_count)
- { input_index += (priv->in_used - priv->in_count) / priv->channels ;
+ { input_index += (priv->in_used - priv->in_count) / state->channels ;
priv->in_used = priv->in_count ;
} ;
- psrc->last_position = input_index ;
+ state->last_position = input_index ;
if (priv->in_used > 0)
- for (ch = 0 ; ch < priv->channels ; ch++)
- priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
+ for (ch = 0 ; ch < state->channels ; ch++)
+ priv->last_value [ch] = data->data_in [priv->in_used - state->channels + ch] ;
/* Save current ratio rather then target ratio. */
- psrc->last_ratio = src_ratio ;
+ state->last_ratio = src_ratio ;
- data->input_frames_used = priv->in_used / priv->channels ;
- data->output_frames_gen = priv->out_gen / priv->channels ;
+ data->input_frames_used = priv->in_used / state->channels ;
+ data->output_frames_gen = priv->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* linear_vari_process */
@@ -139,7 +155,7 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
/*------------------------------------------------------------------------------
*/
-const char*
+LIBSAMPLERATE_DLL_PRIVATE const char*
linear_get_name (int src_enum)
{
if (src_enum == SRC_LINEAR)
@@ -148,7 +164,7 @@ linear_get_name (int src_enum)
return NULL ;
} /* linear_get_name */
-const char*
+LIBSAMPLERATE_DLL_PRIVATE const char*
linear_get_description (int src_enum)
{
if (src_enum == SRC_LINEAR)
@@ -157,53 +173,129 @@ linear_get_description (int src_enum)
return NULL ;
} /* linear_get_descrition */
-int
-linear_set_converter (SRC_PRIVATE *psrc, int src_enum)
-{ LINEAR_DATA *priv = NULL ;
+static LINEAR_DATA *
+linear_data_new (int channels)
+{
+ assert (channels > 0) ;
- if (src_enum != SRC_LINEAR)
- return SRC_ERR_BAD_CONVERTER ;
+ LINEAR_DATA *priv = (LINEAR_DATA *) calloc (1, sizeof (LINEAR_DATA)) ;
+ if (priv)
+ {
+ priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
+ priv->last_value = (float *) calloc (channels, sizeof (float)) ;
+ if (!priv->last_value)
+ {
+ free (priv) ;
+ priv = NULL ;
+ }
+ }
+
+ return priv ;
+}
+
+LIBSAMPLERATE_DLL_PRIVATE SRC_STATE *
+linear_state_new (int channels, SRC_ERROR *error)
+{
+ assert (channels > 0) ;
+ assert (error != NULL) ;
- if (psrc->private_data != NULL)
- { free (psrc->private_data) ;
- psrc->private_data = NULL ;
- } ;
+ SRC_STATE *state = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
+ if (!state)
+ {
+ *error = SRC_ERR_MALLOC_FAILED ;
+ return NULL ;
+ }
- if (psrc->private_data == NULL)
- { priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
- psrc->private_data = priv ;
- } ;
+ state->channels = channels ;
+ state->mode = SRC_MODE_PROCESS ;
- if (priv == NULL)
- return SRC_ERR_MALLOC_FAILED ;
+ state->private_data = linear_data_new (state->channels) ;
+ if (!state->private_data)
+ {
+ free (state) ;
+ *error = SRC_ERR_MALLOC_FAILED ;
+ return NULL ;
+ }
- priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
- priv->channels = psrc->channels ;
+ state->vt = &linear_state_vt ;
- psrc->const_process = linear_vari_process ;
- psrc->vari_process = linear_vari_process ;
- psrc->reset = linear_reset ;
+ linear_reset (state) ;
- linear_reset (psrc) ;
+ *error = SRC_ERR_NO_ERROR ;
- return SRC_ERR_NO_ERROR ;
-} /* linear_set_converter */
+ return state ;
+}
/*===================================================================================
*/
static void
-linear_reset (SRC_PRIVATE *psrc)
+linear_reset (SRC_STATE *state)
{ LINEAR_DATA *priv = NULL ;
- priv = (LINEAR_DATA*) psrc->private_data ;
+ priv = (LINEAR_DATA*) state->private_data ;
if (priv == NULL)
return ;
- priv->channels = psrc->channels ;
- priv->reset = 1 ;
- memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
+ priv->dirty = 0 ;
+ memset (priv->last_value, 0, sizeof (priv->last_value [0]) * state->channels) ;
return ;
} /* linear_reset */
+SRC_STATE *
+linear_copy (SRC_STATE *state)
+{
+ assert (state != NULL) ;
+
+ if (state->private_data == NULL)
+ return NULL ;
+
+ SRC_STATE *to = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
+ if (!to)
+ return NULL ;
+ memcpy (to, state, sizeof (SRC_STATE)) ;
+
+ LINEAR_DATA* from_priv = (LINEAR_DATA*) state->private_data ;
+ LINEAR_DATA *to_priv = (LINEAR_DATA *) calloc (1, sizeof (LINEAR_DATA)) ;
+ if (!to_priv)
+ {
+ free (to) ;
+ return NULL ;
+ }
+
+ memcpy (to_priv, from_priv, sizeof (LINEAR_DATA)) ;
+ to_priv->last_value = (float *) malloc (sizeof (float) * state->channels) ;
+ if (!to_priv->last_value)
+ {
+ free (to) ;
+ free (to_priv) ;
+ return NULL ;
+ }
+ memcpy (to_priv->last_value, from_priv->last_value, sizeof (float) * state->channels) ;
+
+ to->private_data = to_priv ;
+
+ return to ;
+} /* linear_copy */
+
+static void
+linear_close (SRC_STATE *state)
+{
+ if (state)
+ {
+ LINEAR_DATA *linear = (LINEAR_DATA *) state->private_data ;
+ if (linear)
+ {
+ if (linear->last_value)
+ {
+ free (linear->last_value) ;
+ linear->last_value = NULL ;
+ }
+ free (linear) ;
+ linear = NULL ;
+ }
+ free (state) ;
+ state = NULL ;
+ }
+} /* linear_close */
diff --git a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_sinc.c b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_sinc.c
index 44e9fd4e..47175ebc 100644
--- a/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_sinc.c
+++ b/libjamesdsp/subtree/Main/DSPManager/jni/libsamplerate/src_sinc.c
@@ -1,19 +1,172 @@
/*
-** Copyright (c) 2002-2016, Erik de Castro Lopo
+** Copyright (c) 2002-2021, Erik de Castro Lopo
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
-** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
+** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include
#include
#include
#include
+#include
+#include
-#include "config.h"
-#include "float_cast.h"
#include "common.h"
-
+#ifndef M_PI
+#define M_PI 3.14159265358979323846264338328
+#endif
+// Filter generator start
+double sinc(double x)
+{
+ if (x != 0.0)
+ return sin(M_PI * x) / (M_PI * x);
+ else
+ return 1.0;
+}
+double bessi0(double x)
+{
+ double xh, sum, pow, ds;
+ int k;
+ xh = 0.5 * x;
+ sum = 1.0;
+ pow = 1.0;
+ k = 0;
+ ds = 1.0;
+ while (ds > sum * DBL_EPSILON)
+ {
+ ++k;
+ pow = pow * (xh / k);
+ ds = pow * pow;
+ sum = sum + ds;
+ }
+ return sum;
+}
+double chbevl(double x, double array[], int n)
+{
+ double b0, b1, b2, *p;
+ int i;
+
+ p = array;
+ b0 = *p++;
+ b1 = 0.0;
+ i = n - 1;
+
+ do {
+ b2 = b1;
+ b1 = b0;
+ b0 = x * b1 - b2 + *p++;
+ } while (--i);
+
+ return(0.5 * (b0 - b2));
+}
+/* Chebyshev coefficients for exp(-x) I0(x)
+ * in the interval [0,8].
+ *
+ * lim(x->0){ exp(-x) I0(x) } = 1.
+ */
+static double A[] = {
+ -4.41534164647933937950E-18,
+ 3.33079451882223809783E-17,
+ -2.43127984654795469359E-16,
+ 1.71539128555513303061E-15,
+ -1.16853328779934516808E-14,
+ 7.67618549860493561688E-14,
+ -4.85644678311192946090E-13,
+ 2.95505266312963983461E-12,
+ -1.72682629144155570723E-11,
+ 9.67580903537323691224E-11,
+ -5.18979560163526290666E-10,
+ 2.65982372468238665035E-9,
+ -1.30002500998624804212E-8,
+ 6.04699502254191894932E-8,
+ -2.67079385394061173391E-7,
+ 1.11738753912010371815E-6,
+ -4.41673835845875056359E-6,
+ 1.64484480707288970893E-5,
+ -5.75419501008210370398E-5,
+ 1.88502885095841655729E-4,
+ -5.76375574538582365885E-4,
+ 1.63947561694133579842E-3,
+ -4.32430999505057594430E-3,
+ 1.05464603945949983183E-2,
+ -2.37374148058994688156E-2,
+ 4.93052842396707084878E-2,
+ -9.49010970480476444210E-2,
+ 1.71620901522208775349E-1,
+ -3.04682672343198398683E-1,
+ 6.76795274409476084995E-1
+};
+/* Chebyshev coefficients for exp(-x) sqrt(x) I0(x)
+ * in the inverted interval [8,infinity].
+ *
+ * lim(x->inf){ exp(-x) sqrt(x) I0(x) } = 1/sqrt(2pi).
+ */
+static double B[] = {
+ -7.23318048787475395456E-18,
+ -4.83050448594418207126E-18,
+ 4.46562142029675999901E-17,
+ 3.46122286769746109310E-17,
+ -2.82762398051658348494E-16,
+ -3.42548561967721913462E-16,
+ 1.77256013305652638360E-15,
+ 3.81168066935262242075E-15,
+ -9.55484669882830764870E-15,
+ -4.15056934728722208663E-14,
+ 1.54008621752140982691E-14,
+ 3.85277838274214270114E-13,
+ 7.18012445138366623367E-13,
+ -1.79417853150680611778E-12,
+ -1.32158118404477131188E-11,
+ -3.14991652796324136454E-11,
+ 1.18891471078464383424E-11,
+ 4.94060238822496958910E-10,
+ 3.39623202570838634515E-9,
+ 2.26666899049817806459E-8,
+ 2.04891858946906374183E-7,
+ 2.89137052083475648297E-6,
+ 6.88975834691682398426E-5,
+ 3.36911647825569408990E-3,
+ 8.04490411014108831608E-1
+};
+double i0(double x)
+{
+ double y;
+
+ if (x < 0)
+ x = -x;
+ if (x <= 8.0) {
+ y = (x / 2.0) - 2.0;
+ return(exp(x) * chbevl(y, A, 30));
+ }
+ return(exp(x) * chbevl(32.0 / x - 2.0, B, 25) / sqrt(x));
+}
+unsigned int getcoeff(double ratio, double atten, unsigned long long N, unsigned int incre, float *y)
+{
+ unsigned long long m;
+ double bta = (atten + 0.5) / 10;
+ double bes = 1.0 / fabs(i0(bta));
+ double xind = 1.0 / ((N - 1) * (N - 1));
+ double sum = 0.0;
+ y[0] = 1.0;
+ for (m = 1; m < ((N - 1) >> 1) + 1; m++)
+ {
+ double w = i0(bta * sqrt(1.0 - (double)(4 * m * m) * xind)) * bes;
+ double f = sinc(m / ratio) * w;
+ y[m] = f;
+ sum += f;
+ }
+ sum = 1.0 / (y[0] + sum * 2.0);
+ for (m = 0; m < ((N - 1) >> 1) + 1; m++)
+ y[m] = (y[m] * incre) * sum;
+ return ((N - 1) >> 1) + 1;
+}
+// Filter generator end
#define SINC_MAGIC_MARKER MAKE_MAGIC (' ', 's', 'i', 'n', 'c', ' ')
/*========================================================================================
@@ -25,15 +178,23 @@
#define FP_ONE ((double) (((increment_t) 1) << SHIFT_BITS))
#define INV_FP_ONE (1.0 / FP_ONE)
+/* Customixe max channls from Kconfig. */
+#ifndef CONFIG_CHAN_NR
+#define MAX_CHANNELS 128
+#else
+#define MAX_CHANNELS CONFIG_CHAN_NR
+#endif
+
/*========================================================================================
*/
typedef int32_t increment_t ;
+typedef float coeff_t ;
+typedef int _CHECK_SHIFT_BITS[2 * (SHIFT_BITS < sizeof (increment_t) * 8 - 1) - 1]; /* sanity check. */
typedef struct
{ int sinc_magic_marker ;
- int channels ;
long in_count, in_used ;
long out_count, out_gen ;
@@ -41,30 +202,76 @@ typedef struct
double src_ratio, input_index ;
- float const *coeffs ;
+ coeff_t *coeffs ;
int b_current, b_end, b_real_end, b_len ;
/* Sure hope noone does more than 128 channels at once. */
- double left_calc [128], right_calc [128] ;
+ double left_calc [MAX_CHANNELS], right_calc [MAX_CHANNELS] ;
- /* C99 struct flexible array. */
- float buffer [] ;
+ float *buffer ;
} SINC_FILTER ;
-static int sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
-static int sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
-static int sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
-static int sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
-static int sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
-
-static int prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len) WARN_UNUSED ;
-
-static void sinc_reset (SRC_PRIVATE *psrc) ;
+static SRC_ERROR sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data) ;
+static SRC_ERROR sinc_hex_vari_process (SRC_STATE *state, SRC_DATA *data) ;
+static SRC_ERROR sinc_quad_vari_process (SRC_STATE *state, SRC_DATA *data) ;
+static SRC_ERROR sinc_stereo_vari_process (SRC_STATE *state, SRC_DATA *data) ;
+static SRC_ERROR sinc_mono_vari_process (SRC_STATE *state, SRC_DATA *data) ;
+
+static SRC_ERROR prepare_data (SINC_FILTER *filter, int channels, SRC_DATA *data, int half_filter_chan_len) WARN_UNUSED ;
+
+static void sinc_reset (SRC_STATE *state) ;
+static SRC_STATE *sinc_copy (SRC_STATE *state) ;
+static void sinc_close (SRC_STATE *state) ;
+
+static SRC_STATE_VT sinc_multichan_state_vt =
+{
+ sinc_multichan_vari_process,
+ sinc_multichan_vari_process,
+ sinc_reset,
+ sinc_copy,
+ sinc_close
+} ;
+
+static SRC_STATE_VT sinc_hex_state_vt =
+{
+ sinc_hex_vari_process,
+ sinc_hex_vari_process,
+ sinc_reset,
+ sinc_copy,
+ sinc_close
+} ;
+
+static SRC_STATE_VT sinc_quad_state_vt =
+{
+ sinc_quad_vari_process,
+ sinc_quad_vari_process,
+ sinc_reset,
+ sinc_copy,
+ sinc_close
+} ;
+
+static SRC_STATE_VT sinc_stereo_state_vt =
+{
+ sinc_stereo_vari_process,
+ sinc_stereo_vari_process,
+ sinc_reset,
+ sinc_copy,
+ sinc_close
+} ;
+
+static SRC_STATE_VT sinc_mono_state_vt =
+{
+ sinc_mono_vari_process,
+ sinc_mono_vari_process,
+ sinc_reset,
+ sinc_copy,
+ sinc_close
+} ;
static inline increment_t
double_to_fp (double x)
-{ return (lrint ((x) * FP_ONE)) ;
+{ return (increment_t) (psf_lrint ((x) * FP_ONE)) ;
} /* double_to_fp */
static inline increment_t
@@ -87,92 +294,183 @@ fp_to_double (increment_t x)
{ return fp_fraction_part (x) * INV_FP_ONE ;
} /* fp_to_double */
-extern float *decompressedCoefficients;
-int
-sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)
-{ SINC_FILTER *filter, temp_filter ;
- increment_t count ;
- int bits ;
+static inline int
+int_div_ceil (int divident, int divisor) /* == (int) ceil ((float) divident / divisor) */
+{ assert (divident >= 0 && divisor > 0) ; /* For positive numbers only */
+ return (divident + (divisor - 1)) / divisor ;
+}
+
+/*----------------------------------------------------------------------------------------
+*/
- /* Quick sanity check. */
- if (SHIFT_BITS >= sizeof (increment_t) * 8 - 1)
- return SRC_ERR_SHIFT_BITS ;
+LIBSAMPLERATE_DLL_PRIVATE const char*
+sinc_get_name (int src_enum)
+{
+ switch (src_enum)
+ { case SRC_SINC_BEST_QUALITY :
+ return "Best Sinc Interpolator" ;
- if (psrc->private_data != NULL)
- { free (psrc->private_data) ;
- psrc->private_data = NULL ;
+ case SRC_SINC_MEDIUM_QUALITY :
+ return "Medium Sinc Interpolator" ;
+
+ case SRC_SINC_FASTEST :
+ return "Fastest Sinc Interpolator" ;
+
+ default: break ;
} ;
- memset (&temp_filter, 0, sizeof (temp_filter)) ;
+ return NULL ;
+} /* sinc_get_descrition */
- temp_filter.sinc_magic_marker = SINC_MAGIC_MARKER ;
- temp_filter.channels = psrc->channels ;
+LIBSAMPLERATE_DLL_PRIVATE const char*
+sinc_get_description (int src_enum)
+{
+ switch (src_enum)
+ { case SRC_SINC_FASTEST :
+ return "Band limited sinc interpolation, fastest, 97dB SNR, 80% BW." ;
- if (psrc->channels > ARRAY_LEN (temp_filter.left_calc))
- return SRC_ERR_BAD_CHANNEL_COUNT ;
- else if (psrc->channels == 1)
- { psrc->const_process = sinc_mono_vari_process ;
- psrc->vari_process = sinc_mono_vari_process ;
- }
- else
- if (psrc->channels == 2)
- { psrc->const_process = sinc_stereo_vari_process ;
- psrc->vari_process = sinc_stereo_vari_process ;
- }
- else
- if (psrc->channels == 4)
- { psrc->const_process = sinc_quad_vari_process ;
- psrc->vari_process = sinc_quad_vari_process ;
- }
- else
- if (psrc->channels == 6)
- { psrc->const_process = sinc_hex_vari_process ;
- psrc->vari_process = sinc_hex_vari_process ;
- }
- else
- { psrc->const_process = sinc_multichan_vari_process ;
- psrc->vari_process = sinc_multichan_vari_process ;
+ case SRC_SINC_MEDIUM_QUALITY :
+ return "Band limited sinc interpolation, medium quality, 121dB SNR, 90% BW." ;
+
+ case SRC_SINC_BEST_QUALITY :
+ return "Band limited sinc interpolation, best quality, 144dB SNR, 96% BW." ;
+
+ default :
+ break ;
} ;
- psrc->reset = sinc_reset ;
- temp_filter.coeffs = decompressedCoefficients;
- temp_filter.coeff_half_len = 22438 - 2;
- temp_filter.index_inc = 491;
+ return NULL ;
+} /* sinc_get_descrition */
+float *gbl_coeff[3];
+void clean_lpfcoeff()
+{
+ for (unsigned int i = 0; i < 3; i++)
+ {
+ if (gbl_coeff[i])
+ free(gbl_coeff[i]);
+ gbl_coeff[i] = 0;
+ }
+}
+void precompute_lpfcoeff()
+{
+ clean_lpfcoeff();
+ gbl_coeff[0] = (float *)malloc(2464 * sizeof(float));
+ unsigned int halfLen = getcoeff(153.9, 100.3, 4925, 128, gbl_coeff[0]); //1.539440918821971e+02
+ for (unsigned int i = halfLen; i < halfLen + 1; i++)
+ gbl_coeff[0][i] = 0;
+ gbl_coeff[1] = (float *)malloc(22438 * sizeof(float));
+ halfLen = getcoeff(520.0, 122.0, 44873, 491, gbl_coeff[1]); //5.342397164871713e+02
+ for (unsigned int i = halfLen; i < halfLen + 1; i++)
+ gbl_coeff[1][i] = 0;
+ gbl_coeff[2] = (float *)malloc(340239 * sizeof(float));
+ halfLen = getcoeff(2430.0, 160.0, 680475, 2381, gbl_coeff[2]); //2.465496453815475e+03
+ for (unsigned int i = halfLen; i < halfLen + 1; i++)
+ gbl_coeff[2][i] = 0;
+}
+static SINC_FILTER *sinc_filter_new (int converter_type, int channels)
+{
+ assert (converter_type == SRC_SINC_FASTEST ||
+ converter_type == SRC_SINC_MEDIUM_QUALITY ||
+ converter_type == SRC_SINC_BEST_QUALITY) ;
+ assert (channels > 0 && channels <= MAX_CHANNELS) ;
+
+ SINC_FILTER *priv = (SINC_FILTER *) calloc (1, sizeof (SINC_FILTER)) ;
+ if (priv)
+ {
+ priv->sinc_magic_marker = SINC_MAGIC_MARKER ;
+ unsigned int halfLen;
+ switch (converter_type)
+ {
+ case SRC_SINC_FASTEST:
+ priv->coeffs = gbl_coeff[0];
+ priv->index_inc = 128;
+ priv->coeff_half_len = 2464 - 2;
+ break;
+ case SRC_SINC_MEDIUM_QUALITY:
+ priv->coeffs = gbl_coeff[1];
+ priv->index_inc = 491;
+ priv->coeff_half_len = 22438 - 2;
+ break;
+ case SRC_SINC_BEST_QUALITY:
+ priv->coeffs = gbl_coeff[2];
+ priv->index_inc = 2381;
+ priv->coeff_half_len = 340239 - 2;
+ break;
+ }
- /*
- ** FIXME : This needs to be looked at more closely to see if there is
- ** a better way. Need to look at prepare_data () at the same time.
- */
+ priv->b_len = 3 * (int) psf_lrint ((priv->coeff_half_len + 2.0) / priv->index_inc * SRC_MAX_RATIO + 1) ;
+ priv->b_len = MAX (priv->b_len, 4096) ;
+ priv->b_len *= channels ;
+ priv->b_len += 1 ; // There is a <= check against samples_in_hand requiring a buffer bigger than the calculation above
- temp_filter.b_len = lrint (2.5 * temp_filter.coeff_half_len / (temp_filter.index_inc * 1.0) * SRC_MAX_RATIO) ;
- temp_filter.b_len = MAX (temp_filter.b_len, 4096) ;
- temp_filter.b_len *= temp_filter.channels ;
- if ((filter = calloc (1, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + temp_filter.channels))) == NULL)
- return SRC_ERR_MALLOC_FAILED ;
+ priv->buffer = (float *) calloc (priv->b_len + channels, sizeof (float)) ;
+ if (!priv->buffer)
+ {
+ free (priv) ;
+ priv = NULL ;
+ }
+ }
- *filter = temp_filter ;
- memset (&temp_filter, 0xEE, sizeof (temp_filter)) ;
+ return priv ;
+}
- psrc->private_data = filter ;
+LIBSAMPLERATE_DLL_PRIVATE SRC_STATE *
+sinc_state_new (int converter_type, int channels, SRC_ERROR *error)
+{
+ assert (converter_type == SRC_SINC_FASTEST ||
+ converter_type == SRC_SINC_MEDIUM_QUALITY ||
+ converter_type == SRC_SINC_BEST_QUALITY) ;
+ assert (channels > 0) ;
+ assert (error != NULL) ;
- sinc_reset (psrc) ;
+ if (channels > MAX_CHANNELS)
+ {
+ *error = SRC_ERR_BAD_CHANNEL_COUNT ;
+ return NULL ;
+ }
- count = filter->coeff_half_len ;
- for (bits = 0 ; (MAKE_INCREMENT_T (1) << bits) < count ; bits++)
- count |= (MAKE_INCREMENT_T (1) << bits) ;
+ SRC_STATE *state = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
+ if (!state)
+ {
+ *error = SRC_ERR_MALLOC_FAILED ;
+ return NULL ;
+ }
+
+ state->channels = channels ;
+ state->mode = SRC_MODE_PROCESS ;
+
+ if (state->channels == 1)
+ state->vt = &sinc_mono_state_vt ;
+ else if (state->channels == 2)
+ state->vt = &sinc_stereo_state_vt ;
+ else if (state->channels == 4)
+ state->vt = &sinc_quad_state_vt ;
+ else if (state->channels == 6)
+ state->vt = &sinc_hex_state_vt ;
+ else
+ state->vt = &sinc_multichan_state_vt ;
- if (bits + SHIFT_BITS - 1 >= (int) (sizeof (increment_t) * 8))
- return SRC_ERR_FILTER_LEN ;
+ state->private_data = sinc_filter_new (converter_type, state->channels) ;
+ if (!state->private_data)
+ {
+ free (state) ;
+ *error = SRC_ERR_MALLOC_FAILED ;
+ return NULL ;
+ }
- return SRC_ERR_NO_ERROR ;
-} /* sinc_set_converter */
+ sinc_reset (state) ;
+
+ *error = SRC_ERR_NO_ERROR ;
+
+ return state ;
+}
static void
-sinc_reset (SRC_PRIVATE *psrc)
+sinc_reset (SRC_STATE *state)
{ SINC_FILTER *filter ;
- filter = (SINC_FILTER*) psrc->private_data ;
+ filter = (SINC_FILTER*) state->private_data ;
if (filter == NULL)
return ;
@@ -184,9 +482,45 @@ sinc_reset (SRC_PRIVATE *psrc)
memset (filter->buffer, 0, filter->b_len * sizeof (filter->buffer [0])) ;
/* Set this for a sanity check */
- memset (filter->buffer + filter->b_len, 0xAA, filter->channels * sizeof (filter->buffer [0])) ;
+ memset (filter->buffer + filter->b_len, 0xAA, state->channels * sizeof (filter->buffer [0])) ;
} /* sinc_reset */
+static SRC_STATE *
+sinc_copy (SRC_STATE *state)
+{
+ assert (state != NULL) ;
+
+ if (state->private_data == NULL)
+ return NULL ;
+
+ SRC_STATE *to = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
+ if (!to)
+ return NULL ;
+ memcpy (to, state, sizeof (SRC_STATE)) ;
+
+
+ SINC_FILTER* from_filter = (SINC_FILTER*) state->private_data ;
+ SINC_FILTER *to_filter = (SINC_FILTER *) calloc (1, sizeof (SINC_FILTER)) ;
+ if (!to_filter)
+ {
+ free (to) ;
+ return NULL ;
+ }
+ memcpy (to_filter, from_filter, sizeof (SINC_FILTER)) ;
+ to_filter->buffer = (float *) malloc (sizeof (float) * (from_filter->b_len + state->channels)) ;
+ if (!to_filter->buffer)
+ {
+ free (to) ;
+ free (to_filter) ;
+ return NULL ;
+ }
+ memcpy (to_filter->buffer, from_filter->buffer, sizeof (float) * (from_filter->b_len + state->channels)) ;
+
+ to->private_data = to_filter ;
+
+ return to ;
+} /* sinc_copy */
+
/*========================================================================================
** Beware all ye who dare pass this point. There be dragons here.
*/
@@ -206,19 +540,26 @@ calc_output_single (SINC_FILTER *filter, increment_t increment, increment_t star
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current - coeff_count ;
+ if (data_index < 0) /* Avoid underflow access to filter->buffer. */
+ { int steps = -data_index ;
+ /* If the assert triggers we would have to take care not to underflow/overflow */
+ assert (steps <= int_div_ceil (filter_index, increment)) ;
+ filter_index -= increment * steps ;
+ data_index += steps ;
+ }
left = 0.0 ;
- do
+ while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
+ assert (data_index >= 0 && data_index < filter->b_len) ;
+ assert (data_index < filter->b_end) ;
left += icoeff * filter->buffer [data_index] ;
filter_index -= increment ;
data_index = data_index + 1 ;
- }
- while (filter_index >= MAKE_INCREMENT_T (0)) ;
+ } ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
@@ -230,9 +571,10 @@ calc_output_single (SINC_FILTER *filter, increment_t increment, increment_t star
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
+ assert (data_index >= 0 && data_index < filter->b_len) ;
+ assert (data_index < filter->b_end) ;
right += icoeff * filter->buffer [data_index] ;
filter_index -= increment ;
@@ -243,43 +585,43 @@ calc_output_single (SINC_FILTER *filter, increment_t increment, increment_t star
return (left + right) ;
} /* calc_output_single */
-static int
-sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+static SRC_ERROR
+sinc_mono_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
- if (psrc->private_data == NULL)
+ if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
- filter = (SINC_FILTER*) psrc->private_data ;
+ filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
- filter->in_count = data->input_frames * filter->channels ;
- filter->out_count = data->output_frames * filter->channels ;
+ filter->in_count = data->input_frames * state->channels ;
+ filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
- src_ratio = psrc->last_ratio ;
+ src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
- if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
- count /= MIN (psrc->last_ratio, data->src_ratio) ;
+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
+ count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
- half_filter_chan_len = filter->channels * (lrint (count) + 1) ;
+ half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
- input_index = psrc->last_position ;
+ input_index = state->last_position ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
@@ -291,8 +633,8 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
- { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
- return psrc->error ;
+ { if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
+ return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
@@ -305,8 +647,8 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
break ;
} ;
- if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
- src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
@@ -321,23 +663,23 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
- psrc->last_position = input_index ;
+ state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
- psrc->last_ratio = src_ratio ;
+ state->last_ratio = src_ratio ;
- data->input_frames_used = filter->in_used / filter->channels ;
- data->output_frames_gen = filter->out_gen / filter->channels ;
+ data->input_frames_used = filter->in_used / state->channels ;
+ data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_mono_vari_process */
static inline void
-calc_output_stereo (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, double scale, float * output)
+calc_output_stereo (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
{ double fraction, left [2], right [2], icoeff ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
@@ -349,85 +691,93 @@ calc_output_stereo (SINC_FILTER *filter, increment_t increment, increment_t star
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
- data_index = filter->b_current - filter->channels * coeff_count ;
+ data_index = filter->b_current - channels * coeff_count ;
+ if (data_index < 0) /* Avoid underflow access to filter->buffer. */
+ { int steps = int_div_ceil (-data_index, 2) ;
+ /* If the assert triggers we would have to take care not to underflow/overflow */
+ assert (steps <= int_div_ceil (filter_index, increment)) ;
+ filter_index -= increment * steps ;
+ data_index += steps * 2;
+ }
left [0] = left [1] = 0.0 ;
- do
+ while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
- left [0] += icoeff * filter->buffer [data_index] ;
- left [1] += icoeff * filter->buffer [data_index + 1] ;
+ assert (data_index >= 0 && data_index + 1 < filter->b_len) ;
+ assert (data_index + 1 < filter->b_end) ;
+ for (int ch = 0; ch < 2; ch++)
+ left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + 2 ;
- }
- while (filter_index >= MAKE_INCREMENT_T (0)) ;
+ } ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
- data_index = filter->b_current + filter->channels * (1 + coeff_count) ;
+ data_index = filter->b_current + channels * (1 + coeff_count) ;
right [0] = right [1] = 0.0 ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
- right [0] += icoeff * filter->buffer [data_index] ;
- right [1] += icoeff * filter->buffer [data_index + 1] ;
+ assert (data_index >= 0 && data_index + 1 < filter->b_len) ;
+ assert (data_index + 1 < filter->b_end) ;
+ for (int ch = 0; ch < 2; ch++)
+ right [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index - 2 ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
- output [0] = scale * (left [0] + right [0]) ;
- output [1] = scale * (left [1] + right [1]) ;
+ for (int ch = 0; ch < 2; ch++)
+ output [ch] = (float) (scale * (left [ch] + right [ch])) ;
} /* calc_output_stereo */
-static int
-sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+SRC_ERROR
+sinc_stereo_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
- if (psrc->private_data == NULL)
+ if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
- filter = (SINC_FILTER*) psrc->private_data ;
+ filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
- filter->in_count = data->input_frames * filter->channels ;
- filter->out_count = data->output_frames * filter->channels ;
+ filter->in_count = data->input_frames * state->channels ;
+ filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
- src_ratio = psrc->last_ratio ;
+ src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
- if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
- count /= MIN (psrc->last_ratio, data->src_ratio) ;
+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
+ count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
- half_filter_chan_len = filter->channels * (lrint (count) + 1) ;
+ half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
- input_index = psrc->last_position ;
+ input_index = state->last_position ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
@@ -439,8 +789,8 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
- { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
- return psrc->error ;
+ { if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
+ return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
@@ -453,38 +803,38 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
break ;
} ;
- if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
- src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
- calc_output_stereo (filter, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+ calc_output_stereo (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
filter->out_gen += 2 ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
- psrc->last_position = input_index ;
+ state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
- psrc->last_ratio = src_ratio ;
+ state->last_ratio = src_ratio ;
- data->input_frames_used = filter->in_used / filter->channels ;
- data->output_frames_gen = filter->out_gen / filter->channels ;
+ data->input_frames_used = filter->in_used / state->channels ;
+ data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_stereo_vari_process */
static inline void
-calc_output_quad (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, double scale, float * output)
+calc_output_quad (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
{ double fraction, left [4], right [4], icoeff ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
@@ -496,91 +846,94 @@ calc_output_quad (SINC_FILTER *filter, increment_t increment, increment_t start_
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
- data_index = filter->b_current - filter->channels * coeff_count ;
+ data_index = filter->b_current - channels * coeff_count ;
+ if (data_index < 0) /* Avoid underflow access to filter->buffer. */
+ { int steps = int_div_ceil (-data_index, 4) ;
+ /* If the assert triggers we would have to take care not to underflow/overflow */
+ assert (steps <= int_div_ceil (filter_index, increment)) ;
+ filter_index -= increment * steps ;
+ data_index += steps * 4;
+ }
left [0] = left [1] = left [2] = left [3] = 0.0 ;
- do
+ while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
- left [0] += icoeff * filter->buffer [data_index] ;
- left [1] += icoeff * filter->buffer [data_index + 1] ;
- left [2] += icoeff * filter->buffer [data_index + 2] ;
- left [3] += icoeff * filter->buffer [data_index + 3] ;
+ assert (data_index >= 0 && data_index + 3 < filter->b_len) ;
+ assert (data_index + 3 < filter->b_end) ;
+ for (int ch = 0; ch < 4; ch++)
+ left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + 4 ;
- }
- while (filter_index >= MAKE_INCREMENT_T (0)) ;
+ } ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
- data_index = filter->b_current + filter->channels * (1 + coeff_count) ;
+ data_index = filter->b_current + channels * (1 + coeff_count) ;
right [0] = right [1] = right [2] = right [3] = 0.0 ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
+ assert (data_index >= 0 && data_index + 3 < filter->b_len) ;
+ assert (data_index + 3 < filter->b_end) ;
+ for (int ch = 0; ch < 4; ch++)
+ right [ch] += icoeff * filter->buffer [data_index + ch] ;
- right [0] += icoeff * filter->buffer [data_index] ;
- right [1] += icoeff * filter->buffer [data_index + 1] ;
- right [2] += icoeff * filter->buffer [data_index + 2] ;
- right [3] += icoeff * filter->buffer [data_index + 3] ;
filter_index -= increment ;
data_index = data_index - 4 ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
- output [0] = scale * (left [0] + right [0]) ;
- output [1] = scale * (left [1] + right [1]) ;
- output [2] = scale * (left [2] + right [2]) ;
- output [3] = scale * (left [3] + right [3]) ;
+ for (int ch = 0; ch < 4; ch++)
+ output [ch] = (float) (scale * (left [ch] + right [ch])) ;
} /* calc_output_quad */
-static int
-sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+SRC_ERROR
+sinc_quad_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
- if (psrc->private_data == NULL)
+ if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
- filter = (SINC_FILTER*) psrc->private_data ;
+ filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
- filter->in_count = data->input_frames * filter->channels ;
- filter->out_count = data->output_frames * filter->channels ;
+ filter->in_count = data->input_frames * state->channels ;
+ filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
- src_ratio = psrc->last_ratio ;
+ src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
- if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
- count /= MIN (psrc->last_ratio, data->src_ratio) ;
+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
+ count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
- half_filter_chan_len = filter->channels * (lrint (count) + 1) ;
+ half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
- input_index = psrc->last_position ;
+ input_index = state->last_position ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
@@ -592,8 +945,8 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
- { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
- return psrc->error ;
+ { if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
+ return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
@@ -606,38 +959,38 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
break ;
} ;
- if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
- src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
- calc_output_quad (filter, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+ calc_output_quad (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
filter->out_gen += 4 ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
- psrc->last_position = input_index ;
+ state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
- psrc->last_ratio = src_ratio ;
+ state->last_ratio = src_ratio ;
- data->input_frames_used = filter->in_used / filter->channels ;
- data->output_frames_gen = filter->out_gen / filter->channels ;
+ data->input_frames_used = filter->in_used / state->channels ;
+ data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_quad_vari_process */
static inline void
-calc_output_hex (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, double scale, float * output)
+calc_output_hex (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
{ double fraction, left [6], right [6], icoeff ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
@@ -649,97 +1002,93 @@ calc_output_hex (SINC_FILTER *filter, increment_t increment, increment_t start_f
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
- data_index = filter->b_current - filter->channels * coeff_count ;
+ data_index = filter->b_current - channels * coeff_count ;
+ if (data_index < 0) /* Avoid underflow access to filter->buffer. */
+ { int steps = int_div_ceil (-data_index, 6) ;
+ /* If the assert triggers we would have to take care not to underflow/overflow */
+ assert (steps <= int_div_ceil (filter_index, increment)) ;
+ filter_index -= increment * steps ;
+ data_index += steps * 6;
+ }
left [0] = left [1] = left [2] = left [3] = left [4] = left [5] = 0.0 ;
- do
+ while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
- left [0] += icoeff * filter->buffer [data_index] ;
- left [1] += icoeff * filter->buffer [data_index + 1] ;
- left [2] += icoeff * filter->buffer [data_index + 2] ;
- left [3] += icoeff * filter->buffer [data_index + 3] ;
- left [4] += icoeff * filter->buffer [data_index + 4] ;
- left [5] += icoeff * filter->buffer [data_index + 5] ;
+ assert (data_index >= 0 && data_index + 5 < filter->b_len) ;
+ assert (data_index + 5 < filter->b_end) ;
+ for (int ch = 0; ch < 6; ch++)
+ left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + 6 ;
- }
- while (filter_index >= MAKE_INCREMENT_T (0)) ;
+ } ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
- data_index = filter->b_current + filter->channels * (1 + coeff_count) ;
+ data_index = filter->b_current + channels * (1 + coeff_count) ;
right [0] = right [1] = right [2] = right [3] = right [4] = right [5] = 0.0 ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
- right [0] += icoeff * filter->buffer [data_index] ;
- right [1] += icoeff * filter->buffer [data_index + 1] ;
- right [2] += icoeff * filter->buffer [data_index + 2] ;
- right [3] += icoeff * filter->buffer [data_index + 3] ;
- right [4] += icoeff * filter->buffer [data_index + 4] ;
- right [5] += icoeff * filter->buffer [data_index + 5] ;
+ assert (data_index >= 0 && data_index + 5 < filter->b_len) ;
+ assert (data_index + 5 < filter->b_end) ;
+ for (int ch = 0; ch < 6; ch++)
+ right [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index - 6 ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
- output [0] = scale * (left [0] + right [0]) ;
- output [1] = scale * (left [1] + right [1]) ;
- output [2] = scale * (left [2] + right [2]) ;
- output [3] = scale * (left [3] + right [3]) ;
- output [4] = scale * (left [4] + right [4]) ;
- output [5] = scale * (left [5] + right [5]) ;
+ for (int ch = 0; ch < 6; ch++)
+ output [ch] = (float) (scale * (left [ch] + right [ch])) ;
} /* calc_output_hex */
-static int
-sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+SRC_ERROR
+sinc_hex_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
- if (psrc->private_data == NULL)
+ if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
- filter = (SINC_FILTER*) psrc->private_data ;
+ filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
- filter->in_count = data->input_frames * filter->channels ;
- filter->out_count = data->output_frames * filter->channels ;
+ filter->in_count = data->input_frames * state->channels ;
+ filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
- src_ratio = psrc->last_ratio ;
+ src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
- if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
- count /= MIN (psrc->last_ratio, data->src_ratio) ;
+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
+ count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
- half_filter_chan_len = filter->channels * (lrint (count) + 1) ;
+ half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
- input_index = psrc->last_position ;
+ input_index = state->last_position ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
@@ -751,8 +1100,8 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
- { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
- return psrc->error ;
+ { if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
+ return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
@@ -765,32 +1114,32 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
break ;
} ;
- if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
- src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
- calc_output_hex (filter, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+ calc_output_hex (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
filter->out_gen += 6 ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
- psrc->last_position = input_index ;
+ state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
- psrc->last_ratio = src_ratio ;
+ state->last_ratio = src_ratio ;
- data->input_frames_used = filter->in_used / filter->channels ;
- data->output_frames_gen = filter->out_gen / filter->channels ;
+ data->input_frames_used = filter->in_used / state->channels ;
+ data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_hex_vari_process */
@@ -801,7 +1150,7 @@ calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start
/* The following line is 1999 ISO Standard C. If your compiler complains, get a better compiler. */
double *left, *right ;
increment_t filter_index, max_filter_index ;
- int data_index, coeff_count, indx, ch ;
+ int data_index, coeff_count, indx ;
left = filter->left_calc ;
right = filter->right_calc ;
@@ -815,61 +1164,30 @@ calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current - channels * coeff_count ;
+ if (data_index < 0) /* Avoid underflow access to filter->buffer. */
+ { int steps = int_div_ceil (-data_index, channels) ;
+ /* If the assert triggers we would have to take care not to underflow/overflow */
+ assert (steps <= int_div_ceil (filter_index, increment)) ;
+ filter_index -= increment * steps ;
+ data_index += steps * channels ;
+ }
+
memset (left, 0, sizeof (left [0]) * channels) ;
- do
+ while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
- /*
- ** Duff's Device.
- ** See : http://en.wikipedia.org/wiki/Duff's_device
- */
- ch = channels ;
- do
- {
- switch (ch % 8)
- { default :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 7 :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 6 :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 5 :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 4 :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 3 :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 2 :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 1 :
- ch -- ;
- left [ch] += icoeff * filter->buffer [data_index + ch] ;
- } ;
- }
- while (ch > 0) ;
+ assert (data_index >= 0 && data_index + channels - 1 < filter->b_len) ;
+ assert (data_index + channels - 1 < filter->b_end) ;
+ for (int ch = 0; ch < channels; ch++)
+ left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + channels ;
- }
- while (filter_index >= MAKE_INCREMENT_T (0)) ;
+ } ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
@@ -881,132 +1199,61 @@ calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
-
+ assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
-
- ch = channels ;
- do
- {
- switch (ch % 8)
- { default :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 7 :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 6 :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 5 :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 4 :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 3 :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 2 :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- /* Falls through. */
- case 1 :
- ch -- ;
- right [ch] += icoeff * filter->buffer [data_index + ch] ;
- } ;
- }
- while (ch > 0) ;
+ assert (data_index >= 0 && data_index + channels - 1 < filter->b_len) ;
+ assert (data_index + channels - 1 < filter->b_end) ;
+ for (int ch = 0; ch < channels; ch++)
+ right [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index - channels ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
- ch = channels ;
- do
- {
- switch (ch % 8)
- { default :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- /* Falls through. */
- case 7 :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- /* Falls through. */
- case 6 :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- /* Falls through. */
- case 5 :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- /* Falls through. */
- case 4 :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- /* Falls through. */
- case 3 :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- /* Falls through. */
- case 2 :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- /* Falls through. */
- case 1 :
- ch -- ;
- output [ch] = scale * (left [ch] + right [ch]) ;
- } ;
- }
- while (ch > 0) ;
+ for(int ch = 0; ch < channels; ch++)
+ output [ch] = (float) (scale * (left [ch] + right [ch])) ;
return ;
} /* calc_output_multi */
-static int
-sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+static SRC_ERROR
+sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
- if (psrc->private_data == NULL)
+ if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
- filter = (SINC_FILTER*) psrc->private_data ;
+ filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
- filter->in_count = data->input_frames * filter->channels ;
- filter->out_count = data->output_frames * filter->channels ;
+ filter->in_count = data->input_frames * state->channels ;
+ filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
- src_ratio = psrc->last_ratio ;
+ src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
- if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
- count /= MIN (psrc->last_ratio, data->src_ratio) ;
+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
+ count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
- half_filter_chan_len = filter->channels * (lrint (count) + 1) ;
+ half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
- input_index = psrc->last_position ;
+ input_index = state->last_position ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
@@ -1018,8 +1265,8 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
- { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
- return psrc->error ;
+ { if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
+ return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
@@ -1032,32 +1279,32 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
break ;
} ;
- if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
- src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
- calc_output_multi (filter, increment, start_filter_index, filter->channels, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
- filter->out_gen += psrc->channels ;
+ calc_output_multi (filter, increment, start_filter_index, state->channels, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+ filter->out_gen += state->channels ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
- filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+ filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
- psrc->last_position = input_index ;
+ state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
- psrc->last_ratio = src_ratio ;
+ state->last_ratio = src_ratio ;
- data->input_frames_used = filter->in_used / filter->channels ;
- data->output_frames_gen = filter->out_gen / filter->channels ;
+ data->input_frames_used = filter->in_used / state->channels ;
+ data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_multichan_vari_process */
@@ -1065,12 +1312,15 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
/*----------------------------------------------------------------------------------------
*/
-static int
-prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len)
+static SRC_ERROR
+prepare_data (SINC_FILTER *filter, int channels, SRC_DATA *data, int half_filter_chan_len)
{ int len = 0 ;
if (filter->b_real_end >= 0)
- return 0 ; /* Should be terminating. Just return. */
+ return SRC_ERR_NO_ERROR ; /* Should be terminating. Just return. */
+
+ if (data->data_in == NULL)
+ return SRC_ERR_NO_ERROR ;
if (filter->b_current == 0)
{ /* Initial state. Set up zeros at the start of the buffer and
@@ -1080,7 +1330,7 @@ prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len)
filter->b_current = filter->b_end = half_filter_chan_len ;
}
- else if (filter->b_end + half_filter_chan_len + filter->channels < filter->b_len)
+ else if (filter->b_end + half_filter_chan_len + channels < filter->b_len)
{ /* Load data at current end position. */
len = MAX (filter->b_len - filter->b_current - half_filter_chan_len, 0) ;
}
@@ -1097,8 +1347,8 @@ prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len)
len = MAX (filter->b_len - filter->b_current - half_filter_chan_len, 0) ;
} ;
- len = MIN (filter->in_count - filter->in_used, len) ;
- len -= (len % filter->channels) ;
+ len = MIN ((int) (filter->in_count - filter->in_used), len) ;
+ len -= (len % channels) ;
if (len < 0 || filter->b_end + len > filter->b_len)
return SRC_ERR_SINC_PREPARE_DATA_BAD_LEN ;
@@ -1135,7 +1385,26 @@ prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len)
filter->b_end += len ;
} ;
- return 0 ;
+ return SRC_ERR_NO_ERROR ;
} /* prepare_data */
-
+static void
+sinc_close (SRC_STATE *state)
+{
+ if (state)
+ {
+ SINC_FILTER *sinc = (SINC_FILTER *) state->private_data ;
+ if (sinc)
+ {
+ if (sinc->buffer)
+ {
+ free (sinc->buffer) ;
+ sinc->buffer = NULL ;
+ }
+ free (sinc) ;
+ sinc = NULL ;
+ }
+ free (state) ;
+ state = NULL ;
+ }
+} /* sinc_close */
diff --git a/libjamesdsp/subtree/Main/DSPManager/jni/main/JdspImpResToolbox.c b/libjamesdsp/subtree/Main/DSPManager/jni/main/JdspImpResToolbox.c
index 71523a9a..d5118b07 100644
--- a/libjamesdsp/subtree/Main/DSPManager/jni/main/JdspImpResToolbox.c
+++ b/libjamesdsp/subtree/Main/DSPManager/jni/main/JdspImpResToolbox.c
@@ -284,7 +284,7 @@ void checkStartEnd(float **signal, int channels, int nsamples, float normalizedD
range[0] = firstSmpsPrevious != (nsamples - 1) ? firstSmpsPrevious : 0;
range[1] = lastSmpsPrevious + 1;
}
-#include "../libsamplerate\samplerate.h"
+#include "../libsamplerate/samplerate.h"
#define DRMP3_IMPLEMENTATION
#include "../dr_mp3.h"
#define DR_FLAC_IMPLEMENTATION
@@ -297,84 +297,6 @@ const char *get_filename_ext(const char *filename)
if (!dot || dot == filename) return "";
return dot + 1;
}
-float *decompressedCoefficients = 0;
-static const double compressedCoeffMQ[701] = { 0.919063234986138511, 0.913619994199411201, 0.897406560667438402, 0.870768836078722797, 0.834273523109754001, 0.788693711602254766, 0.734989263333015286, 0.674282539592362951, 0.607830143521649657, 0.536991457245508341, 0.463194839157173466, 0.387902406850539450, 0.312574364478514499, 0.238633838900749129, 0.167433166845669668, 0.100222526262645231, 0.038121730693097225, -0.017904091793426027, -0.067064330735278010, -0.108757765594775291, -0.142582153044975485, -0.168338357500518510, -0.186029009837402531, -0.195851834439330574, -0.198187933840591440, -0.193585458951914369, -0.182739217157973949, -0.166466876941489483, -0.145682513177707279, -0.121368299577954988, -0.094545192393702127, -0.066243461643369750, -0.037473912797399318, -0.009200603832691301, 0.017684198632122932, 0.042382162574711987, 0.064207571946511041, 0.082602100079150684, 0.097145355203635028, 0.107561011406507381, 0.113718474453852247, 0.115630166683615837, 0.113444644504459249, 0.107435882084395071, 0.097989162055837783, 0.085584105452548076, 0.070775446120293309, 0.054172207614333223, 0.036415971885660689, 0.018158938330246815, 0.000042459196338912, -0.017323296238410713, -0.033377949403731559, -0.047627263300716267, -0.059656793081079629, -0.069142490141500798, -0.075858019256578396, -0.079678658979652428, -0.080581767609623323, -0.078643906863599317, -0.074034819562284179, -0.067008552930955145, -0.057892102695980191, -0.047072022601671190, -0.034979497375161483, -0.022074413174279148, -0.008828977400685476, 0.004288560713652965, 0.016829555699174666, 0.028379479813981756, 0.038570858162652835, 0.047094241683417769, 0.053706909605020871, 0.058239076113395197, 0.060597464446319166, 0.060766202425508065, 0.058805083502616720, 0.054845323789501445, 0.049083025498695095, 0.041770628243703020, 0.033206689594802247, 0.023724383421121997, 0.013679137601712221, 0.003435850879130631, -0.006643868309165797, -0.016214010012738603, -0.024955612937682017, -0.032586990530198853, -0.038872417226545809, -0.043629018879643239, -0.046731678346964158, -0.048115839004410917, -0.047778163016171563, -0.045775074997070689, -0.042219292770236193, -0.037274512912134725, -0.031148477572630149, -0.024084698830208532, -0.016353156105483747, -0.008240309809337577, -0.000038789761018515, 0.007962880277736915, 0.015490170167632772, 0.022291712611484882, 0.028147455724642705, 0.032875542265754551, 0.036337708303315903, 0.038443049556812471, 0.039150063091460026, 0.038466933347880143, 0.036450092517807633, 0.033201143952433128, 0.028862291652591764, 0.023610467168487866, 0.017650385903971395, 0.011206796641134264, 0.004516210167813600, -0.002181595351151269, -0.008651993358287469, -0.014673562407359826, -0.020045503214184583, -0.024594176093158650, -0.028178551235573571, -0.030694406321622035, -0.032077152831841031, -0.032303222419993387, -0.031389996039150381, -0.029394309376722470, -0.026409616804964359, -0.022561940854659814, -0.018004773700230153, -0.012913130046223239, -0.007476976122050557, -0.001894276500050309, 0.003636091270827173, 0.008921304789011335, 0.013781207467236415, 0.018054338893886482, 0.021603186795815136, 0.024318493648450956, 0.026122487293166251, 0.026970945047679402, 0.026854043263213976, 0.025795987570079431, 0.023853461640206807, 0.021112972713804853, 0.017687209024348168, 0.013710556397414673, 0.009333947668859192, 0.004719238361448204, 0.000033314715823999, -0.004557854609777880, -0.008895014112733140, -0.012831064739959125, -0.016235971633599879, -0.019000975419769615, -0.021041973670496809, -0.022301970824562707, -0.022752529440111541, -0.022394191906072568, -0.021255878361951062, -0.019393302279828196, -0.016886478718542881, -0.013836430536684995, -0.010361223853106050, -0.006591484944463394, -0.002665565936317155, 0.001275464342459697, 0.005092825309417521, 0.008654850008311749, 0.011841465274590917, 0.014548176385701671, 0.016689426206986688, 0.018201223316688792, 0.019042961289876651, 0.019198381208357294, 0.018675660452129358, 0.017506641810096972, 0.015745246837337051, 0.013465145155917528, 0.010756776112709417, 0.007723840062309154, 0.004479392878420811, 0.001141688626311485, -0.002170078649346380, -0.005339982462341837, -0.008259373919338373, -0.010830557217282604, -0.012970007990380254, -0.014611030342508765, -0.015705770153788771, -0.016226526478563909, -0.016166328657139784, -0.015538773207899238, -0.014377140707818779, -0.012732837794565421, -0.010673232279050818, -0.008278969379415602, -0.005640873626063710, -0.002856553527664500, -0.000026834265658038, 0.002747852704083721, 0.005370995258360709, 0.007753319014958258, 0.009815785813909824, 0.011492173003678219, 0.012731150958433296, 0.013497795530424229, 0.013774493273929109, 0.013561219484126362, 0.012875191572278549, 0.011749922250546383, 0.010233717662138146, 0.008387684262046795, 0.006283324310867826, 0.003999812773708582, 0.001621057822818793, -0.000767347236997687, -0.003081171091507831, -0.005240483245491547, -0.007172383140908554, -0.008813427537033921, -0.010111676574189758, -0.011028293954650051, -0.011538653669060464, -0.011632924035784708, -0.011316118830412747, -0.010607624279109693, -0.009540229002217340, -0.008158700990423423, -0.006517970800651516, -0.004680992876389242, -0.002716366825287035, -0.000695807329823454, 0.001308445056270027, 0.003226179724201707, 0.004991648959431359, 0.006545794666321473, 0.007838194454033614, 0.008828664063258869, 0.009488466505815606, 0.009801093167340614, 0.009762597931815446, 0.009381481548192093, 0.008678139395534967, 0.007683900954968532, 0.006439703144240938, 0.004994451750326167, 0.003403135115410580, 0.001724761684323746, 0.000020197792912962, -0.001650015947868542, -0.003227792151864713, -0.004659494079420105, -0.005897735119564774, -0.006902920847777659, -0.007644484483944344, -0.008101778413755888, -0.008264597354555087, -0.008133322264400958, -0.007718687720230902, -0.007041188742854554, -0.006130155461650219, -0.005022535167821778, -0.003761430832691131, -0.002394452762763960, -0.000971945496911797, 0.000454844825025831, 0.001835596641714852, 0.003122668316617104, 0.004272722114380925, 0.005248162177843576, 0.006018339594106877, 0.006560486855847911, 0.006860354383749922, 0.006912532886871314, 0.006720456790559610, 0.006296095343184246, 0.005659348921651181, 0.004837178114662079, 0.003862502033291890, 0.002772909691220670, 0.001609233980906675, 0.000414041581645497, -0.000769906024675906, -0.001901165407831948, -0.002941044990442539, -0.003854910802244932, -0.004613320774623974, -0.005192951162290093, -0.005577286818932973, -0.005757056020769449, -0.005730399990410974, -0.005502776877353867, -0.005086609356845171, -0.004500693886508907, -0.003769397706347888, -0.002921676615038254, -0.001989952181071211, -0.001008891180284735, -0.000014132577398601, 0.000958991766382216, 0.001876697269289887, 0.002707904681562794, 0.003425276863778077, 0.004006100299408528, 0.004432983601002821, 0.004694352366032693, 0.004784727410211850, 0.004704781367912914, 0.004461176612085595, 0.004066195127045020, 0.003537178100163921, 0.002895799341758980, 0.002167201988627001, 0.001379032128141500, 0.000560405874095270, -0.000259152041390146, -0.001050759947470964, -0.001787184184342184, -0.002443762818329620, -0.002999217281793143, -0.003436325772772713, -0.003742437746853627, -0.003909814939345641, -0.003935790838753386, -0.003822747153675574, -0.003577912336230492, -0.003212993416401785, -0.002743658050835511, -0.002188888608264336, -0.001570234143874397, -0.000910989133812205, -0.000235329764723561, 0.000432560641279413, 0.001069345839998360, 0.001653340745377959, 0.002165238082962834, 0.002588733711954676, 0.002911030869493576, 0.003123208352342977, 0.003220442832479460, 0.003202080909987641, 0.003071561941475896, 0.002836197950977609, 0.002506821849485185, 0.002097319592184942, 0.001624065644771860, 0.001105284094542681, 0.000560359841433201, 0.000009125484808694, -0.000528850236297424, -0.001034947274672293, -0.001492128764321782, -0.001885503916298735, -0.002202801129643487, -0.002434736758218434, -0.002575269035034838, -0.002621730990172647, -0.002574840645573092, -0.002438591168737718, -0.002220027862259672, -0.001928922712789991, -0.001577360593112676, -0.001179253996234489, -0.000749805296090004, -0.000304936916893765, 0.000139289578942291, 0.000567244609490058, 0.000964271897894877, 0.001317181565737385, 0.001614678737960774, 0.001847714105275549, 0.002009746006742852, 0.002096907004167219, 0.002108071492117578, 0.002044824491385029, 0.001911335280223238, 0.001714142804308648, 0.001461862761483392, 0.001164828784166054, 0.000834682161765550, 0.000483925998593740, 0.000125460552453497, -0.000227883269383389, -0.000563795658925073, -0.000870909262856999, -0.001139175997920627, -0.001360187135536317, -0.001527426803455576, -0.001636451679881492, -0.001684992470943874, -0.001672975660262524, -0.001602466894019970, -0.001477540114542411, -0.001304079085075351, -0.001089520173828018, -0.000842547115162114, -0.000572749884052837, -0.000290260767615715, -0.000005381173403155, 0.000271787324682131, 0.000531694720882059, 0.000765665077860444, 0.000966179147256847, 0.001127108176071712, 0.001243891947014572, 0.001313656276814221, 0.001335267482640161, 0.001309323638539731, 0.001238084697878249, 0.001125345675261167, 0.000976258990458714, 0.000797113715033597, 0.000595080778704776, 0.000377934148912837, 0.000153758569481225, -0.000069345376995143, -0.000283548328671139, -0.000481561352316614, -0.000656878246049437, -0.000803983100343503, -0.000918516742461215, -0.000997397336828164, -0.001038892182663637, -0.001042639573678904, -0.001009621396079384, -0.000942088876021349, -0.000843445486235168, -0.000718092430499951, -0.000571243299133416, -0.000408715393446694, -0.000236705827693455, -0.000061560820167541, 0.000110453421068778, 0.000273370118506192, 0.000421724138601977, 0.000550730322629083, 0.000656432310144007, 0.000735817450677950, 0.000786894740519778, 0.000808734131933592, 0.000801466989262860, 0.000766248858509478, 0.000705187025332569, 0.000621236516650982, 0.000518069214751335, 0.000399921568730665, 0.000271426983019702, 0.000137439322056229, 0.000002854088234340, -0.000127566289796932, -0.000249356967950712, -0.000358499459727905, -0.000451549869015331, -0.000525742663600061, -0.000579067066332711, -0.000610314210246149, -0.000619094306052033, -0.000605824164738963, -0.000571686465475047, -0.000518563123569660, -0.000448945962885840, -0.000365828604967228, -0.000272584032349123, -0.000172832651673869, -0.000070305865763902, 0.000031289837955523, 0.000128403456337462, 0.000217760218406138, 0.000296468531144650, 0.000362109765670523, 0.000412808249833617, 0.000447279627497663, 0.000464856578836417, 0.000465491738613502, 0.000449738470059130, 0.000418710921836804, 0.000374025488711351, 0.000317726390511799, 0.000252198560764628, 0.000180071382714710, 0.000104117018254314, 0.000027147141711448, -0.000048088182130861, -0.000118995940709898, -0.000183226726188442, -0.000238749615318076, -0.000283913107803554, -0.000317490431754438, -0.000338708143110164, -0.000347257581417331, -0.000343289373546324, -0.000327391777412823, -0.000300554208881314, -0.000264117778630104, -0.000219715066774411, -0.000169201669906033, -0.000114582260151285, -0.000057933995063949, -0.000001330110803372, 0.000053233576939992, 0.000103906741924272, 0.000149044949497856, 0.000187260510974094, 0.000217462319983746, 0.000238883649294571, 0.000251097355835207, 0.000254018413730855, 0.000247894152903089, 0.000233283008194432, 0.000211022966716673, 0.000182191226994878, 0.000148056842795767, 0.000110028310364557, 0.000069598166140896, 0.000028286691831679, -0.000012413223177511, -0.000051088131137235, -0.000086451240238396, -0.000117383287411682, -0.000142965848616867, -0.000162506184310969, -0.000175553056891817, -0.000181903303379713, -0.000181599287597338, -0.000174917679492114, -0.000162350303974188, -0.000144578058136870, -0.000122439106161612, -0.000096892719738482, -0.000068980234721197, -0.000039784640417051, -0.000010390306964679, 0.000018155708707897, 0.000044879452343343, 0.000068911789142910, 0.000089515073669816, 0.000106104020030281, 0.000118260259226232, 0.000125740319217347, 0.000128477011389261, 0.000126574445796332, 0.000120297118433995, 0.000110053709582710, 0.000096376396848920, 0.000079896615190895, 0.000061318285745045, 0.000041389584008291, 0.000020874325790195, 0.000000524017729422, -0.000018948449136533, -0.000036892585232981, -0.000052740818819573, -0.000066025144314650, -0.000076389469747209, -0.000083597404911355, -0.000087535408131387, -0.000088211381288728, -0.000085748963835814, -0.000080377921496540, -0.000072421149619506, -0.000062278911057702, -0.000050411001395778, -0.000037317578835504, -0.000023519411693731, -0.000009538283954733, 0.000004121739654397, 0.000016991550435446, 0.000028652179052461, 0.000038747470023706, 0.000046993903986995, 0.000053187343852112, 0.000057206603209622, 0.000059013855762422, 0.000058652018744224, 0.000056239347370971, 0.000051961567969763, 0.000046061951828715, 0.000038829788015541, 0.000030587750191730, 0.000021678669346899, 0.000012452221695327, 0.000003252019725938, -0.000005596443768274, -0.000013796601731427, -0.000021090036946349, -0.000027263866219030, -0.000032156106624670, -0.000035658928433894, -0.000037719781474555, -0.000038340460301533, -0.000037574245901964, -0.000035521325378456, -0.000032322744186229, -0.000028153186597604, -0.000023212908194301, -0.000017719158939021, -0.000011897436866734, -0.000005972901266780, -0.000000162251446552, 0.000005333655793588, 0.000010336218246169, 0.000014694346087313, 0.000018288433744639, 0.000021032968627464, 0.000022877753957232, 0.000023807775391314, 0.000023841789731823, 0.000023029757133319, 0.000021449274538926, 0.000019201196577477, 0.000016404650185715, 0.000013191660473528, 0.000009701607868611, 0.000006075730729441, 0.000002451874068818, -0.000001040335292299, -0.000004283732788372, -0.000007177155365100, -0.000009638185206925, -0.000011605042076524, -0.000013037603419542, -0.000013917565218600, -0.000014247788012456, -0.000014050900469913, -0.000013367256554309, -0.000012252360976939, -0.000010773890887184, -0.000009008449384796, -0.000007038188493661, -0.000004947435946560, -0.000002819451929447, -0.000000733429418017, 0.000001238164361723, 0.000003031826677860, 0.000004594780305705, 0.000005886220575305, 0.000006878033995645, 0.000007554995005623, 0.000007914466875845, 0.000007965650064675, 0.000007728435880102, 0.000007231934716903, 0.000006512756173231, 0.000005613122895949, 0.000004578901096601, 0.000003457628489583, 0.000002296615219305, 0.000001141185552533, 0.000000033118183302, -0.000000990668545558, -0.000001899152803076, -0.000002667946210802, -0.000003279724008567, -0.000003724353373815, -0.000003998736284580, -0.000004106393367485, -0.000004056823505075, -0.000003864680371659, -0.000003548811395079, -0.000003131206866384, -0.000002635907089885, -0.000002087913711897, -0.000001512147886406, -0.000000932492985725, -0.000000370953442845, 0.000000153045653294, 0.000000623201057861, 0.000001026706448750, 0.000001354458044511, 0.000001601095747237, 0.000001764891111188, 0.000001847498832724, 0.000001853592772907, 0.000001790410657756, 0.000001667233505382, 0.000001494826511430, 0.000001284867642241, 0.000001049388641653, 0.000000800250692844, 0.000000548673760673, 0.000000304834862491, 0.000000077546377014, -0.000000125978796206, -0.000000300272674786, -0.000000441669721214, -0.000000548281621807, -0.000000619897641839, -0.000000657821438861, -0.000000664657100282, -0.000000644058349094, -0.000000600455333568, -0.000000538773213853, -0.000000464155939282, -0.000000381707256690, -0.000000296259201847, -0.000000212176215381, -0.000000133200709942, -0.000000062343516559, 0.0 };
-void decompressResamplerMQ(const double y[701], float *yi)
-{
- double breaks[701];
- double coefs[2800];
- int32_t k;
- double s[701];
- double dx[700];
- double dvdf[700];
- double r, dzzdx, dzdxdx;
- for (k = 0; k < 700; k++)
- {
- r = 0.0014285714285714286 * ((double)k + 1.0) - 0.0014285714285714286 * (double)k;
- dx[k] = r;
- dvdf[k] = (y[k + 1] - y[k]) / r;
- }
- s[0] = ((dx[0] + 0.0057142857142857143) * dx[1] * dvdf[0] + dx[0] * dx[0] * dvdf[1]) / 0.0028571428571428571;
- s[700] = ((dx[699] + 0.0057142857142857828) * dx[698] * dvdf[699] + dx[699] * dx[699] * dvdf[698]) / 0.0028571428571428914;
- breaks[0] = dx[1];
- breaks[700] = dx[698];
- for (k = 0; k < 699; k++)
- {
- r = dx[k + 1];
- s[k + 1] = 3.0 * (r * dvdf[k] + dx[k] * dvdf[k + 1]);
- breaks[k + 1] = 2.0 * (r + dx[k]);
- }
- r = dx[1] / breaks[0];
- breaks[1] -= r * 0.0028571428571428571;
- s[1] -= r * s[0];
- for (k = 0; k < 698; k++)
- {
- r = dx[k + 2] / breaks[k + 1];
- breaks[k + 2] -= r * dx[k];
- s[k + 2] -= r * s[k + 1];
- }
- r = 0.0028571428571428914 / breaks[699];
- breaks[700] -= r * dx[698];
- s[700] -= r * s[699];
- s[700] /= breaks[700];
- for (k = 698; k >= 0; k--)
- s[k + 1] = (s[k + 1] - dx[k] * s[k + 2]) / breaks[k + 1];
- s[0] = (s[0] - 0.0028571428571428571 * s[1]) / breaks[0];
- for (k = 0; k < 701; k++)
- breaks[k] = 0.0014285714285714286 * (double)k;
- for (k = 0; k < 700; k++)
- {
- r = 1.0 / dx[k];
- dzzdx = (dvdf[k] - s[k]) * r;
- dzdxdx = (s[k + 1] - dvdf[k]) * r;
- coefs[k] = (dzdxdx - dzzdx) * r;
- coefs[k + 700] = 2.0 * dzzdx - dzdxdx;
- coefs[k + 1400] = s[k];
- coefs[k + 2100] = y[k];
- }
- double d = 1.0 / 22437.0;
- int32_t low_i, low_ip1, high_i, mid_i;
- for (k = 0; k < 22438; k++)
- {
- low_i = 0;
- low_ip1 = 2;
- high_i = 701;
- r = k * d;
- while (high_i > low_ip1)
- {
- mid_i = ((low_i + high_i) + 1) >> 1;
- if (r >= breaks[mid_i - 1])
- {
- low_i = mid_i - 1;
- low_ip1 = mid_i + 1;
- }
- else
- high_i = mid_i;
- }
- double xloc = r - breaks[low_i];
- yi[k] = xloc * (xloc * (xloc * coefs[low_i] + coefs[low_i + 700]) + coefs[low_i + 1400]) + coefs[low_i + 2100];
- }
-}
void reverse(float *arr, int32_t start, int32_t end)
{
while (start < end)
@@ -402,18 +324,14 @@ void circshift(float *x, int n, int k)
ierper pch1, pch2, pch3;
__attribute__((constructor)) static void initialize(void)
{
- if (decompressedCoefficients)
- free(decompressedCoefficients);
- decompressedCoefficients = (float*)malloc(22438 * sizeof(float));
- decompressResamplerMQ(compressedCoeffMQ, decompressedCoefficients);
+ precompute_lpfcoeff();
initIerper(&pch1, NUMPTS + 2);
initIerper(&pch2, NUMPTS + 2);
initIerper(&pch3, NUMPTS_DRS + 2);
}
__attribute__((destructor)) static void destruction(void)
{
- free(decompressedCoefficients);
- decompressedCoefficients = 0;
+ clean_lpfcoeff();
freeIerper(&pch1);
freeIerper(&pch2);
freeIerper(&pch3);
@@ -492,7 +410,7 @@ JNIEXPORT jfloatArray JNICALL Java_james_dsp_activity_JdspImpResToolbox_ReadImpu
if (strlen(mIRFileName) <= 0) return 0;
unsigned int channels;
drwav_uint64 frameCount;
- float *pFrameBuffer = loadAudioFile(mIRFileName, targetSampleRate, &channels, &frameCount, 1);
+ float *pFrameBuffer = loadAudioFile(mIRFileName, targetSampleRate, &channels, &frameCount, SRC_SINC_BEST_QUALITY);
if (channels == 0 || channels == 3 || channels > 4)
{
free(pFrameBuffer);
@@ -623,7 +541,7 @@ JNIEXPORT jstring JNICALL Java_james_dsp_activity_JdspImpResToolbox_OfflineAudio
snprintf(filenameIR, needed, "%s%s", jnipath, mIRFileName);
unsigned int channels;
drwav_uint64 frameCount;
- float *pFrameBuffer = loadAudioFile(filenameIR, targetSampleRate, &channels, &frameCount, 0);
+ float *pFrameBuffer = loadAudioFile(filenameIR, targetSampleRate, &channels, &frameCount, SRC_SINC_BEST_QUALITY);
free(filenameIR);
if (!pFrameBuffer)
{
diff --git a/libjamesdsp/subtree/Main/DSPManager/project.properties b/libjamesdsp/subtree/Main/DSPManager/project.properties
index 0fabc5d1..a78cc3e3 100644
--- a/libjamesdsp/subtree/Main/DSPManager/project.properties
+++ b/libjamesdsp/subtree/Main/DSPManager/project.properties
@@ -11,6 +11,6 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
-target=android-28
+target=android-29
proguard.config=proguard.txt
android.library.reference.1=../../../appcompatSupport
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/arrays.xml b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/arrays.xml
index a067c97e..7fd927a8 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/arrays.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/arrays.xml
@@ -17,9 +17,10 @@
- 极高
- - 均匀(短时傅里叶)
- - 多解析率(连续小波)
- - 多解析率(时域)
+ - 均匀(降采样短时傅里叶)
+ - 多解析率(连续小波不完整对偶帧)
+ - 伪多解析率(降采样帧)
+ - 伪多解析率(时域零延时)
- 最小相位FIR
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/strings.xml b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/strings.xml
index 9b6a4b1c..a1c09c22 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/strings.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rCN/strings.xml
@@ -85,7 +85,7 @@
请先启用全域模式或者惯用模式来注册DSP,以便从音讯DSP中获取采样率
载入冲激响应失败\n请选择正确冲激响应档案
冲激响应档案%1$s的采样率%2$d与DSP模组采样率%3$d不吻合\n目前正使用快速重采样器\n预先使用离线重采样器可改善冲激响应质量。
- 缓冲区大小:%1$s\n动态容器容量:%2$d\n采样率:%3$d
+ 缓冲区大小:%1$s\n动态容器容量:%2$d
成功载入冲激响应:%1$s\n声道:%2$s\n每声道样本总数:%3$d\n截短后的每声道样本总数:%4$d
压限器阈值[-60 到 -0.1 dB]
压限器时间常数[1.5 到 500 ms]
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/arrays.xml b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/arrays.xml
index 7d9412bb..d6cf79e4 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/arrays.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/arrays.xml
@@ -17,9 +17,10 @@
- 極高
- - 均勻(短時傅立葉)
- - 多解析率(連續小波)
- - 多解析率(時域)
+ - 均勻(降採樣短時傅立葉)
+ - 多解析率(連續小波不完整對偶幀)
+ - 偽多解析率(降採樣幀)
+ - 偽多解析率(時域零延時)
- 開啟
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/strings.xml b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/strings.xml
index 14419b9f..296dae9d 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/strings.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rHK/strings.xml
@@ -85,7 +85,7 @@
請先啟用全域模式或者慣用模式來註冊DSP,以便從音訊DSP中獲取採樣率
載入脈衝響應失敗\n請選擇正確脈衝響應檔案
脈衝響應檔案%1$s的採樣率%2$d與DSP模組採樣率%3$d不吻合\n目前正使用快速重採樣器\n預先使用離線重採樣器可改善脈衝響應質量。
- 緩衝區大小:%1$s\n動態容器容量:%2$d\n採樣率:%3$d
+ 緩衝區大小:%1$s\n動態容器容量:%2$d
成功載入脈衝響應:%1$s\n聲道:%2$s\n每聲道樣本總數:%3$d\n截短後的每聲道樣本總數:%4$d
壓限器閾值[-60 到 -0.1 dB]
壓限器時間常數[1.5 到 500 ms]
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/arrays.xml b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/arrays.xml
index 7d9412bb..d6cf79e4 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/arrays.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/arrays.xml
@@ -17,9 +17,10 @@
- 極高
- - 均勻(短時傅立葉)
- - 多解析率(連續小波)
- - 多解析率(時域)
+ - 均勻(降採樣短時傅立葉)
+ - 多解析率(連續小波不完整對偶幀)
+ - 偽多解析率(降採樣幀)
+ - 偽多解析率(時域零延時)
- 開啟
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/strings.xml b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/strings.xml
index 14419b9f..296dae9d 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/strings.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values-zh-rTW/strings.xml
@@ -85,7 +85,7 @@
請先啟用全域模式或者慣用模式來註冊DSP,以便從音訊DSP中獲取採樣率
載入脈衝響應失敗\n請選擇正確脈衝響應檔案
脈衝響應檔案%1$s的採樣率%2$d與DSP模組採樣率%3$d不吻合\n目前正使用快速重採樣器\n預先使用離線重採樣器可改善脈衝響應質量。
- 緩衝區大小:%1$s\n動態容器容量:%2$d\n採樣率:%3$d
+ 緩衝區大小:%1$s\n動態容器容量:%2$d
成功載入脈衝響應:%1$s\n聲道:%2$s\n每聲道樣本總數:%3$d\n截短後的每聲道樣本總數:%4$d
壓限器閾值[-60 到 -0.1 dB]
壓限器時間常數[1.5 到 500 ms]
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values/arrays.xml b/libjamesdsp/subtree/Main/DSPManager/res/values/arrays.xml
index 686c51c1..daf72417 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values/arrays.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values/arrays.xml
@@ -63,14 +63,16 @@
- 4
- - Uniform(Short time Fourier)
- - Multiresolution(Continuous wavelet)
- - Multiresolution(Time domain)
+ - Uniform(Short time Fourier transform)
+ - Multiresolution(Continuous wavelet incomplete dual frame)
+ - Pseudo multiresolution(Undersampling frame)
+ - Pseudo multiresolution(Time domain, zero latency)
- 0
- 1
- 2
+ - 3
@@ -93,6 +95,16 @@
- 18
+
+ - @string/eq_preset_flat
+ - @string/eq_preset_custom
+
+
+
+ - 95.0;200.0;400.0;800.0;1600.0;3400.0;7500.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0
+ - custom
+
+
- @string/eq_preset_flat
- @string/eq_preset_custom
@@ -101,7 +113,6 @@
- 25.0;40.0;63.0;100.0;160.0;250.0;400.0;630.0;1000.0;1600.0;2500.0;4000.0;6300.0;10000.0;16000.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0;0.0
- custom
-
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/values/strings.xml b/libjamesdsp/subtree/Main/DSPManager/res/values/strings.xml
index f71703de..ec533f6c 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/values/strings.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/values/strings.xml
@@ -83,7 +83,7 @@
Please first register audio engine by enabling global effect or open a music player if using conventional mode in order to retrive sample rate from audio engine
Load impulse failed\nPlease choose right impulse response file!
Impulse response %1$s sample rate (%2$d) is not matching with driver sample rate(%3$d)\nWill use low quality resampler to resample…\nUse Offline Resampler for higher qualtiy resampling!
- Buffer len: %1$s\nAllocated block size: %2$d\nSample rate: %3$d
+ Buffer len: %1$s\nAllocated block size: %2$d
Impulse response %1$s loaded\nChannel info:%2$s\nSamples per channel:%3$d\nSamples per channel(Truncated):%4$d
Limiter threshold [-60 – -0.1 dB]
Limiter release [1.5 – 500 ms]
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/xml/bluetooth_preferences.xml b/libjamesdsp/subtree/Main/DSPManager/res/xml/bluetooth_preferences.xml
index 255cbdc0..e351f2b1 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/xml/bluetooth_preferences.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/xml/bluetooth_preferences.xml
@@ -58,12 +58,12 @@
android:entryValues="@array/compression_tfresolution_values"
android:title="@string/dialog_compression_tfresolution" />
+ android:entryValues="@array/compander_preset_values" />
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/xml/headset_preferences.xml b/libjamesdsp/subtree/Main/DSPManager/res/xml/headset_preferences.xml
index 255cbdc0..e351f2b1 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/xml/headset_preferences.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/xml/headset_preferences.xml
@@ -58,12 +58,12 @@
android:entryValues="@array/compression_tfresolution_values"
android:title="@string/dialog_compression_tfresolution" />
+ android:entryValues="@array/compander_preset_values" />
diff --git a/libjamesdsp/subtree/Main/DSPManager/res/xml/speaker_preferences.xml b/libjamesdsp/subtree/Main/DSPManager/res/xml/speaker_preferences.xml
index 255cbdc0..e351f2b1 100644
--- a/libjamesdsp/subtree/Main/DSPManager/res/xml/speaker_preferences.xml
+++ b/libjamesdsp/subtree/Main/DSPManager/res/xml/speaker_preferences.xml
@@ -58,12 +58,12 @@
android:entryValues="@array/compression_tfresolution_values"
android:title="@string/dialog_compression_tfresolution" />
+ android:entryValues="@array/compander_preset_values" />
diff --git a/libjamesdsp/subtree/Main/DSPManager/src/james/dsp/service/HeadsetService.java b/libjamesdsp/subtree/Main/DSPManager/src/james/dsp/service/HeadsetService.java
index 7ec94ab1..e279e79a 100644
--- a/libjamesdsp/subtree/Main/DSPManager/src/james/dsp/service/HeadsetService.java
+++ b/libjamesdsp/subtree/Main/DSPManager/src/james/dsp/service/HeadsetService.java
@@ -761,7 +761,7 @@ private void updateDsp(SharedPreferences preferences, JDSPModule session, boolea
}
float timeConstant = Float.valueOf(preferences.getString("dsp.compression.timeconstant", "0.22"));
float granularity = Float.valueOf(preferences.getString("dsp.compression.granularity", "4"));
- float tfresolution = Float.valueOf(preferences.getString("dsp.compression.tfresolution", "1"));
+ float tfresolution = Float.valueOf(preferences.getString("dsp.compression.tfresolution", "0"));
float compConfig[] = new float[]{ timeConstant, granularity, tfresolution };
float sendAry[] = mergeFloatArray(compConfig, compLevels);
//Log.i(DSPManager.TAG, "Compander: " + Arrays.toString(compLevels));
@@ -954,7 +954,7 @@ private void updateDsp(SharedPreferences preferences, JDSPModule session, boolea
session.setParameterShort(session.JamesDSP, 10004, (short)1); // Notify send array completed and resize array in native side
if (DSPManager.devMsgDisplay)
{
- Toast.makeText(HeadsetService.this, getString(R.string.basicinfo, dspBufferLen, dspAllocatedBlockLen, dspModuleSamplingRate), Toast.LENGTH_SHORT).show();
+ Toast.makeText(HeadsetService.this, getString(R.string.basicinfo, dspBufferLen, dspAllocatedBlockLen), Toast.LENGTH_SHORT).show();
if (impinfo[0] == 1)
Toast.makeText(HeadsetService.this, getString(R.string.convolversuccess, mConvIRFileName, getString(R.string.mono_conv), impinfo[1], (int)impulseCutted), Toast.LENGTH_SHORT).show();
else if (impinfo[0] == 2)
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/Android.mk b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/Android.mk
index a6db4927..d3b43bae 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/Android.mk
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/Android.mk
@@ -26,6 +26,7 @@ LOCAL_SRC_FILES := \
jdsp/Effects/arbEqConv.c \
jdsp/Effects/eel2/numericSys/libsamplerate/samplerate.c \
jdsp/Effects/eel2/numericSys/libsamplerate/src_sinc.c \
+ jdsp/Effects/eel2/numericSys/libsamplerate/src_linear.c \
jdsp/Effects/eel2/numericSys/FilterDesign/generalFdesign.c \
jdsp/Effects/eel2/numericSys/FilterDesign/cos_fib_paraunitary.c \
jdsp/Effects/eel2/numericSys/FilterDesign/polyphaseFilterbank.c \
@@ -41,6 +42,44 @@ LOCAL_SRC_FILES := \
jdsp/Effects/eel2/numericSys/cpoly.c \
jdsp/Effects/eel2/numericSys/MersenneTwister.c \
jdsp/Effects/eel2/numericSys/quadprog.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/atox.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/constant.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxaop.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxbasic.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxconstant.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxconvf.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxexp.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxhypb.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxidiv.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxpow.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxprcmp.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/cxtrig.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/hpaconf.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/prcxpr.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/print.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/prxpr.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/sfmod.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/shift.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xadd.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xchcof.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xdiv.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xevtch.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xexp.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xfmod.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xfrac.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xhypb.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xivhypb.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xivtrg.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xlog.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xmul.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xneg.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xprcmp.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xpwr.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xsigerr.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xsqrt.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xtodbl.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xtoflt.c \
+ jdsp/Effects/eel2/numericSys/HPFloat/xtrig.c \
jdsp/Effects/eel2/s_str.c \
jdsp/Effects/eel2/fft.c \
jdsp/Effects/eel2/nseel-compiler.c \
@@ -52,17 +91,17 @@ LOCAL_SRC_FILES := \
# terminator
LOCAL_LDLIBS := -llog
ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
-LOCAL_CPPFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv7-a -mfpu=neon -ftree-vectorize -fvisibility=hidden #-DDEBUG
-LOCAL_CFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv7-a -mfpu=neon -ftree-vectorize -fvisibility=hidden #-DDEBUG
+LOCAL_CPPFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv7-a -mfpu=neon -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
+LOCAL_CFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv7-a -mfpu=neon -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
else ifeq ($(TARGET_ARCH_ABI), arm64-v8a)
-LOCAL_CPPFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv8-a -mfpu=neon -ftree-vectorize -fvisibility=hidden #-DDEBUG
-LOCAL_CFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv8-a -mfpu=neon -ftree-vectorize -fvisibility=hidden #-DDEBUG
+LOCAL_CPPFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv8-a -mfpu=neon -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
+LOCAL_CFLAGS += -Wall -Wextra -ffunction-sections -fdata-sections -Ofast -march=armv8-a -mfpu=neon -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
else ifeq ($(TARGET_ARCH_ABI), x86)
-LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden #-DDEBUG
-LOCAL_CFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden #-DDEBUG
+LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
+LOCAL_CFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
else ifeq ($(TARGET_ARCH_ABI), armeabi)
-LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden #-DDEBUG
-LOCAL_CFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden #-DDEBUG
+LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
+LOCAL_CFLAGS += -ffunction-sections -fdata-sections -Ofast -ftree-vectorize -fvisibility=hidden -DJAMESDSP_REFERENCE_IMPL #-DDEBUG
endif
LOCAL_LDFLAGS += -Wl,--gc-sections,--exclude-libs,ALL
include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jamesdsp.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jamesdsp.c
index b80ba12b..25378879 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jamesdsp.c
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jamesdsp.c
@@ -202,7 +202,7 @@ int32_t EffectDSPMainCommand(EffectDSPMain *dspmain, uint32_t cmdCode, uint32_t
replyData->psize = 4;
replyData->vsize = 4;
replyData->cmd = 20001;
- replyData->data = (int32_t)dspmain->jdsp.trueSampleRate;
+ replyData->data = (int32_t)dspmain->jdsp.fs;
*replySize = sizeof(reply1x4_1x4_t);
return 0;
}
@@ -550,7 +550,7 @@ int32_t EffectDSPMainCommand(EffectDSPMain *dspmain, uint32_t cmdCode, uint32_t
for (int i = 0; i < 7; i++)
LOGI("%1.7lf %1.7lf; ", param[i], param[i + 7]);
#endif
- CompressorSetParam(&dspmain->jdsp, timeconstant, granularity, tfresolution);
+ CompressorSetParam(&dspmain->jdsp, timeconstant, granularity, tfresolution, 0);
CompressorSetGain(&dspmain->jdsp, param, param + 7, 1);
*replyData = 0;
return 0;
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/crossfeed.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/crossfeed.c
index 0d127ba9..7e5155b4 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/crossfeed.c
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/crossfeed.c
@@ -10,6 +10,7 @@ void CrossfeedConstructor(JamesDSPLib *jdsp)
}
void CrossfeedDestructor(JamesDSPLib *jdsp)
{
+ jdsp_lock(jdsp);
if (jdsp->advXF.conv[0])
{
FFTConvolver2x4x2Free(jdsp->advXF.conv[0]);
@@ -29,6 +30,7 @@ void CrossfeedDestructor(JamesDSPLib *jdsp)
FFTConvolver2x4x2Free(jdsp->advXF.convLong_S_S);
free(jdsp->advXF.convLong_S_S);
}
+ jdsp_unlock(jdsp);
}
void CrossfeedProcessFFTConvolver2x4x2(JamesDSPLib *jdsp, size_t n)
{
@@ -40,6 +42,7 @@ void CrossfeedProcessTwoStageFFTConvolver2x4x2(JamesDSPLib *jdsp, size_t n)
}
void CrossfeedEnable(JamesDSPLib *jdsp, char enable)
{
+ jdsp_lock(jdsp);
if (jdsp->crossfeedForceRefresh || !jdsp->advXF.conv[0] || !jdsp->advXF.conv[1] || !jdsp->advXF.conv[2] || !jdsp->advXF.convLong_S_S || !jdsp->advXF.convLong_T_S)
{
if (jdsp->advXF.conv[0])
@@ -55,11 +58,13 @@ void CrossfeedEnable(JamesDSPLib *jdsp, char enable)
{
TwoStageFFTConvolver2x4x2Free(jdsp->advXF.convLong_T_S);
free(jdsp->advXF.convLong_T_S);
+ jdsp->advXF.convLong_T_S = NULL;
}
if (jdsp->advXF.convLong_S_S)
{
FFTConvolver2x4x2Free(jdsp->advXF.convLong_S_S);
free(jdsp->advXF.convLong_S_S);
+ jdsp->advXF.convLong_S_S = NULL;
}
jdsp->advXF.conv[0] = (FFTConvolver2x4x2 *)malloc(sizeof(FFTConvolver2x4x2));
FFTConvolver2x4x2Init(jdsp->advXF.conv[0]);
@@ -96,6 +101,7 @@ void CrossfeedEnable(JamesDSPLib *jdsp, char enable)
}
if (enable)
jdsp->crossfeedEnabled = 1;
+ jdsp_unlock(jdsp);
}
void CrossfeedDisable(JamesDSPLib *jdsp)
{
@@ -135,4 +141,4 @@ void CrossfeedProcess(JamesDSPLib *jdsp, size_t n)
FFTConvolver2x4x2Process(jdsp->advXF.conv[jdsp->advXF.mode - 2], jdsp->tmpBuffer[0], jdsp->tmpBuffer[1], jdsp->tmpBuffer[0], jdsp->tmpBuffer[1], (unsigned int)n);
else
jdsp->advXF.process(jdsp, (unsigned int)n);
-}
\ No newline at end of file
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/dynamic.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/dynamic.c
index 625fa1d6..281acf1d 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/dynamic.c
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/dynamic.c
@@ -1,5 +1,10 @@
+#include
+#include
+#include
#include
#include
+#include "eel2/numericSys/codelet.h"
+#include "eel2/ns-eel.h"
#include "../jdsp_header.h"
void JLimiterSetCoefficients(JamesDSPLib *jdsp, double thresholddB, double msRelease)
{
@@ -12,13 +17,6 @@ void JLimiterInit(JamesDSPLib *jdsp)
{
jdsp->limiter.envOverThreshold = 0.0f;
}
-#include
-#include
-#include
-#include
-#include
-#include "eel2/numericSys/codelet.h"
-#include "eel2/ns-eel.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
@@ -26,61 +24,6 @@ float map(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
-static void getAsymmetricWindow(float *analysisWnd, float *synthesisWnd, int k, int m, int p, double freq_temporal)
-{
- int i;
- if ((k / m) < 4)
- freq_temporal = 1.0f;
- if (freq_temporal > 9.0f)
- freq_temporal = 9.0f;
- memset(synthesisWnd, 0, k * sizeof(float));
- int n = ((k - m) << 1) + 2;
- for (i = 0; i < k - m; ++i)
- analysisWnd[i] = (float)pow(0.5 * (1.0 - cos(2.0 * M_PI * (i + 1.0) / (double)n)), freq_temporal);
- n = (m << 1) + 2;
- if (freq_temporal > 1.02)
- freq_temporal = 1.02;
- for (i = k - m; i < k; ++i)
- analysisWnd[i] = (float)pow(sqrt(0.5 * (1.0 - cos(2.0 * M_PI * ((m + i - (k - m)) + 1.0) / (double)n))), freq_temporal);
- n = m << 1;
- for (i = k - (m << 1); i < k; ++i)
- synthesisWnd[i] = (float)(0.5 * (1.0 - cos(2.0 * M_PI * (double)(i - (k - (m << 1))) / (double)n))) / analysisWnd[i];
- // Pre-shift window function
- for (i = 0; i < k - p; i++)
- synthesisWnd[i] = synthesisWnd[i + p];
-}
-unsigned int LLIntegerLog2M(unsigned int v)
-{
- unsigned int i = 0;
- while (v > 1)
- {
- ++i;
- v >>= 1;
- }
- return i;
-}
-unsigned LLRevBitsM(unsigned int x, unsigned int bits)
-{
- unsigned int y = 0;
- while (bits--)
- {
- y = (y + y) + (x & 1);
- x >>= 1;
- }
- return y;
-}
-void LLbitReversalTblM(unsigned *dst, unsigned int fftLen)
-{
- unsigned int bits = LLIntegerLog2M(fftLen);
- for (unsigned int i = 0; i < fftLen; ++i)
- dst[i] = LLRevBitsM(i, bits);
-}
-void LLsinHalfTblFloatM(float *dst, unsigned int fftLen)
-{
- const double twopi_over_n = 6.283185307179586476925286766559 / fftLen;
- for (int i = 0; i < fftLen >> 1; ++i)
- dst[i] = (float)sin(twopi_over_n * i);
-}
#include "../generalDSP/spectralInterpolatorFloat.h"
static size_t choose(float *a, float *b, size_t src1, size_t src2)
{
@@ -123,7 +66,7 @@ static size_t fast_upper_bound4(float *vec, size_t n, float *value)
}
return low;
}
-static float lerp1DNoExtrapo(float val, float *x, float *y, int n)
+static inline float lerp1DNoExtrapo(float val, float *x, float *y, int n)
{
if (val <= x[0])
return y[0];
@@ -132,6 +75,92 @@ static float lerp1DNoExtrapo(float val, float *x, float *y, int n)
size_t j = fast_upper_bound4(x, n, &val);
return ((val - x[j - 1]) / (x[j] - x[j - 1])) * (y[j] - y[j - 1]) + y[j - 1]; // Interpolation
}
+void printMatrixFile(char *filename, double *mat, int rows, int cols)
+{
+ int i, j;
+ FILE *fp = fopen(filename, "wb");
+ for (i = 0; i < rows; i++)
+ {
+ for (j = 0; j < cols; j++)
+ fprintf(fp, "%1.14lf,", mat[i * cols + j]);
+ fprintf(fp, "\n");
+ }
+ fclose(fp);
+}
+#ifndef min
+#define min(a,b) (((a)<(b))?(a):(b))
+#endif
+#ifndef max
+#define max(a,b) (((a)>(b))?(a):(b))
+#endif
+void gammatoneAP(double fc, double fs, int n, double bwERB, double *bReal, double *bImag, double *aRe, double *aIm, double *delay, double *postGain)
+{
+ // One ERB value in Hz at this centre frequency
+ double ERBHz = 24.7 + 0.108 * fc;
+ // Bandwidth of the filter in Hertz
+ double bwHz = bwERB * ERBHz;
+ // This is when the function peaks
+ *delay = (n - 1.0) / (2.0 * M_PI * bwHz);
+ double btmp = pow(1.0 - exp(-2.0 * M_PI * bwHz / fs), (double)n);
+ double tmpRe = -2.0 * M_PI * bwHz / fs;
+ double tmpIm = -2.0 * M_PI * fc / fs;
+ double atildeRe, atildeIm;
+ cplxexp(tmpRe, tmpIm, ãRe, ãIm);
+ double bRe, bIm;
+ tmpRe = 0.0;
+ tmpIm = 2 * M_PI * fc * *delay;
+ cplxexp(tmpRe, tmpIm, &bRe, &bIm);
+ bRe = bRe * btmp;
+ bIm = bIm * btmp;
+ aRe[0] = 1.0; aIm[0] = 0.0;
+ for (int j = 1; j < n + 1; j++)
+ {
+ aRe[j] = 0.0;
+ aIm[j] = 0.0;
+ }
+ double *tRe = (double *)malloc(n * sizeof(double));
+ double *tIm = (double *)malloc(n * sizeof(double));
+ // Repeat the pole n times, and expand the polynomial
+ // a = poly(atilde*ones(1,n));
+ for (int j = 0; j < n; j++)
+ {
+ for (int i = 0; i < j + 1; i++)
+ complexMultiplication(atildeRe, atildeIm, aRe[i], aIm[i], &tRe[i], &tIm[i]);
+ for (int i = 0; i < j + 1; i++)
+ {
+ aRe[i + 1] = aRe[i + 1] - tRe[i];
+ aIm[i + 1] = aIm[i + 1] - tIm[i];
+ }
+ }
+ free(tRe);
+ free(tIm);
+ double maxV = max(fabs(bRe), fabs(bIm));
+ if (maxV < ((double)FLT_EPSILON))
+ {
+ *bReal = bRe / maxV * ((double)FLT_EPSILON);
+ *bImag = bIm / maxV * ((double)FLT_EPSILON);
+ *postGain = maxV / ((double)FLT_EPSILON);
+ }
+ else
+ {
+ *bReal = bRe;
+ *bImag = bIm;
+ *postGain = 1.0;
+ }
+}
+void gammatoneAPFirstOrder(double fc, double fs, double bwERB, float *bRe, float *aRe, float *aIm)
+{
+ double bwHz = bwERB * (24.7 + 0.108 * fc);
+ *bRe = (float)(1.0 - exp(-2.0 * M_PI * bwHz / fs));
+ double atildeRe, atildeIm;
+ cplxexp(-2.0 * M_PI * bwHz / fs, -2.0 * M_PI * fc / fs, ãRe, ãIm);
+ *aRe = (float)(-atildeRe);
+ *aIm = (float)(-atildeIm);
+}
+const float freq4Points[6] = { 0, 200, 1200, 3000, 10000, 24000 };
+const float asnr4Points[6] = { 25, 17, 16, 15, 14, 25 };
+const float wtNPoints[6] = { 0, 15, 23, 28, 40, 70 };
+const float pspri = 0.9; // prior speech probability [0.5] (18)
#define MIN(a, b) (((a)<(b))?(a):(b))
#define MAX(a, b) (((a)>(b))?(a):(b))
static float db2mag2(float db)
@@ -140,12 +169,7 @@ static float db2mag2(float db)
}
static float mag2db(float mag)
{
- // Fix: mag is zero after stopping playback since the input buffer is zeroed.
- // This would cause a div-by-zero FPE, so we define a special case for zero.
- if(mag == 0)
- return -100;
-
- return 20.0f * log10f(mag);
+ return 20.0f * log10f(mag + 1e-5f);
}
static inline float processfftComp(FFTCompander *comp, unsigned int idx, float logIn)
{
@@ -157,6 +181,751 @@ static inline float processfftComp(FFTCompander *comp, unsigned int idx, float l
multBuf = comp->headRoomdB;
return db2mag2(multBuf);
}
+static inline float processfftCompdB(FFTCompander *comp, unsigned int idx, float logIn)
+{
+ float multBuf = logIn - comp->oldBuf[idx];
+ if (multBuf < 0.0f)
+ multBuf = 0.0f;
+ multBuf *= comp->DREmult[idx];
+ if (multBuf > comp->headRoomdB)
+ multBuf = comp->headRoomdB;
+ return multBuf;
+}
+void getwndDBL(double *wnd, unsigned int m, unsigned int n, char *mode)
+{
+ unsigned int i;
+ double x;
+ if (!strcmp(mode, "hann"))
+ {
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (double)(0.5 - 0.5 * cos(2 * M_PI * x));
+ }
+ }
+ else if (!strcmp(mode, "hamming"))
+ {
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (double)(0.54 - 0.46 * cos(2 * M_PI * x));
+ }
+ }
+ else if (!strcmp(mode, "blackman"))
+ {
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (double)(0.42 - 0.5 * cos(2 * M_PI * x) + 0.08 * cos(4 * M_PI * x));
+ }
+ }
+ else if (!strcmp(mode, "flattop"))
+ {
+ double a0 = 0.21557895;
+ double a1 = 0.41663158;
+ double a2 = 0.277263158;
+ double a3 = 0.083578947;
+ double a4 = 0.006947368;
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (double)(a0 - a1 * cos(2 * M_PI * x) + a2 * cos(4 * M_PI * x) - a3 * cos(6 * M_PI * x) + a4 * cos(8 * M_PI * x));
+ }
+ }
+}
+void genWndDBL(double *wnd, unsigned int N, char *type)
+{
+ unsigned int plus1 = N + 1;
+ unsigned int half;
+ unsigned int i;
+ if (plus1 % 2 == 0)
+ {
+ half = plus1 / 2;
+ getwndDBL(wnd, half, plus1, type);
+ for (i = 0; i < half - 1; i++)
+ wnd[i + half] = wnd[half - i - 1];
+ }
+ else
+ {
+ half = (plus1 + 1) / 2;
+ getwndDBL(wnd, half, plus1, type);
+ for (i = 0; i < half - 2; i++)
+ wnd[i + half] = wnd[half - i - 2];
+ }
+}
+#include "info.h"
+static inline void conjugatePadFilteringDepad(FFTCompander *cm)
+{
+ unsigned int i;
+ for (i = 0; i < cm->prepad; ++i)
+ {
+ cm->specHannReal[0][cm->prepad - i - 1] = cm->specHannReal[0][cm->prepad + i + 1];
+ cm->specHannImag[0][cm->prepad - i - 1] = -cm->specHannImag[0][cm->prepad + i + 1];
+ cm->specHannReal[1][cm->prepad - i - 1] = cm->specHannReal[1][cm->prepad + i + 1];
+ cm->specHannImag[1][cm->prepad - i - 1] = -cm->specHannImag[1][cm->prepad + i + 1];
+ }
+ for (i = 0; i < cm->pospad - 1; ++i)
+ {
+ cm->specHannReal[0][cm->prepad + cm->halfLen + cm->pospad - i - 2] = cm->specHannReal[0][cm->prepad + cm->halfLen - cm->pospad + i];
+ cm->specHannImag[0][cm->prepad + cm->halfLen + cm->pospad - i - 2] = -cm->specHannImag[0][cm->prepad + cm->halfLen - cm->pospad + i];
+ cm->specHannReal[1][cm->prepad + cm->halfLen + cm->pospad - i - 2] = cm->specHannReal[1][cm->prepad + cm->halfLen - cm->pospad + i];
+ cm->specHannImag[1][cm->prepad + cm->halfLen + cm->pospad - i - 2] = -cm->specHannImag[1][cm->prepad + cm->halfLen - cm->pospad + i];
+ }
+ // LTV Gaussian
+ cplx z1[2], z2[2], o[2], st[2];
+ z1[0].real = z1[0].imag = 0;
+ z2[0].real = z2[0].imag = 0;
+ z1[1].real = z1[1].imag = 0;
+ z2[1].real = z2[1].imag = 0;
+ for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; i++)
+ {
+ o[0].real = cm->specHannReal[0][i] - z1[0].real - z2[0].real;
+ o[0].imag = cm->specHannImag[0][i] - z1[0].imag - z2[0].imag;
+ st[0].real = cm->gauss_c2[i] * z1[0].real;
+ st[0].imag = cm->gauss_c2[i] * z1[0].imag;
+ cm->tmp[0][i].real = cm->gauss_b[i] * o[0].real + 2 * st[0].real + z2[0].real;
+ cm->tmp[0][i].imag = cm->gauss_b[i] * o[0].imag + 2 * st[0].imag + z2[0].imag;
+ z2[0].real = z2[0].real + st[0].real;
+ z2[0].imag = z2[0].imag + st[0].imag;
+ z1[0].real = z1[0].real + cm->gauss_c1[i] * o[0].real;
+ z1[0].imag = z1[0].imag + cm->gauss_c1[i] * o[0].imag;
+ o[1].real = cm->specHannReal[1][i] - z1[1].real - z2[1].real;
+ o[1].imag = cm->specHannImag[1][i] - z1[1].imag - z2[1].imag;
+ st[1].real = cm->gauss_c2[i] * z1[1].real;
+ st[1].imag = cm->gauss_c2[i] * z1[1].imag;
+ cm->tmp[1][i].real = cm->gauss_b[i] * o[1].real + 2 * st[1].real + z2[1].real;
+ cm->tmp[1][i].imag = cm->gauss_b[i] * o[1].imag + 2 * st[1].imag + z2[1].imag;
+ z2[1].real = z2[1].real + st[1].real;
+ z2[1].imag = z2[1].imag + st[1].imag;
+ z1[1].real = z1[1].real + cm->gauss_c1[i] * o[1].real;
+ z1[1].imag = z1[1].imag + cm->gauss_c1[i] * o[1].imag;
+ }
+ z1[0].real = z1[0].imag = 0;
+ z2[0].real = z2[0].imag = 0;
+ z1[1].real = z1[1].imag = 0;
+ z2[1].real = z2[1].imag = 0;
+ for (i = cm->prepad + cm->halfLen + cm->pospad - 1; i-- > 0; )
+ {
+ o[0].real = cm->tmp[0][i].real - z1[0].real - z2[0].real;
+ o[0].imag = cm->tmp[0][i].imag - z1[0].imag - z2[0].imag;
+ st[0].real = cm->gauss_c2[i] * z1[0].real;
+ st[0].imag = cm->gauss_c2[i] * z1[0].imag;
+ cm->specHannReal[0][i] = cm->gauss_b[i] * o[0].real + 2 * st[0].real + z2[0].real;
+ cm->specHannImag[0][i] = cm->gauss_b[i] * o[0].imag + 2 * st[0].imag + z2[0].imag;
+ z2[0].real = z2[0].real + st[0].real;
+ z2[0].imag = z2[0].imag + st[0].imag;
+ z1[0].real = z1[0].real + cm->gauss_c1[i] * o[0].real;
+ z1[0].imag = z1[0].imag + cm->gauss_c1[i] * o[0].imag;
+ o[1].real = cm->tmp[1][i].real - z1[1].real - z2[1].real;
+ o[1].imag = cm->tmp[1][i].imag - z1[1].imag - z2[1].imag;
+ st[1].real = cm->gauss_c2[i] * z1[1].real;
+ st[1].imag = cm->gauss_c2[i] * z1[1].imag;
+ cm->specHannReal[1][i] = cm->gauss_b[i] * o[1].real + 2 * st[1].real + z2[1].real;
+ cm->specHannImag[1][i] = cm->gauss_b[i] * o[1].imag + 2 * st[1].imag + z2[1].imag;
+ z2[1].real = z2[1].real + st[1].real;
+ z2[1].imag = z2[1].imag + st[1].imag;
+ z1[1].real = z1[1].real + cm->gauss_c1[i] * o[1].real;
+ z1[1].imag = z1[1].imag + cm->gauss_c1[i] * o[1].imag;
+ }
+ //for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; ++i)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, cm->specHannReal[i], cm->specHannImag[i]);
+ for (i = cm->prepad; i < cm->prepad + cm->halfLen; ++i)
+ {
+ cm->specHannReal[0][i - cm->prepad] = cm->specHannReal[0][i] * cm->corrF[i - cm->prepad];
+ cm->specHannImag[0][i - cm->prepad] = cm->specHannImag[0][i] * cm->corrF[i - cm->prepad];
+ cm->specHannReal[1][i - cm->prepad] = cm->specHannReal[1][i] * cm->corrF[i - cm->prepad];
+ cm->specHannImag[1][i - cm->prepad] = cm->specHannImag[1][i] * cm->corrF[i - cm->prepad];
+ }
+ cm->specHannImag[0][0] = cm->specHannImag[0][cm->halfLen - 1] = 0;
+ cm->specHannImag[1][0] = cm->specHannImag[1][cm->halfLen - 1] = 0;
+}
+FILE *dbg = 0;
+//int ifa = 0;
+void CWTFrameInversion(FFTCompander *cm)
+{
+ //ifa++;
+ unsigned int i, j;
+ // Forward transform
+ for (i = 0; i < cm->fftLen; ++i)
+ {
+ const unsigned int k = (i + cm->mInputPos) & cm->minus_fftLen;
+ //fwrite(&cm->mInput[0][k], sizeof(float), 1, dbg);
+ cm->fftBuf[0][cm->bitrevfftshift[i]] = cm->mInput[0][k];
+ cm->fftBuf[1][cm->bitrevfftshift[i]] = cm->mInput[1][k];
+ }
+ cm->fft(cm->fftBuf[0], cm->mSineTab);
+ cm->fft(cm->fftBuf[1], cm->mSineTab);
+ int symIdx;
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ cm->real[0][i] = cm->fftBuf[0][i] + cm->fftBuf[0][symIdx];
+ cm->imag[0][i] = -(cm->fftBuf[0][i] - cm->fftBuf[0][symIdx]);
+ cm->real[1][i] = cm->fftBuf[1][i] + cm->fftBuf[1][symIdx];
+ cm->imag[1][i] = -(cm->fftBuf[1][i] - cm->fftBuf[1][symIdx]);
+ }
+ cm->real[0][0] = cm->fftBuf[0][0] * 2.0f;
+ cm->imag[0][0] = 0;
+ cm->real[1][0] = cm->fftBuf[1][0] * 2.0f;
+ cm->imag[1][0] = 0;
+ //for (i = 0; i < cm->halfLen; ++i)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, cm->real[i], cm->imag[i]);
+ // Hann windowing
+ cm->specHannReal[0][cm->prepad + 0] = (cm->real[0][0] * 2.0f + cm->real[0][1] + cm->real[0][1]) / 8.0f; // DC
+ cm->specHannImag[0][cm->prepad + 0] = 0.0; // DC
+ cm->specHannReal[1][cm->prepad + 0] = (cm->real[1][0] * 2.0f + cm->real[1][1] + cm->real[1][1]) / 8.0f; // DC
+ cm->specHannImag[1][cm->prepad + 0] = 0.0; // DC
+ for (i = 1; i < cm->halfLen - 1; i++)
+ {
+ cm->specHannReal[0][cm->prepad + i] = (cm->real[0][i] * 2.0f + cm->real[0][i - 1] + cm->real[0][i + 1]) / 8.0f;
+ cm->specHannImag[0][cm->prepad + i] = (cm->imag[0][i] * 2.0f + cm->imag[0][i - 1] + cm->imag[0][i + 1]) / 8.0f;
+ cm->specHannReal[1][cm->prepad + i] = (cm->real[1][i] * 2.0f + cm->real[1][i - 1] + cm->real[1][i + 1]) / 8.0f;
+ cm->specHannImag[1][cm->prepad + i] = (cm->imag[1][i] * 2.0f + cm->imag[1][i - 1] + cm->imag[1][i + 1]) / 8.0f;
+ }
+ cm->specHannReal[0][cm->prepad + cm->halfLen - 1] = (cm->real[0][cm->halfLen - 1] * 2.0f + cm->real[0][cm->halfLen - 2] + cm->real[0][cm->halfLen - 2]) / 8.0f; // Nyquist
+ cm->specHannImag[0][cm->prepad + cm->halfLen - 1] = 0.0f;
+ cm->specHannReal[1][cm->prepad + cm->halfLen - 1] = (cm->real[1][cm->halfLen - 1] * 2.0f + cm->real[1][cm->halfLen - 2] + cm->real[1][cm->halfLen - 2]) / 8.0f; // Nyquist
+ cm->specHannImag[1][cm->prepad + cm->halfLen - 1] = 0.0f;
+ conjugatePadFilteringDepad(cm);
+ // Spectral analysis
+ float leftMag, rightMag, mask;
+ //idxFrame++;
+ unsigned int specLen = *((unsigned int *)(cm->octaveSmooth));
+ float reciprocal = *((float *)(cm->octaveSmooth + sizeof(unsigned int)));
+ unsigned int lpLen = *((unsigned int *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float)));
+ float *lv1 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float));
+ float *lv2 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float) + (lpLen + 3) * sizeof(float));
+ if (!cm->noGridDownsampling)
+ {
+ for (i = 0; i < cm->procUpTo; i++)
+ {
+ float lR = cm->specHannReal[0][i];
+ float lI = cm->specHannImag[0][i];
+ float rR = cm->specHannReal[1][i];
+ float rI = cm->specHannImag[1][i];
+ float absV1 = fabsf(lR);
+ float absV2 = fabsf(lI);
+ leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ absV1 = fabsf(rR);
+ absV2 = fabsf(rI);
+ rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ cm->mag[i] = (leftMag + rightMag) * 0.5f;
+ }
+ ShrinkGridSpectralInterpolator(cm->octaveSmooth, cm->procUpTo, cm->mag, cm->aheight);
+ for (i = 0; i < cm->smallGridSize; i++)
+ {
+ float magNormalized = mag2db(cm->aheight[i]);
+ cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
+ // Log conversion
+ float mask = processfftComp(cm, i, magNormalized);
+ cm->finalGain[i] = mask;
+ }
+ for (i = 0; i < cm->procUpTo; i++)
+ {
+ float val = i * reciprocal;
+ if (val <= lv1[0])
+ mask = cm->finalGain[0];
+ else if (val >= lv1[lpLen + 3 - 1])
+ mask = cm->finalGain[lpLen + 3 - 1];
+ else
+ {
+ size_t j = fast_upper_bound4(lv1, lpLen + 3, &val);
+ mask = ((val - lv1[j - 1]) * lv2[j - 1]) * (cm->finalGain[j] - cm->finalGain[j - 1]) + cm->finalGain[j - 1];
+ }
+ cm->specHannReal[0][i] = cm->specHannReal[0][i] * mask;
+ cm->specHannImag[0][i] = cm->specHannImag[0][i] * mask;
+ cm->specHannReal[1][i] = cm->specHannReal[1][i] * mask;
+ cm->specHannImag[1][i] = cm->specHannImag[1][i] * mask;
+ }
+ //printf("\n");
+ }
+ else
+ {
+ for (i = 0; i < cm->procUpTo; i++)
+ {
+ float lR = cm->specHannReal[0][i];
+ float lI = cm->specHannImag[0][i];
+ float rR = cm->specHannReal[1][i];
+ float rI = cm->specHannImag[1][i];
+ float absV1 = fabsf(lR);
+ float absV2 = fabsf(lI);
+ leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ absV1 = fabsf(rR);
+ absV2 = fabsf(rI);
+ rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ float magNormalized = mag2db((leftMag + rightMag) * 0.5f);
+ cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
+ // Log conversion
+ mask = processfftComp(cm, i, magNormalized);
+ cm->specHannReal[0][i] = cm->specHannReal[0][i] * mask;
+ cm->specHannImag[0][i] = cm->specHannImag[0][i] * mask;
+ cm->specHannReal[1][i] = cm->specHannReal[1][i] * mask;
+ cm->specHannImag[1][i] = cm->specHannImag[1][i] * mask;
+ }
+ }
+ cm->imag[0][0] = cm->imag[1][0] = 0;
+ //for (i = 0; i < cm->halfLen; ++i)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, cm->specHannReal[i], cm->specHannImag[i]);
+ //fwrite(cm->specHannReal[1], sizeof(float), cm->halfLen, dbg);
+ //fwrite(cm->specHannImag[1], sizeof(float), cm->halfLen, dbg);
+ // Inverse transform
+ cm->real[0][0] = (cm->specHannReal[0][0] * 2.0f + cm->specHannReal[0][1] + cm->specHannReal[0][1]) / 4.0f; // DC
+ cm->imag[0][0] = 0.0; // DC
+ cm->real[1][0] = (cm->specHannReal[1][0] * 2.0f + cm->specHannReal[1][1] + cm->specHannReal[1][1]) / 4.0f; // DC
+ cm->imag[1][0] = 0.0; // DC
+ for (i = 1; i < cm->halfLen - 1; i++)
+ {
+ cm->real[0][i] = (cm->specHannReal[0][i] * 2.0f + cm->specHannReal[0][i - 1] + cm->specHannReal[0][i + 1]) / 4.0f;
+ cm->imag[0][i] = (cm->specHannImag[0][i] * 2.0f + cm->specHannImag[0][i - 1] + cm->specHannImag[0][i + 1]) / 4.0f;
+ cm->real[1][i] = (cm->specHannReal[1][i] * 2.0f + cm->specHannReal[1][i - 1] + cm->specHannReal[1][i + 1]) / 4.0f;
+ cm->imag[1][i] = (cm->specHannImag[1][i] * 2.0f + cm->specHannImag[1][i - 1] + cm->specHannImag[1][i + 1]) / 4.0f;
+ }
+ cm->real[0][cm->halfLen - 1] = (cm->specHannReal[0][cm->halfLen - 1] * 2.0f + cm->specHannReal[0][cm->halfLen - 2] + cm->specHannReal[0][cm->halfLen - 2]) / 4.0f; // Nyquist
+ cm->imag[0][cm->halfLen - 1] = 0.0;
+ cm->real[1][cm->halfLen - 1] = (cm->specHannReal[1][cm->halfLen - 1] * 2.0f + cm->specHannReal[1][cm->halfLen - 2] + cm->specHannReal[1][cm->halfLen - 2]) / 4.0f; // Nyquist
+ cm->imag[1][cm->halfLen - 1] = 0.0;
+ cm->fftBuf[0][0] = cm->real[0][0];
+ cm->fftBuf[1][0] = cm->real[1][0];
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ unsigned int bitRevFwd = cm->mBitRev[i];
+ unsigned int bitRevSym = cm->mBitRev[symIdx];
+ cm->fftBuf[0][bitRevFwd] = cm->real[0][i] + (-cm->imag[0][i]);
+ cm->fftBuf[0][bitRevSym] = cm->real[0][i] - (-cm->imag[0][i]);
+ cm->fftBuf[1][bitRevFwd] = cm->real[1][i] + (-cm->imag[1][i]);
+ cm->fftBuf[1][bitRevSym] = cm->real[1][i] - (-cm->imag[1][i]);
+ }
+ //for (i = 0; i < cm->halfLen; ++i)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, cm->real[i], cm->imag[i]);
+ cm->fft(cm->fftBuf[0], cm->mSineTab);
+ cm->fft(cm->fftBuf[1], cm->mSineTab);
+ for (i = 0; i < cm->fftLen; ++i)
+ {
+ cm->getbackCorrectedToSpectrum1[0][cm->mBitRev[i]] = cm->fftBuf[0][i] * prec_correctionWnd[i];
+ cm->getbackCorrectedToSpectrum1[1][cm->mBitRev[i]] = cm->fftBuf[1][i] * prec_correctionWnd[i];
+ }
+ cm->fft(cm->getbackCorrectedToSpectrum1[0], cm->mSineTab);
+ cm->fft(cm->getbackCorrectedToSpectrum1[1], cm->mSineTab);
+ float getbackCorrectedToSpectrum1Re1 = cm->getbackCorrectedToSpectrum1[0][0] / cm->fftLen;
+ cm->specHannReal[0][cm->prepad + 0] = cm->real[0][0] * prec_wndCorrectionWeightingLF[0] + getbackCorrectedToSpectrum1Re1 * prec_wndCorrectionWeightingHF[0];
+ cm->specHannImag[0][cm->prepad + 0] = 0;
+ float getbackCorrectedToSpectrum1Re2 = cm->getbackCorrectedToSpectrum1[1][0] / cm->fftLen;
+ cm->specHannReal[1][cm->prepad + 0] = cm->real[1][0] * prec_wndCorrectionWeightingLF[0] + getbackCorrectedToSpectrum1Re2 * prec_wndCorrectionWeightingHF[0];
+ cm->specHannImag[1][cm->prepad + 0] = 0;
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ getbackCorrectedToSpectrum1Re1 = (cm->getbackCorrectedToSpectrum1[0][i] + cm->getbackCorrectedToSpectrum1[0][symIdx]) * cm->scalarGain;
+ float getbackCorrectedToSpectrum1Im1 = (-(cm->getbackCorrectedToSpectrum1[0][i] - cm->getbackCorrectedToSpectrum1[0][symIdx])) * cm->scalarGain;
+ cm->specHannReal[0][cm->prepad + i] = cm->real[0][i] * prec_wndCorrectionWeightingLF[i] + getbackCorrectedToSpectrum1Re1 * prec_wndCorrectionWeightingHF[i];
+ cm->specHannImag[0][cm->prepad + i] = cm->imag[0][i] * prec_wndCorrectionWeightingLF[i] + getbackCorrectedToSpectrum1Im1 * prec_wndCorrectionWeightingHF[i];
+ getbackCorrectedToSpectrum1Re2 = (cm->getbackCorrectedToSpectrum1[1][i] + cm->getbackCorrectedToSpectrum1[1][symIdx]) * cm->scalarGain;
+ float getbackCorrectedToSpectrum1Im2 = (-(cm->getbackCorrectedToSpectrum1[1][i] - cm->getbackCorrectedToSpectrum1[1][symIdx])) * cm->scalarGain;
+ cm->specHannReal[1][cm->prepad + i] = cm->real[1][i] * prec_wndCorrectionWeightingLF[i] + getbackCorrectedToSpectrum1Re2 * prec_wndCorrectionWeightingHF[i];
+ cm->specHannImag[1][cm->prepad + i] = cm->imag[1][i] * prec_wndCorrectionWeightingLF[i] + getbackCorrectedToSpectrum1Im2 * prec_wndCorrectionWeightingHF[i];
+ //printf("%d %1.14lf %1.14lf\n", i + 1, re, im);
+ }
+ // Conjugate pad
+ for (i = 0; i < cm->prepad; ++i)
+ {
+ cm->specHannReal[0][cm->prepad - i - 1] = cm->specHannReal[0][cm->prepad + i + 1];
+ cm->specHannImag[0][cm->prepad - i - 1] = -cm->specHannImag[0][cm->prepad + i + 1];
+ cm->specHannReal[1][cm->prepad - i - 1] = cm->specHannReal[1][cm->prepad + i + 1];
+ cm->specHannImag[1][cm->prepad - i - 1] = -cm->specHannImag[1][cm->prepad + i + 1];
+ }
+ for (i = 0; i < cm->pospad - 1; ++i)
+ {
+ cm->specHannReal[0][cm->prepad + cm->halfLen + cm->pospad - i - 2] = cm->specHannReal[0][cm->prepad + cm->halfLen - cm->pospad + i];
+ cm->specHannImag[0][cm->prepad + cm->halfLen + cm->pospad - i - 2] = -cm->specHannImag[0][cm->prepad + cm->halfLen - cm->pospad + i];
+ cm->specHannReal[1][cm->prepad + cm->halfLen + cm->pospad - i - 2] = cm->specHannReal[1][cm->prepad + cm->halfLen - cm->pospad + i];
+ cm->specHannImag[1][cm->prepad + cm->halfLen + cm->pospad - i - 2] = -cm->specHannImag[1][cm->prepad + cm->halfLen - cm->pospad + i];
+ }
+ //for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; i++)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, cm->specHannReal[i], cm->specHannImag[i]);
+ unsigned int ptrAcc = 0;
+ for (i = 0; i < cm->halfLen; i++)
+ {
+ unsigned int numMultiplications = prec_mtxStrides[i];
+ float sumRe[2] = { 0 };
+ float sumIm[2] = { 0 };
+ for (j = 0; j < numMultiplications; j++)
+ {
+ unsigned int readIdx = ptrAcc + j;
+ sumRe[0] += cm->specHannReal[0][prec_mtxElementPos[readIdx]] * (float)prec_correctionMatrix[readIdx];
+ sumIm[0] += cm->specHannImag[0][prec_mtxElementPos[readIdx]] * (float)prec_correctionMatrix[readIdx];
+ sumRe[1] += cm->specHannReal[1][prec_mtxElementPos[readIdx]] * (float)prec_correctionMatrix[readIdx];
+ sumIm[1] += cm->specHannImag[1][prec_mtxElementPos[readIdx]] * (float)prec_correctionMatrix[readIdx];
+ //printf("%d, ", readIdx);
+ }
+ cm->real[0][i] = sumRe[0];
+ cm->imag[0][i] = sumIm[0];
+ cm->real[1][i] = sumRe[1];
+ cm->imag[1][i] = sumIm[1];
+ ptrAcc += numMultiplications;
+ }
+ cm->fftBuf[0][0] = cm->real[0][0] / cm->fftLen;
+ cm->fftBuf[1][0] = cm->real[1][0] / cm->fftLen;
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ unsigned int bitRevFwd = cm->mBitRev[i];
+ unsigned int bitRevSym = cm->mBitRev[symIdx];
+ cm->fftBuf[0][bitRevFwd] = (cm->real[0][i] + (-cm->imag[0][i])) / cm->fftLen;
+ cm->fftBuf[0][bitRevSym] = (cm->real[0][i] - (-cm->imag[0][i])) / cm->fftLen;
+ cm->fftBuf[1][bitRevFwd] = (cm->real[1][i] + (-cm->imag[1][i])) / cm->fftLen;
+ cm->fftBuf[1][bitRevSym] = (cm->real[1][i] - (-cm->imag[1][i])) / cm->fftLen;
+ }
+ cm->fft(cm->fftBuf[0], cm->mSineTab);
+ cm->fft(cm->fftBuf[1], cm->mSineTab);
+ //fwrite(cm->fftBuf, sizeof(float), cm->fftLen, dbg);
+ cm->mOutputBufferCount++;
+ float *outBuffer = cm->mOutputBuffer[cm->mOutputBufferCount - 1];
+ unsigned int currentBlockIndex, nextBlockIndex, blockOffset;
+ for (i = 0; i < cm->ovpLen; ++i)
+ {
+ outBuffer[0] = cm->mOverlapStage2dash[0][0][i] + cm->fftBuf[0][i];
+ outBuffer[1] = cm->mOverlapStage2dash[1][0][i] + cm->fftBuf[1][i];
+ outBuffer += 2;
+ // overlapping
+ currentBlockIndex = 0;
+ nextBlockIndex = 1;
+ blockOffset = cm->ovpLen;
+ while (nextBlockIndex < cm->ovpCount - 1) {
+ cm->mOverlapStage2dash[0][currentBlockIndex][i] = cm->mOverlapStage2dash[0][nextBlockIndex][i] + cm->fftBuf[0][blockOffset + i];
+ cm->mOverlapStage2dash[1][currentBlockIndex][i] = cm->mOverlapStage2dash[1][nextBlockIndex][i] + cm->fftBuf[1][blockOffset + i];
+ currentBlockIndex++;
+ nextBlockIndex++;
+ blockOffset += cm->ovpLen;
+ }
+ cm->mOverlapStage2dash[0][currentBlockIndex][i] = cm->fftBuf[0][blockOffset + i];
+ cm->mOverlapStage2dash[1][currentBlockIndex][i] = cm->fftBuf[1][blockOffset + i];
+ }
+ cm->mInputSamplesNeeded = cm->ovpLen;
+}
+void CWTFrameSTFTInversion(FFTCompander *cm)
+{
+ //ifa++;
+ unsigned int i, j;
+ // Forward transform
+ for (i = 0; i < cm->fftLen; ++i)
+ {
+ const unsigned int k = (i + cm->mInputPos) & cm->minus_fftLen;
+ cm->fftBuf[0][cm->bitrevfftshift[i]] = cm->mInput[0][k] * cm->analysisWnd[i];
+ cm->fftBuf[1][cm->bitrevfftshift[i]] = cm->mInput[1][k] * cm->analysisWnd[i];
+ }
+ cm->fft(cm->fftBuf[0], cm->mSineTab);
+ cm->fft(cm->fftBuf[1], cm->mSineTab);
+ int symIdx;
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ cm->real[0][i] = cm->fftBuf[0][i] + cm->fftBuf[0][symIdx];
+ cm->imag[0][i] = -(cm->fftBuf[0][i] - cm->fftBuf[0][symIdx]);
+ cm->real[1][i] = cm->fftBuf[1][i] + cm->fftBuf[1][symIdx];
+ cm->imag[1][i] = -(cm->fftBuf[1][i] - cm->fftBuf[1][symIdx]);
+ }
+ cm->real[0][0] = cm->fftBuf[0][0] * 2.0f;
+ cm->imag[0][0] = 0;
+ cm->real[1][0] = cm->fftBuf[1][0] * 2.0f;
+ cm->imag[1][0] = 0;
+ //for (i = 0; i < cm->halfLen; ++i)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, cm->real[i], cm->imag[i]);
+ // Hann windowing
+ memcpy(cm->specHannReal[0] + cm->prepad, cm->real[0], cm->halfLen * sizeof(float));
+ memcpy(cm->specHannImag[0] + cm->prepad, cm->imag[0], cm->halfLen * sizeof(float));
+ memcpy(cm->specHannReal[1] + cm->prepad, cm->real[1], cm->halfLen * sizeof(float));
+ memcpy(cm->specHannImag[1] + cm->prepad, cm->imag[1], cm->halfLen * sizeof(float));
+ conjugatePadFilteringDepad(cm);
+ //fwrite(cm->specHannReal[1], sizeof(float), cm->halfLen, dbg);
+ //fwrite(cm->specHannImag[1], sizeof(float), cm->halfLen, dbg);
+
+
+ // Spectral analysis
+ float leftMag, rightMag, mask;
+ unsigned int bitRevFwd, bitRevSym;
+ //idxFrame++;
+ unsigned int specLen = *((unsigned int *)(cm->octaveSmooth));
+ float reciprocal = *((float *)(cm->octaveSmooth + sizeof(unsigned int)));
+ unsigned int lpLen = *((unsigned int *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float)));
+ float *lv1 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float));
+ float *lv2 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float) + (lpLen + 3) * sizeof(float));
+ if (!cm->noGridDownsampling)
+ {
+ for (i = 0; i < cm->procUpTo; i++)
+ {
+ float lR = cm->specHannReal[0][i];
+ float lI = cm->specHannImag[0][i];
+ float rR = cm->specHannReal[1][i];
+ float rI = cm->specHannImag[1][i];
+ float absV1 = fabsf(lR);
+ float absV2 = fabsf(lI);
+ leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ absV1 = fabsf(rR);
+ absV2 = fabsf(rI);
+ rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ cm->mag[i] = (leftMag + rightMag) * 0.5f;
+ }
+ ShrinkGridSpectralInterpolator(cm->octaveSmooth, cm->procUpTo, cm->mag, cm->aheight);
+ for (i = 0; i < cm->smallGridSize; i++)
+ {
+ float magNormalized = mag2db(cm->aheight[i]);
+ cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
+ // Log conversion
+ float mask = processfftComp(cm, i, magNormalized);
+ cm->finalGain[i] = mask;
+ }
+ for (i = 0; i < cm->procUpTo; i++)
+ {
+ float val = i * reciprocal;
+ if (val <= lv1[0])
+ mask = cm->finalGain[0];
+ else if (val >= lv1[lpLen + 3 - 1])
+ mask = cm->finalGain[lpLen + 3 - 1];
+ else
+ {
+ size_t j = fast_upper_bound4(lv1, lpLen + 3, &val);
+ mask = ((val - lv1[j - 1]) * lv2[j - 1]) * (cm->finalGain[j] - cm->finalGain[j - 1]) + cm->finalGain[j - 1];
+ }
+ cm->real[0][i] = cm->real[0][i] * mask;
+ cm->imag[0][i] = cm->imag[0][i] * mask;
+ cm->real[1][i] = cm->real[1][i] * mask;
+ cm->imag[1][i] = cm->imag[1][i] * mask;
+ }
+ //printf("\n");
+ }
+ else
+ {
+ for (i = 0; i < cm->procUpTo; i++)
+ {
+ float lR = cm->specHannReal[0][i];
+ float lI = cm->specHannImag[0][i];
+ float rR = cm->specHannReal[1][i];
+ float rI = cm->specHannImag[1][i];
+ float absV1 = fabsf(lR);
+ float absV2 = fabsf(lI);
+ leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ absV1 = fabsf(rR);
+ absV2 = fabsf(rI);
+ rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ float magNormalized = mag2db((leftMag + rightMag) * 0.5f);
+ cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
+ // Log conversion
+ mask = processfftComp(cm, i, magNormalized);
+ cm->real[0][i] = cm->real[0][i] * mask;
+ cm->imag[0][i] = cm->imag[0][i] * mask;
+ cm->real[1][i] = cm->real[1][i] * mask;
+ cm->imag[1][i] = cm->imag[1][i] * mask;
+ }
+ }
+ cm->imag[0][0] = cm->imag[1][0] = 0;
+
+ cm->fftBuf[0][0] = cm->real[0][0];
+ cm->fftBuf[1][0] = cm->real[1][0];
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ unsigned int bitRevFwd = cm->mBitRev[i];
+ unsigned int bitRevSym = cm->mBitRev[symIdx];
+ cm->fftBuf[0][bitRevFwd] = (cm->real[0][i] + (-cm->imag[0][i])) * cm->shiftCentre[i];
+ cm->fftBuf[0][bitRevSym] = (cm->real[0][i] - (-cm->imag[0][i])) * cm->shiftCentre[i];
+ cm->fftBuf[1][bitRevFwd] = (cm->real[1][i] + (-cm->imag[1][i])) * cm->shiftCentre[i];
+ cm->fftBuf[1][bitRevSym] = (cm->real[1][i] - (-cm->imag[1][i])) * cm->shiftCentre[i];
+ }
+ cm->fft(cm->fftBuf[0], cm->mSineTab);
+ cm->fft(cm->fftBuf[1], cm->mSineTab);
+ for (i = 0; i < cm->ovpLen * 2; i++)
+ {
+ cm->fftBuf[0][i] = cm->fftBuf[0][i + (cm->fftLen / 2 - cm->ovpLen)] * cm->synthesisWnd[i];
+ cm->fftBuf[1][i] = cm->fftBuf[1][i + (cm->fftLen / 2 - cm->ovpLen)] * cm->synthesisWnd[i];
+ }
+ //fwrite(cm->fftBuf, sizeof(float), cm->ovpLen * 2, dbg);
+ cm->mOutputBufferCount++;
+ float *outBuffer = cm->mOutputBuffer[cm->mOutputBufferCount - 1];
+ for (i = 0; i < cm->ovpLen; ++i)
+ {
+ outBuffer[0] = cm->mOverlapStage2dash[0][0][i] + cm->fftBuf[0][i];
+ outBuffer[1] = cm->mOverlapStage2dash[1][0][i] + cm->fftBuf[1][i];
+ outBuffer += 2;
+ // overlapping
+ cm->mOverlapStage2dash[0][0][i] = cm->fftBuf[0][cm->ovpLen + i];
+ cm->mOverlapStage2dash[1][0][i] = cm->fftBuf[1][cm->ovpLen + i];
+ }
+ cm->mInputSamplesNeeded = cm->ovpLen;
+}
+static inline double fnc1(double x)
+{
+ return ((606.0 * x * x) / 1087.0 - (3009.0 * x) / 5513.0 + 712.0 / 5411.0) / (x * x - (496.0 * x) / 541.0 + 719.0 / 1034.0);
+}
+double complexMultiplicationConj(double xReal, double xImag, double yReal, double yImag)
+{
+ return xReal * yReal - xImag * yImag;
+}
+void regularSTFT(FFTCompander *cm)
+{
+ unsigned int i;
+ // copy to temporary buffer and FHT
+ for (i = 0; i < cm->fftLen; ++i)
+ {
+ const unsigned int k = (i + cm->mInputPos) & cm->minus_fftLen;
+ const float w = cm->analysisWnd[i];
+ cm->mTempLBuffer[cm->mBitRev[i]] = (cm->mInput[0][k] * w);
+ cm->mTempRBuffer[cm->mBitRev[i]] = (cm->mInput[1][k] * w);
+ }
+ cm->fft(cm->mTempLBuffer, cm->mSineTab);
+ cm->fft(cm->mTempRBuffer, cm->mSineTab);
+ // Spectral analysis
+ int symIdx;
+ float lR = cm->mTempLBuffer[0] * 2.0f;
+ float rR = cm->mTempRBuffer[0] * 2.0f;
+ float leftMag, rightMag, mask;
+ cm->timeDomainOut[0][0] = lR;
+ cm->timeDomainOut[1][0] = rR;
+ unsigned int bitRevFwd, bitRevSym;
+ //idxFrame++;
+ unsigned int specLen = *((unsigned int *)(cm->octaveSmooth));
+ float reciprocal = *((float *)(cm->octaveSmooth + sizeof(unsigned int)));
+ unsigned int lpLen = *((unsigned int *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float)));
+ float *lv1 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float));
+ float *lv2 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float) + (lpLen + 3) * sizeof(float));
+ if (!cm->noGridDownsampling)
+ {
+ leftMag = fabsf(lR);
+ rightMag = fabsf(rR);
+ cm->mag[0] = (leftMag + rightMag) * 0.5f;
+ for (i = 1; i < cm->procUpTo; i++)
+ {
+ symIdx = cm->fftLen - i;
+ bitRevFwd = cm->mBitRev[i];
+ bitRevSym = cm->mBitRev[symIdx];
+ lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
+ float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
+ rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
+ float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
+ float absV1 = fabsf(lR);
+ float absV2 = fabsf(lI);
+ leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ absV1 = fabsf(rR);
+ absV2 = fabsf(rI);
+ rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ cm->mag[i] = (leftMag + rightMag) * 0.5f;
+ }
+ ShrinkGridSpectralInterpolator(cm->octaveSmooth, cm->procUpTo, cm->mag, cm->aheight);
+ for (i = 0; i < cm->smallGridSize; i++)
+ {
+ float magNormalized = mag2db(cm->aheight[i]);
+ cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
+ // Log conversion
+ float mask = processfftComp(cm, i, magNormalized);
+ cm->finalGain[i] = mask;
+ }
+ for (i = 1; i < cm->procUpTo; i++)
+ {
+ symIdx = cm->fftLen - i;
+ bitRevFwd = cm->mBitRev[i];
+ bitRevSym = cm->mBitRev[symIdx];
+ float val = i * reciprocal;
+ if (val <= lv1[0])
+ mask = cm->finalGain[0];
+ else if (val >= lv1[lpLen + 3 - 1])
+ mask = cm->finalGain[lpLen + 3 - 1];
+ else
+ {
+ size_t j = fast_upper_bound4(lv1, lpLen + 3, &val);
+ mask = ((val - lv1[j - 1]) * lv2[j - 1]) * (cm->finalGain[j] - cm->finalGain[j - 1]) + cm->finalGain[j - 1];
+ }
+ lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
+ float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
+ rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
+ float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
+ cm->timeDomainOut[0][bitRevFwd] = (lR + lI) * mask;
+ cm->timeDomainOut[0][bitRevSym] = (lR - lI) * mask;
+ cm->timeDomainOut[1][bitRevFwd] = (rR + rI) * mask;
+ cm->timeDomainOut[1][bitRevSym] = (rR - rI) * mask;
+ }
+ //printf("\n");
+ }
+ else
+ {
+ leftMag = fabsf(cm->mTempLBuffer[0]);
+ rightMag = fabsf(cm->mTempRBuffer[0]);
+ float magNormalized = mag2db((leftMag + rightMag) * 0.5f);
+ cm->oldBuf[0] = cm->oldBuf[0] + cm->fgt_fac * (magNormalized - cm->oldBuf[0]);
+ // Log conversion
+ float mask = processfftComp(cm, 0, magNormalized);
+ cm->timeDomainOut[0][0] = cm->mTempLBuffer[0] * mask;
+ cm->timeDomainOut[1][0] = cm->mTempRBuffer[0] * mask;
+ for (i = 1; i < cm->procUpTo; i++)
+ {
+ symIdx = cm->fftLen - i;
+ bitRevFwd = cm->mBitRev[i];
+ bitRevSym = cm->mBitRev[symIdx];
+ lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
+ float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
+ rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
+ float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
+ float absV1 = fabsf(lR);
+ float absV2 = fabsf(lI);
+ leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ absV1 = fabsf(rR);
+ absV2 = fabsf(rI);
+ rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
+ magNormalized = mag2db((leftMag + rightMag) * 0.5f);
+ cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
+ // Log conversion
+ mask = processfftComp(cm, i, magNormalized);
+ cm->timeDomainOut[0][bitRevFwd] = (lR + lI) * mask;
+ cm->timeDomainOut[0][bitRevSym] = (lR - lI) * mask;
+ cm->timeDomainOut[1][bitRevFwd] = (rR + rI) * mask;
+ cm->timeDomainOut[1][bitRevSym] = (rR - rI) * mask;
+ }
+ }
+ for (i = cm->procUpTo; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ bitRevFwd = cm->mBitRev[i];
+ bitRevSym = cm->mBitRev[symIdx];
+ lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
+ float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
+ rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
+ float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
+ cm->timeDomainOut[0][bitRevFwd] = lR + lI;
+ cm->timeDomainOut[0][bitRevSym] = lR - lI;
+ cm->timeDomainOut[1][bitRevFwd] = rR + rI;
+ cm->timeDomainOut[1][bitRevSym] = rR - rI;
+ }
+ // reconstitute left/right channels
+ cm->fft(cm->timeDomainOut[0], cm->mSineTab);
+ cm->fft(cm->timeDomainOut[1], cm->mSineTab);
+ for (i = 0; i < cm->fftLen; i++)
+ {
+ cm->timeDomainOut[0][i] = cm->timeDomainOut[0][i] * cm->synthesisWnd[i];
+ cm->timeDomainOut[1][i] = cm->timeDomainOut[1][i] * cm->synthesisWnd[i];
+ }
+ cm->mOutputBufferCount++;
+ float *outBuffer = cm->mOutputBuffer[cm->mOutputBufferCount - 1];
+ unsigned int currentBlockIndex, nextBlockIndex, blockOffset;
+ for (i = 0; i < cm->ovpLen; ++i)
+ {
+ outBuffer[0] = cm->mOverlapStage2dash[0][0][i] + cm->timeDomainOut[0][i];
+ outBuffer[1] = cm->mOverlapStage2dash[1][0][i] + cm->timeDomainOut[1][i];
+ outBuffer += 2;
+ // overlapping
+ currentBlockIndex = 0;
+ nextBlockIndex = 1;
+ blockOffset = cm->ovpLen;
+ while (nextBlockIndex < cm->ovpCount - 1) {
+ cm->mOverlapStage2dash[0][currentBlockIndex][i] = cm->mOverlapStage2dash[0][nextBlockIndex][i] + cm->timeDomainOut[0][blockOffset + i];
+ cm->mOverlapStage2dash[1][currentBlockIndex][i] = cm->mOverlapStage2dash[1][nextBlockIndex][i] + cm->timeDomainOut[1][blockOffset + i];
+ currentBlockIndex++;
+ nextBlockIndex++;
+ blockOffset += cm->ovpLen;
+ }
+ cm->mOverlapStage2dash[0][currentBlockIndex][i] = cm->timeDomainOut[0][blockOffset + i];
+ cm->mOverlapStage2dash[1][currentBlockIndex][i] = cm->timeDomainOut[1][blockOffset + i];
+ }
+ cm->mInputSamplesNeeded = cm->ovpLen;
+}
int FFTCompanderProcessSamples(FFTCompander *cm, const float *inLeft, const float *inRight, unsigned int inSampleCount, float *outL, float *outR)
{
unsigned int outSampleCount, maxOutSampleCount, copyCount;
@@ -181,159 +950,7 @@ int FFTCompanderProcessSamples(FFTCompander *cm, const float *inLeft, const floa
cm->mInputPos = (cm->mInputPos + copyCount) & cm->minus_fftLen;
cm->mInputSamplesNeeded -= copyCount;
if (cm->mInputSamplesNeeded == 0)
- {
- unsigned int i;
- // copy to temporary buffer and FHT
- for (i = 0; i < cm->fftLen; ++i)
- {
- const unsigned int k = (i + cm->mInputPos) & cm->minus_fftLen;
- const float w = cm->analysisWnd[i];
- cm->mTempLBuffer[cm->mBitRev[i]] = (cm->mInput[0][k] * w);
- cm->mTempRBuffer[cm->mBitRev[i]] = (cm->mInput[1][k] * w);
- }
- cm->fft(cm->mTempLBuffer, cm->mSineTab);
- cm->fft(cm->mTempRBuffer, cm->mSineTab);
- // Spectral analysis
- int symIdx;
- float lR = cm->mTempLBuffer[0] * 2.0f;
- float rR = cm->mTempRBuffer[0] * 2.0f;
- float leftMag, rightMag, currentMagnitude, mask;
- cm->timeDomainOut[0][0] = lR;
- cm->timeDomainOut[1][0] = rR;
- unsigned int bitRevFwd, bitRevSym;
- //idxFrame++;
- unsigned int specLen = *((unsigned int*)(cm->octaveSmooth));
- float reciprocal = *((float*)(cm->octaveSmooth + sizeof(unsigned int)));
- unsigned int lpLen = *((unsigned int*)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float)));
- float *lv1 = (float*)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float));
- float *lv2 = (float*)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float) + (lpLen + 3) * sizeof(float));
- if (!cm->noGridDownsampling)
- {
- leftMag = fabsf(lR);
- rightMag = fabsf(rR);
- cm->mag[0] = leftMag > rightMag ? leftMag : rightMag;
- for (i = 1; i < cm->procUpTo; i++)
- {
- symIdx = cm->fftLen - i;
- bitRevFwd = cm->mBitRev[i];
- bitRevSym = cm->mBitRev[symIdx];
- lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
- float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
- rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
- float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
- float absV1 = fabsf(lR);
- float absV2 = fabsf(lI);
- leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
- absV1 = fabsf(rR);
- absV2 = fabsf(rI);
- rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
- currentMagnitude = leftMag > rightMag ? leftMag : rightMag;
- cm->mag[i] = currentMagnitude;
- }
- ShrinkGridSpectralInterpolator(cm->octaveSmooth, cm->procUpTo, cm->mag, cm->aheight);
- for (i = 0; i < cm->smallGridSize; i++)
- {
- float magNormalized = mag2db(cm->aheight[i]);
- cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
- // Log conversion
- float mask = processfftComp(cm, i, magNormalized);
- cm->finalGain[i] = mask;
- }
- for (i = 1; i < cm->procUpTo; i++)
- {
- symIdx = cm->fftLen - i;
- bitRevFwd = cm->mBitRev[i];
- bitRevSym = cm->mBitRev[symIdx];
- float val = i * reciprocal;
- if (val <= lv1[0])
- mask = cm->finalGain[0];
- else if (val >= lv1[lpLen + 3 - 1])
- mask = cm->finalGain[lpLen + 3 - 1];
- else
- {
- size_t j = fast_upper_bound4(lv1, lpLen + 3, &val);
- mask = ((val - lv1[j - 1]) * lv2[j - 1]) * (cm->finalGain[j] - cm->finalGain[j - 1]) + cm->finalGain[j - 1];
- }
- lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
- float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
- rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
- float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
- cm->timeDomainOut[0][bitRevFwd] = (lR + lI) * mask;
- cm->timeDomainOut[0][bitRevSym] = (lR - lI) * mask;
- cm->timeDomainOut[1][bitRevFwd] = (rR + rI) * mask;
- cm->timeDomainOut[1][bitRevSym] = (rR - rI) * mask;
- }
- //printf("\n");
- }
- else
- {
- leftMag = fabsf(cm->mTempLBuffer[0]);
- rightMag = fabsf(cm->mTempRBuffer[0]);
- currentMagnitude = leftMag > rightMag ? leftMag : rightMag;
- float magNormalized = mag2db(currentMagnitude);
- cm->oldBuf[0] = cm->oldBuf[0] + cm->fgt_fac * (magNormalized - cm->oldBuf[0]);
- // Log conversion
- float mask = processfftComp(cm, 0, magNormalized);
- cm->timeDomainOut[0][0] = cm->mTempLBuffer[0] * mask;
- cm->timeDomainOut[1][0] = cm->mTempRBuffer[0] * mask;
- for (i = 1; i < cm->procUpTo; i++)
- {
- symIdx = cm->fftLen - i;
- bitRevFwd = cm->mBitRev[i];
- bitRevSym = cm->mBitRev[symIdx];
- lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
- float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
- rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
- float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
- float absV1 = fabsf(lR);
- float absV2 = fabsf(lI);
- leftMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
- absV1 = fabsf(rR);
- absV2 = fabsf(rI);
- rightMag = max((127.0f / 128.0f) * max(absV1, absV2) + (3.0f / 16.0f) * min(absV1, absV2), (27.0f / 32.0f) * max(absV1, absV2) + (71.0f / 128.0f) * min(absV1, absV2));
- currentMagnitude = leftMag > rightMag ? leftMag : rightMag;
- magNormalized = mag2db(currentMagnitude);
- cm->oldBuf[i] = cm->oldBuf[i] + cm->fgt_fac * (magNormalized - cm->oldBuf[i]);
- // Log conversion
- mask = processfftComp(cm, i, magNormalized);
- cm->timeDomainOut[0][bitRevFwd] = (lR + lI) * mask;
- cm->timeDomainOut[0][bitRevSym] = (lR - lI) * mask;
- cm->timeDomainOut[1][bitRevFwd] = (rR + rI) * mask;
- cm->timeDomainOut[1][bitRevSym] = (rR - rI) * mask;
- }
- }
- for (i = cm->procUpTo; i < cm->halfLen; i++)
- {
- symIdx = cm->fftLen - i;
- bitRevFwd = cm->mBitRev[i];
- bitRevSym = cm->mBitRev[symIdx];
- lR = cm->mTempLBuffer[i] + cm->mTempLBuffer[symIdx];
- float lI = cm->mTempLBuffer[i] - cm->mTempLBuffer[symIdx];
- rR = cm->mTempRBuffer[i] + cm->mTempRBuffer[symIdx];
- float rI = cm->mTempRBuffer[i] - cm->mTempRBuffer[symIdx];
- cm->timeDomainOut[0][bitRevFwd] = lR + lI;
- cm->timeDomainOut[0][bitRevSym] = lR - lI;
- cm->timeDomainOut[1][bitRevFwd] = rR + rI;
- cm->timeDomainOut[1][bitRevSym] = rR - rI;
- }
- // reconstitute left/right channels
- cm->fft(cm->timeDomainOut[0], cm->mSineTab);
- cm->fft(cm->timeDomainOut[1], cm->mSineTab);
- cm->mOutputBufferCount++;
- if (cm->mOutputBufferCount > 2)
- continue;
- float *outBuffer = cm->mOutputBuffer[cm->mOutputBufferCount - 1];
- for (i = 0; i < cm->ovpLen; ++i)
- {
- outBuffer[0] = cm->mOverlapStage2dash[0][i] + (cm->timeDomainOut[0][i + cm->smpShift] * cm->synthesisWnd[i]);
- outBuffer[1] = cm->mOverlapStage2dash[1][i] + (cm->timeDomainOut[1][i + cm->smpShift] * cm->synthesisWnd[i]);
- outBuffer += 2;
- // overlapping
- cm->mOverlapStage2dash[0][i] = (cm->timeDomainOut[0][cm->smpShift + cm->ovpLen + i] * cm->synthesisWnd[i + cm->ovpLen]);
- cm->mOverlapStage2dash[1][i] = (cm->timeDomainOut[1][cm->smpShift + cm->ovpLen + i] * cm->synthesisWnd[i + cm->ovpLen]);
- }
- cm->mInputSamplesNeeded = cm->ovpLen;
- }
+ cm->process(cm);
}
while ((cm->mOutputBufferCount > 0) && (outSampleCount < maxOutSampleCount)) {
float *sampD = cm->mOutputBuffer[0];
@@ -391,19 +1008,114 @@ void FFTCompanderSetavgBW(FFTCompander *cm, double avgBW)
cm->noGridDownsampling = 1;
}
}
-void FFTCompanderInit(FFTCompander *cm, float fs)
+static inline void filter2(float *Zre, float *Zim, float *bRe, float *aRe, float *aIm, float Xi, float *yRe, float *yIm)
{
- //memset(cm, 0, sizeof(FFTCompander));
- unsigned int i;
- const float oX[10] = { 750, 1500, 3000, 6000, 12000, 24000, 48000, 96000, 192000, 256000 };
- const float oY[10] = { 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 8192 };
- const float oX2[6] = { 0.0f, 0.25f, 0.4f, 0.5f, 0.75f, 1.0f };
- const float oY2[6] = { 9.0f, 7.0f, 4.5f, 4.0f, 2.0f, 1.0f };
- float frameLen = lerp1DNoExtrapo(fs, oX, oY, 10);
- float nextPwr2 = powf(2.0f, ceilf(logf(frameLen) / logf(2.0f)));
- float paddingRatio = map(frameLen / nextPwr2, 0.5f, 1.0f, 0.0f, 1.0f);
- float wndBeta = lerp1DNoExtrapo(paddingRatio, oX2, oY2, 6);
- cm->fftLen = (unsigned int)nextPwr2;
+ *yRe = *bRe * Xi + *Zre;
+ *yIm = *Zim;
+ *Zre = -*aRe * *yRe - -*aIm * *yIm;
+ *Zim = -*aRe * *yIm + -*aIm * *yRe;
+}
+void HSHOSVF2nd(double gain, double overallGainDb, float *c1, float *c2, float *d0, float *d1, float *overallGain, double *trigo)
+{
+ double GB = pow(10.0, ((1.0 / sqrt(2.0)) * gain / 20.0));
+ double G = pow(10.0, gain / 20.0);
+ *overallGain = (float)pow(10.0, overallGainDb / 20.0);
+ double gR;
+ if (fabs(gain) < 8.0 * DBL_EPSILON)
+ gR = 0;
+ else
+ gR = (G * G - GB * GB) / (GB * GB - 1);
+ double ratOrd = sqrt(gR);
+ double ratRO = sqrt(sqrt(gR));
+ double gP1 = sqrt(G);
+ const double si = 0.70710678118654752440084436210485;
+ *c1 = (float)(2.0 - 2.0 * (trigo[1] - ratOrd) / (trigo[1] + ratOrd - 2.0 * ratRO * trigo[0] * si));
+ *c2 = (float)((ratRO * trigo[3]) / (ratRO * trigo[3] - si * trigo[2]));
+ *d0 = (float)((ratOrd + G * trigo[1] - 2.0 * gP1 * ratRO * trigo[0] * si) / (trigo[1] + ratOrd - 2.0 * ratRO * trigo[0] * si));
+ *d1 = (float)((ratRO * trigo[3] - gP1 * si * trigo[2]) / (ratRO * trigo[3] - si * trigo[2]));
+}
+void HSHOSVF2ndNoOverallGain(double gain, float *c1, float *c2, float *d0, float *d1, double *trigo)
+{
+ double GB = pow(10.0, ((1.0 / sqrt(2.0)) * gain / 20.0));
+ double G = pow(10.0, gain / 20.0);
+ double gR;
+ if (fabs(gain) < 8.0 * DBL_EPSILON)
+ gR = 0;
+ else
+ gR = (G * G - GB * GB) / (GB * GB - 1);
+ double ratOrd = sqrt(gR);
+ double ratRO = sqrt(sqrt(gR));
+ double gP1 = sqrt(G);
+ const double si = 0.70710678118654752440084436210485;
+ *c1 = (float)(2.0 - 2.0 * (trigo[1] - ratOrd) / (trigo[1] + ratOrd - 2.0 * ratRO * trigo[0] * si));
+ *c2 = (float)((ratRO * trigo[3]) / (ratRO * trigo[3] - si * trigo[2]));
+ *d0 = (float)((ratOrd + G * trigo[1] - 2.0 * gP1 * ratRO * trigo[0] * si) / (trigo[1] + ratOrd - 2.0 * ratRO * trigo[0] * si));
+ *d1 = (float)((ratRO * trigo[3] - gP1 * si * trigo[2]) / (ratRO * trigo[3] - si * trigo[2]));
+}
+void HSHOSVF2ndPrecompute(double fs, double fc, double *trigo)
+{
+ double Dw = M_PI * (fc / fs - 0.5);
+ double ntD = tan(Dw);
+ double ntD2 = ntD * ntD;
+ double stD = sin(Dw);
+ double ctD = cos(Dw);
+ trigo[0] = ntD;
+ trigo[1] = ntD2;
+ trigo[2] = stD;
+ trigo[3] = ctD;
+}
+void LLraisedCosTblFloat(float *dst, int n, int overlapCount)
+{
+ const double twopi_over_n = 6.283185307179586476925286766559 / n;
+ const double scalefac = 1.0 / n;
+ float power = 1.0f;
+ if (overlapCount == 2)
+ power = 0.5f;
+ for (int i = 0; i < n; ++i)
+ dst[i] = (float)(scalefac * pow(0.5 * (1.0 - cos(twopi_over_n * (i + 0.5))), power));
+}
+void LLCreatePostWindowFloat(float *dst, int windowSize, int overlapCount)
+{
+ const float powerIntegrals[8] = { 1.0f, 1.0f / 2.0f, 3.0f / 8.0f, 5.0f / 16.0f, 35.0f / 128.0f,
+ 63.0f / 256.0f, 231.0f / 1024.0f, 429.0f / 2048.0f };
+ int power = 1;
+ if (overlapCount == 2)
+ power = 0;
+ const float scalefac = (float)windowSize * (powerIntegrals[1] / powerIntegrals[power + 1]);
+ LLraisedCosTblFloat(dst, windowSize, overlapCount);
+ for (int i = 0; i < windowSize; ++i)
+ dst[i] *= scalefac;
+}
+void FFTCompanderInit(FFTCompander *cm, float fs, int tfresolution, unsigned int reqSynthesisWnd, double HFSamplingLimit)
+{
+ unsigned int i, j, k;
+ double oct;
+ // FFT method
+ if (tfresolution == 0) // STFT
+ {
+ cm->fftLen = 2048;
+ cm->ovpCount = 8;
+ cm->process = regularSTFT;
+ }
+ else if (tfresolution == 1) // CWT
+ {
+ cm->fftLen = 4096;
+ cm->ovpCount = 8;
+ oct = 32;
+ cm->process = CWTFrameInversion;
+ }
+ else if (tfresolution == 2) // CWT STFT inverse
+ {
+ cm->fftLen = 4096;
+ cm->ovpCount = 8;
+ oct = 32;
+ cm->process = CWTFrameSTFTInversion;
+ }
+ else
+ {
+ cm->fftLen = 32;
+ cm->ovpCount = 1;
+ }
if (cm->fftLen == 32)
cm->fft = DFT32;
else if (cm->fftLen == 64)
@@ -423,7 +1135,7 @@ void FFTCompanderInit(FFTCompander *cm, float fs)
else
cm->fft = DFT8192;
cm->minus_fftLen = cm->fftLen - 1;
- cm->ovpLen = cm->fftLen / ANALYSIS_OVERLAP_DRS;
+ cm->ovpLen = cm->fftLen / cm->ovpCount;
cm->halfLen = (cm->fftLen >> 1) + 1;
cm->smpShift = (cm->fftLen - (cm->ovpLen << 1));
const float desiredProcessFreq = 24000.0f;
@@ -432,22 +1144,446 @@ void FFTCompanderInit(FFTCompander *cm, float fs)
cm->procUpTo = cm->halfLen;
else
cm->procUpTo = idx;
- LLbitReversalTblM(cm->mBitRev, cm->fftLen);
- LLsinHalfTblFloatM(cm->mSineTab, cm->fftLen);
+ LLbitReversalTbl(cm->mBitRev, cm->fftLen);
+ fhtsinHalfTblFloat(cm->mSineTab, cm->fftLen);
for (i = 0; i < MAX_OUTPUT_BUFFERS_DRS; i++)
cm->mOutputBuffer[i] = cm->buffer[i];
cm->mInputSamplesNeeded = cm->ovpLen;
cm->mInputPos = 0;
cm->mOutputBufferCount = 0;
cm->mOutputReadSampleOffset = 0;
- getAsymmetricWindow(cm->analysisWnd, cm->synthesisWnd, cm->fftLen, cm->ovpLen, cm->smpShift, wndBeta);
- for (i = 0; i < cm->fftLen; i++)
- cm->analysisWnd[i] *= (1.0f / cm->fftLen) * 0.5f;
- float sum = 0.0f;
- for (i = 0; i < cm->fftLen; i++)
- sum += cm->analysisWnd[i];
+ LLraisedCosTblFloat(cm->analysisWnd, cm->fftLen, cm->ovpCount);
+ LLCreatePostWindowFloat(cm->synthesisWnd, cm->fftLen, cm->ovpCount);
+ for (i = 0; i < cm->fftLen; ++i)
+ cm->synthesisWnd[i] *= 0.5f * (2.0f / (float)cm->ovpCount);
FFTCompanderSetavgBW(cm, 1.2);
- cm->spectralRate = fs / (float)cm->fftLen * (float)ANALYSIS_OVERLAP_DRS;
+ cm->spectralRate = fs / (float)cm->fftLen * (float)cm->ovpCount;
+ for (i = 0; i < HALFWNDLEN_DRS; i++)
+ cm->oldBuf[i] = -20.0f;
+ unsigned int NFFTDIV2 = cm->fftLen >> 1;
+ for (i = 0; i < cm->halfLen; i++)
+ {
+ if (i % 2 == 0)
+ cm->shiftCentre[i] = 1;
+ else
+ cm->shiftCentre[i] = -1;
+ }
+ // Initialization
+ for (i = 0; i < cm->halfLen; i++)
+ cm->corrF[i] = 1.0;
+ // Copy overlapping buffer to FFT buffer with fftshift
+ unsigned int *idxfftshift = (unsigned int *)malloc(cm->fftLen * sizeof(unsigned int));
+ for (i = 0; i < NFFTDIV2; i++)
+ idxfftshift[i] = NFFTDIV2 + i;
+ for (i = NFFTDIV2; i < cm->fftLen; i++)
+ idxfftshift[i] = i - NFFTDIV2;
+ for (i = 0; i < cm->fftLen; i++)
+ cm->bitrevfftshift[i] = cm->mBitRev[idxfftshift[i]];
+ unsigned int zp = 1;
+ // number of points of pre andpost padding used to set initial conditions
+ cm->prepad = (unsigned int)(cm->fftLen / 102.4);
+ cm->pospad = (unsigned int)(cm->fftLen / 102.4) + 2;
+ if (tfresolution > 1 && tfresolution < 3)
+ {
+ double *thetas1 = (double *)malloc((cm->prepad + cm->fftLen + cm->pospad - 1) * sizeof(double));
+ for (i = 0; i < cm->halfLen + cm->pospad - 1; i++)
+ thetas1[cm->prepad + i] = i;
+ thetas1[cm->prepad] = DBL_EPSILON;
+ for (i = 0; i < cm->prepad; i++)
+ thetas1[cm->prepad - i - 1] = i + 1;
+ for (i = 0; i < cm->prepad + cm->halfLen - 1; i++)
+ thetas1[cm->prepad + cm->halfLen + i] = thetas1[cm->prepad + cm->halfLen - i - 2];
+ double *synWnd = (double *)malloc(cm->fftLen * sizeof(double));
+ genWndDBL(synWnd, cm->fftLen, "hann");
+ double *analysisWnd = (double *)malloc(cm->fftLen * sizeof(double));
+ double *b = (double *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ double *c1 = (double *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ double *c2 = (double *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ for (i = 0; i < cm->fftLen; i++)
+ {
+ analysisWnd[i] = pow(synWnd[i], 1.0 / reqSynthesisWnd);
+ cm->analysisWnd[i] = (float)analysisWnd[i];
+ }
+ double *chopedWnd1 = analysisWnd + cm->halfLen - 1;
+ double *chopedWnd2 = synWnd + cm->halfLen - 1;
+ unsigned int div = (unsigned int)round(cm->ovpLen / (1 + HFSamplingLimit));
+ unsigned int halfWndLen = cm->halfLen - 1;
+ double *digw = (double *)malloc(halfWndLen * sizeof(double));
+ linspace(digw, 0, M_PI - M_PI / halfWndLen, halfWndLen);
+ digw[halfWndLen - 1] = M_PI - M_PI / halfWndLen;
+ double sRe = cos(digw[div - 1]);
+ double sIm = sin(digw[div - 1]);
+ double *hHopPt = (double *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ double tmpRe, tmpIm;
+ complexMultiplication(sRe, sIm, sRe, sIm, &tmpRe, &tmpIm);
+ double wndPwr = pow(chopedWnd2[div - 1], reqSynthesisWnd);
+ double top = -DBL_MIN, down = DBL_MAX;
+ for (i = 0; i < (cm->prepad + cm->halfLen + cm->pospad - 1); i++)
+ {
+ double sigmas = (thetas1[i] / cm->fftLen) / oct / M_PI * cm->fftLen;
+ double mp = exp(-137 / (100 * sigmas));
+ double a1 = 2.0 * cos(fnc1(sigmas) / sigmas) * mp;
+ double a[3] = { 1.0, -a1, mp * mp };
+ double b = a[0] + a[1] + a[2];
+ c1[i] = 2.0 - a1;
+ c2[i] = b / c1[i];
+ double bDeflatedRe = tmpRe * b;
+ double bDeflatedIm = tmpIm * b;
+ double aDeflatedRe = tmpRe + sRe * a[1] + a[2];
+ double aDeflatedIm = tmpIm + sIm * a[1];
+ double hHopPtCplxRe, hHopPtCplxIm;
+ //printf("%d %1.14lf %1.14lf %1.14lf %1.14lf\n", i + 1, bDeflatedRe, bDeflatedIm, aDeflatedRe, aDeflatedIm);
+ cdivid(bDeflatedRe, bDeflatedIm, aDeflatedRe, aDeflatedIm, &hHopPtCplxRe, &hHopPtCplxIm);
+ hHopPt[i] = complexMultiplicationConj(hHopPtCplxRe, hHopPtCplxIm, hHopPtCplxRe, -hHopPtCplxIm) * chopedWnd1[div - 1] * wndPwr;
+ if (hHopPt[i] > top)
+ top = hHopPt[i];
+ if (hHopPt[i] < down)
+ down = hHopPt[i];
+ }
+ double thres = (top + down) / 2.0;
+ double *shiftedhHopPt = hHopPt + cm->prepad;
+ char isEmpty = 1;
+ for (i = 0; i < cm->halfLen; i++)
+ {
+ if (shiftedhHopPt[i] <= thres)
+ {
+ isEmpty = 0;
+ break;
+ }
+ }
+ unsigned int firstUndersampling = cm->prepad + min(i + 1, (unsigned int)(cm->fftLen / 4 - 1) - cm->prepad) - 1;
+ if (!isEmpty)
+ {
+ double thetaclipping = thetas1[firstUndersampling - 1];
+ unsigned int len = cm->halfLen - firstUndersampling + 1;
+ for (i = 0; i < len; i++)
+ thetas1[i + firstUndersampling - 1] = thetaclipping;
+ for (i = 0; i < cm->prepad; i++)
+ thetas1[i] = thetas1[cm->prepad * 2 - i];
+ len = cm->halfLen - (cm->halfLen - cm->prepad - cm->pospad + 1);
+ for (i = 0; i < len; i++)
+ thetas1[cm->halfLen + i] = thetas1[cm->halfLen - i - 2];
+ // Eliminate oscillation around corner
+ double time = 0.026 * cm->fftLen / zp; // More elements in array less smoothing is needed
+ double alpha = 1 / (1 + time);
+ double alph = tan((M_PI * alpha) / 2.0);
+ double bCoef = alph / (1.0 + alph);
+ double iir_b[2] = { bCoef, bCoef };
+ double iir_a = -(1.0 - alph) / (1.0 + alph);
+ double zi = (iir_b[1] - iir_b[0] * iir_a) / (1.0 + iir_a);
+ double *ytemp = (double *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1 + 2 * 3) * sizeof(double));
+ ytemp[0] = 2.0 * thetas1[0] - thetas1[3];
+ ytemp[1] = 2.0 * thetas1[0] - thetas1[2];
+ ytemp[2] = 2.0 * thetas1[0] - thetas1[1];
+ memcpy(ytemp + 3, thetas1, (cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ ytemp[3 + (cm->prepad + cm->halfLen + cm->pospad - 1) + 0] = 2.0 * thetas1[cm->prepad + cm->halfLen + cm->pospad - 2] - thetas1[cm->prepad + cm->halfLen + cm->pospad - 3];
+ ytemp[3 + (cm->prepad + cm->halfLen + cm->pospad - 1) + 1] = 2.0 * thetas1[cm->prepad + cm->halfLen + cm->pospad - 2] - thetas1[cm->prepad + cm->halfLen + cm->pospad - 4];
+ ytemp[3 + (cm->prepad + cm->halfLen + cm->pospad - 1) + 2] = 2.0 * thetas1[cm->prepad + cm->halfLen + cm->pospad - 2] - thetas1[cm->prepad + cm->halfLen + cm->pospad - 5];
+ double zLPF = zi * ytemp[0];
+ for (i = 0; i < (cm->prepad + cm->halfLen + cm->pospad - 1 + 2 * 3); i++)
+ {
+ double out = ytemp[i] * bCoef + zLPF;
+ zLPF = ytemp[i] * bCoef - iir_a * out;
+ ytemp[i] = out;
+ }
+ int left = 0;
+ int right = (cm->prepad + cm->halfLen + cm->pospad - 1 + 2 * 3 - 1);
+ while (left < right)
+ {
+ double tmp = ytemp[left];
+ ytemp[left++] = ytemp[right];
+ ytemp[right--] = tmp;
+ }
+ zLPF = zi * ytemp[0];
+ for (i = 0; i < (cm->prepad + cm->halfLen + cm->pospad - 1 + 2 * 3); i++)
+ {
+ double out = ytemp[i] * bCoef + zLPF;
+ zLPF = ytemp[i] * bCoef - iir_a * out;
+ ytemp[i] = out;
+ }
+ left = 0;
+ right = (cm->prepad + cm->halfLen + cm->pospad - 1 + 2 * 3 - 1);
+ while (left < right)
+ {
+ double tmp = ytemp[left];
+ ytemp[left++] = ytemp[right];
+ ytemp[right--] = tmp;
+ }
+ memcpy(thetas1, ytemp + 3, (cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ free(ytemp);
+ for (i = 0; i < (cm->prepad + cm->halfLen + cm->pospad - 1); i++)
+ {
+ double sigmas = (thetas1[i] / cm->fftLen) / oct / M_PI * cm->fftLen;
+ double mp = exp(-137 / (100 * sigmas));
+ double a1 = 2.0 * cos(fnc1(sigmas) / sigmas) * mp;
+ double a[3] = { 1.0, -a1, mp * mp };
+ b[i] = a[0] + a[1] + a[2];
+ c1[i] = 2.0 - a1;
+ c2[i] = b[i] / c1[i];
+ }
+ //for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; i++)
+ // printf("%d %1.14lf %1.14lf %1.14lf\n", i + 1, b[i], c1[i], c2[i]);
+ }
+ double meaTheta = 0.0;
+ for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; i++)
+ meaTheta += thetas1[i];
+ meaTheta /= (cm->prepad + cm->halfLen + cm->pospad - 1);
+ char flat = 0;
+ for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; i++)
+ {
+ if (fabs(thetas1[i] - meaTheta) < DBL_EPSILON)
+ {
+ flat = 1;
+ break;
+ }
+ }
+ double *mSineTab = (double *)malloc(cm->fftLen * sizeof(double));
+ LLsinHalfTbl(mSineTab, cm->fftLen);
+ unsigned int xlen = cm->fftLen + ((cm->ovpCount - 1) - 1) * cm->ovpLen;
+ double *systemImpulse = (double *)malloc(xlen * sizeof(double));
+ memset(systemImpulse, 0, xlen * sizeof(double));
+ double *tmpreal = (double *)malloc(cm->halfLen * sizeof(double));
+ double *tmpimag = (double *)malloc(cm->halfLen * sizeof(double));
+ double *tmpspecHannReal = (double *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ double *tmpspecHannImag = (double *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(double));
+ cplxDouble *tmCplx = (cplxDouble *)malloc((cm->prepad + cm->halfLen + cm->pospad - 1) * sizeof(cplxDouble));
+ double *fftBuf = (double *)malloc(cm->fftLen * sizeof(double));
+ for (j = 0; j < cm->ovpCount - 1; j++)
+ {
+ unsigned int stepSize1 = (cm->fftLen - cm->ovpLen * (j + 1)) % cm->fftLen;
+ unsigned int stepSize = (cm->fftLen - cm->ovpLen * (j + 1) - cm->fftLen / 2 - 1) % cm->fftLen;
+ double cons1 = stepSize * 2 * M_PI / (double)cm->fftLen;
+ double anawnd = cm->analysisWnd[stepSize1 - 1];
+ for (i = 0; i < cm->halfLen; i++)
+ {
+ double idx = -cons1 * i;
+ tmpspecHannReal[i + cm->prepad] = anawnd * cos(idx);
+ tmpspecHannImag[i + cm->prepad] = anawnd * sin(idx);
+ }
+ for (i = 0; i < cm->prepad; ++i)
+ {
+ tmpspecHannReal[cm->prepad - i - 1] = tmpspecHannReal[cm->prepad + i + 1];
+ tmpspecHannImag[cm->prepad - i - 1] = -tmpspecHannImag[cm->prepad + i + 1];
+ }
+ for (i = 0; i < cm->pospad - 1; ++i)
+ {
+ tmpspecHannReal[cm->prepad + cm->halfLen + cm->pospad - i - 2] = tmpspecHannReal[cm->prepad + cm->halfLen - cm->pospad + i];
+ tmpspecHannImag[cm->prepad + cm->halfLen + cm->pospad - i - 2] = -tmpspecHannImag[cm->prepad + cm->halfLen - cm->pospad + i];
+ }
+ // LTV Gaussian
+ cplxDouble z1, z2, o, st;
+ z1.real = z1.imag = 0;
+ z2.real = z2.imag = 0;
+ for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; i++)
+ {
+ o.real = tmpspecHannReal[i] - z1.real - z2.real;
+ o.imag = tmpspecHannImag[i] - z1.imag - z2.imag;
+ st.real = c2[i] * z1.real;
+ st.imag = c2[i] * z1.imag;
+ tmCplx[i].real = b[i] * o.real + 2 * st.real + z2.real;
+ tmCplx[i].imag = b[i] * o.imag + 2 * st.imag + z2.imag;
+ z2.real = z2.real + st.real;
+ z2.imag = z2.imag + st.imag;
+ z1.real = z1.real + c1[i] * o.real;
+ z1.imag = z1.imag + c1[i] * o.imag;
+ }
+ z1.real = z1.imag = 0;
+ z2.real = z2.imag = 0;
+ for (i = cm->prepad + cm->halfLen + cm->pospad - 1; i-- > 0; )
+ {
+ o.real = tmCplx[i].real - z1.real - z2.real;
+ o.imag = tmCplx[i].imag - z1.imag - z2.imag;
+ st.real = c2[i] * z1.real;
+ st.imag = c2[i] * z1.imag;
+ tmpspecHannReal[i] = b[i] * o.real + 2 * st.real + z2.real;
+ tmpspecHannImag[i] = b[i] * o.imag + 2 * st.imag + z2.imag;
+ z2.real = z2.real + st.real;
+ z2.imag = z2.imag + st.imag;
+ z1.real = z1.real + c1[i] * o.real;
+ z1.imag = z1.imag + c1[i] * o.imag;
+ }
+ //for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; ++i)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, tmpspecHannReal[i], tmpspecHannImag[i]);
+ for (i = cm->prepad; i < cm->prepad + cm->halfLen; ++i)
+ {
+ tmpspecHannReal[i - cm->prepad] = tmpspecHannReal[i] * cm->corrF[i - cm->prepad];
+ tmpspecHannImag[i - cm->prepad] = tmpspecHannImag[i] * cm->corrF[i - cm->prepad];
+ }
+ tmpspecHannImag[0] = tmpspecHannImag[cm->halfLen - 1] = 0;
+ double *reTar = tmpreal;
+ double *imTar = tmpimag;
+ double *reSrc = tmpspecHannReal;
+ double *imSrc = tmpspecHannImag;
+ // Inverse transform
+ for (k = 0; k < reqSynthesisWnd; k++)
+ {
+ reTar[0] = (reSrc[0] * 2.0 + reSrc[1] + reSrc[1]) / 4.0; // DC
+ imTar[0] = 0.0; // DC
+ for (i = 1; i < cm->halfLen - 1; i++)
+ {
+ reTar[i] = (reSrc[i] * 2.0 + reSrc[i - 1] + reSrc[i + 1]) / 4.0;
+ imTar[i] = (imSrc[i] * 2.0 + imSrc[i - 1] + imSrc[i + 1]) / 4.0;
+ }
+ reTar[cm->halfLen - 1] = (reSrc[cm->halfLen - 1] * 2.0 + reSrc[cm->halfLen - 2] + reSrc[cm->halfLen - 2]) / 4.0; // Nyquist
+ imTar[cm->halfLen - 1] = 0.0;
+ double *retmp = reSrc;
+ double *imtmp = imSrc;
+ reSrc = reTar;
+ imSrc = imTar;
+ reTar = retmp;
+ imTar = imtmp;
+ }
+ fftBuf[0] = reSrc[0];
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ unsigned int symIdx = cm->fftLen - i;
+ unsigned int bitRevFwd = cm->mBitRev[i];
+ unsigned int bitRevSym = cm->mBitRev[symIdx];
+ fftBuf[bitRevFwd] = reSrc[i] + (-imSrc[i]);
+ fftBuf[bitRevSym] = reSrc[i] - (-imSrc[i]);
+ }
+ //for (i = 0; i < cm->halfLen; ++i)
+ // printf("%d %1.14lf %1.14lf\n", i + 1, tmpreal[i], tmpimag[i]);
+ discreteHartleyTransform(fftBuf, cm->fftLen, mSineTab);
+ double *ptr = systemImpulse + j * cm->ovpLen;
+ for (i = 0; i < cm->fftLen; ++i)
+ ptr[i] += fftBuf[idxfftshift[i]] / cm->fftLen;
+ }
+ double *truncatedSystemImpulse = (double *)malloc((cm->fftLen + 1) * sizeof(double));
+ if (cm->ovpLen != NFFTDIV2)
+ {
+ xlen = (cm->fftLen - cm->ovpLen) - ((cm->fftLen - cm->ovpLen) - (cm->fftLen / 2)) + 1;
+ memcpy(truncatedSystemImpulse, systemImpulse + (cm->fftLen - cm->ovpLen) - (cm->fftLen / 2) - 1, xlen * sizeof(double));
+ }
+ else
+ {
+ xlen = cm->fftLen - cm->ovpLen;
+ truncatedSystemImpulse[0] = 0;
+ memcpy(truncatedSystemImpulse + 1, systemImpulse, xlen * sizeof(double));
+ }
+ for (i = 0; i < NFFTDIV2; i++)
+ truncatedSystemImpulse[cm->halfLen + i] = truncatedSystemImpulse[cm->halfLen - 2 - i];
+ double *truncatedSystemImpulseptr = truncatedSystemImpulse + 1;
+ for (i = 0; i < cm->fftLen; i++)
+ fftBuf[cm->mBitRev[i]] = truncatedSystemImpulseptr[i];
+ discreteHartleyTransform(fftBuf, cm->fftLen, mSineTab);
+ double *impulseSpectrum = (double *)malloc(cm->halfLen * sizeof(double));
+ impulseSpectrum[0] = fftBuf[0];
+ unsigned int symIdx;
+ double mm = fftBuf[0];
+ for (i = 1; i < cm->halfLen; i++)
+ {
+ symIdx = cm->fftLen - i;
+ impulseSpectrum[i] = hypot(fftBuf[i] + fftBuf[symIdx], -(fftBuf[i] - fftBuf[symIdx])) * 0.5;
+ mm += impulseSpectrum[i];
+ }
+ if (flat)
+ {
+ mm = 1.0 / (mm / cm->halfLen);
+ for (i = 0; i < cm->halfLen; i++)
+ cm->corrF[i] = (float)mm;
+ }
+ else
+ {
+ for (i = 0; i < cm->halfLen; i++)
+ cm->corrF[i] = (float)(1.0 / impulseSpectrum[i]);
+ }
+ double *synth_win = (double *)malloc(cm->fftLen * sizeof(double));
+ memset(synth_win, 0, cm->fftLen * sizeof(double));
+ genWndDBL(synth_win + cm->fftLen / 2 - cm->ovpLen, cm->ovpLen * 2, "hann");
+ double *tmpWnd = (double *)malloc(cm->fftLen * sizeof(double));
+ for (i = 0; i < cm->fftLen; i++)
+ tmpWnd[i] = synth_win[i] * cm->analysisWnd[i];
+ xlen = cm->fftLen + (cm->ovpCount * 2 - 1) * cm->ovpLen;
+ double *correctionWndHF = (double *)malloc(xlen * sizeof(double));
+ memset(correctionWndHF, 0, xlen * sizeof(double));
+ for (j = 0; j < cm->ovpCount * 2; j++)
+ {
+ double *ptr = correctionWndHF + j * cm->ovpLen;
+ for (i = 0; i < cm->fftLen; ++i)
+ ptr[i] += tmpWnd[i];
+ }
+ double *wndValidPart1 = synth_win + (cm->fftLen / 2 - cm->ovpLen);
+ double *wndValidPart2 = correctionWndHF + (cm->fftLen - cm->ovpLen) + (cm->fftLen / 2 - cm->ovpLen);
+ for (j = 0; j < cm->ovpLen * 2; j++)
+ cm->synthesisWnd[j] = (float)((wndValidPart1[j] / wndValidPart2[j]) / (cm->fftLen * 2.0));
+ /*FILE *fpp = fopen("dd.dat", "wb");
+ fwrite(cm->synthesisWnd, sizeof(float), cm->ovpLen * 2, fpp);
+ fclose(fpp);*/
+ /*FILE *fpp = fopen("dd.dat", "wb");
+ fwrite(cm->corrF, sizeof(float), cm->halfLen, fpp);
+ fclose(fpp);*/
+ for (i = 0; i < cm->prepad + cm->halfLen + cm->pospad - 1; i++)
+ {
+ cm->gauss_b[i] = (float)b[i];
+ cm->gauss_c1[i] = (float)c1[i];
+ cm->gauss_c2[i] = (float)c2[i];
+ }
+ free(thetas1);
+ free(synWnd);
+ free(analysisWnd);
+ free(b);
+ free(c1);
+ free(c2);
+ free(digw);
+ free(hHopPt);
+ free(mSineTab);
+ free(systemImpulse);
+ free(tmpreal);
+ free(tmpimag);
+ free(tmpspecHannReal);
+ free(tmpspecHannImag);
+ free(tmCplx);
+ free(fftBuf);
+ free(truncatedSystemImpulse);
+ free(impulseSpectrum);
+ free(synth_win);
+ free(tmpWnd);
+ free(correctionWndHF);
+ }
+ else if (tfresolution == 1)
+ {
+ memcpy(cm->gauss_b, prec_b, sizeof(prec_b));
+ memcpy(cm->gauss_c1, prec_c1, sizeof(prec_c1));
+ memcpy(cm->gauss_c2, prec_c2, sizeof(prec_c2));
+ memcpy(cm->corrF, prec_corrF, sizeof(prec_corrF));
+ cm->scalarGain = (float)(1.0 / cm->fftLen / 2.0);
+ }
+ free(idxfftshift);
+ if (tfresolution == 3)
+ {
+ // Time domain method
+ double fb_bwERBs = 3.0;
+ double fb_lowFreqHz = 40.0;
+ double fb_highFreqHz = 20000.0;
+#define freq2erb(freq) (9.265 * log(1.0 + freq / (24.7 * 9.265)))
+#define erb2freq(erb) (24.7 * 9.265 * (exp(erb / 9.265) - 1))
+ double ERBS[DYN_BANDS_GAMMATONE];
+ linspace(ERBS, DYN_BANDS_GAMMATONE, freq2erb(fb_lowFreqHz), freq2erb(fb_highFreqHz));
+ memset(cm->Zre, 0, DYN_BANDS_GAMMATONE * 2 * sizeof(float));
+ memset(cm->Zim, 0, DYN_BANDS_GAMMATONE * 2 * sizeof(float));
+ for (i = 0; i < DYN_BANDS_GAMMATONE; i++)
+ {
+ cm->gmtFreq[i] = erb2freq(ERBS[i]);
+ gammatoneAPFirstOrder(cm->gmtFreq[i], fs, fb_bwERBs, &cm->bRe[i], &cm->aRe[i], &cm->aIm[i]);
+ }
+ memcpy(cm->freq3 + 1, cm->gmtFreq, sizeof(cm->gmtFreq));
+ cm->freq3[0] = 0.0f;
+ cm->freq3[DYN_BANDS_GAMMATONE + 1] = fs * 0.5f;
+ float *fq = cm->freq3 + 1;
+ HSHOSVF2ndPrecompute(fs, fq[0], cm->trigo);
+ for (unsigned int sb = 1; sb < DYN_BANDS_GAMMATONE - 1; sb++)
+ {
+ double designFreq = (fq[sb + 1] + fq[sb]) * 0.5;
+ HSHOSVF2ndPrecompute(fs, designFreq, cm->trigo + sb * 4);
+ }
+ HSHOSVF2nd(0, 0, &cm->c1[0], &cm->c2[0], &cm->d0[0], &cm->d1[0], &cm->overallGain, cm->trigo);
+ for (i = 1; i < DYN_BANDS_GAMMATONE - 1; i++)
+ HSHOSVF2ndNoOverallGain(0, &cm->c1[i], &cm->c2[i], &cm->d0[i], &cm->d1[i], cm->trigo + i * 4);
+ cm->updatePerNSmps = 2;
+ cm->dsSm = 1.0f / (1.0f + cm->updatePerNSmps);
+ cm->alpha = 0.5f / cm->updatePerNSmps;
+ }
}
void CompressorConstructor(JamesDSPLib *jdsp)
{
@@ -458,7 +1594,6 @@ void CompressorConstructor(JamesDSPLib *jdsp)
cm->gains2[0] = cm->gains2[1];
cm->freq2[NUMPTS_DRS + 1] = 24000.0;
initIerper(&cm->pch, NUMPTS_DRS + 2);
- FFTCompanderInit(cm, jdsp->fs);
}
void CompressorDestructor(JamesDSPLib *jdsp)
{
@@ -468,8 +1603,7 @@ void CompressorEnable(JamesDSPLib *jdsp, char enable)
{
if (jdsp->compForceRefresh)
{
- FFTCompanderInit(&jdsp->comp, jdsp->fs);
- CompressorSetParam(jdsp, jdsp->comp.fgt_facT, jdsp->comp.granularity, jdsp->comp.tfresolution);
+ CompressorSetParam(jdsp, jdsp->comp.fgt_facT, jdsp->comp.granularity, jdsp->comp.tfresolution, 1);
CompressorSetGain(jdsp, 0, 0, 0);
}
if (enable)
@@ -479,29 +1613,40 @@ void CompressorDisable(JamesDSPLib *jdsp)
{
jdsp->compEnabled = 0;
}
-void CompressorSetParam(JamesDSPLib *jdsp, float fgt_facT, int granularity, int tfresolution)
+void CompressorSetParam(JamesDSPLib *jdsp, float fgt_facT, int granularity, int tfresolution, char forceRefresh)
{
FFTCompander *cm = (FFTCompander *)(&jdsp->comp);
- cm->fgt_facT = fgt_facT;
- cm->fgt_fac = (float)(1.0 - exp(-1.0 / (cm->fgt_facT * jdsp->comp.spectralRate)));
- cm->granularity = granularity;
- cm->tfresolution = tfresolution;
- double avgBW;
- if (!cm->granularity)
- avgBW = 1.65;
- else if (cm->granularity == 1)
- avgBW = 1.45;
- else if (cm->granularity == 2)
- avgBW = 1.2;
- else if (cm->granularity == 3)
- avgBW = 1.15;
- else
- avgBW = 1.1;
- FFTCompanderSetavgBW(cm, avgBW);
+ if ((fgt_facT != cm->fgt_facT || tfresolution != cm->tfresolution || granularity != cm->granularity) || forceRefresh)
+ {
+ FFTCompanderInit(&jdsp->comp, jdsp->fs, tfresolution, 3, 1.0);
+ cm->fgt_facT = fgt_facT;
+ cm->tfresolution = tfresolution;
+ cm->granularity = granularity;
+ if (cm->tfresolution < 3)
+ {
+ cm->fgt_fac = (float)(1.0 - exp(-1.0 / (cm->fgt_facT * jdsp->comp.spectralRate)));
+ double avgBW;
+ if (!cm->granularity)
+ avgBW = 1.65;
+ else if (cm->granularity == 1)
+ avgBW = 1.45;
+ else if (cm->granularity == 2)
+ avgBW = 1.2;
+ else if (cm->granularity == 3)
+ avgBW = 1.15;
+ else
+ avgBW = 1.08;
+ FFTCompanderSetavgBW(cm, avgBW);
+ }
+ else if (cm->tfresolution == 3)
+ {
+ cm->fgt_fac = (float)(1.0 - exp(-1.0 / (cm->fgt_facT * jdsp->fs)));
+ }
+ }
}
void CompressorSetGain(JamesDSPLib *jdsp, double *freq, double *gains, char cpy)
{
- FFTCompander *cm = (FFTCompander*)(&jdsp->comp);
+ FFTCompander *cm = (FFTCompander *)(&jdsp->comp);
if (cpy)
{
memcpy(cm->freq2 + 1, freq, NUMPTS_DRS * sizeof(double));
@@ -517,33 +1662,155 @@ void CompressorSetGain(JamesDSPLib *jdsp, double *freq, double *gains, char cpy)
unsigned int lpLen = *((unsigned int *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float)));
float *lv1 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float));
float *lv2 = (float *)(cm->octaveSmooth + sizeof(unsigned int) + sizeof(float) + sizeof(unsigned int) + (lpLen << 1) * sizeof(unsigned int) + lpLen * sizeof(float) + (lpLen + 3) * sizeof(float));
- for (int i = 0; i < HALFWNDLEN_DRS; i++)
- cm->DREmultUniform[i] = getValueAt(&cm->pch.cb, i * jdsp->fs / cm->fftLen * 0.25);
- if (!cm->noGridDownsampling)
- ShrinkGridSpectralInterpolator(cm->octaveSmooth, cm->procUpTo, cm->DREmultUniform, cm->DREmult);
- else
- memcpy(cm->DREmult, cm->DREmultUniform, cm->procUpTo * sizeof(float));
- cm->headRoomdB = 10.0f;
- if (!cm->noGridDownsampling)
+ if (cm->tfresolution < 3)
{
- for (int i = 0; i < cm->smallGridSize; i++)
- if (cm->headRoomdB < cm->DREmult[i] * 12.0f)
- cm->headRoomdB = cm->DREmult[i] * 12.0f;
+ for (int i = 0; i < HALFWNDLEN_DRS; i++)
+ cm->DREmultUniform[i] = getValueAt(&cm->pch.cb, i * jdsp->fs / cm->fftLen * 0.25);
+ if (!cm->noGridDownsampling)
+ ShrinkGridSpectralInterpolator(cm->octaveSmooth, cm->procUpTo, cm->DREmultUniform, cm->DREmult);
+ else
+ memcpy(cm->DREmult, cm->DREmultUniform, cm->procUpTo * sizeof(float));
+ cm->headRoomdB = 10.0f;
+ if (!cm->noGridDownsampling)
+ {
+ for (int i = 0; i < cm->smallGridSize; i++)
+ {
+ if (cm->DREmult[i] < -1.2)
+ cm->DREmult[i] = -1.2;
+ if (cm->DREmult[i] > 1.2)
+ cm->DREmult[i] = 1.2;
+ if (cm->headRoomdB < cm->DREmult[i] * 12.0f)
+ cm->headRoomdB = cm->DREmult[i] * 12.0f;
+ }
+ }
+ else
+ {
+ for (int i = 0; i < cm->procUpTo; i++)
+ {
+ if (cm->DREmult[i] < -1.2)
+ cm->DREmult[i] = -1.2;
+ if (cm->DREmult[i] > 1.2)
+ cm->DREmult[i] = 1.2;
+ if (cm->headRoomdB < cm->DREmult[i] * 12.0f)
+ cm->headRoomdB = cm->DREmult[i] * 12.0f;
+ }
+ }
}
else
{
- for (int i = 0; i < cm->procUpTo; i++)
+ float avgGain = 0.0f;
+ for (int i = 0; i < DYN_BANDS_GAMMATONE; i++)
+ {
+ cm->DREmult[i] = getValueAt(&cm->pch.cb, cm->gmtFreq[i]);
+ if (cm->DREmult[i] < -1.2)
+ cm->DREmult[i] = -1.2;
+ if (cm->DREmult[i] > 1.2)
+ cm->DREmult[i] = 1.2;
+ avgGain += cm->DREmult[i];
+ }
+ avgGain /= DYN_BANDS_GAMMATONE;
+ const float oX[11] = { -1.2, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.2 };
+ const float oY[11] = { 0.05, 0.09, 0.15, 0.17, 0.2, 0.25, 0.1, 0.05, 0.008, 0.005, 0.003 };
+ float rate = lerp1DNoExtrapo(avgGain, oX, oY, 11);
+ if (!cm->granularity)
+ rate *= 0.9f;
+ else if (cm->granularity == 1)
+ rate *= 0.95f;
+ else if (cm->granularity == 3)
+ rate *= 0.99f;
+ else if (cm->granularity == 3)
+ rate *= 1.0f;
+ cm->alpha = rate / cm->updatePerNSmps;
+ cm->headRoomdB = 10.0f;
+ for (int i = 0; i < DYN_BANDS_GAMMATONE; i++)
if (cm->headRoomdB < cm->DREmult[i] * 12.0f)
cm->headRoomdB = cm->DREmult[i] * 12.0f;
}
}
void CompressorProcess(JamesDSPLib *jdsp, size_t n)
{
- unsigned int offset = 0;
- while (offset < n)
+ FFTCompander *cm = (FFTCompander *)(&jdsp->comp);
+ if (cm->tfresolution < 3)
+ {
+ unsigned int offset = 0;
+ while (offset < n)
+ {
+ const unsigned int processing = min(n - offset, cm->ovpLen);
+ FFTCompanderProcessSamples(cm, jdsp->tmpBuffer[0] + offset, jdsp->tmpBuffer[1] + offset, processing, jdsp->tmpBuffer[0] + offset, jdsp->tmpBuffer[1] + offset);
+ offset += processing;
+ }
+ }
+ else
{
- const unsigned int processing = min(n - offset, jdsp->comp.ovpLen);
- FFTCompanderProcessSamples(&jdsp->comp, jdsp->tmpBuffer[0] + offset, jdsp->tmpBuffer[1] + offset, processing, jdsp->tmpBuffer[0] + offset, jdsp->tmpBuffer[1] + offset);
- offset += processing;
+ unsigned int smp, i, sb;
+ float yre, yim;
+ float *ZreL = cm->Zre;
+ float *ZimL = cm->Zim;
+ float *ZreR = ZreL + DYN_BANDS_GAMMATONE;
+ float *ZimR = ZimL + DYN_BANDS_GAMMATONE;
+ for (smp = 0; smp < n; smp++)
+ {
+ for (sb = 0; sb < DYN_BANDS_GAMMATONE; sb++)
+ {
+ filter2(&ZreL[sb], &ZimL[sb], &cm->bRe[sb], &cm->aRe[sb], &cm->aIm[sb], jdsp->tmpBuffer[0][smp], &yre, &yim);
+ float leftMag = hypotf(yre, yim);
+ filter2(&ZreR[sb], &ZimR[sb], &cm->bRe[sb], &cm->aRe[sb], &cm->aIm[sb], jdsp->tmpBuffer[1][smp], &yre, &yim);
+ float rightMag = hypotf(yre, yim);
+ float magNormalized = mag2db((leftMag + rightMag) * 0.5f);
+ cm->oldBuf[sb] = cm->oldBuf[sb] + cm->fgt_fac * (magNormalized - cm->oldBuf[sb]);
+ cm->interpolatedGain[sb + 1] = processfftCompdB(cm, sb, magNormalized);
+ }
+ cm->interpolatedGain[0] = cm->interpolatedGain[1];
+ cm->interpolatedGain[DYN_BANDS_GAMMATONE + 1] = cm->interpolatedGain[DYN_BANDS_GAMMATONE];
+ float *gn = cm->interpolatedGain + 1;
+ cm->diffGain[0] = gn[0] + cm->dsSm * (cm->diffGain[0] - gn[0]);
+ for (sb = 0; sb < DYN_BANDS_GAMMATONE - 1; sb++)
+ {
+ float diff = gn[sb + 1] - gn[sb];
+ cm->diffGain[sb + 1] = diff + cm->dsSm * (cm->diffGain[sb + 1] - diff);
+ }
+ cm->updateIdx = (cm->updateIdx + 1) & (cm->updatePerNSmps - 1);
+ if (cm->updateIdx == 0)
+ {
+ float c1, c2, d0, d1, unityGain;
+ HSHOSVF2nd(cm->diffGain[0 + 1], cm->diffGain[0], &c1, &c2, &d0, &d1, &unityGain, cm->trigo);
+ cm->d0step[0] = (d0 - cm->d0[0]) * cm->alpha;
+ cm->d1step[0] = (d1 - cm->d1[0]) * cm->alpha;
+ cm->c1step[0] = (c1 - cm->c1[0]) * cm->alpha;
+ cm->c2step[0] = (c2 - cm->c2[0]) * cm->alpha;
+ cm->overallGainstep = (unityGain - cm->overallGain) * cm->alpha;
+ for (sb = 1; sb < DYN_BANDS_GAMMATONE - 1; sb++)
+ {
+ HSHOSVF2ndNoOverallGain(cm->diffGain[sb + 1], &c1, &c2, &d0, &d1, cm->trigo + sb * 4);
+ cm->d0step[sb] = (d0 - cm->d0[sb]) * cm->alpha;
+ cm->d1step[sb] = (d1 - cm->d1[sb]) * cm->alpha;
+ cm->c1step[sb] = (c1 - cm->c1[sb]) * cm->alpha;
+ cm->c2step[sb] = (c2 - cm->c2[sb]) * cm->alpha;
+ }
+ }
+ for (sb = 0; sb < DYN_BANDS_GAMMATONE - 1; sb++)
+ {
+ cm->d0[sb] += cm->d0step[sb];
+ cm->d1[sb] += cm->d1step[sb];
+ cm->c1[sb] += cm->c1step[sb];
+ cm->c2[sb] += cm->c2step[sb];
+ }
+ cm->overallGain += cm->overallGainstep;
+ float x1 = jdsp->tmpBuffer[0][smp];
+ float x2 = jdsp->tmpBuffer[1][smp];
+ for (i = 0; i < DYN_BANDS_GAMMATONE - 1; i++)
+ {
+ float y1 = x1 - cm->z1_AL[i] - cm->z2_AL[i];
+ x1 = cm->d0[i] * y1 + cm->d1[i] * cm->z1_AL[i] + cm->z2_AL[i];
+ cm->z2_AL[i] = cm->z2_AL[i] + cm->c2[i] * cm->z1_AL[i];
+ cm->z1_AL[i] = cm->z1_AL[i] + cm->c1[i] * y1;
+ float y2 = x2 - cm->z1_AR[i] - cm->z2_AR[i];
+ x2 = cm->d0[i] * y2 + cm->d1[i] * cm->z1_AR[i] + cm->z2_AR[i];
+ cm->z2_AR[i] = cm->z2_AR[i] + cm->c2[i] * cm->z1_AR[i];
+ cm->z1_AR[i] = cm->z1_AR[i] + cm->c1[i] * y2;
+ }
+ jdsp->tmpBuffer[0][smp] = x1 * cm->overallGain;
+ jdsp->tmpBuffer[1][smp] = x2 * cm->overallGain;
+ }
}
}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/eelCommon.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/eelCommon.h
index cfc40848..6b187635 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/eelCommon.h
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/eelCommon.h
@@ -1,4 +1,4 @@
-#if defined(TURN_ON_VST)
+#ifdef TURN_ON_VST
// Config a custom CLI buffer
#define CUSTOM_CMD
#endif
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel-int.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel-int.h
index 2ba4ec87..6f630ee1 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel-int.h
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel-int.h
@@ -116,9 +116,9 @@ typedef struct {
typedef struct
{
int32_t slot, inuse;
- int32_t *map;
- s_str *m_literal_strings;
-} eel_string_context_state;
+ void **memRegion;
+ char *type;
+} eel_builtin_memRegion;
#define MAX_CMD_LEN 8192
#define HISTORY_COUNT 15000
#include "cpthread.h"
@@ -141,14 +141,7 @@ typedef struct
} abstractThreads;
typedef struct
{
- uint32_t numberOfThreads;
- uint32_t threadMap[1024];
- abstractThreads *codePtrThreadSink[1024];
pthread_mutex_t globalLocker;
- uint32_t numberOfConvolver;
- uint32_t *convolverMap;
- uint32_t *convolverType;
- void **convolverSink;
const char *(*func_check)(const char *fn_name, void *user); // return error message if not permitted
void *func_check_user;
float **varTable_Values;
@@ -182,7 +175,7 @@ typedef struct
codeHandleType *tmpCodeHandle;
float ram_state[NSEEL_RAM_ITEMSPERBLOCK];
void *caller_this;
- eel_string_context_state *m_string_context;
+ eel_builtin_memRegion *region_context;
char printfbuf[20000];
} compileContext;
void *NSEEL_PProc_RAM(void *data, int32_t data_size, compileContext *ctx);
@@ -246,6 +239,7 @@ opcodeRec *nseel_translate(compileContext *ctx, const char *tmp, size_t tmplen);
#define __NSEEL_RAMAlloc(pblocks, w) (pblocks + w)
float * NSEEL_CGEN_CALL __NSEEL_RAM_MemSet(float *blocks,float *dest, float *v, float *lenptr);
float * NSEEL_CGEN_CALL __NSEEL_RAM_MemCpy(float *blocks,float *dest, float *src, float *lenptr);
+float *dataSectionToRamDisk(void *opaque, size_t len);
extern float NSEEL_CGEN_CALL nseel_int_rand(float amplitude);
#ifdef __cplusplus
}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel.h
index c80d157b..5af07826 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel.h
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/ns-eel.h
@@ -40,7 +40,7 @@ typedef uintptr_t UINT_PTR;
#ifndef min
#define min(x,y) ((x)<(y)?(x):(y))
#endif
-#if !defined(max)
+#ifndef max
#define max(x,y) ((x)<(y)?(y):(x))
#endif
#ifndef _WIN32
@@ -73,7 +73,7 @@ void NSEEL_start(); // Init global variables
void NSEEL_quit(); // Delete global variables
int32_t *NSEEL_getstats(); // returns a pointer to 5 ints... source bytes, static code bytes, call code bytes, data bytes, number of code handles
void NSEEL_VM_freevars(NSEEL_VMCTX _ctx);
-void NSEEL_init_string(NSEEL_VMCTX ctx);
+void NSEEL_init_memRegion(NSEEL_VMCTX ctx);
NSEEL_VMCTX NSEEL_VM_alloc(); // return a handle
void NSEEL_VM_free(NSEEL_VMCTX ctx); // free when done with a VM and ALL of its code have been freed, as well
// validateFunc can return error message if not permitted
@@ -108,7 +108,6 @@ int32_t *NSEEL_code_getstats(NSEEL_CODEHANDLE code); // 4 ints...source bytes, s
#include
#define NSEEL_NATIVE_FLT_MAX_INT (1 << FLT_MANT_DIG) // Next value will no longer be accurately represented
#define NSEEL_MAX_FUNCTION_SIZE_FOR_INLINE 2048
-#define NSEEL_RAM_ITEMSPERBLOCK_LOG2 24 // How many float precision floating point items per block
#define NSEEL_RAM_ITEMSPERBLOCK NSEEL_NATIVE_FLT_MAX_INT // Must be smaller or equal than max floating pointing representable integer
#define EEL_BC_TYPE int32_t
#ifdef CUSTOM_CMD
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c
index 6438f893..7f1a978e 100644
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c
@@ -26,6 +26,10 @@
#include
#include "eelCommon.h"
#include "glue_port.h"
+#include
+#include "eel_matrix.h"
+#include "numericSys/FFTConvolver.h"
+#include "numericSys/HPFloat/xpre.h"
static void lstrcpyn_safe(char *o, const char *in, int32_t count)
{
if (count > 0)
@@ -132,6 +136,11 @@ struct opcodeRec
// OPCODETYPE_FUNC* with fntype=FUNCTYPE_EELFUNC
const char *relname;
};
+float *dataSectionToRamDisk(void *opaque, size_t len)
+{
+ compileContext *c = (compileContext*)opaque;
+ return c->ram_state + (NSEEL_RAM_ITEMSPERBLOCK - len);
+}
static void *newTmpBlock(compileContext *ctx, int32_t size)
{
const int32_t align = 8;
@@ -535,7 +544,7 @@ void discreteHartleyTransformFloat(float *A, const int32_t nPoints, const float
theta_inc >>= 1;
}
}
-#define M_PIDouble 3.1415926535897932384626433832795f
+#define M_PIDouble 3.1415926535897932384626433832795
void getAsymmetricWindow(float *analysisWnd, float *synthesisWnd, int32_t k, int32_t m, float freq_temporal)
{
int32_t i;
@@ -546,15 +555,77 @@ void getAsymmetricWindow(float *analysisWnd, float *synthesisWnd, int32_t k, int
freq_temporal = 1.8f;
int32_t n = ((k - m) << 1) + 2;
for (i = 0; i < k - m; ++i)
- analysisWnd[i] = (float)pow(sqrt(0.5f * (1.0f - cos(2.0f * M_PIDouble * (i + 1.0f) / (float)n))), freq_temporal);
+ analysisWnd[i] = (float)pow(sqrt(0.5 * (1.0 - cos(2.0 * M_PIDouble * (i + 1.0) / (double)n))), freq_temporal);
n = (m << 1) + 2;
if (freq_temporal > 1.5f)
freq_temporal = 1.5f;
for (i = k - m; i < k; ++i)
- analysisWnd[i] = (float)pow(sqrt(0.5f * (1.0f - cos(2.0f * M_PIDouble * ((m + i - (k - m)) + 1.0f) / (float)n))), freq_temporal);
+ analysisWnd[i] = (float)pow(sqrt(0.5 * (1.0 - cos(2.0 * M_PIDouble * ((m + i - (k - m)) + 1.0) / (double)n))), freq_temporal);
n = m << 1;
for (i = k - (m << 1); i < k; ++i)
- synthesisWnd[i] = (float)(0.5f * (1.0f - cos(2.0f * M_PIDouble * (float)(i - (k - (m << 1))) / (float)n))) / analysisWnd[i];
+ synthesisWnd[i - (k - (m << 1))] = (float)(0.5 * (1.0 - cos(2.0 * M_PIDouble * (double)(i - (k - (m << 1))) / (double)n))) / analysisWnd[i];
+}
+void getwnd(float *wnd, unsigned int m, unsigned int n, char *mode)
+{
+ unsigned int i;
+ double x;
+ if (!strcmp(mode, "hann"))
+ {
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (float)(0.5 - 0.5 * cos(2 * M_PIDouble * x));
+ }
+ }
+ else if (!strcmp(mode, "hamming"))
+ {
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (float)(0.54 - 0.46 * cos(2 * M_PIDouble * x));
+ }
+ }
+ else if (!strcmp(mode, "blackman"))
+ {
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (float)(0.42 - 0.5 * cos(2 * M_PIDouble * x) + 0.08 * cos(4 * M_PIDouble * x));
+ }
+ }
+ else if (!strcmp(mode, "flattop"))
+ {
+ double a0 = 0.21557895;
+ double a1 = 0.41663158;
+ double a2 = 0.277263158;
+ double a3 = 0.083578947;
+ double a4 = 0.006947368;
+ for (i = 0; i < m; i++)
+ {
+ x = i / (double)(n - 1);
+ wnd[i] = (float)(a0 - a1 * cos(2 * M_PIDouble * x) + a2 * cos(4 * M_PIDouble * x) - a3 * cos(6 * M_PIDouble * x) + a4 * cos(8 * M_PIDouble * x));
+ }
+ }
+}
+void genWnd(float *wnd, unsigned int N, char *type)
+{
+ unsigned int plus1 = N + 1;
+ unsigned int half;
+ unsigned int i;
+ if (plus1 % 2 == 0)
+ {
+ half = plus1 / 2;
+ getwnd(wnd, half, plus1, type);
+ for (i = 0; i < half - 1; i++)
+ wnd[i + half] = wnd[half - i - 1];
+ }
+ else
+ {
+ half = (plus1 + 1) / 2;
+ getwnd(wnd, half, plus1, type);
+ for (i = 0; i < half - 2; i++)
+ wnd[i + half] = wnd[half - i - 2];
+ }
}
void STFT_DynInit(int32_t *indexFw, float *analysisWnd)
{
@@ -589,7 +660,7 @@ void STFT_DynInit(int32_t *indexFw, float *analysisWnd)
getAsymmetricWindow(analysisWnd, synthesisWnd, indexFw[0], ovpSmps, indexFw[5] / (float)32767);
// Pre-shift window function
for (i = 0; i < indexFw[0] - indexFw[2]; i++)
- synthesisWnd[i] = synthesisWnd[i + indexFw[2]] * (1.0f / indexFw[0]) * 0.5f;
+ synthesisWnd[i] = synthesisWnd[i] * (1.0f / indexFw[0]) * 0.5f;
}
int32_t STFTCartesian(float *indexer, float *analysisWnd, float *ptr)
{
@@ -611,31 +682,7 @@ int32_t STFTCartesian(float *indexer, float *analysisWnd, float *ptr)
lR = mTempBuffer[i] + mTempBuffer[symIdx];
lI = mTempBuffer[i] - mTempBuffer[symIdx];
ptr[i << 1] = lR;
- ptr[(i << 1) + 1] = lI;
- }
- return indexFw[0] + 2;
-}
-int32_t STFTPolar(float *indexer, float *analysisWnd, float *ptr)
-{
- int32_t *indexFw = (int32_t*)indexer;
- float *mSineTab = analysisWnd + indexFw[0] * 2;
- float *mInput = mSineTab + indexFw[0];
- float *mTempBuffer = mInput + indexFw[0];
- uint32_t *bitRevTbl = (uint32_t*)(analysisWnd + (indexFw[0] * 6) + indexFw[3] + indexFw[3]);
- int32_t i, symIdx;
- for (i = 0; i < indexFw[0]; ++i)
- mTempBuffer[bitRevTbl[i]] = mInput[(i + indexFw[4]) & (indexFw[0] - 1)] * analysisWnd[i];
- discreteHartleyTransformFloat(mTempBuffer, indexFw[0], mSineTab);
- ptr[0] = fabsf(mTempBuffer[0] * 2.0f);
- ptr[1] = ((mTempBuffer[0] < 0.0f) ? M_PIDouble : 0.0f);
- float lR, lI;
- for (i = 1; i < ((indexFw[0] >> 1) + 1); i++)
- {
- symIdx = indexFw[0] - i;
- lR = mTempBuffer[i] + mTempBuffer[symIdx];
- lI = mTempBuffer[i] - mTempBuffer[symIdx];
- ptr[i << 1] = hypotf(lR, lI);
- ptr[(i << 1) + 1] = atan2f(lI, lR);
+ ptr[(i << 1) + 1] = -lI;
}
return indexFw[0] + 2;
}
@@ -654,40 +701,7 @@ int32_t STFTCartesianInverse(float *indexer, float *analysisWnd, float *ptr)
for (i = 1; i < ((indexFw[0] >> 1) + 1); i++)
{
lR = ptr[i << 1];
- lI = ptr[(i << 1) + 1];
- timeDomainOut[bitRevTbl[i]] = (lR + lI);
- timeDomainOut[bitRevTbl[indexFw[0] - i]] = (lR - lI);
- }
- discreteHartleyTransformFloat(timeDomainOut, indexFw[0], mSineTab);
- for (i = 0; i < indexFw[0] - indexFw[2]; i++)
- timeDomainOut[i] = timeDomainOut[i + indexFw[2]] * synthesisWnd[i];
- for (i = 0; i < indexFw[3]; ++i)
- {
- mOutputBuffer[i] = mOverlapStage2Ldash[i] + timeDomainOut[i];
- mOverlapStage2Ldash[i] = timeDomainOut[indexFw[3] + i];
- }
- return indexFw[3];
-}
-int32_t STFTPolarInverse(float *indexer, float *analysisWnd, float *ptr)
-{
- int32_t *indexFw = (int32_t*)indexer;
- float *synthesisWnd = analysisWnd + indexFw[0];
- float *mSineTab = synthesisWnd + indexFw[0];
- float *timeDomainOut = mSineTab + indexFw[0] * 3;
- float *mOutputBuffer = timeDomainOut + indexFw[0];
- float *mOverlapStage2Ldash = mOutputBuffer + indexFw[3];
- uint32_t *bitRevTbl = (uint32_t*)(analysisWnd + (indexFw[0] * 6) + indexFw[3] + indexFw[3]);
- int32_t i;
- float magnitude = ptr[0];
- float phase = ptr[1];
- float lR, lI;
- timeDomainOut[0] = magnitude * cosf(phase);
- for (i = 1; i < ((indexFw[0] >> 1) + 1); i++)
- {
- magnitude = ptr[i << 1];
- phase = ptr[(i << 1) + 1];
- lR = magnitude * cosf(phase);
- lI = magnitude * sinf(phase);
+ lI = -ptr[(i << 1) + 1];
timeDomainOut[bitRevTbl[i]] = (lR + lI);
timeDomainOut[bitRevTbl[indexFw[0] - i]] = (lR - lI);
}
@@ -715,6 +729,35 @@ static float NSEEL_CGEN_CALL stftInit(void *opaque, INT_PTR num_param, float **p
STFT_DynInit(indexFw, stftFloatStruct);
return (float)indexFw[3];
}
+void STFT_SetWnd(int32_t *indexFw, float *stftFloatStruct, float *desired_analysisWnd, float *desired_synthesisWnd)
+{
+ int32_t i;
+ float *synthesisWnd = stftFloatStruct + indexFw[0];
+ for (i = 0; i < indexFw[0]; i++)
+ stftFloatStruct[i] = desired_analysisWnd[i];
+ for (i = 0; i < indexFw[0] - indexFw[2]; i++)
+ synthesisWnd[i] = desired_synthesisWnd[i] * (1.0f / indexFw[0]) * 0.5f;
+}
+static float NSEEL_CGEN_CALL stftSetAsymWnd(void *opaque, INT_PTR num_param, float **parms)
+{
+ compileContext *c = (compileContext *)opaque;
+ float *blocks = c->ram_state;
+ float *start1 = parms[0];
+ int32_t offs1 = (int32_t)(*start1 + NSEEL_CLOSEFACTOR);
+ float *start2 = parms[1];
+ int32_t offs2 = (int32_t)(*start2 + NSEEL_CLOSEFACTOR);
+ float *start3 = parms[2];
+ int32_t offs3 = (int32_t)(*start3 + NSEEL_CLOSEFACTOR);
+ float *start4 = parms[3];
+ int32_t offs4 = (int32_t)(*start4 + NSEEL_CLOSEFACTOR);
+ float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ float *stftFloatStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
+ float *desired_analysisWnd = __NSEEL_RAMAlloc(blocks, (uint64_t)offs3);
+ float *desired_synthesisWnd = __NSEEL_RAMAlloc(blocks, (uint64_t)offs4);
+ int32_t *indexFw = (int32_t *)indexer;
+ STFT_SetWnd(indexFw, stftFloatStruct, desired_analysisWnd, desired_synthesisWnd);
+ return 0;
+}
static float NSEEL_CGEN_CALL stftGetWindowPower(void *opaque, INT_PTR num_param, float **parms)
{
compileContext *c = (compileContext*)opaque;
@@ -741,15 +784,11 @@ static float NSEEL_CGEN_CALL stftForward(void *opaque, INT_PTR num_param, float
int32_t offs2 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
float *stftFloatStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t cartesian = (int32_t)(*parms[3]);
int32_t *indexFw = (int32_t*)indexer;
float *mInput = stftFloatStruct + indexFw[0] * 3;
memcpy(&mInput[indexFw[4]], ptr, indexFw[3] * sizeof(float));
indexFw[4] = (indexFw[4] + indexFw[3]) & (indexFw[0] - 1);
- if (cartesian)
- return (float)STFTCartesian(indexer, stftFloatStruct, ptr);
- else
- return (float)STFTPolar(indexer, stftFloatStruct, ptr);
+ return (float)STFTCartesian(indexer, stftFloatStruct, ptr);
}
static float NSEEL_CGEN_CALL stftBackward(void *opaque, INT_PTR num_param, float **parms)
{
@@ -761,13 +800,9 @@ static float NSEEL_CGEN_CALL stftBackward(void *opaque, INT_PTR num_param, float
int32_t offs2 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
float *stftFloatStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t cartesian = (int32_t)(*parms[3]);
int32_t *indexFw = (int32_t*)indexer;
int32_t ret;
- if (cartesian)
- ret = STFTCartesianInverse(indexer, stftFloatStruct, ptr);
- else
- ret = STFTPolarInverse(indexer, stftFloatStruct, ptr);
+ ret = STFTCartesianInverse(indexer, stftFloatStruct, ptr);
memcpy(ptr, stftFloatStruct + indexFw[0] * 6, indexFw[3] * sizeof(float));
return (float)ret;
}
@@ -794,6 +829,391 @@ static float NSEEL_CGEN_CALL stftCheckMemoryRequirement(void *opaque, INT_PTR nu
int32_t analyOv = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
return (float)STFT_DynConstructor(indexer, fftlen, analyOv, *parms[3]);
}
+static inline double ipowp(double x, long n)
+{
+ assert(n >= 0);
+ double z = 1.0;
+ while (n != 0)
+ {
+ if ((n & 1) != 0)
+ z *= x;
+ n >>= 1;
+ x *= x;
+ }
+ return z;
+}
+static inline void compute_transition_param(double *k, double *q, double transition)
+{
+ assert(transition > 0);
+ assert(transition < 0.5);
+ *k = tan((1 - transition * 2) * M_PIDouble / 4);
+ *k *= *k;
+ assert(*k < 1);
+ assert(*k > 0);
+ double kksqrt = pow(1.0 - *k * *k, 0.25);
+ const double e = 0.5 * (1 - kksqrt) / (1 + kksqrt);
+ const double e2 = e * e;
+ const double e4 = e2 * e2;
+ *q = e * (1 + e4 * (2 + e4 * (15 + 150 * e4)));
+ assert(*q > 0);
+}
+static inline double compute_acc_num(double q, int order, int c)
+{
+ assert(c >= 1);
+ assert(c < order * 2);
+ int i = 0;
+ int j = 1;
+ double acc = 0;
+ double q_ii1;
+ do
+ {
+ q_ii1 = ipowp(q, i * (i + 1));
+ q_ii1 *= sin((i * 2 + 1) * c * M_PIDouble / order) * j;
+ acc += q_ii1;
+ j = -j;
+ ++i;
+ } while (fabs(q_ii1) > 1e-100);
+ return acc;
+}
+static inline double compute_acc_den(double q, int order, int c)
+{
+ assert(c >= 1);
+ assert(c < order * 2);
+ int i = 1;
+ int j = -1;
+ double acc = 0;
+ double q_i2;
+ do
+ {
+ q_i2 = ipowp(q, i * i);
+ q_i2 *= cos(i * 2 * c * M_PIDouble / order) * j;
+ acc += q_i2;
+ j = -j;
+ ++i;
+ } while (fabs(q_i2) > 1e-100);
+ return acc;
+}
+static inline double compute_coef(int index, double k, double q, int order)
+{
+ assert(index >= 0);
+ assert(index * 2 < order);
+ const int c = index + 1;
+ const double num = compute_acc_num(q, order, c) * pow(q, 0.25);
+ const double den = compute_acc_den(q, order, c) + 0.5;
+ const double ww = num / den;
+ const double wwsq = ww * ww;
+ const double x = sqrt((1 - wwsq * k) * (1 - wwsq / k)) / (1 + wwsq);
+ const double coef = (1 - x) / (1 + x);
+ return coef;
+}
+static inline void compute_coefs_spec_order_tbw(double coef_arr[], int nbr_coefs, double transition)
+{
+ assert(nbr_coefs > 0);
+ assert(transition > 0);
+ assert(transition < 0.5);
+ double k;
+ double q;
+ compute_transition_param(&k, &q, transition);
+ const int order = nbr_coefs * 2 + 1;
+ // Coefficient calculation
+ for (int index = 0; index < nbr_coefs; ++index)
+ coef_arr[index] = compute_coef(index, k, q, order);
+}
+static inline double IIR2thOrder(double *Xi, double *b, double z[2])
+{
+ double Yi = *b * *Xi + z[0];
+ z[0] = z[1];
+ z[1] = *b * Yi - *Xi;
+ return Yi;
+}
+typedef struct
+{
+ unsigned int stages;
+ double *path, *z;
+ double imOld;
+} IIRHilbert;
+static inline void ProcessIIRHilbert(IIRHilbert *hil, double Xi, double *re, double *im)
+{
+ double imTmp;
+ imTmp = *re = Xi;
+ for (unsigned int j = 0; j < hil->stages; j++)
+ {
+ imTmp = IIR2thOrder(&imTmp, &hil->path[j], &hil->z[2 * j]);
+ *re = IIR2thOrder(re, &hil->path[hil->stages + j], &hil->z[hil->stages * 2 + 2 * j]);
+ }
+ *im = hil->imOld;
+ hil->imOld = imTmp;
+}
+static float NSEEL_CGEN_CALL iirHilbertProcess(float *blocks, float *offptr, float *x, float *y)
+{
+ uint32_t offs1 = (uint32_t)(*offptr + NSEEL_CLOSEFACTOR);
+ IIRHilbert *hil = (IIRHilbert *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ uint32_t offs2 = (uint32_t)(*y + NSEEL_CLOSEFACTOR);
+ float *out = (float *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
+ double re, im;
+ ProcessIIRHilbert(hil, *x, &re, &im);
+ out[0] = re;
+ out[1] = im;
+ return 2;
+}
+static float NSEEL_CGEN_CALL iirHilbertInit(void *opaque, INT_PTR num_param, float **parms)
+{
+ compileContext *c = (compileContext *)opaque;
+ float *blocks = c->ram_state;
+ float *start1 = parms[0];
+ int32_t offs1 = (int32_t)(*start1 + NSEEL_CLOSEFACTOR);
+ IIRHilbert *hil = (IIRHilbert *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ unsigned int numStages = (unsigned int)(*parms[1] + NSEEL_CLOSEFACTOR);
+ float transition = *parms[2];
+ unsigned int numCoefs = numStages << 1;
+ size_t memSize = sizeof(IIRHilbert) + (numCoefs + (numStages << 2)) * sizeof(double);
+ hil->stages = numStages;
+ double *coefs = (double *)malloc(numCoefs * sizeof(double));
+ hil->path = (double*)(hil + 1);
+ hil->z = hil->path + numCoefs;
+ memset(hil->z, 0, (hil->stages << 2) * sizeof(double));
+ compute_coefs_spec_order_tbw(coefs, numCoefs, transition);
+ unsigned int i;
+ // Phase reference path coefficients
+ for (i = 1; i < numCoefs; i += 2)
+ hil->path[i >> 1] = coefs[i];
+ // +90 deg path coefficients
+ for (i = 0; i < numCoefs; i += 2)
+ hil->path[hil->stages + (i >> 1)] = coefs[i];
+ free(coefs);
+ hil->imOld = 0.0;
+ return (float)(1 + memSize / sizeof(float));
+}
+typedef struct
+{
+ float data;
+ float maximum, minimum;
+} node;
+typedef struct
+{
+ unsigned int capacity, top;
+ node *items;
+} stack;
+static inline void insertDat(stack *s2, float val)
+{
+ if (!s2->top)
+ {
+ s2->items[s2->top].data = val;
+ s2->items[s2->top].maximum = val;
+ s2->items[s2->top++].minimum = val;
+ }
+ else
+ {
+ s2->items[s2->top].data = val;
+ s2->items[s2->top].minimum = min(val, s2->items[s2->top - 1].minimum);
+ s2->items[s2->top++].maximum = max(val, s2->items[s2->top - 1].maximum);
+ }
+}
+static inline void removeDat(stack *s1, stack *s2)
+{
+ if (s1->top)
+ s1->top--;
+ else
+ {
+ while (s2->top)
+ {
+ insertDat(s1, s2->items[s2->top - 1].data);
+ s2->top--;
+ }
+ s1->top--;
+ }
+}
+typedef struct mmStk
+{
+ stack s1, s2;
+ unsigned int windowSize, cnt;
+ void(*process)(struct mmStk *stk, float, float *, float *);
+} runningMinMax;
+void ProcessStkMaxLater(runningMinMax *stk, float a, float *minV, float *maxV)
+{
+ removeDat(&stk->s1, &stk->s2);
+ insertDat(&stk->s2, a);
+ // the maximum of both stack will be the maximum of overall window
+ if (stk->s1.top)
+ {
+ *minV = min(stk->s1.items[stk->s1.top - 1].minimum, stk->s2.items[stk->s2.top - 1].minimum);
+ *maxV = max(stk->s1.items[stk->s1.top - 1].maximum, stk->s2.items[stk->s2.top - 1].maximum);
+ }
+ else
+ {
+ *minV = stk->s2.items[stk->s2.top - 1].minimum;
+ *maxV = stk->s2.items[stk->s2.top - 1].maximum;
+ }
+}
+void ProcessStkBeginning(runningMinMax *stk, float a, float *minV, float *maxV)
+{
+ stk->cnt++;
+ if (stk->cnt >= stk->windowSize)
+ stk->process = ProcessStkMaxLater;
+ insertDat(&stk->s2, a);
+ // the maximum of both stack will be the maximum of overall window
+ *minV = stk->s2.items[stk->s2.top - 1].minimum;
+ *maxV = stk->s2.items[stk->s2.top - 1].maximum;
+}
+static float NSEEL_CGEN_CALL movingMinMaxProcess(float *blocks, float *offptr, float *x, float *y)
+{
+ uint32_t offs1 = (uint32_t)(*offptr + NSEEL_CLOSEFACTOR);
+ runningMinMax *stk = (runningMinMax *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ uint32_t offs2 = (uint32_t)(*y + NSEEL_CLOSEFACTOR);
+ float *out = (float *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
+ float minV = 0, maxV = 0;
+ stk->process(stk, *x, &minV, &maxV);
+ out[0] = minV;
+ out[1] = maxV;
+ return 2;
+}
+static float NSEEL_CGEN_CALL movingMinMaxInit(float *blocks, float *offptr, float *parm1)
+{
+ uint32_t offs1 = (uint32_t)(*offptr + NSEEL_CLOSEFACTOR);
+ runningMinMax *stk = (runningMinMax *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ uint32_t windowSize = (uint32_t)(*parm1 + NSEEL_CLOSEFACTOR);
+ size_t memSize = sizeof(runningMinMax) + sizeof(node) * windowSize * 2;
+ stk->s1.top = 0;
+ stk->s1.capacity = windowSize;
+ stk->s2.top = 0;
+ stk->s2.capacity = windowSize;
+ stk->s1.items = (node*)(stk + 1);
+ stk->s2.items = (node*)(((char*)stk->s1.items) + sizeof(node) * windowSize);
+ stk->windowSize = windowSize;
+ stk->cnt = 0;
+ stk->process = ProcessStkBeginning;
+ return (float)(1 + memSize / sizeof(float));
+}
+#define ItemLess(a,b) ((a)<(b))
+#define ItemMean(a,b) (((a)+(b))/2)
+typedef struct
+{
+ float *data; //circular queue of values
+ int *pos; //index into `heap` for each value
+ int *heap; //max/median/min heap holding indexes into `data`.
+ int N; //allocated size.
+ int idx; //position in circular queue
+ int ct; //count of items in queue
+} runningMedian;
+#define minCt(m) (((m)->ct-1)/2) //count of items in minheap
+#define maxCt(m) (((m)->ct)/2) //count of items in maxheap
+//returns 1 if heap[i] < heap[j]
+static inline int mmless(runningMedian *m, int i, int j)
+{
+ return ItemLess(m->data[m->heap[i]], m->data[m->heap[j]]);
+}
+//swaps items i&j in heap, maintains indexes
+static inline int mmexchange(runningMedian *m, int i, int j)
+{
+ int t = m->heap[i];
+ m->heap[i] = m->heap[j];
+ m->heap[j] = t;
+ m->pos[m->heap[i]] = i;
+ m->pos[m->heap[j]] = j;
+ return 1;
+}
+//swaps items i&j if i 1 && i < minCt(m) && mmless(m, i + 1, i))
+ ++i;
+ if (!mmCmpExch(m, i, i / 2))
+ break;
+ }
+}
+//maintains maxheap property for all items below i/2. (negative indexes)
+static inline void maxSortDown(runningMedian *m, int i)
+{
+ for (; i >= -maxCt(m); i *= 2)
+ {
+ if (i<-1 && i > -maxCt(m) && mmless(m, i, i - 1))
+ --i;
+ if (!mmCmpExch(m, i / 2, i))
+ break;
+ }
+}
+//maintains minheap property for all items above i, including median
+//returns true if median changed
+static inline int minSortUp(runningMedian *m, int i)
+{
+ while (i > 0 && mmCmpExch(m, i, i / 2))
+ i /= 2;
+ return i == 0;
+}
+//maintains maxheap property for all items above i, including median
+//returns true if median changed
+static inline int maxSortUp(runningMedian *m, int i)
+{
+ while (i < 0 && mmCmpExch(m, i / 2, i))
+ i /= 2;
+ return i == 0;
+}
+//Inserts item, maintains median in O(lg nItems)
+float runningMedianInsert(runningMedian *m, float v)
+{
+ int isNew = (m->ct < m->N);
+ int p = m->pos[m->idx];
+ float old = m->data[m->idx];
+ m->data[m->idx] = v;
+ m->idx = (m->idx + 1) % m->N;
+ m->ct += isNew;
+ if (p > 0) //new item is in minHeap
+ {
+ if (!isNew && ItemLess(old, v))
+ minSortDown(m, p * 2);
+ else if (minSortUp(m, p))
+ maxSortDown(m, -1);
+ }
+ else if (p < 0) //new item is in maxheap
+ {
+ if (!isNew && ItemLess(v, old))
+ maxSortDown(m, p * 2);
+ else if (maxSortUp(m, p))
+ minSortDown(m, 1);
+ }
+ else //new item is at median
+ {
+ if (maxCt(m))
+ maxSortDown(m, -1);
+ if (minCt(m))
+ minSortDown(m, 1);
+ }
+ v = m->data[m->heap[0]];
+ if ((m->ct & 1) == 0)
+ v = ItemMean(v, m->data[m->heap[-1]]);
+ return v;
+}
+static float NSEEL_CGEN_CALL movingMedianProcess(float *blocks, float *offptr, float *x)
+{
+ uint32_t offs1 = (uint32_t)(*offptr + NSEEL_CLOSEFACTOR);
+ runningMedian *m = (runningMedian *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ return runningMedianInsert(m, *x);
+}
+static float NSEEL_CGEN_CALL movingMedianInit(float *blocks, float *offptr, float *parm1)
+{
+ uint32_t offs1 = (uint32_t)(*offptr + NSEEL_CLOSEFACTOR);
+ runningMedian *m = (runningMedian *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ uint32_t windowSize = (uint32_t)(*parm1 + NSEEL_CLOSEFACTOR);
+ size_t memSize = sizeof(runningMedian) + windowSize * (sizeof(float) + sizeof(int) * 2);
+ m->data = (float *)(m + 1);
+ m->pos = (int *)(m->data + windowSize);
+ m->heap = m->pos + windowSize + (windowSize / 2); //points to middle of storage.
+ m->N = windowSize;
+ m->ct = m->idx = 0;
+ while (windowSize--) //set up initial heap fill pattern: median,max,min,max,...
+ {
+ m->pos[windowSize] = ((windowSize + 1) / 2) * ((windowSize & 1) ? -1 : 1);
+ m->heap[m->pos[windowSize]] = windowSize;
+ }
+ return (float)(1 + memSize / sizeof(float));
+}
void runStateArburg(double *Z, double *b, double x, int n)
{
for (int j = 1; j < n; j++) // Update conditions
@@ -808,13 +1228,13 @@ double predictArburg(double *Z, double *a, int n)
Z[n - 1] = -a[n] * Yi;
return Yi; // Write to output
}
-void TrainArburg(char *bg, float *xn, unsigned int xLen)
+void TrainArburg(char *bg, float *xn, int positionStart, int positionEnd)
{
unsigned int i, j;
char getPredictionState = *bg;
unsigned int *flag = (unsigned int*)(bg + 1);
const unsigned int _mCoefficientsNumber = *flag;
- unsigned int lenM1 = xLen - 1;
+ int to = positionEnd + 1;
// Creates internal variables with desirable length
double *predictionCoefficients = (double*)(flag + 1);
@@ -836,12 +1256,12 @@ void TrainArburg(char *bg, float *xn, unsigned int xLen)
for (j = 0; j <= _mCoefficientsNumber; j++)
{
_c[j] = 0.0;
- for (i = 0; i < xLen - j; i++)
- _c[j] += xn[i] * xn[i + j];
+ for (i = 0; i <= positionEnd - j; i++)
+ _c[j] += xn[i + positionStart] * xn[i + positionStart + j];
}
unsigned int _iIterationCounter = 0;
predictionCoefficients[0] = 1.0;
- _g[0] = 2.0 * _c[0] - fabs(xn[0]) * fabs(xn[0]) - fabs(xn[lenM1]) * fabs(xn[lenM1]);
+ _g[0] = 2.0 * _c[0] - fabs(xn[0 + positionStart]) * fabs(xn[0 + positionStart]) - fabs(xn[positionEnd + positionStart]) * fabs(xn[positionEnd + positionStart]);
_g[1] = 2.0 * _c[1];
// the paper says r[1], error in paper?
_r[0] = 2.0 * _c[1];
@@ -850,13 +1270,16 @@ void TrainArburg(char *bg, float *xn, unsigned int xLen)
{
// Computes vector of reflection coefficients. For details see step 1 of algorithm on page 3 of the paper
double nominator = 0.0;
- double denominator = (double)FLT_EPSILON;
+ double denominator = ((double)FLT_EPSILON) * 100.0;
for (i = 0; i <= _iIterationCounter + 1; i++)
{
nominator += predictionCoefficients[i] * _g[(_iIterationCounter + 1) - i];
denominator += predictionCoefficients[i] * _g[i];
}
- reflectionCoefficient[_iIterationCounter] = -nominator / denominator;
+ if (fabs(nominator) < ((double)FLT_EPSILON) * 10.0 && fabs(denominator) < ((double)FLT_EPSILON) * 10.0)
+ reflectionCoefficient[_iIterationCounter] = -1.0 + FLT_EPSILON;
+ else
+ reflectionCoefficient[_iIterationCounter] = -nominator / denominator;
// Updates vector of prediction coefficients. For details see step 2 of algorithm on page 3 of the paper
memcpy(tmp, predictionCoefficients, (_mCoefficientsNumber + 1) * sizeof(double));
for (i = 0; i <= _iIterationCounter + 1; i++)
@@ -868,10 +1291,11 @@ void TrainArburg(char *bg, float *xn, unsigned int xLen)
{
memset(forwardState, 0, (_mCoefficientsNumber + 1) * sizeof(double));
memset(backwardState, 0, (_mCoefficientsNumber + 1) * sizeof(double));
- for (i = 0; i < xLen; i++)
+ int idx2 = to - 1 + positionStart;
+ for (int i = positionStart; i < to; i++)
{
runStateArburg(forwardState, predictionCoefficients, xn[i], _mCoefficientsNumber); // Forward
- runStateArburg(backwardState, predictionCoefficients, xn[lenM1 - i], _mCoefficientsNumber); // Backward
+ runStateArburg(backwardState, predictionCoefficients, xn[idx2 - i], _mCoefficientsNumber); // Backward
}
}
break;
@@ -879,22 +1303,22 @@ void TrainArburg(char *bg, float *xn, unsigned int xLen)
// Updates vector r. For details see step 5 of algorithm on page 3 of the paper
memcpy(tmp, _r, (_mCoefficientsNumber + 1) * sizeof(double));
for (i = 0; i <= _iIterationCounter - 1; i++)
- _r[i + 1] = tmp[i] - xn[i] * xn[_iIterationCounter] - xn[lenM1 - i] * xn[lenM1 - _iIterationCounter];
+ _r[i + 1] = tmp[i] - xn[i + positionStart] * xn[_iIterationCounter + positionStart] - xn[positionEnd - i + positionStart] * xn[positionEnd - _iIterationCounter + positionStart];
_r[0] = 2.0 * _c[_iIterationCounter + 1];
// Calculates vector deltaRAndAProduct. For details see step 6 of algorithm on page 3 of the paper
- unsigned int posEnd = lenM1 - _iIterationCounter;
- unsigned int _iIterationCounterA1 = _iIterationCounter + 1;
+ int posBegin = _iIterationCounter;
+ int posEnd = positionEnd - _iIterationCounter;
for (i = 0; i <= _iIterationCounter; i++)
{
double innerProduct1 = 0.0;
double innerProduct2 = 0.0;
for (j = 0; j <= _iIterationCounter; j++)
{
- innerProduct1 += xn[_iIterationCounter - j] * predictionCoefficients[j];
- innerProduct2 += xn[posEnd + j] * predictionCoefficients[j];
+ innerProduct1 += xn[posBegin - j + positionStart] * predictionCoefficients[j];
+ innerProduct2 += xn[posEnd + j + positionStart] * predictionCoefficients[j];
}
- _deltaRAndAProduct[i] = -xn[_iIterationCounter - i] * innerProduct1 - xn[posEnd + i] * innerProduct2;
+ _deltaRAndAProduct[i] = -xn[posBegin - i + positionStart] * innerProduct1 - xn[posEnd + i + positionStart] * innerProduct2;
}
// Updates vector g. For details see step 7 of algorithm on page 3 of the paper
memcpy(tmp, _g, (_mCoefficientsNumber + 2) * sizeof(double));
@@ -923,29 +1347,9 @@ static float NSEEL_CGEN_CALL arburgTrainModel(void *opaque, INT_PTR num_param, f
*burg = (char)(*parms[2] + NSEEL_CLOSEFACTOR);
unsigned int *flag = (unsigned int*)(burg + 1);
*flag = (unsigned int)(*parms[1] + NSEEL_CLOSEFACTOR);
- uint32_t xLen = (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- TrainArburg(burg, xn, xLen);
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL arburgGetPredictionReflectionCoeff(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- char *bg = (char*)__NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- int32_t offs1 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *pdC = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *rfC = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- unsigned int *flag = (unsigned int*)(bg + 1);
- const unsigned int _mCoefficientsNumber = *flag;
- double *predictionCoefficients = (double*)(flag + 1);
- double *reflectionCoefficient = predictionCoefficients + (_mCoefficientsNumber + 1);
- for (unsigned int i = 0; i < _mCoefficientsNumber + 1; i++)
- {
- pdC[i] = (float)predictionCoefficients[i];
- rfC[i] = (float)reflectionCoefficient[i];
- }
+ int32_t from = (int32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
+ int32_t to = (int32_t)(*parms[5] + NSEEL_CLOSEFACTOR);
+ TrainArburg(burg, xn, from, to);
return 0.0f;
}
static float NSEEL_CGEN_CALL arburgPredictBackward(float *blocks, float *start)
@@ -1195,7 +1599,7 @@ static float NSEEL_CGEN_CALL eel_max(float *blocks, float *start, float *length
float ma = ptr[0];
for (uint32_t i = 1; i < (uint32_t)(*length + NSEEL_CLOSEFACTOR); i++)
{
- if (ptr[i] > ma)
+ if (fabsf(ptr[i]) > fabsf(ma))
ma = ptr[i];
}
return ma;
@@ -1206,7 +1610,7 @@ static float NSEEL_CGEN_CALL eel_min(float *blocks, float *start, float *length
float mi = ptr[0];
for (uint32_t i = 1; i < (uint32_t)(*length + NSEEL_CLOSEFACTOR); i++)
{
- if (ptr[i] < mi)
+ if (fabsf(ptr[i]) < fabsf(mi))
mi = ptr[i];
}
return mi;
@@ -1312,7 +1716,7 @@ static float * NSEEL_CGEN_CALL eel_convolve_c(float *blocks, float *dest, float
WDL_fft_complexmul((WDL_FFT_COMPLEX*)destptr, (WDL_FFT_COMPLEX*)srcptr, (len / 2)&~1);
return dest;
}
-int32_t nseel_stringsegments_tobuf(char *bufOut, int32_t bufout_sz, eelStringSegmentRec *list) // call with NULL to calculate size, or non-null to generate to buffer (returning size used)
+static inline int32_t nseel_stringsegments_tobuf(char *bufOut, int32_t bufout_sz, eelStringSegmentRec *list) // call with NULL to calculate size, or non-null to generate to buffer (returning size used)
{
int32_t pos = 0;
while (list)
@@ -1328,98 +1732,165 @@ int32_t nseel_stringsegments_tobuf(char *bufOut, int32_t bufout_sz, eelStringSeg
}
return pos;
}
-void Initeel_string_context_state(eel_string_context_state *st)
+static inline void eelThread_start(abstractThreads *info)
{
- st->inuse = 0;
- st->slot = 2;
- st->map = (int32_t*)malloc(st->slot * sizeof(s_str));
- st->m_literal_strings = (s_str*)malloc(st->slot * sizeof(s_str));
- for (int32_t i = 0; i < st->slot; i++)
- {
- st->map[i] = 0;
- st->m_literal_strings[i] = 0;
- }
-}
-void Freeel_string_context_state(eel_string_context_state *st)
-{
- for (int32_t i = 0; i < st->slot; i++)
- s_str_destroy(&st->m_literal_strings[i]);
- free(st->map);
- free(st->m_literal_strings);
- st->slot = 0;
- st->inuse = 0;
+ // ensure worker is waiting
+ pthread_mutex_lock(&(info->work_mtx));
+ // set job information & state
+ info->state = EEL_WORKING;
+ // wake-up signal
+ pthread_cond_signal(&(info->work_cond));
+ pthread_mutex_unlock(&(info->work_mtx));
}
-int32_t arySearch(int32_t *array, int32_t N, int32_t x)
+static inline void eelThread_wait(abstractThreads *info)
{
- for (int32_t i = 0; i < N; i++)
+ while (1)
{
- if (array[i] == x)
- return i;
+ pthread_cond_wait(&(info->boss_cond), &(info->boss_mtx));
+ if (EEL_IDLE == info->state)
+ break;
}
- return -1;
}
-#define FLOIDX 20000
-void* GetStringForIndex(eel_string_context_state *st, float val, int32_t write)
+void* GetStringForIndex(eel_builtin_memRegion *st, float val, int32_t write)
{
- int32_t castedValue = (int32_t)(val + 0.5f);
- if (castedValue < FLOIDX)
- return 0;
- int32_t idx = arySearch(st->map, st->slot, castedValue);
- if (idx < 0)
- return 0;
+ int32_t idx = (int32_t)(val + 0.5f);
if (!write)
{
- s_str *tmp = &st->m_literal_strings[idx];
+ s_str *tmp = &st->memRegion[idx];
const char *s = s_str_c_str(tmp);
return (void*)s;
}
else
- return (void*)&st->m_literal_strings[idx];
+ return (void*)&st->memRegion[idx];
}
-int32_t AddString(eel_string_context_state *st, char *ns)
+static inline int32_t getEmptyRegion(eel_builtin_memRegion *st)
{
- const int32_t l = strlen(ns);
int32_t x;
- for (x = 0; x < st->inuse; x++)
- {
- s_str *tmp = &st->m_literal_strings[x];
- const char *s = s_str_c_str(tmp);
- if (strlen(s) == l && !strcmp(s, ns))
+ for (x = 0; x < st->slot; x++)
+ if (!st->memRegion[x])
break;
- }
- if (x < st->inuse)
- free(ns);
- else
+ if (st->inuse > (st->slot - 1))
{
- int32_t currentSlot = st->inuse;
- if (currentSlot > (st->slot - 1))
+ st->slot += 10;
+ st->memRegion = (void**)realloc(st->memRegion, st->slot * sizeof(void*));
+ st->memRegion[st->inuse] = 0;
+ st->type = (char*)realloc(st->type, st->slot * sizeof(char));
+ for (int32_t i = st->inuse; i < st->slot; i++)
{
- st->slot++;
- st->m_literal_strings = (s_str*)realloc(st->m_literal_strings, st->slot * sizeof(s_str));
- st->m_literal_strings[st->inuse] = 0;
- st->map = (int32_t*)realloc(st->map, st->slot * sizeof(int32_t));
- st->map[st->inuse] = 0;
+ st->memRegion[i] = 0;
+ st->type[i] = 0;
}
- st->m_literal_strings[st->inuse] = s_str_create_from_c_str(ns);
- st->map[st->inuse] = x + FLOIDX;
- st->inuse++;
+ }
+ st->inuse++;
+ return x;
+}
+void DeleteSlot(eel_builtin_memRegion *st, float val)
+{
+ int32_t idx = (int32_t)(val + 0.5f);
+ if (!st->memRegion[idx])
+ goto decrement;
+ if (st->type[idx] == 0)
+ s_str_destroy(&st->memRegion[idx]);
+ else if (st->type[idx] == 1)
+ {
+ FFTConvolver1x1 *conv = (FFTConvolver1x1 *)st->memRegion[idx];
+ FFTConvolver1x1Free(conv);
+ free(conv);
+ }
+ else if (st->type[idx] == 2)
+ {
+ FFTConvolver2x2 *conv = (FFTConvolver2x2 *)st->memRegion[idx];
+ FFTConvolver2x2Free(conv);
+ free(conv);
+ }
+ else if (st->type[idx] == 3)
+ {
+ FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2 *)st->memRegion[idx];
+ FFTConvolver2x4x2Free(conv);
+ free(conv);
+ }
+ else if (st->type[idx] == 4)
+ {
+ abstractThreads *ptr = (abstractThreads *)st->memRegion[idx];
+ // ensure the worker is waiting
+ if (ptr->state == EEL_WORKING)
+ eelThread_wait(ptr);
+ pthread_mutex_lock(&(ptr->work_mtx));
+ ptr->state = EEL_GET_OFF_FROM_WORK;
+ // wake-up signal
+ pthread_cond_signal(&(ptr->work_cond));
+ pthread_mutex_unlock(&(ptr->work_mtx));
+ // wait for thread to exit
+ pthread_join(ptr->threadID, NULL);
+ pthread_mutex_destroy(&(ptr->work_mtx));
+ pthread_cond_destroy(&(ptr->work_cond));
+ pthread_mutex_unlock(&(ptr->boss_mtx));
+ pthread_mutex_destroy(&(ptr->boss_mtx));
+ pthread_cond_destroy(&(ptr->boss_cond));
+ NSEEL_code_free(ptr->codePtr);
+ free(ptr);
+ }
+ else
+ free(st->memRegion[idx]);
+ st->memRegion[idx] = 0;
+decrement:
+ st->inuse--;
+}
+void FreeRegion_context(eel_builtin_memRegion *st)
+{
+ for (int32_t i = 0; i < st->slot; i++)
+ DeleteSlot(st, (float)i + 0.1f);
+ free(st->type);
+ free(st->memRegion);
+ st->slot = 0;
+ st->inuse = 0;
+}
+int32_t AddData(eel_builtin_memRegion *st, void *ns, char type)
+{
+ int32_t x = getEmptyRegion(st);
+ if (type == 0)
+ {
+ st->memRegion[x] = s_str_create_from_c_str((char *)ns);
free(ns);
}
- return x + FLOIDX;
+ else
+ st->memRegion[x] = ns;
+ st->type[x] = type;
+ return x;
}
static float addStringCallback(void *opaque, eelStringSegmentRec *list)
{
compileContext *c = (compileContext*)opaque;
- eel_string_context_state *_this = c->m_string_context;
// could probably do a faster implementation using AddRaw() etc but this should also be OK
int32_t sz = nseel_stringsegments_tobuf(NULL, 0, list);
char *ns = (char*)malloc(sz + 32);
memset(ns, 0, sz + 32);
sz = nseel_stringsegments_tobuf(ns, sz, list) + 1;
ns = (char*)realloc(ns, sz);
- int32_t id = AddString(_this, ns);
+ int32_t id = AddData(c->region_context, (void*)ns, 0);
return (float)id;
}
+static const xpr *xConstant[19] = { &xZero, &xOne, &xTwo, &xTen, &xPinf, &xMinf, &xNaN, &xPi, &xPi2, &xPi4, &xEe, &xSqrt2, &xLn2, &xLn10, &xLog2_e, &xLog2_10, &xLog10_e, &HPA_MIN, &HPA_MAX };
+static const char xVarName[19][10] = { "$hZero", "$hOne", "$hTwo", "$hTen", "$hPinf", "$hMinf", "$hNaN", "$hPi", "$hPi2", "$hPi4", "$hEe", "$hSqrt2", "$hLn2", "$hLn10", "$hLog2_e", "$hLog2_10", "$hLog10_e", "$HPA_MIN", "$HPA_MAX" };
+static inline void InitRegion_context(eel_builtin_memRegion *st)
+{
+ st->inuse = 0;
+ st->slot = 30;
+ st->type = (char *)malloc(st->slot * sizeof(char));
+ st->memRegion = (s_str *)malloc(st->slot * sizeof(s_str));
+ for (int32_t i = 0; i < st->slot; i++)
+ {
+ st->type[i] = 0;
+ st->memRegion[i] = 0;
+ }
+ for (int32_t i = 0; i < 19; i++)
+ {
+ xpr br = *xConstant[i];
+ void *ptr = malloc(sizeof(xpr));
+ memcpy(ptr, (void *)&br, sizeof(xpr));
+ int32_t id = AddData(st, ptr, 5);
+ }
+}
static int32_t eel_string_match(compileContext *c, const char *fmt, const char *msg, int32_t match_fmt_pos, int32_t ignorecase, const char *fmt_endptr, const char *msg_endptr, int32_t num_fmt_parms, float **fmt_parms)
{
// %d=12345
@@ -1514,7 +1985,7 @@ static int32_t eel_string_match(compileContext *c, const char *fmt, const char *
{
if (varOut == &vv) // %{#foo}c
{
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, vv, 1);
+ s_str *wr = (s_str*)GetStringForIndex(c->region_context, vv, 1);
if (wr)
s_str_destroy(wr);
*wr = s_str_create_from_c_str(msg);
@@ -1585,7 +2056,7 @@ static int32_t eel_string_match(compileContext *c, const char *fmt, const char *
{
if (fmt_char == 's')
{
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, *varOut, 1);
+ s_str *wr = (s_str*)GetStringForIndex(c->region_context, *varOut, 1);
if (wr)
s_str_destroy(wr);
if (wr)
@@ -1622,7 +2093,7 @@ static int32_t eel_string_match(compileContext *c, const char *fmt, const char *
lstrcpyn_safe(tmp, msg, min(len + 1, (int32_t)sizeof(tmp)));
if (varOut == &vv)
{
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, vv, 1);
+ s_str *wr = (s_str*)GetStringForIndex(c->region_context, vv, 1);
if (wr)
s_str_destroy(wr);
*wr = s_str_create_from_c_str(tmp);
@@ -1651,13 +2122,40 @@ static int32_t eel_string_match(compileContext *c, const char *fmt, const char *
}
}
}
+static float NSEEL_CGEN_CALL getCosineWindows(void *opaque, INT_PTR num_param, float **parms)
+{
+ compileContext *c = (compileContext *)opaque;
+ float *blocks = c->ram_state;
+ float *start1 = parms[0];
+ int32_t offs2 = (int32_t)(*start1 + NSEEL_CLOSEFACTOR);
+ float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
+ float *fmt_index = parms[2];
+ const char *fmt = (const char *)GetStringForIndex(c->region_context, *fmt_index, 0);
+ float *start2 = parms[1];
+ genWnd(indexer, (int32_t)(*start2 + NSEEL_CLOSEFACTOR), fmt);
+ return 0;
+}
+static float NSEEL_CGEN_CALL getAsymmetricCosine(void *opaque, INT_PTR num_param, float **parms)
+{
+ compileContext *c = (compileContext *)opaque;
+ float *blocks = c->ram_state;
+ uint32_t offs1 = (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
+ float *analysisWnd = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
+ uint32_t offs2 = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
+ float *synthesisWnd = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
+ int32_t fftlen = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
+ int32_t ovpSmps = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
+ float tf_res = *parms[4];
+ getAsymmetricWindow(analysisWnd, synthesisWnd, fftlen, ovpSmps, tf_res);
+ return 0;
+}
static float NSEEL_CGEN_CALL _eel_match(void *opaque, INT_PTR num_parms, float **parms)
{
if (num_parms >= 2)
{
compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- const char *msg = (const char*)GetStringForIndex(c->m_string_context, *parms[1], 0);
+ const char *fmt = (const char*)GetStringForIndex(c->region_context, *parms[0], 0);
+ const char *msg = (const char*)GetStringForIndex(c->region_context, *parms[1], 0);
if (fmt && msg)
return eel_string_match(c, fmt, msg, 0, 0, fmt + strlen(fmt), msg + strlen(msg), (int32_t)num_parms - 2, parms + 2) ? 1.0f : 0.0f;
}
@@ -1668,8 +2166,8 @@ static float NSEEL_CGEN_CALL _eel_matchi(void *opaque, INT_PTR num_parms, float
if (num_parms >= 2)
{
compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- const char *msg = (const char*)GetStringForIndex(c->m_string_context, *parms[1], 0);
+ const char *fmt = (const char*)GetStringForIndex(c->region_context, *parms[0], 0);
+ const char *msg = (const char*)GetStringForIndex(c->region_context, *parms[1], 0);
if (fmt && msg)
return eel_string_match(opaque, fmt, msg, 0, 1, fmt + strlen(fmt), msg + strlen(msg), (int32_t)num_parms - 2, parms + 2) ? 1.0f : 0.0f;
}
@@ -1687,7 +2185,7 @@ static int32_t eel_validate_format_specifier(const char *fmt_in, char *typeOut,
{
const char c = *fmt++;
if (fmtOut_sz < 2) return 0;
- if (c == 'f' || c == 'e' || c == 'E' || c == 'g' || c == 'G' || c == 'd' || c == 'u' || c == 'x' || c == 'X' || c == 'c' || c == 'C' || c == 's' || c == 'S' || c == 'i')
+ if (c == 'f' || c == 'F' || c == 'e' || c == 'E' || c == 'g' || c == 'G' || c == 'd' || c == 'u' || c == 'x' || c == 'X' || c == 'c' || c == 'C' || c == 's' || c == 'S' || c == 'i')
{
*typeOut = c;
fmtOut[0] = c;
@@ -1751,15 +2249,25 @@ int32_t eel_format_strings(void *opaque, const char *fmt, const char *fmt_end, c
float v = varptr ? (float)*varptr : 0.0f;
if (ct == 'x' || ct == 'X' || ct == 'd' || ct == 'u' || ct == 'i')
{
- stbsp_snprintf(op, 64, fs, (int32_t)(v));
+ stbsp_snprintf(op, 128, fs, (int32_t)(v));
}
else if (ct == 's' || ct == 'S')
{
compileContext *c = (compileContext*)opaque;
- const char *str = (const char*)GetStringForIndex(c->m_string_context, v, 0);
+ const char *str = (const char*)GetStringForIndex(c->region_context, v, 0);
const size_t maxl = (size_t)(buf + buf_sz - 2u - op);
stbsp_snprintf(op, maxl, fs, str ? str : "");
}
+ else if (ct == 'F')
+ {
+ compileContext *c = (compileContext*)opaque;
+ int32_t idx = (int32_t)(v + NSEEL_CLOSEFACTOR);
+ xpr *br = (xpr *)c->region_context->memRegion[idx];
+ char *str = xpr_asprint(*br, 1, 0, (XDIM * 48) / 10 - 2);
+ int maxl = strlen(str);
+ stbsp_snprintf(op, min(maxl + 1, 128), "%s", str ? str : "");
+ free(str);
+ }
else if (ct == 'c')
{
*op++ = (char)(int32_t)v;
@@ -1781,7 +2289,7 @@ int32_t eel_format_strings(void *opaque, const char *fmt, const char *fmt_end, c
*op = 0;
}
else
- stbsp_snprintf(op, 64, fs, v);
+ stbsp_snprintf(op, 128, fs, v);
while (*op) op++;
fmt += l;
}
@@ -1796,7 +2304,7 @@ float NSEEL_CGEN_CALL _eel_printf(void *opaque, INT_PTR num_param, float **parms
if (num_param > 0)
{
compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *(parms[0]), 0);
+ const char *fmt = (const char*)GetStringForIndex(c->region_context, *(parms[0]), 0);
if (fmt)
{
int32_t stringLength = strlen(fmt);
@@ -1825,10 +2333,10 @@ float NSEEL_CGEN_CALL _eel_sprintf(void *opaque, INT_PTR num_param, float **parm
if (num_param > 0)
{
compileContext *c = (compileContext*)opaque;
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, *(parms[0]), 1);
+ s_str *wr = (s_str*)GetStringForIndex(c->region_context, *(parms[0]), 1);
if (wr)
s_str_destroy(wr);
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *(parms[1]), 0);
+ const char *fmt = (const char*)GetStringForIndex(c->region_context, *(parms[1]), 0);
if (wr && fmt)
{
int32_t stringLength = strlen(fmt);
@@ -1882,8 +2390,8 @@ static float _eel_strcmp_int(const char *a, int32_t a_len, const char *b, int32_
static float NSEEL_CGEN_CALL _eel_strncmp(void *opaque, float *aa, float *bb, float *maxlen)
{
compileContext *c = (compileContext*)opaque;
- const char *a = (const char*)GetStringForIndex(c->m_string_context, *aa, 0);
- const char *b = (const char*)GetStringForIndex(c->m_string_context, *bb, 0);
+ const char *a = (const char*)GetStringForIndex(c->region_context, *aa, 0);
+ const char *b = (const char*)GetStringForIndex(c->region_context, *bb, 0);
if (!a || !b)
{
const char *badStr = "strncmp: bad specifier(s)";
@@ -1900,8 +2408,8 @@ static float NSEEL_CGEN_CALL _eel_strncmp(void *opaque, float *aa, float *bb, fl
static float NSEEL_CGEN_CALL _eel_strnicmp(void *opaque, float *aa, float *bb, float *maxlen)
{
compileContext *c = (compileContext*)opaque;
- const char *a = (const char*)GetStringForIndex(c->m_string_context, *aa, 0);
- const char *b = (const char*)GetStringForIndex(c->m_string_context, *bb, 0);
+ const char *a = (const char*)GetStringForIndex(c->region_context, *aa, 0);
+ const char *b = (const char*)GetStringForIndex(c->region_context, *bb, 0);
if (!a || !b)
{
const char *badStr = "strnicmp: bad specifier(s)";
@@ -1926,7 +2434,7 @@ static float NSEEL_CGEN_CALL _eel_stricmp(void *opaque, float *strOut, float *fm
static float NSEEL_CGEN_CALL _eel_strlen(void *opaque, float *fmt_index)
{
compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *fmt_index, 0);
+ const char *fmt = (const char*)GetStringForIndex(c->region_context, *fmt_index, 0);
if (fmt)
return (float)strlen(fmt);
return 0.0f;
@@ -1961,7 +2469,7 @@ static float NSEEL_CGEN_CALL _eel_cd(void *opaque, float *fmt_index)
if (opaque)
{
compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *fmt_index, 0);
+ const char *fmt = (const char*)GetStringForIndex(c->region_context, *fmt_index, 0);
if (fmt)
#ifdef _WIN32
return (float)_chdir(fmt);
@@ -1977,7 +2485,7 @@ static float NSEEL_CGEN_CALL _eel_eval(void *opaque, float *s)
NSEEL_CODEHANDLE ch = NULL;
if (r)
{
- const char *str = (const char*)GetStringForIndex(r->m_string_context, *s, 0);
+ const char *str = (const char*)GetStringForIndex(r->region_context, *s, 0);
if (!str)
{
const char *badStr = "eval() passed invalid string handle\n";
@@ -2009,7 +2517,7 @@ static float NSEEL_CGEN_CALL _eel_evalFile(void *opaque, float *s)
compileContext *r = (compileContext*)opaque;
if (r)
{
- const char *str = (const char*)GetStringForIndex(r->m_string_context, *s, 0);
+ const char *str = (const char*)GetStringForIndex(r->region_context, *s, 0);
if (!str)
{
const char *badStr = "eval() passed invalid string handle\n";
@@ -2059,10 +2567,10 @@ static float NSEEL_CGEN_CALL _eel_base64_encode(void *opaque, float *destination
if (opaque)
{
compileContext *c = (compileContext*)opaque;
- s_str *dest = (s_str*)GetStringForIndex(c->m_string_context, *destination, 1);
+ s_str *dest = (s_str*)GetStringForIndex(c->region_context, *destination, 1);
if (dest)
s_str_destroy(dest);
- s_str *srcClass = (s_str*)GetStringForIndex(c->m_string_context, *source, 1);
+ s_str *srcClass = (s_str*)GetStringForIndex(c->region_context, *source, 1);
size_t len = (size_t)(*maxlen + NSEEL_CLOSEFACTOR);
if (len > s_str_capacity(srcClass))
return -1;
@@ -2130,8 +2638,8 @@ static float NSEEL_CGEN_CALL _eel_base64_encodeBinaryToTextFile(void *opaque, fl
if (opaque)
{
compileContext *c = (compileContext*)opaque;
- const char *dest = (const char*)GetStringForIndex(c->m_string_context, *destination, 0);
- const char *src = (const char *)GetStringForIndex(c->m_string_context, *source, 0);
+ const char *dest = (const char*)GetStringForIndex(c->region_context, *destination, 0);
+ const char *src = (const char *)GetStringForIndex(c->region_context, *source, 0);
if (dest && src)
{
unsigned char *buffer = 0;
@@ -2172,10 +2680,10 @@ static float NSEEL_CGEN_CALL _eel_base64_decode(void *opaque, float *destination
if (opaque)
{
compileContext *c = (compileContext*)opaque;
- s_str *dest = (s_str*)GetStringForIndex(c->m_string_context, *destination, 1);
+ s_str *dest = (s_str*)GetStringForIndex(c->region_context, *destination, 1);
if (dest)
s_str_destroy(dest);
- s_str *srcClass = (s_str*)GetStringForIndex(c->m_string_context, *source, 1);
+ s_str *srcClass = (s_str*)GetStringForIndex(c->region_context, *source, 1);
size_t len = (size_t)(*maxlen + NSEEL_CLOSEFACTOR);
if (len > s_str_capacity(srcClass))
return -1;
@@ -2244,8 +2752,8 @@ static float NSEEL_CGEN_CALL _eel_base64_decodeBinaryToTextFile(void *opaque, fl
if (opaque)
{
compileContext *c = (compileContext*)opaque;
- const char *dest = (const char*)GetStringForIndex(c->m_string_context, *destination, 0);
- const char *src = (const char *)GetStringForIndex(c->m_string_context, *source, 0);
+ const char *dest = (const char*)GetStringForIndex(c->region_context, *destination, 0);
+ const char *src = (const char *)GetStringForIndex(c->region_context, *source, 0);
if (dest && src)
{
unsigned char *buffer = 0;
@@ -2281,12 +2789,12 @@ static float NSEEL_CGEN_CALL _eel_base64_decodeBinaryToTextFile(void *opaque, fl
}
return 0.0f;
}
-static float NSEEL_CGEN_CALL _eel_delete_all_strings(void *opaque, INT_PTR num_param, float **parms)
+static float NSEEL_CGEN_CALL _eel_resetSysMemRegion(void *opaque, INT_PTR num_param, float **parms)
{
compileContext *c = (compileContext*)opaque;
- eel_string_context_state *state = c->m_string_context;
- Freeel_string_context_state(state);
- Initeel_string_context_state(state);
+ eel_builtin_memRegion *state = c->region_context;
+ FreeRegion_context(state);
+ InitRegion_context(state);
return 0.0f;
}
int32_t get_float(char *val, float *F)
@@ -2334,7 +2842,7 @@ float* string2FloatArray(char *frArbitraryEqString, int32_t *elements)
static float NSEEL_CGEN_CALL _eel_importFloatArrayFromString(void *opaque, float *fn_index, float *pointer)
{
compileContext *c = (compileContext*)opaque;
- const char *FLTBuf = (const char*)GetStringForIndex(c->m_string_context, *fn_index, 0);
+ const char *FLTBuf = (const char*)GetStringForIndex(c->region_context, *fn_index, 0);
uint32_t offs1 = (uint32_t)(*pointer + NSEEL_CLOSEFACTOR);
float *userspaceFLT = __NSEEL_RAMAlloc(c->ram_state, offs1);
int32_t elements;
@@ -2754,7 +3262,7 @@ static float NSEEL_CGEN_CALL _eel_iirBandSplitterInit(void *opaque, INT_PTR num_
if (num_param > 9)
return -1;
size_t requireMemSize;
- void *ptr = 0;
+ void *ptr;
if (num_param == 3)
{
requireMemSize = sizeof(LinkwitzRileyCrossover);
@@ -2803,7 +3311,7 @@ static float NSEEL_CGEN_CALL _eel_iirBandSplitterInit(void *opaque, INT_PTR num_
init7BandsCrossover(bps, fs, *parms[2], *parms[3], *parms[4], *parms[5], *parms[6], *parms[7]);
ptr = bps;
}
- else if (num_param == 9)
+ else
{
requireMemSize = sizeof(EightBandsCrossover);
EightBandsCrossover *bps = (EightBandsCrossover*)malloc(requireMemSize);
@@ -2913,38 +3421,18 @@ static float NSEEL_CGEN_CALL _eel_iirBandSplitterProcess(void *opaque, INT_PTR n
}
return 1;
}
-#include "eel_matrix.h"
-#include "numericSys/FFTConvolver.h"
static float NSEEL_CGEN_CALL _eel_initfftconv1d(void *opaque, INT_PTR num_param, float **parms)
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- if (c->numberOfConvolver > 1024 - 1)
- return -1;
- uint32_t ranN;
- while (1)
- {
- ranN = (uint32_t)(nseel_int_rand(1.0f) * 1024.0);
- uint32_t counter = 0;
- for (uint32_t i = 0; i < c->numberOfConvolver; i++)
- {
- if (ranN == c->convolverMap[i])
- {
- counter++;
- break;
- }
- }
- if (!counter)
- break;
- }
- void *ptr = 0;
- uint32_t convType;
+ void *ptr;
+ char convType;
if (num_param == 3)
convType = 1;
else if (num_param == 4)
convType = 2;
else if (num_param == 6)
- convType = 4;
+ convType = 3;
else
return -2;
uint32_t latency = (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
@@ -2958,7 +3446,7 @@ static float NSEEL_CGEN_CALL _eel_initfftconv1d(void *opaque, INT_PTR num_param,
FFTConvolver1x1LoadImpulseResponse(conv, latency, impulseresponse, irLen);
ptr = (void*)conv;
}
- if (convType == 2)
+ else if (convType == 2)
{
uint32_t offs1 = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
uint32_t offs2 = (uint32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
@@ -2969,7 +3457,7 @@ static float NSEEL_CGEN_CALL _eel_initfftconv1d(void *opaque, INT_PTR num_param,
FFTConvolver2x2LoadImpulseResponse(conv, latency, leftImp, rightImp, irLen);
ptr = (void*)conv;
}
- if (convType == 4)
+ else
{
uint32_t offs1 = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
uint32_t offs2 = (uint32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
@@ -2984,88 +3472,16 @@ static float NSEEL_CGEN_CALL _eel_initfftconv1d(void *opaque, INT_PTR num_param,
FFTConvolver2x4x2LoadImpulseResponse(conv, latency, LL, LR, RL, RR, irLen);
ptr = (void*)conv;
}
- c->numberOfConvolver++;
- int32_t idx = c->numberOfConvolver - 1;
- if (idx)
- {
- c->convolverMap = (uint32_t*)realloc(c->convolverMap, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverType = (uint32_t*)realloc(c->convolverType, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverSink = (void**)realloc(c->convolverSink, c->numberOfConvolver * sizeof(void*));
- }
- else
- {
- c->convolverMap = (uint32_t*)malloc(c->numberOfConvolver * sizeof(uint32_t));
- c->convolverType = (uint32_t*)malloc(c->numberOfConvolver * sizeof(uint32_t));
- c->convolverSink = (void**)malloc(c->numberOfConvolver * sizeof(void*));
- }
- c->convolverMap[idx] = ranN;
- c->convolverType[idx] = convType;
- c->convolverSink[idx] = ptr;
- return (float)ranN;
-}
-static float NSEEL_CGEN_CALL _eel_deletefftconv1d(void *opaque, float *v)
-{
- compileContext *c = (compileContext*)opaque;
- if (!c->convolverMap)
- return -1;
- int32_t idx = arySearch(c->convolverMap, c->numberOfConvolver, (int32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return -2;
- void *ptr = c->convolverSink[idx];
- int32_t convType = c->convolverType[idx];
- if (convType == 1)
- {
- FFTConvolver1x1 *conv = (FFTConvolver1x1*)ptr;
- FFTConvolver1x1Free(conv);
- free(conv);
- }
- if (convType == 2)
- {
- FFTConvolver2x2 *conv = (FFTConvolver2x2*)ptr;
- FFTConvolver2x2Free(conv);
- free(conv);
- }
- if (convType == 4)
- {
- FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2*)ptr;
- FFTConvolver2x4x2Free(conv);
- free(conv);
- }
- for (uint32_t i = idx; i < c->numberOfConvolver - 1; i++)
- {
- c->convolverMap[i] = c->convolverMap[i + 1];
- c->convolverType[i] = c->convolverType[i + 1];
- c->convolverSink[i] = c->convolverSink[i + 1];
- }
- c->numberOfConvolver--;
- if (c->numberOfConvolver)
- {
- c->convolverMap = (uint32_t*)realloc(c->convolverMap, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverType = (uint32_t*)realloc(c->convolverType, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverSink = (void**)realloc(c->convolverSink, c->numberOfConvolver * sizeof(void*));
- }
- else
- {
- free(c->convolverMap);
- free(c->convolverType);
- free(c->convolverSink);
- c->convolverMap = 0;
- c->convolverType = 0;
- c->convolverSink = 0;
- }
- return 1;
+ int32_t id = AddData(c->region_context, ptr, convType);
+ return (float)id;
}
static float NSEEL_CGEN_CALL _eel_processfftconv1d(void *opaque, INT_PTR num_param, float **parms)
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- if (!c->convolverMap)
- return -1;
- int32_t idx = arySearch(c->convolverMap, c->numberOfConvolver, (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return 0;
- void *ptr = c->convolverSink[idx];
- int32_t convType = c->convolverType[idx];
+ int32_t idx = (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
+ void *ptr = c->region_context->memRegion[idx];
+ char convType = c->region_context->type[idx];
if (convType == 1)
{
FFTConvolver1x1 *conv = (FFTConvolver1x1*)ptr;
@@ -3082,7 +3498,7 @@ static float NSEEL_CGEN_CALL _eel_processfftconv1d(void *opaque, INT_PTR num_par
float *x2 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
FFTConvolver2x2Process(conv, x1, x2, x1, x2, conv->_blockSize);
}
- if (convType == 4)
+ if (convType == 3)
{
FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2*)ptr;
uint32_t offs1 = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
@@ -3093,7 +3509,6 @@ static float NSEEL_CGEN_CALL _eel_processfftconv1d(void *opaque, INT_PTR num_par
}
return 1;
}
-
void *task_user_created(void *arg)
{
abstractThreads *info = (abstractThreads *)arg;
@@ -3127,30 +3542,8 @@ void *task_user_created(void *arg)
pthread_exit(NULL);
return 0;
}
-void eelThread_start(compileContext *st, size_t task)
-{
- abstractThreads *info = st->codePtrThreadSink[task];
- // ensure worker is waiting
- pthread_mutex_lock(&(info->work_mtx));
- // set job information & state
- info->state = EEL_WORKING;
- // wake-up signal
- pthread_cond_signal(&(info->work_cond));
- pthread_mutex_unlock(&(info->work_mtx));
-}
-void eelThread_wait(compileContext *st, size_t task)
-{
- abstractThreads *info = st->codePtrThreadSink[task];
- while (1)
- {
- pthread_cond_wait(&(info->boss_cond), &(info->boss_mtx));
- if (EEL_IDLE == info->state)
- break;
- }
-}
-void thread_init(compileContext *st, int task)
+void thread_init(abstractThreads *info)
{
- abstractThreads *info = st->codePtrThreadSink[task];
info->state = EEL_SETUP;
pthread_cond_init(&(info->work_cond), NULL);
pthread_mutex_init(&(info->work_mtx), NULL);
@@ -3158,32 +3551,12 @@ void thread_init(compileContext *st, int task)
pthread_mutex_init(&(info->boss_mtx), NULL);
pthread_mutex_lock(&(info->boss_mtx));
pthread_create(&info->threadID, NULL, task_user_created, (void *)info);
- eelThread_wait(st, task);
-}
-void thread_delete(compileContext *st, int task)
-{
- abstractThreads *info = st->codePtrThreadSink[task];
- // ensure the worker is waiting
- if (info->state == EEL_WORKING)
- eelThread_wait(st, task);
- pthread_mutex_lock(&(info->work_mtx));
- info->state = EEL_GET_OFF_FROM_WORK;
- // wake-up signal
- pthread_cond_signal(&(info->work_cond));
- pthread_mutex_unlock(&(info->work_mtx));
- // wait for thread to exit
- pthread_join(info->threadID, NULL);
- pthread_mutex_destroy(&(info->work_mtx));
- pthread_cond_destroy(&(info->work_cond));
- pthread_mutex_unlock(&(info->boss_mtx));
- pthread_mutex_destroy(&(info->boss_mtx));
- pthread_cond_destroy(&(info->boss_cond));
- NSEEL_code_free(info->codePtr);
+ eelThread_wait(info);
}
static float NSEEL_CGEN_CALL _eel_initthread(void *opaque, float *stringID)
{
compileContext *c = (compileContext*)opaque;
- const char *codePtr = (const char*)GetStringForIndex(c->m_string_context, *stringID, 0);
+ const char *codePtr = (const char*)GetStringForIndex(c->region_context, *stringID, 0);
NSEEL_CODEHANDLE compiledCode = NSEEL_code_compile_ex(c, codePtr, 0, 1);
char *err;
char badStr[128];
@@ -3193,73 +3566,32 @@ static float NSEEL_CGEN_CALL _eel_initthread(void *opaque, float *stringID)
EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
return -2;
}
- float *blocks = c->ram_state;
- if (c->numberOfThreads > 1024 - 1)
- return -1;
- uint32_t ranN;
- while (1)
- {
- ranN = (uint32_t)(nseel_int_rand(1.0f) * 1024.0);
- uint32_t counter = 0;
- for (uint32_t i = 0; i < c->numberOfThreads; i++)
- {
- if (ranN == c->threadMap[i])
- {
- counter++;
- break;
- }
- }
- if (!counter)
- break;
- }
- c->numberOfThreads++;
- int32_t idx = c->numberOfThreads - 1;
- c->codePtrThreadSink[idx] = (abstractThreads*)malloc(sizeof(abstractThreads));
- thread_init(c, idx);
- c->codePtrThreadSink[idx]->codePtr = compiledCode;
- c->threadMap[idx] = ranN;
- return (float)ranN;
+ abstractThreads *pth = (abstractThreads*)malloc(sizeof(abstractThreads));
+ pth->codePtr = compiledCode;
+ thread_init(pth);
+ int32_t id = AddData(c->region_context, (void *)pth, 4);
+ return (float)id;
}
-static float NSEEL_CGEN_CALL _eel_deletethread(void *opaque, float *v)
+static float NSEEL_CGEN_CALL _eel_deleteSysVariable(void *opaque, float *v)
{
compileContext *c = (compileContext*)opaque;
- if (!c->threadMap)
- return -1;
- int32_t idx = arySearch(c->threadMap, c->numberOfThreads, (int32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return -2;
- thread_delete(c, idx);
- free(c->codePtrThreadSink[idx]);
- for (uint32_t i = idx; i < c->numberOfThreads - 1; i++)
- {
- c->threadMap[i] = c->threadMap[i + 1];
- c->codePtrThreadSink[i] = c->codePtrThreadSink[i + 1];
- }
- c->numberOfThreads--;
+ DeleteSlot(c->region_context, (int32_t)(*v + NSEEL_CLOSEFACTOR));
return 1;
}
static float NSEEL_CGEN_CALL _eel_createThread(void *opaque, float *v)
{
compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- if (!c->threadMap)
- return -1;
- int32_t idx = arySearch(c->threadMap, c->numberOfThreads, (uint32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return 0;
- eelThread_start(c, idx);
+ int32_t idx = (int32_t)(*v + NSEEL_CLOSEFACTOR);
+ abstractThreads *ptr = (abstractThreads *)c->region_context->memRegion[idx];
+ eelThread_start(ptr);
return 1;
}
static float NSEEL_CGEN_CALL _eel_joinThread(void *opaque, float *v)
{
compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- if (!c->threadMap)
- return -1;
- int32_t idx = arySearch(c->threadMap, c->numberOfThreads, (uint32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return 0;
- eelThread_wait(c, idx);
+ int32_t idx = (int32_t)(*v + NSEEL_CLOSEFACTOR);
+ abstractThreads *ptr = (abstractThreads *)c->region_context->memRegion[idx];
+ eelThread_wait(ptr);
return 1;
}
static float NSEEL_CGEN_CALL _eel_lockThread(void *opaque, float *v)
@@ -3274,7 +3606,208 @@ static float NSEEL_CGEN_CALL _eel_unlockThread(void *opaque, float *v)
pthread_mutex_unlock(&c->globalLocker);
return 1;
}
-
+// HPFloat
+#define HPFREPEATBLKEND \
+void *ptr = malloc(sizeof(xpr)); \
+memcpy(ptr, (void *)&br, sizeof(xpr)); \
+int32_t id = AddData(c->region_context, ptr, 5); \
+return id;
+static float NSEEL_CGEN_CALL _eel_createHPFloatFromString(void *opaque, float *v)
+{
+ compileContext *c = (compileContext *)opaque;
+ const char *decimal = (const char *)GetStringForIndex(c->region_context, *v, 0);
+ xpr br = atox(decimal);
+ HPFREPEATBLKEND
+}
+static float NSEEL_CGEN_CALL _eel_createHPFloatFromFloat32(void *opaque, float *flt)
+{
+ compileContext *c = (compileContext *)opaque;
+ xpr br = flttox(*flt);
+ void *ptr = malloc(sizeof(xpr));
+ memcpy(ptr, (void *)&br, sizeof(xpr));
+ int32_t id = AddData(c->region_context, ptr, 5);
+ return id;
+}
+static float NSEEL_CGEN_CALL _eel_createHPFloatToFloat32(void *opaque, float *v)
+{
+ compileContext *c = (compileContext *)opaque;
+ int32_t idx = (int32_t)(*v + NSEEL_CLOSEFACTOR);
+ xpr *br = (xpr *)c->region_context->memRegion[idx];
+ return xtoflt(*br);
+}
+static float NSEEL_CGEN_CALL _eel_createHPFloatToString(void *opaque, float *v)
+{
+ compileContext *c = (compileContext *)opaque;
+ int32_t idx = (int32_t)(*v + NSEEL_CLOSEFACTOR);
+ xpr *br = (xpr *)c->region_context->memRegion[idx];
+ char *str = xpr_asprint(*br, 1, 0, (XDIM * 48) / 10 - 2);
+ int32_t id = AddData(c->region_context, (void*)str, 0);
+ return id;
+}
+#define HPFREPEATBLKDYADIC \
+compileContext *c = (compileContext *)opaque; \
+xpr *x1 = (xpr *)c->region_context->memRegion[(int32_t)(*parms[0] + NSEEL_CLOSEFACTOR)]; \
+xpr *x2 = (xpr *)c->region_context->memRegion[(int32_t)(*parms[1] + NSEEL_CLOSEFACTOR)];
+#define HPFREPEATBLK1O \
+compileContext *c = (compileContext *)opaque; \
+xpr *x = (xpr *)c->region_context->memRegion[(int32_t)(*parms[0] + NSEEL_CLOSEFACTOR)];
+static float NSEEL_CGEN_CALL _eel_HPFAdd(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLKDYADIC
+ xpr br = xadd(*x1, *x2, 0);
+ HPFREPEATBLKEND
+}
+static float NSEEL_CGEN_CALL _eel_HPFSub(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLKDYADIC
+ xpr br = xadd(*x1, *x2, 1);
+ HPFREPEATBLKEND
+}
+static float NSEEL_CGEN_CALL _eel_HPFMul(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLKDYADIC
+ xpr br = xmul(*x1, *x2);
+ HPFREPEATBLKEND
+}
+static float NSEEL_CGEN_CALL _eel_HPFDiv(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLKDYADIC
+ xpr br = xdiv(*x1, *x2);
+ HPFREPEATBLKEND
+}
+// Math functions
+static float NSEEL_CGEN_CALL _eel_HPFfrexp(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLK1O
+ float *blocks = c->ram_state;
+ int p;
+ xpr br = xfrexp(*x, &p);
+ uint32_t offs2 = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
+ float *out = (float *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
+ void *ptr = malloc(sizeof(xpr));
+ memcpy(ptr, (void *)&br, sizeof(xpr));
+ out[0] = AddData(c->region_context, ptr, 5);
+ ptr = malloc(sizeof(xpr));
+ br = dbltox((double)p);
+ memcpy(ptr, (void *)&br, sizeof(xpr));
+ out[1] = AddData(c->region_context, ptr, 5);
+ return 0;
+}
+static float NSEEL_CGEN_CALL _eel_HPFqfmod(void *opaque, INT_PTR num_param, float **parms)
+{
+ compileContext *c = (compileContext *)opaque;
+ xpr *s = (xpr *)c->region_context->memRegion[(int32_t)(*parms[0] + NSEEL_CLOSEFACTOR)];
+ xpr *t = (xpr *)c->region_context->memRegion[(int32_t)(*parms[1] + NSEEL_CLOSEFACTOR)];
+ xpr *q = (xpr *)c->region_context->memRegion[(int32_t)(*parms[2] + NSEEL_CLOSEFACTOR)];
+ xpr br = xfmod(*s, *t, q);
+ HPFREPEATBLKEND
+}
+static float NSEEL_CGEN_CALL _eel_HPFfmod(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLKDYADIC
+ xpr q;
+ xpr br = xfmod(*x1, *x2, &q);
+ HPFREPEATBLKEND
+}
+static float NSEEL_CGEN_CALL _eel_HPFsfmod(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLK1O
+ float *blocks = c->ram_state;
+ int p;
+ xpr br = xsfmod(*x, &p);
+ uint32_t offs2 = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
+ float *out = (float *)__NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
+ void *ptr = malloc(sizeof(xpr));
+ memcpy(ptr, (void *)&br, sizeof(xpr));
+ out[0] = AddData(c->region_context, ptr, 5);
+ ptr = malloc(sizeof(xpr));
+ br = dbltox((double)p);
+ memcpy(ptr, (void *)&br, sizeof(xpr));
+ out[1] = AddData(c->region_context, ptr, 5);
+ return 0;
+}
+static float NSEEL_CGEN_CALL _eel_HPFMulPowOf2(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLK1O
+ xpr br = xpr2(*x, (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR));
+ HPFREPEATBLKEND
+}
+#define HPFLogicGen1O(fname, expr) \
+static float NSEEL_CGEN_CALL fname(void *opaque, INT_PTR num_param, float **parms) \
+{ \
+ HPFREPEATBLK1O \
+ int lg = expr; \
+ return lg; \
+}
+#define HPFLogicGenDYADIC(fname, expr) \
+static float NSEEL_CGEN_CALL fname(void *opaque, INT_PTR num_param, float **parms) \
+{ \
+ HPFREPEATBLKDYADIC \
+ int lg = expr; \
+ return lg; \
+}
+#define HPFGen(fname, expr) \
+static float NSEEL_CGEN_CALL fname(void *opaque, INT_PTR num_param, float **parms) \
+{ \
+ HPFREPEATBLK1O \
+ xpr br = expr(*x); \
+ HPFREPEATBLKEND \
+}
+HPFGen(_eel_HPFfrac, xfrac)
+HPFGen(_eel_HPFabs, xabs)
+HPFGen(_eel_HPFtrunc, xtrunc)
+HPFGen(_eel_HPFround, xround)
+HPFGen(_eel_HPFceil, xceil)
+HPFGen(_eel_HPFfloor, xfloor)
+HPFGen(_eel_HPFfix, xfix)
+HPFGen(_eel_HPFtan, xtan)
+HPFGen(_eel_HPFsin, xsin)
+HPFGen(_eel_HPFcos, xcos)
+HPFGen(_eel_HPFatan, xatan)
+HPFGen(_eel_HPFasin, xasin)
+HPFGen(_eel_HPFacos, xacos)
+HPFGen(_eel_HPFNegation, xneg)
+static float NSEEL_CGEN_CALL _eel_HPFatan2(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLKDYADIC
+ xpr br = xatan2(*x1, *x2);
+ HPFREPEATBLKEND
+}
+HPFGen(_eel_HPFsqrt, xsqrt)
+HPFGen(_eel_HPFexp, xexp)
+HPFGen(_eel_HPFexp2, xexp2)
+HPFGen(_eel_HPFexp10, xexp10)
+HPFGen(_eel_HPFlog, xlog)
+HPFGen(_eel_HPFlog2, xlog2)
+HPFGen(_eel_HPFlog10, xlog10)
+HPFGen(_eel_HPFtanh, xtanh)
+HPFGen(_eel_HPFsinh, xsinh)
+HPFGen(_eel_HPFcosh, xcosh)
+HPFGen(_eel_HPFatanh, xatanh)
+HPFGen(_eel_HPFasinh, xasinh)
+HPFGen(_eel_HPFacosh, xacosh)
+HPFGen(_eel_HPFclone, )
+static float NSEEL_CGEN_CALL _eel_HPFpow(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLKDYADIC
+ xpr br = xpow(*x1, *x2);
+ HPFREPEATBLKEND
+}
+static float NSEEL_CGEN_CALL _eel_HPFIntPow(void *opaque, INT_PTR num_param, float **parms)
+{
+ HPFREPEATBLK1O
+ xpr br = xpwr(*x, (int32_t)roundf(*parms[1]));
+ HPFREPEATBLKEND
+}
+HPFLogicGen1O(_eel_HPFiszero, xis0(x))
+HPFLogicGen1O(_eel_HPFisneg, x_neg(x))
+HPFLogicGen1O(_eel_HPFbinaryexp, x_exp(x))
+HPFLogicGenDYADIC(_eel_HPFeq, (xprcmp(x1, x2) == 0))
+HPFLogicGenDYADIC(_eel_HPFneq, (xprcmp(x1, x2) != 0))
+HPFLogicGenDYADIC(_eel_HPFle, (xprcmp(x1, x2) <= 0))
+HPFLogicGenDYADIC(_eel_HPFge, (xprcmp(x1, x2) >= 0))
+HPFLogicGenDYADIC(_eel_HPFgt, (xprcmp(x1, x2) > 0))
+HPFLogicGenDYADIC(_eel_HPFlt, (xprcmp(x1, x2) < 0))
static void channel_split(float *buffer, uint64_t num_frames, float **chan_buffers, uint32_t num_channels)
{
uint64_t i, samples = num_frames * num_channels;
@@ -3394,7 +3927,7 @@ static float NSEEL_CGEN_CALL _eel_flacDecodeFile(void *opaque, INT_PTR num_param
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- const char *filename = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
+ const char *filename = (const char*)GetStringForIndex(c->region_context, *parms[0], 0);
uint32_t channels, fs;
uint64_t frameCount;
float *signal = drflac_open_file_and_read_pcm_frames_f32(filename, &channels, &fs, &frameCount, 0);
@@ -3454,7 +3987,7 @@ static float NSEEL_CGEN_CALL _eel_flacDecodeMemory(void *opaque, INT_PTR num_par
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- const char *base64String = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
+ const char *base64String = (const char*)GetStringForIndex(c->region_context, *parms[0], 0);
size_t actualSize;
unsigned char *memoryBlk = base64_decode((const unsigned char*)base64String, strlen(base64String), &actualSize);
uint32_t channels, fs;
@@ -3517,7 +4050,7 @@ static float NSEEL_CGEN_CALL _eel_wavDecodeFile(void *opaque, INT_PTR num_param,
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- const char *filename = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
+ const char *filename = (const char*)GetStringForIndex(c->region_context, *parms[0], 0);
uint32_t channels, fs;
uint64_t frameCount;
float *signal = drwav_open_file_and_read_pcm_frames_f32(filename, &channels, &fs, &frameCount, 0);
@@ -3577,7 +4110,7 @@ static float NSEEL_CGEN_CALL _eel_wavDecodeMemory(void *opaque, INT_PTR num_para
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- const char *base64String = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
+ const char *base64String = (const char*)GetStringForIndex(c->region_context, *parms[0], 0);
size_t actualSize;
unsigned char *memoryBlk = base64_decode((const unsigned char*)base64String, strlen(base64String), &actualSize);
uint32_t channels, fs;
@@ -3846,7 +4379,7 @@ static float NSEEL_CGEN_CALL _eel_writeWavFile(void *opaque, INT_PTR num_param,
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- const char *filename = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
+ const char *filename = (const char*)GetStringForIndex(c->region_context, *parms[0], 0);
uint32_t channels = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
uint32_t fs = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
uint64_t frameCount = (uint64_t)(*parms[3] + NSEEL_CLOSEFACTOR);
@@ -3875,7 +4408,7 @@ static float NSEEL_CGEN_CALL _eel_writeWavMemory(void *opaque, INT_PTR num_param
{
compileContext *c = (compileContext*)opaque;
float *blocks = c->ram_state;
- s_str *dest = (s_str*)GetStringForIndex(c->m_string_context, *parms[0], 1);
+ s_str *dest = (s_str*)GetStringForIndex(c->region_context, *parms[0], 1);
uint32_t channels = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
uint32_t fs = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
uint64_t frameCount = (uint64_t)(*parms[3] + NSEEL_CLOSEFACTOR);
@@ -3921,7 +4454,7 @@ static float NSEEL_CGEN_CALL _eel_listSystemVariable(void *opaque, INT_PTR num_p
{
for (int j = 0; j < NSEEL_VARS_PER_BLOCK; j++)
{
- char *valid = GetStringForIndex(c->m_string_context, c->varTable_Values[i][j], 1);
+ char *valid = GetStringForIndex(c->region_context, c->varTable_Values[i][j], 1);
if (!valid)
strncpy(isString, "Is not string", 16);
else
@@ -4031,50 +4564,50 @@ redirect(roundf)
redirect(floorf)
redirect(ceilf)
static functionType fnTable1[] = {
- { "sin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sinf} },
- { "cos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_cosf} },
- { "tan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_tanf} },
- { "sqrt", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sqrtf}, },
- { "asin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_asinf}, },
- { "acos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_acosf}, },
- { "atan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_atanf}, },
- { "atan2", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_atan2f}, },
- { "sinh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sinhf} },
- { "cosh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_coshf} },
- { "tanh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_tanhf} },
- { "asinh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_asinhf}, },
- { "acosh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_acoshf}, },
- { "atanh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_atanhf}, },
- { "log", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_logf} },
- { "log10", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_log10f} },
- { "hypot", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_hypotf}, },
- { "pow", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_powf}, },
- { "exp", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_expf}, },
- { "abs", nseel_asm_abs,nseel_asm_abs_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(0) | BIF_WONTMAKEDENORMAL },
- { "sqr", nseel_asm_sqr,nseel_asm_sqr_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(1) },
- { "min", nseel_asm_min,nseel_asm_min_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_FPSTACKUSE(3) | BIF_WONTMAKEDENORMAL },
- { "max", nseel_asm_max,nseel_asm_max_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_FPSTACKUSE(3) | BIF_WONTMAKEDENORMAL },
- { "sign", nseel_asm_sign,nseel_asm_sign_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL, },
- { "rand", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&nseel_int_rand}, },
- { "round", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_roundf} },
- { "floor", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_floorf} },
- { "ceil", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_ceilf} },
- { "expint", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&expint} },
- { "expintFast",nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&expint_interpolation} },
- { "invsqrt",nseel_asm_1pdd,nseel_asm_1pdd_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(3), {(void**)&invsqrt} },
- { "invsqrtFast",nseel_asm_invsqrt,nseel_asm_invsqrt_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(3), },
- { "circshift",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&__NSEEL_circshift},NSEEL_PProc_RAM},
- { "convolve_c",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&eel_convolve_c},NSEEL_PProc_RAM},
- { "maxVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_max},NSEEL_PProc_RAM},
- { "minVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_min},NSEEL_PProc_RAM},
- { "meanVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_mean},NSEEL_PProc_RAM},
- { "medianVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_median},NSEEL_PProc_RAM},
- { "fft",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft},NSEEL_PProc_RAM},
- { "ifft",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft},NSEEL_PProc_RAM},
- { "fft_real",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft_real},NSEEL_PProc_RAM},
- { "ifft_real",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft_real},NSEEL_PProc_RAM},
- { "fft_permute",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft_permute},NSEEL_PProc_RAM},
- { "fft_ipermute",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft_permute},NSEEL_PProc_RAM},
+ {"sin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sinf} },
+ {"cos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_cosf} },
+ {"tan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_tanf} },
+ {"sqrt", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sqrtf}, },
+ {"asin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_asinf}, },
+ {"acos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_acosf}, },
+ {"atan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_atanf}, },
+ {"atan2", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_atan2f}, },
+ {"sinh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sinhf} },
+ {"cosh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_coshf} },
+ {"tanh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_tanhf} },
+ {"asinh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_asinhf}, },
+ {"acosh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_acoshf}, },
+ {"atanh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_atanhf}, },
+ {"log", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_logf} },
+ {"log10", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_log10f} },
+ {"hypot", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_hypotf}, },
+ {"pow", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_powf}, },
+ {"exp", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_expf}, },
+ {"abs", nseel_asm_abs,nseel_asm_abs_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(0) | BIF_WONTMAKEDENORMAL },
+ {"sqr", nseel_asm_sqr,nseel_asm_sqr_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(1) },
+ {"min", nseel_asm_min,nseel_asm_min_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_FPSTACKUSE(3) | BIF_WONTMAKEDENORMAL },
+ {"max", nseel_asm_max,nseel_asm_max_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_FPSTACKUSE(3) | BIF_WONTMAKEDENORMAL },
+ {"sign", nseel_asm_sign,nseel_asm_sign_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL, },
+ {"rand", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&nseel_int_rand}, },
+ {"round", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_roundf} },
+ {"floor", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_floorf} },
+ {"ceil", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_ceilf} },
+ {"expint", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&expint} },
+ {"expintFast",nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&expint_interpolation} },
+ {"invsqrt",nseel_asm_1pdd,nseel_asm_1pdd_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(3), {(void**)&invsqrt} },
+ {"invsqrtFast",nseel_asm_invsqrt,nseel_asm_invsqrt_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(3), },
+ {"circshift",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&__NSEEL_circshift},NSEEL_PProc_RAM},
+ {"convolve_c",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&eel_convolve_c},NSEEL_PProc_RAM},
+ {"maxVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_max},NSEEL_PProc_RAM},
+ {"minVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_min},NSEEL_PProc_RAM},
+ {"meanVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_mean},NSEEL_PProc_RAM},
+ {"medianVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_median},NSEEL_PProc_RAM},
+ {"fft",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft},NSEEL_PProc_RAM},
+ {"ifft",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft},NSEEL_PProc_RAM},
+ {"fft_real",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft_real},NSEEL_PProc_RAM},
+ {"ifft_real",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft_real},NSEEL_PProc_RAM},
+ {"fft_permute",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft_permute},NSEEL_PProc_RAM},
+ {"fft_ipermute",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft_permute},NSEEL_PProc_RAM},
{"memcpy",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&__NSEEL_RAM_MemCpy},NSEEL_PProc_RAM},
{"memset",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&__NSEEL_RAM_MemSet},NSEEL_PProc_RAM},
{"sleep",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK,{(void**)&_eel_sleep}},
@@ -4093,18 +4626,26 @@ static functionType fnTable1[] = {
{"strnicmp",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&_eel_strnicmp},NSEEL_PProc_THIS},
{"printf",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_printf},NSEEL_PProc_THIS},
{"sprintf",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_sprintf},NSEEL_PProc_THIS},
- {"resetStringContainers",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_delete_all_strings},NSEEL_PProc_THIS},
+ {"resetSysMemRegion",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_resetSysMemRegion},NSEEL_PProc_THIS},
{"importFLTFromStr",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&_eel_importFloatArrayFromString},NSEEL_PProc_THIS},
{"arburgCheckMemoryRequirement",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&arburgCheckMemoryRequirement},NSEEL_PProc_RAM},
- {"arburgTrainModel",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&arburgTrainModel},NSEEL_PProc_THIS},
- {"arburgGetPredictionReflectionCoeff",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&arburgGetPredictionReflectionCoeff},NSEEL_PProc_THIS},
+ {"arburgTrainModel",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&arburgTrainModel},NSEEL_PProc_THIS},
{"arburgPredictBackward",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&arburgPredictBackward},NSEEL_PProc_RAM},
{"arburgPredictForward",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&arburgPredictForward},NSEEL_PProc_RAM},
+ {"getCosineWindows",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&getCosineWindows},NSEEL_PProc_THIS},
+ {"getAsymmetricCosine",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&getAsymmetricCosine},NSEEL_PProc_THIS},
{"stftCheckMemoryRequirement",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftCheckMemoryRequirement},NSEEL_PProc_THIS},
{"stftInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftInit},NSEEL_PProc_THIS},
+ {"iirHilbertProcess",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void **)&iirHilbertProcess},NSEEL_PProc_RAM},
+ {"iirHilbertInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&iirHilbertInit},NSEEL_PProc_THIS},
+ {"movingMinMaxProcess",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void **)&movingMinMaxProcess},NSEEL_PProc_RAM},
+ {"movingMinMaxInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&movingMinMaxInit},NSEEL_PProc_RAM},
+ {"movingMedianProcess",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void **)&movingMedianProcess},NSEEL_PProc_RAM},
+ {"movingMedianInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&movingMedianInit},NSEEL_PProc_RAM},
{"stftGetWindowPower",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftGetWindowPower},NSEEL_PProc_THIS},
{"stftForward",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftForward},NSEEL_PProc_THIS},
{"stftBackward",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftBackward},NSEEL_PProc_THIS},
+ {"stftSetAsymWnd",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftSetAsymWnd},NSEEL_PProc_THIS},
{"InitPinkNoise",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&pinkNoiseInit},NSEEL_PProc_THIS},
{"GeneratePinkNoise",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&pinkNoiseGen},NSEEL_PProc_THIS},
{"InitPolyphaseFilterbank",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankInit},NSEEL_PProc_THIS},
@@ -4144,9 +4685,6 @@ static functionType fnTable1[] = {
{"IIRBandSplitterInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_iirBandSplitterInit},NSEEL_PProc_THIS},
{"IIRBandSplitterClearState",_asm_generic1parm_retd,_asm_generic1parm_retd_end, 1 | BIF_RETURNSONSTACK,{(void**)&_eel_iirBandSplitterClearState},NSEEL_PProc_RAM},
{"IIRBandSplitterProcess",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_iirBandSplitterProcess},NSEEL_PProc_THIS},
- {"Conv1DInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_initfftconv1d},NSEEL_PProc_THIS},
- {"Conv1DProcess",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_processfftconv1d},NSEEL_PProc_THIS},
- {"Conv1DFree",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_deletefftconv1d},NSEEL_PProc_THIS},
{"decodeFLACFromFile",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_flacDecodeFile},NSEEL_PProc_THIS},
{"decodeFLACFromMemory",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_flacDecodeMemory},NSEEL_PProc_THIS},
{"decodeWavFromFile",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_wavDecodeFile},NSEEL_PProc_THIS},
@@ -4160,17 +4698,70 @@ static functionType fnTable1[] = {
{"vectorizeMinus",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeMinus},NSEEL_PProc_THIS },
{"vectorizeMultiply",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeMultiply},NSEEL_PProc_THIS },
{"vectorizeDivide",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeDivide},NSEEL_PProc_THIS },
+ { "lerpAt",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_lerp},NSEEL_PProc_THIS },
{"ls",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_ls},NSEEL_PProc_THIS },
{"cd",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_cd},NSEEL_PProc_THIS },
{"eval",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_eval},NSEEL_PProc_THIS },
{"evalFile",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_evalFile},NSEEL_PProc_THIS },
+ {"Conv1DInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_initfftconv1d},NSEEL_PProc_THIS },
+ {"Conv1DProcess",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_processfftconv1d},NSEEL_PProc_THIS },
{"ThreadInit",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_initthread},NSEEL_PProc_THIS },
{"ThreadCreate",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_createThread},NSEEL_PProc_THIS },
{"ThreadJoin",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_joinThread},NSEEL_PProc_THIS },
- {"ThreadDelete",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_deletethread},NSEEL_PProc_THIS },
{"ThreadMutexLock",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_lockThread},NSEEL_PProc_THIS },
{"ThreadMutexUnlock",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_unlockThread},NSEEL_PProc_THIS },
- {"lerpAt",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_lerp},NSEEL_PProc_THIS },
+ {"xFloatS",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void **)&_eel_createHPFloatFromString},NSEEL_PProc_THIS },
+ {"xFloatF",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void **)&_eel_createHPFloatFromFloat32},NSEEL_PProc_THIS },
+ {"xF2f32",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void **)&_eel_createHPFloatToFloat32},NSEEL_PProc_THIS },
+ {"xF2str",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void **)&_eel_createHPFloatToString},NSEEL_PProc_THIS },
+ {"xAdd",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFAdd},NSEEL_PProc_THIS },
+ {"xSub",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFSub},NSEEL_PProc_THIS },
+ {"xMul",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFMul},NSEEL_PProc_THIS },
+ {"xDiv",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFDiv},NSEEL_PProc_THIS },
+ {"xfrexp",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFfrexp},NSEEL_PProc_THIS },
+ {"xqfmod",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFqfmod},NSEEL_PProc_THIS },
+ {"xfmod",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFfmod},NSEEL_PProc_THIS },
+ {"xsfmod",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFsfmod},NSEEL_PProc_THIS },
+ {"xMulPowOf2",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFMulPowOf2},NSEEL_PProc_THIS },
+ {"xfrac",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFfrac},NSEEL_PProc_THIS },
+ {"xabs",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFabs},NSEEL_PProc_THIS },
+ {"xtrunc",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFtrunc},NSEEL_PProc_THIS },
+ {"xround",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFround},NSEEL_PProc_THIS },
+ {"xceil",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFceil},NSEEL_PProc_THIS },
+ {"xfloor",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFfloor},NSEEL_PProc_THIS },
+ {"xfix",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFfix},NSEEL_PProc_THIS },
+ {"xtan",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFtan},NSEEL_PProc_THIS },
+ {"xsin",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFsin},NSEEL_PProc_THIS },
+ {"xcos",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFcos},NSEEL_PProc_THIS },
+ {"xatan",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFatan},NSEEL_PProc_THIS },
+ {"xasin",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFasin},NSEEL_PProc_THIS },
+ {"xacos",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFacos},NSEEL_PProc_THIS },
+ {"xNegation",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFNegation},NSEEL_PProc_THIS },
+ {"xatan2",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFatan2},NSEEL_PProc_THIS },
+ {"xsqrt",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFsqrt},NSEEL_PProc_THIS },
+ {"xexp",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFexp},NSEEL_PProc_THIS },
+ {"xexp2",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFexp2},NSEEL_PProc_THIS },
+ {"xexp10",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFexp10},NSEEL_PProc_THIS },
+ {"xlog",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFlog},NSEEL_PProc_THIS },
+ {"xlog2",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFlog2},NSEEL_PProc_THIS },
+ {"xlog10",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFlog10},NSEEL_PProc_THIS },
+ {"xtanh",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFtanh},NSEEL_PProc_THIS },
+ {"xsinh",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFsinh},NSEEL_PProc_THIS },
+ {"xcosh",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFcosh},NSEEL_PProc_THIS },
+ {"xatanh",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFatanh},NSEEL_PProc_THIS },
+ {"xasinh",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFasinh},NSEEL_PProc_THIS },
+ {"xacosh",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFacosh},NSEEL_PProc_THIS },
+ {"xclone",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFclone},NSEEL_PProc_THIS },
+ {"xpow",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFpow},NSEEL_PProc_THIS },
+ {"xintpow",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFIntPow},NSEEL_PProc_THIS },
+ {"xbinexp",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFbinaryexp},NSEEL_PProc_THIS },
+ {"xequal",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFeq},NSEEL_PProc_THIS },
+ {"xnotequal",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFneq},NSEEL_PProc_THIS },
+ {"xlessequal",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFle},NSEEL_PProc_THIS },
+ {"xgreaterequal",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFge},NSEEL_PProc_THIS },
+ {"xgreater",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFgt},NSEEL_PProc_THIS },
+ {"xless",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void **)&_eel_HPFlt},NSEEL_PProc_THIS },
+ {"DeleteSysVariable",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void **)&_eel_deleteSysVariable},NSEEL_PProc_THIS },
};
void printFunctions()
{
@@ -4181,9 +4772,17 @@ void printFunctions()
EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
}
}
-
+int XLITTLE_ENDIAN;
void NSEEL_start()
{
+ union
+ {
+ unsigned char cc[4];
+ unsigned short s[2];
+ unsigned long n;
+ } u;
+ u.n = 0x12345678;
+ XLITTLE_ENDIAN = (u.s[0] == 0x5678 && u.s[1] == 0x1234 && u.cc[0] == 0x78 && u.cc[1] == 0x56 && u.cc[2] == 0x34 && u.cc[3] == 0x12);
// Global memory
if (decompressedCoefficients)
free(decompressedCoefficients);
@@ -4618,9 +5217,7 @@ eelStringSegmentRec *nseel_createStringSegmentRec(compileContext *ctx, const cha
opcodeRec *nseel_eelMakeOpcodeFromStringSegments(compileContext *ctx, eelStringSegmentRec *rec)
{
if (ctx && ctx->onString)
- {
return nseel_createCompiledValue(ctx, ctx->onString(ctx->caller_this, rec));
- }
return NULL;
}
opcodeRec *nseel_createMoreParametersOpcode(compileContext *ctx, opcodeRec *code1, opcodeRec *code2)
@@ -5779,7 +6376,7 @@ unsigned char *compileCodeBlockWithRet(compileContext *ctx, opcodeRec *rec, int3
p += funcsz;
memcpy(p, &GLUE_RET, sizeof(GLUE_RET)); p += sizeof(GLUE_RET);
#ifdef __arm__
- //__clear_cache(newblock2, p);
+ __clear_cache(newblock2, p);
#endif
ctx->l_stats[2] += funcsz + 2;
return newblock2;
@@ -7187,7 +7784,7 @@ NSEEL_CODEHANDLE NSEEL_code_compile_ex(NSEEL_VMCTX _ctx, const char *_expression
ctx->l_stats[1] = size;
handle->code_size = (int32_t)(writeptr - (unsigned char *)handle->code);
#ifdef __arm__
- //__clear_cache(handle->code, writeptr);
+ __clear_cache(handle->code, writeptr);
#endif
}
handle->blocks = ctx->blocks_head;
@@ -7271,72 +7868,26 @@ void NSEEL_VM_freevars(NSEEL_VMCTX _ctx)
if (_ctx)
{
compileContext *ctx = (compileContext*)_ctx;
- memset(ctx->ram_state, 0, sizeof(ctx->ram_state));
free(ctx->varTable_Values);
free(ctx->varTable_Names);
ctx->varTable_Values = 0;
ctx->varTable_Names = 0;
ctx->varTable_numBlocks = 0;
- if (ctx->numberOfConvolver)
- {
- for (uint32_t i = 0; i < ctx->numberOfConvolver; i++)
- {
- void *ptr = ctx->convolverSink[i];
- int32_t convType = ctx->convolverType[i];
- if (convType == 1)
- {
- FFTConvolver1x1 *conv = (FFTConvolver1x1*)ptr;
- FFTConvolver1x1Free(conv);
- free(conv);
- }
- if (convType == 2)
- {
- FFTConvolver2x2 *conv = (FFTConvolver2x2*)ptr;
- FFTConvolver2x2Free(conv);
- free(conv);
- }
- if (convType == 4)
- {
- FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2*)ptr;
- FFTConvolver2x4x2Free(conv);
- free(conv);
- }
- }
- if (ctx->convolverMap)
- free(ctx->convolverMap);
- if (ctx->convolverType)
- free(ctx->convolverType);
- if (ctx->convolverSink)
- free(ctx->convolverSink);
- ctx->convolverMap = 0;
- ctx->convolverType = 0;
- ctx->convolverSink = 0;
- ctx->numberOfConvolver = 0;
- }
- if (ctx->numberOfThreads)
- {
- for (uint32_t i = 0; i < ctx->numberOfThreads; i++)
- {
- thread_delete(ctx, i);
- free(ctx->codePtrThreadSink[i]);
- }
- ctx->numberOfThreads = 0;
- }
- if (ctx->m_string_context)
+ if (ctx->region_context)
{
- Freeel_string_context_state(ctx->m_string_context);
- free(ctx->m_string_context);
- ctx->m_string_context = 0;
+ FreeRegion_context(ctx->region_context);
+ free(ctx->region_context);
+ ctx->region_context = 0;
}
}
}
-void NSEEL_init_string(NSEEL_VMCTX _ctx)
+void NSEEL_init_memRegion(NSEEL_VMCTX _ctx)
{
if (_ctx)
{
compileContext *ctx = (compileContext*)_ctx;
- ctx->m_string_context = (eel_string_context_state*)malloc(sizeof(eel_string_context_state));
- Initeel_string_context_state(ctx->m_string_context);
+ ctx->region_context = (eel_builtin_memRegion*)malloc(sizeof(eel_builtin_memRegion));
+ InitRegion_context(ctx->region_context);
}
}
NSEEL_VMCTX NSEEL_VM_alloc() // return a handle
@@ -7348,7 +7899,7 @@ NSEEL_VMCTX NSEEL_VM_alloc() // return a handle
ctx->caller_this = ctx;
ctx->scanner = ctx;
ctx->onString = addStringCallback;
- NSEEL_init_string((NSEEL_VMCTX)ctx);
+ NSEEL_init_memRegion((NSEEL_VMCTX)ctx);
}
return ctx;
}
@@ -7631,6 +8182,9 @@ opcodeRec *nseel_createFunctionByName(compileContext *ctx, const char *name, int
}
#include
//------------------------------------------------------------------------------
+#define GENCONSTANTIF_ELSE(idx) \
+else if (!tmplen ? !stricmp(tmp, xVarName[idx]) : (tmplen == strlen(xVarName[idx]) && !strnicmp(tmp, xVarName[idx], strlen(xVarName[idx])))) \
+return nseel_createCompiledValue(ctx, idx);
opcodeRec *nseel_translate(compileContext *ctx, const char *tmp, size_t tmplen) // tmplen 0 = null term
{
// this depends on the string being nul terminated eventually, tmplen is used more as a hint than anything else
@@ -7651,13 +8205,30 @@ opcodeRec *nseel_translate(compileContext *ctx, const char *tmp, size_t tmplen)
else if (!tmplen ? !stricmp(tmp, "$E") : (tmplen == 2 && !strnicmp(tmp, "$E", 2)))
return nseel_createCompiledValue(ctx, (float)2.71828182845904523536);
else if (!tmplen ? !stricmp(tmp, "$PI") : (tmplen == 3 && !strnicmp(tmp, "$PI", 3)))
- return nseel_createCompiledValue(ctx, (float)3.141592653589793238463);
+ return nseel_createCompiledValue(ctx, (float)M_PIDouble);
else if (!tmplen ? !stricmp(tmp, "$PHI") : (tmplen == 4 && !strnicmp(tmp, "$PHI", 4)))
return nseel_createCompiledValue(ctx, (float)1.618033988749894848205);
else if (!tmplen ? !stricmp(tmp, "$EPS") : (tmplen == 4 && !strnicmp(tmp, "$EPS", 4)))
return nseel_createCompiledValue(ctx, (float)FLT_EPSILON);
- else if (!tmplen ? !stricmp(tmp, "$DBL_MAX") : (tmplen == 4 && !strnicmp(tmp, "$DBL_MAX", 4)))
- return nseel_createCompiledValue(ctx, (float)FLT_MAX);
+ GENCONSTANTIF_ELSE(0)
+ GENCONSTANTIF_ELSE(1)
+ GENCONSTANTIF_ELSE(2)
+ GENCONSTANTIF_ELSE(3)
+ GENCONSTANTIF_ELSE(4)
+ GENCONSTANTIF_ELSE(5)
+ GENCONSTANTIF_ELSE(6)
+ GENCONSTANTIF_ELSE(7)
+ GENCONSTANTIF_ELSE(8)
+ GENCONSTANTIF_ELSE(9)
+ GENCONSTANTIF_ELSE(10)
+ GENCONSTANTIF_ELSE(11)
+ GENCONSTANTIF_ELSE(12)
+ GENCONSTANTIF_ELSE(13)
+ GENCONSTANTIF_ELSE(14)
+ GENCONSTANTIF_ELSE(15)
+ GENCONSTANTIF_ELSE(16)
+ GENCONSTANTIF_ELSE(17)
+ GENCONSTANTIF_ELSE(18)
else if (!tmplen ? !stricmp(tmp, "$MEMBLKLIMIT") : (tmplen == 12 && !strnicmp(tmp, "$MEMBLKLIMIT", 12)))
return nseel_createCompiledValue(ctx, (float)NSEEL_RAM_ITEMSPERBLOCK);
else if ((!tmplen || tmplen == 4) && tmp[1] == '\'' && tmp[2] && tmp[3] == '\'')
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c.bak b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c.bak
deleted file mode 100644
index 6ccf9b08..00000000
--- a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c.bak
+++ /dev/null
@@ -1,7687 +0,0 @@
-/*
- Expression Evaluator Library (NS-EEL) v2
- Copyright (C) 2004-2013 Cockos Incorporated
- Copyright (C) 1999-2003 Nullsoft, Inc.
- nseel-compiler.c
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "eelCommon.h"
-#include "glue_port.h"
-static void lstrcpyn_safe(char *o, const char *in, int32_t count)
-{
- if (count > 0)
- {
- while (--count > 0 && *in) *o++ = *in++;
- *o = 0;
- }
-}
-static void lstrcatn(char *o, const char *in, int32_t count)
-{
- if (count > 0)
- {
- while (*o) { if (--count < 1) return; o++; }
- while (--count > 0 && *in) *o++ = *in++;
- *o = 0;
- }
-}
-#define STB_SPRINTF_IMPLEMENTATION
-#include "stb_sprintf.h"
-static void snprintf_append(char *o, int32_t count, const char *format, ...)
-{
- if (count > 0)
- {
- va_list va;
- while (*o) { if (--count < 1) return; o++; }
- va_start(va, format);
- stbsp_vsnprintf(o, count, format, va);
- va_end(va);
- }
-}
-#define NSEEL_VARS_MALLOC_CHUNKSIZE 8
-#define RET_MINUS1_FAIL(x) return -1;
-#define MIN_COMPUTABLE_SIZE 32 // always use at least this big of a temp storage table (and reset the temp ptr when it goes past this boundary)
-#define COMPUTABLE_EXTRA_SPACE 16 // safety buffer, if EEL_VALIDATE_WORKTABLE_USE set, used for magic-value-checking
-/*
- P1 is rightmost parameter
- P2 is second rightmost, if any
- P3 is third rightmost, if any
- registers on x86 are (RAX etc on x86-64)
- P1(ret) EAX
- P2 EDI
- P3 ECX
- WTP RSI
- x86_64: r12 is a pointer to ram_state
- x86_64: r13 is a pointer to closenessfactor
- registers on PPC are:
- P1(ret) r3
- P2 r14
- P3 r15
- WTP r16 (r17 has the original value)
- r13 is a pointer to ram_state
- ppc uses f31 and f30 and others for certain constants
- */
- // used by //#eel-no-optimize:xxx, in 0
-#define OPTFLAG_NO_FPSTACK 2
-#define OPTFLAG_NO_INLINEFUNC 4
-#define MAX_SUB_NAMESPACES 32
-typedef struct
-{
- const char *namespacePathToThis;
- const char *subParmInfo[MAX_SUB_NAMESPACES];
-} namespaceInformation;
-static int32_t nseel_evallib_stats[5]; // source bytes, static code bytes, call code bytes, data bytes, segments
-int32_t *NSEEL_getstats()
-{
- return nseel_evallib_stats;
-}
-static int32_t findLineNumber(const char *exp, int32_t byteoffs)
-{
- int32_t lc = 0;
- while (byteoffs-- > 0 && *exp) if (*exp++ == '\n') lc++;
- return lc;
-}
-static void *__newBlock(llBlock **start, int32_t size);
-#define OPCODE_IS_TRIVIAL(x) ((x)->opcodeType <= OPCODETYPE_VARPTRPTR)
-enum {
- OPCODETYPE_DIRECTVALUE = 0,
- OPCODETYPE_DIRECTVALUE_TEMPSTRING, // like directvalue, but will generate a new tempstring value on generate
- OPCODETYPE_VALUE_FROM_NAMESPACENAME, // this.* or namespace.* are encoded this way
- OPCODETYPE_VARPTR,
- OPCODETYPE_VARPTRPTR,
- OPCODETYPE_FUNC1,
- OPCODETYPE_FUNC2,
- OPCODETYPE_FUNC3,
- OPCODETYPE_FUNCX,
- OPCODETYPE_MOREPARAMS,
- OPCODETYPE_INVALID,
-};
-struct opcodeRec
-{
- int32_t opcodeType;
- int32_t fntype;
- void *fn;
- union {
- struct opcodeRec *parms[3];
- struct {
- float directValue;
- float *valuePtr; // if direct value, valuePtr can be cached
- } dv;
- } parms;
- int32_t namespaceidx;
- // OPCODETYPE_VALUE_FROM_NAMESPACENAME (relname is either empty or blah)
- // OPCODETYPE_VARPTR if it represents a global variable, will be nonempty
- // OPCODETYPE_FUNC* with fntype=FUNCTYPE_EELFUNC
- const char *relname;
-};
-static void *newTmpBlock(compileContext *ctx, int32_t size)
-{
- const int32_t align = 8;
- const int32_t a1 = align - 1;
- char *p = (char*)__newBlock(&ctx->tmpblocks_head, size + a1);
- return p + ((align - (((INT_PTR)p)&a1))&a1);
-}
-static void *__newBlock_align(compileContext *ctx, int32_t size, int32_t align, int32_t isForCode)
-{
- const int32_t a1 = align - 1;
- char *p = (char*)__newBlock(
- (
- isForCode < 0 ? (isForCode == -2 ? &ctx->pblocks : &ctx->tmpblocks_head) :
- isForCode > 0 ? &ctx->blocks_head :
- &ctx->blocks_head_data), size + a1);
- return p + ((align - (((INT_PTR)p)&a1))&a1);
-}
-static opcodeRec *newOpCode(compileContext *ctx, const char *str, int32_t opType)
-{
- const size_t strszfull = str ? strlen(str) : 0;
- const size_t str_sz = min(NSEEL_MAX_VARIABLE_NAMELEN, strszfull);
- opcodeRec *rec = (opcodeRec*)__newBlock_align(ctx,
- (int32_t)(sizeof(opcodeRec) + (str_sz > 0 ? str_sz + 1 : 0)),
- 8, ctx->isSharedFunctions ? 0 : -1);
- if (rec)
- {
- memset(rec, 0, sizeof(*rec));
- rec->opcodeType = opType;
- if (str_sz > 0)
- {
- char *p = (char *)(rec + 1);
- memcpy(p, str, str_sz);
- p[str_sz] = 0;
- rec->relname = p;
- }
- else
- {
- rec->relname = "";
- }
- }
- return rec;
-}
-#define newCodeBlock(x,a) __newBlock_align(ctx,x,a,1)
-#define newDataBlock(x,a) __newBlock_align(ctx,x,a,0)
-#define newCtxDataBlock(x,a) __newBlock_align(ctx,x,a,-2)
-static void freeBlocks(llBlock **start);
-#ifndef DECL_ASMFUNC
-#define DECL_ASMFUNC(x) \
- void nseel_asm_##x(void); \
- void nseel_asm_##x##_end(void);
-void _asm_megabuf(void);
-void _asm_megabuf_end(void);
-#endif
-#define FUNCTIONTYPE_PARAMETERCOUNTMASK 0xff
-#define BIF_NPARAMS_MASK 0x7ffff00
-#define BIF_RETURNSONSTACK 0x0000100
-#define BIF_LASTPARMONSTACK 0x0000200
-#define BIF_RETURNSBOOL 0x0000400
-#define BIF_LASTPARM_ASBOOL 0x0000800
-// 0x00?0000 -- taken by FP stack flags
-#define BIF_TAKES_VARPARM 0x0400000
-#define BIF_TAKES_VARPARM_EX 0x0C00000 // this is like varparm but check count exactly
-#define BIF_WONTMAKEDENORMAL 0x0100000
-#define BIF_CLEARDENORMAL 0x0200000
-#if defined(GLUE_HAS_FXCH) && GLUE_MAX_FPSTACK_SIZE > 0
-#define BIF_SECONDLASTPARMST 0x0001000 // use with BIF_LASTPARMONSTACK only (last two parameters get passed on fp stack)
-#define BIF_LAZYPARMORDERING 0x0002000 // allow optimizer to avoid fxch when using BIF_TWOPARMSONFPSTACK_LAZY etc
-#define BIF_REVERSEFPORDER 0x0004000 // force a fxch (reverse order of last two parameters on fp stack, used by comparison functions)
-#ifndef BIF_FPSTACKUSE
-#define BIF_FPSTACKUSE(x) (((x)>=0&&(x)<8) ? ((7-(x))<<16):0)
-#endif
-#ifndef BIF_GETFPSTACKUSE
-#define BIF_GETFPSTACKUSE(x) (7 - (((x)>>16)&7))
-#endif
-#else
- // do not support fp stack use unless GLUE_HAS_FXCH and GLUE_MAX_FPSTACK_SIZE>0
-#define BIF_SECONDLASTPARMST 0
-#define BIF_LAZYPARMORDERING 0
-#define BIF_REVERSEFPORDER 0
-#define BIF_FPSTACKUSE(x) 0
-#define BIF_GETFPSTACKUSE(x) 0
-#endif
-#define BIF_TWOPARMSONFPSTACK (BIF_SECONDLASTPARMST|BIF_LASTPARMONSTACK)
-#define BIF_TWOPARMSONFPSTACK_LAZY (BIF_LAZYPARMORDERING|BIF_SECONDLASTPARMST|BIF_LASTPARMONSTACK)
-float NSEEL_CGEN_CALL nseel_int_rand(float f);
-#define FNPTR_HAS_CONDITIONAL_EXEC(op) \
- (op->fntype == FN_LOGICAL_AND || \
- op->fntype == FN_LOGICAL_OR || \
- op->fntype == FN_IF_ELSE || \
- op->fntype == FN_WHILE || \
- op->fntype == FN_LOOP)
-// Add custom functions
-static const unsigned char base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-/**
- * base64_encode - Base64 encode
- * @src: Data to be encoded
- * @len: Length of the data to be encoded
- * @out_len: Pointer to output length variable, or %NULL if not used
- * Returns: Allocated buffer of out_len bytes of encoded data,
- * or %NULL on failure
- *
- * Caller is responsible for freeing the returned buffer. Returned buffer is
- * nul terminated to make it easier to use as a C string. The nul terminator is
- * not included in out_len.
- */
-static unsigned char* base64_encode(const unsigned char *src, size_t len, size_t *out_len)
-{
- unsigned char *out, *pos;
- const unsigned char *end, *in;
- size_t olen;
- olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
- olen += olen / 72; /* line feeds */
- olen++; /* nul termination */
- if (olen < len)
- return NULL; /* integer overflow */
- out = (unsigned char*)malloc(olen);
- if (out == NULL)
- return NULL;
- end = src + len;
- in = src;
- pos = out;
- while (end - in >= 3) {
- *pos++ = base64_table[in[0] >> 2];
- *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
- *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)];
- *pos++ = base64_table[in[2] & 0x3f];
- in += 3;
- }
-
- if (end - in) {
- *pos++ = base64_table[in[0] >> 2];
- if (end - in == 1) {
- *pos++ = base64_table[(in[0] & 0x03) << 4];
- *pos++ = '=';
- }
- else {
- *pos++ = base64_table[((in[0] & 0x03) << 4) |
- (in[1] >> 4)];
- *pos++ = base64_table[(in[1] & 0x0f) << 2];
- }
- *pos++ = '=';
- }
- *pos = '\0';
- if (out_len)
- *out_len = pos - out;
- return out;
-}
-/**
- * base64_decode - Base64 decode
- * @src: Data to be decoded
- * @len: Length of the data to be decoded
- * @out_len: Pointer to output length variable
- * Returns: Allocated buffer of out_len bytes of decoded data,
- * or %NULL on failure
- *
- * Caller is responsible for freeing the returned buffer.
- */
-static unsigned char* base64_decode(const unsigned char *src, size_t len, size_t *out_len)
-{
- unsigned char dtable[256], *out, *pos, block[4], tmp;
- size_t i, count, olen;
- int32_t pad = 0;
-
- memset(dtable, 0x80, 256);
- for (i = 0; i < sizeof(base64_table) - 1; i++)
- dtable[base64_table[i]] = (unsigned char)i;
- dtable['='] = 0;
-
- count = 0;
- for (i = 0; i < len; i++) {
- if (dtable[src[i]] != 0x80)
- count++;
- }
-
- if (count == 0 || count % 4)
- return NULL;
-
- olen = count / 4 * 3;
- pos = out = malloc(olen);
- if (out == NULL)
- return NULL;
-
- count = 0;
- for (i = 0; i < len; i++) {
- tmp = dtable[src[i]];
- if (tmp == 0x80)
- continue;
-
- if (src[i] == '=')
- pad++;
- block[count] = tmp;
- count++;
- if (count == 4) {
- *pos++ = (block[0] << 2) | (block[1] >> 4);
- *pos++ = (block[1] << 4) | (block[2] >> 2);
- *pos++ = (block[2] << 6) | block[3];
- count = 0;
- if (pad) {
- if (pad == 1)
- pos--;
- else if (pad == 2)
- pos -= 2;
- else {
- /* Invalid padding */
- free(out);
- return NULL;
- }
- break;
- }
- }
- }
-
- *out_len = pos - out;
- return out;
-}
-#include
-#ifndef _WIN32
-#include
-#include
-#endif
-static float NSEEL_CGEN_CALL _eel_sleep(float amt)
-{
- if (amt >= 0.0f)
- {
-#ifdef _WIN32
- if (amt > 30000000.0) Sleep(30000000);
- else Sleep((DWORD)(amt + 0.5f));
-#else
- if (amt > 30000000.0) usleep(((useconds_t)30000000) * 1000);
- else usleep((useconds_t)(amt * 1000.0 + 0.5f));
-#endif
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_time(void *opaque)
-{
- return (float)time(NULL);
-}
-static float NSEEL_CGEN_CALL _eel_time_precise(void *opaque)
-{
-#ifdef _WIN32
- LARGE_INTEGER freq, now;
- QueryPerformanceFrequency(&freq);
- QueryPerformanceCounter(&now);
- return (float)now.QuadPart / (float)freq.QuadPart;
-#else
- struct timeval tm = { 0, };
- gettimeofday(&tm, NULL);
- return (float)tm.tv_sec + (float)tm.tv_usec * 0.000001;
-#endif
-}
-void discreteHartleyTransform(double *A, const int32_t nPoints, const double *sinTab)
-{
- int32_t i, j, n, n2, theta_inc, nptDiv2;
- double alpha, beta;
- for (i = 0; i < nPoints; i += 4)
- {
- const double x0 = A[i];
- const double x1 = A[i + 1];
- const double x2 = A[i + 2];
- const double x3 = A[i + 3];
- const double y0 = x0 + x1;
- const double y1 = x0 - x1;
- const double y2 = x2 + x3;
- const double y3 = x2 - x3;
- A[i] = y0 + y2;
- A[i + 2] = y0 - y2;
- A[i + 1] = y1 + y3;
- A[i + 3] = y1 - y3;
- }
- for (i = 0; i < nPoints; i += 8)
- {
- alpha = A[i];
- beta = A[i + 4];
- A[i] = alpha + beta;
- A[i + 4] = alpha - beta;
- alpha = A[i + 2];
- beta = A[i + 6];
- A[i + 2] = alpha + beta;
- A[i + 6] = alpha - beta;
- alpha = A[i + 1];
- const double beta1 = 0.70710678118654752440084436210485*(A[i + 5] + A[i + 7]);
- const double beta2 = 0.70710678118654752440084436210485*(A[i + 5] - A[i + 7]);
- A[i + 1] = alpha + beta1;
- A[i + 5] = alpha - beta1;
- alpha = A[i + 3];
- A[i + 3] = alpha + beta2;
- A[i + 7] = alpha - beta2;
- }
- n = 16;
- n2 = 8;
- theta_inc = nPoints >> 4;
- nptDiv2 = nPoints >> 2;
- while (n <= nPoints)
- {
- for (i = 0; i < nPoints; i += n)
- {
- int32_t theta = theta_inc;
- const int32_t n4 = n2 >> 1;
- alpha = A[i];
- beta = A[i + n2];
- A[i] = alpha + beta;
- A[i + n2] = alpha - beta;
- alpha = A[i + n4];
- beta = A[i + n2 + n4];
- A[i + n4] = alpha + beta;
- A[i + n2 + n4] = alpha - beta;
- for (j = 1; j < n4; j++)
- {
- double sinval = sinTab[theta];
- double cosval = sinTab[theta + nptDiv2];
- double alpha1 = A[i + j];
- double alpha2 = A[i - j + n2];
- double beta1 = A[i + j + n2] * cosval + A[i - j + n] * sinval;
- double beta2 = A[i + j + n2] * sinval - A[i - j + n] * cosval;
- theta += theta_inc;
- A[i + j] = alpha1 + beta1;
- A[i + j + n2] = alpha1 - beta1;
- A[i - j + n2] = alpha2 + beta2;
- A[i - j + n] = alpha2 - beta2;
- }
- }
- n <<= 1;
- n2 <<= 1;
- theta_inc >>= 1;
- }
-}
-void discreteHartleyTransformFloat(float *A, const int32_t nPoints, const float *sinTab)
-{
- int32_t i, j, n, n2, theta_inc, nptDiv2;
- float alpha, beta;
- for (i = 0; i < nPoints; i += 4)
- {
- const float x0 = A[i];
- const float x1 = A[i + 1];
- const float x2 = A[i + 2];
- const float x3 = A[i + 3];
- const float y0 = x0 + x1;
- const float y1 = x0 - x1;
- const float y2 = x2 + x3;
- const float y3 = x2 - x3;
- A[i] = y0 + y2;
- A[i + 2] = y0 - y2;
- A[i + 1] = y1 + y3;
- A[i + 3] = y1 - y3;
- }
- for (i = 0; i < nPoints; i += 8)
- {
- alpha = A[i];
- beta = A[i + 4];
- A[i] = alpha + beta;
- A[i + 4] = alpha - beta;
- alpha = A[i + 2];
- beta = A[i + 6];
- A[i + 2] = alpha + beta;
- A[i + 6] = alpha - beta;
- alpha = A[i + 1];
- const float beta1 = 0.70710678118654752440084436210485f*(A[i + 5] + A[i + 7]);
- const float beta2 = 0.70710678118654752440084436210485f*(A[i + 5] - A[i + 7]);
- A[i + 1] = alpha + beta1;
- A[i + 5] = alpha - beta1;
- alpha = A[i + 3];
- A[i + 3] = alpha + beta2;
- A[i + 7] = alpha - beta2;
- }
- n = 16;
- n2 = 8;
- theta_inc = nPoints >> 4;
- nptDiv2 = nPoints >> 2;
- while (n <= nPoints)
- {
- for (i = 0; i < nPoints; i += n)
- {
- int32_t theta = theta_inc;
- const int32_t n4 = n2 >> 1;
- alpha = A[i];
- beta = A[i + n2];
- A[i] = alpha + beta;
- A[i + n2] = alpha - beta;
- alpha = A[i + n4];
- beta = A[i + n2 + n4];
- A[i + n4] = alpha + beta;
- A[i + n2 + n4] = alpha - beta;
- for (j = 1; j < n4; j++)
- {
- float sinval = sinTab[theta];
- float cosval = sinTab[theta + nptDiv2];
- float alpha1 = A[i + j];
- float alpha2 = A[i - j + n2];
- float beta1 = A[i + j + n2] * cosval + A[i - j + n] * sinval;
- float beta2 = A[i + j + n2] * sinval - A[i - j + n] * cosval;
- theta += theta_inc;
- A[i + j] = alpha1 + beta1;
- A[i + j + n2] = alpha1 - beta1;
- A[i - j + n2] = alpha2 + beta2;
- A[i - j + n] = alpha2 - beta2;
- }
- }
- n <<= 1;
- n2 <<= 1;
- theta_inc >>= 1;
- }
-}
-#define M_PIDouble 3.1415926535897932384626433832795f
-void getAsymmetricWindow(float *analysisWnd, float *synthesisWnd, int32_t k, int32_t m, float freq_temporal)
-{
- int32_t i;
- memset(synthesisWnd, 0, k * sizeof(float));
- if (freq_temporal < 0.4f)
- freq_temporal = 0.4f;
- if (freq_temporal > 1.8f)
- freq_temporal = 1.8f;
- int32_t n = ((k - m) << 1) + 2;
- for (i = 0; i < k - m; ++i)
- analysisWnd[i] = (float)pow(sqrt(0.5f * (1.0f - cos(2.0f * M_PIDouble * (i + 1.0f) / (float)n))), freq_temporal);
- n = (m << 1) + 2;
- if (freq_temporal > 1.5f)
- freq_temporal = 1.5f;
- for (i = k - m; i < k; ++i)
- analysisWnd[i] = (float)pow(sqrt(0.5f * (1.0f - cos(2.0f * M_PIDouble * ((m + i - (k - m)) + 1.0f) / (float)n))), freq_temporal);
- n = m << 1;
- for (i = k - (m << 1); i < k; ++i)
- synthesisWnd[i] = (float)(0.5f * (1.0f - cos(2.0f * M_PIDouble * (float)(i - (k - (m << 1))) / (float)n))) / analysisWnd[i];
-}
-void STFT_DynInit(int32_t *indexFw, float *analysisWnd)
-{
- int32_t i;
- int32_t ovpSmps = indexFw[0] / indexFw[1];
- int32_t bufferSize = (indexFw[0] * 6) + indexFw[3] + indexFw[3] + (int32_t)((float)(indexFw[0] * sizeof(uint32_t)) / (float)(sizeof(float) / sizeof(uint32_t)));
- memset(analysisWnd, 0, bufferSize * sizeof(float));
- float *synthesisWnd = analysisWnd + indexFw[0];
- uint32_t *bitRevTbl = (uint32_t*)(analysisWnd + (indexFw[0] * 6) + indexFw[3] + indexFw[3]);
- uint32_t bitsConst = 0;
- uint32_t v = indexFw[0];
- while (v > 1)
- {
- ++bitsConst;
- v >>= 1;
- }
- for (i = 0; i < indexFw[0]; ++i)
- {
- uint32_t bits = bitsConst;
- uint32_t x = i;
- bitRevTbl[i] = 0;
- while (bits--)
- {
- bitRevTbl[i] = (bitRevTbl[i] + bitRevTbl[i]) + (x & 1);
- x >>= 1;
- }
- }
- float *sineTbl = synthesisWnd + indexFw[0];
- float pi2dN = (M_PIDouble * 2.0f) / indexFw[0];
- for (i = 0; i < indexFw[0]; ++i)
- sineTbl[i] = (float)sin(pi2dN * i);
- getAsymmetricWindow(analysisWnd, synthesisWnd, indexFw[0], ovpSmps, indexFw[5] / (float)32767);
- // Pre-shift window function
- for (i = 0; i < indexFw[0] - indexFw[2]; i++)
- synthesisWnd[i] = synthesisWnd[i + indexFw[2]] * (1.0f / indexFw[0]) * 0.5f;
-}
-int32_t STFTCartesian(float *indexer, float *analysisWnd, float *ptr)
-{
- int32_t *indexFw = (int32_t*)indexer;
- float *mSineTab = analysisWnd + indexFw[0] * 2;
- float *mInput = mSineTab + indexFw[0];
- float *mTempBuffer = mInput + indexFw[0];
- uint32_t *bitRevTbl = (uint32_t*)(analysisWnd + (indexFw[0] * 6) + indexFw[3] + indexFw[3]);
- int32_t i, symIdx;
- for (i = 0; i < indexFw[0]; ++i)
- mTempBuffer[bitRevTbl[i]] = mInput[(i + indexFw[4]) & (indexFw[0] - 1)] * analysisWnd[i];
- discreteHartleyTransformFloat(mTempBuffer, indexFw[0], mSineTab);
- ptr[0] = mTempBuffer[0] * 2.0f;
- ptr[1] = 0.0f;
- float lR, lI;
- for (i = 1; i < ((indexFw[0] >> 1) + 1); i++)
- {
- symIdx = indexFw[0] - i;
- lR = mTempBuffer[i] + mTempBuffer[symIdx];
- lI = mTempBuffer[i] - mTempBuffer[symIdx];
- ptr[i << 1] = lR;
- ptr[(i << 1) + 1] = lI;
- }
- return indexFw[0] + 2;
-}
-int32_t STFTPolar(float *indexer, float *analysisWnd, float *ptr)
-{
- int32_t *indexFw = (int32_t*)indexer;
- float *mSineTab = analysisWnd + indexFw[0] * 2;
- float *mInput = mSineTab + indexFw[0];
- float *mTempBuffer = mInput + indexFw[0];
- uint32_t *bitRevTbl = (uint32_t*)(analysisWnd + (indexFw[0] * 6) + indexFw[3] + indexFw[3]);
- int32_t i, symIdx;
- for (i = 0; i < indexFw[0]; ++i)
- mTempBuffer[bitRevTbl[i]] = mInput[(i + indexFw[4]) & (indexFw[0] - 1)] * analysisWnd[i];
- discreteHartleyTransformFloat(mTempBuffer, indexFw[0], mSineTab);
- ptr[0] = fabsf(mTempBuffer[0] * 2.0f);
- ptr[1] = ((mTempBuffer[0] < 0.0f) ? M_PIDouble : 0.0f);
- float lR, lI;
- for (i = 1; i < ((indexFw[0] >> 1) + 1); i++)
- {
- symIdx = indexFw[0] - i;
- lR = mTempBuffer[i] + mTempBuffer[symIdx];
- lI = mTempBuffer[i] - mTempBuffer[symIdx];
- ptr[i << 1] = hypotf(lR, lI);
- ptr[(i << 1) + 1] = atan2f(lI, lR);
- }
- return indexFw[0] + 2;
-}
-int32_t STFTCartesianInverse(float *indexer, float *analysisWnd, float *ptr)
-{
- int32_t *indexFw = (int32_t*)indexer;
- float *synthesisWnd = analysisWnd + indexFw[0];
- float *mSineTab = synthesisWnd + indexFw[0];
- float *timeDomainOut = mSineTab + indexFw[0] * 3;
- float *mOutputBuffer = timeDomainOut + indexFw[0];
- float *mOverlapStage2Ldash = mOutputBuffer + indexFw[3];
- uint32_t *bitRevTbl = (uint32_t*)(analysisWnd + (indexFw[0] * 6) + indexFw[3] + indexFw[3]);
- int32_t i;
- timeDomainOut[0] = ptr[0];
- float lR, lI;
- for (i = 1; i < ((indexFw[0] >> 1) + 1); i++)
- {
- lR = ptr[i << 1];
- lI = ptr[(i << 1) + 1];
- timeDomainOut[bitRevTbl[i]] = (lR + lI);
- timeDomainOut[bitRevTbl[indexFw[0] - i]] = (lR - lI);
- }
- discreteHartleyTransformFloat(timeDomainOut, indexFw[0], mSineTab);
- for (i = 0; i < indexFw[0] - indexFw[2]; i++)
- timeDomainOut[i] = timeDomainOut[i + indexFw[2]] * synthesisWnd[i];
- for (i = 0; i < indexFw[3]; ++i)
- {
- mOutputBuffer[i] = mOverlapStage2Ldash[i] + timeDomainOut[i];
- mOverlapStage2Ldash[i] = timeDomainOut[indexFw[3] + i];
- }
- return indexFw[3];
-}
-int32_t STFTPolarInverse(float *indexer, float *analysisWnd, float *ptr)
-{
- int32_t *indexFw = (int32_t*)indexer;
- float *synthesisWnd = analysisWnd + indexFw[0];
- float *mSineTab = synthesisWnd + indexFw[0];
- float *timeDomainOut = mSineTab + indexFw[0] * 3;
- float *mOutputBuffer = timeDomainOut + indexFw[0];
- float *mOverlapStage2Ldash = mOutputBuffer + indexFw[3];
- uint32_t *bitRevTbl = (uint32_t*)(analysisWnd + (indexFw[0] * 6) + indexFw[3] + indexFw[3]);
- int32_t i;
- float magnitude = ptr[0];
- float phase = ptr[1];
- float lR, lI;
- timeDomainOut[0] = magnitude * cosf(phase);
- for (i = 1; i < ((indexFw[0] >> 1) + 1); i++)
- {
- magnitude = ptr[i << 1];
- phase = ptr[(i << 1) + 1];
- lR = magnitude * cosf(phase);
- lI = magnitude * sinf(phase);
- timeDomainOut[bitRevTbl[i]] = (lR + lI);
- timeDomainOut[bitRevTbl[indexFw[0] - i]] = (lR - lI);
- }
- discreteHartleyTransformFloat(timeDomainOut, indexFw[0], mSineTab);
- for (i = 0; i < indexFw[0] - indexFw[2]; i++)
- timeDomainOut[i] = timeDomainOut[i + indexFw[2]] * synthesisWnd[i];
- for (i = 0; i < indexFw[3]; ++i)
- {
- mOutputBuffer[i] = mOverlapStage2Ldash[i] + timeDomainOut[i];
- mOverlapStage2Ldash[i] = timeDomainOut[indexFw[3] + i];
- }
- return indexFw[3];
-}
-static float NSEEL_CGEN_CALL stftInit(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- float *start1 = parms[0];
- int32_t offs1 = (int32_t)(*start1 + NSEEL_CLOSEFACTOR);
- float *start2 = parms[1];
- int32_t offs2 = (int32_t)(*start2 + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *stftFloatStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t *indexFw = (int32_t*)indexer;
- STFT_DynInit(indexFw, stftFloatStruct);
- return (float)indexFw[3];
-}
-static float NSEEL_CGEN_CALL stftGetWindowPower(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- float *start1 = parms[0];
- int32_t offs1 = (int32_t)(*start1 + NSEEL_CLOSEFACTOR);
- float *start2 = parms[1];
- int32_t offs2 = (int32_t)(*start2 + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *stftFloatStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t *indexFw = (int32_t*)indexer;
- float sumOfPreWindow = 0.0f;
- for (int i = 0; i < indexFw[0]; i++)
- sumOfPreWindow += stftFloatStruct[i];
- return 1.0f / sumOfPreWindow;
-}
-static float NSEEL_CGEN_CALL stftForward(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *ptr = __NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- int32_t offs1 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- int32_t offs2 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *stftFloatStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t cartesian = (int32_t)(*parms[3]);
- int32_t *indexFw = (int32_t*)indexer;
- float *mInput = stftFloatStruct + indexFw[0] * 3;
- memcpy(&mInput[indexFw[4]], ptr, indexFw[3] * sizeof(float));
- indexFw[4] = (indexFw[4] + indexFw[3]) & (indexFw[0] - 1);
- if (cartesian)
- return (float)STFTCartesian(indexer, stftFloatStruct, ptr);
- else
- return (float)STFTPolar(indexer, stftFloatStruct, ptr);
-}
-static float NSEEL_CGEN_CALL stftBackward(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *ptr = __NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- int32_t offs1 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- int32_t offs2 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *stftFloatStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t cartesian = (int32_t)(*parms[3]);
- int32_t *indexFw = (int32_t*)indexer;
- int32_t ret;
- if (cartesian)
- ret = STFTCartesianInverse(indexer, stftFloatStruct, ptr);
- else
- ret = STFTPolarInverse(indexer, stftFloatStruct, ptr);
- memcpy(ptr, stftFloatStruct + indexFw[0] * 6, indexFw[3] * sizeof(float));
- return (float)ret;
-}
-int32_t STFT_DynConstructor(float *indexer, int32_t fftLen, int32_t analysisOvp, float tf_res)
-{
- int32_t ovpSmps = fftLen / analysisOvp;
- int32_t sampleShift = (fftLen - (ovpSmps << 1));
- int32_t *indexFw = (int32_t*)indexer;
- indexFw[0] = fftLen;
- indexFw[1] = analysisOvp;
- indexFw[2] = sampleShift;
- indexFw[3] = ovpSmps;
- indexFw[4] = 0;
- indexFw[5] = (int32_t)(tf_res * (float)32767);
- return ((fftLen * 6) + ovpSmps + ovpSmps + (int32_t)((float)(fftLen * sizeof(uint32_t)) / (float)(sizeof(float) / sizeof(uint32_t))));
-}
-static float NSEEL_CGEN_CALL stftCheckMemoryRequirement(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- uint32_t offs1 = (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t fftlen = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- int32_t analyOv = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- return (float)STFT_DynConstructor(indexer, fftlen, analyOv, *parms[3]);
-}
-void runStateArburg(double *Z, double *b, double x, int n)
-{
- for (int j = 1; j < n; j++) // Update conditions
- Z[j - 1] = -b[j] * x + Z[j];
- Z[n - 1] = -b[n] * x;
-}
-double predictArburg(double *Z, double *a, int n)
-{
- double Yi = Z[0]; // Filtered value
- for (int j = 1; j < n; j++) // Update conditions
- Z[j - 1] = Z[j] - a[j] * Yi;
- Z[n - 1] = -a[n] * Yi;
- return Yi; // Write to output
-}
-void TrainArburg(char *bg, float *xn, unsigned int xLen)
-{
- unsigned int i, j;
- char getPredictionState = *bg;
- unsigned int *flag = (unsigned int*)(bg + 1);
- const unsigned int _mCoefficientsNumber = *flag;
- unsigned int lenM1 = xLen - 1;
-
- // Creates internal variables with desirable length
- double *predictionCoefficients = (double*)(flag + 1);
- memset(predictionCoefficients, 0, (_mCoefficientsNumber + 1) * sizeof(double));
- double *reflectionCoefficient = predictionCoefficients + (_mCoefficientsNumber + 1);
- memset(reflectionCoefficient, 0, (_mCoefficientsNumber + 1) * sizeof(double));
- double *_r = reflectionCoefficient + (_mCoefficientsNumber + 1);
- memset(_r, 0, (_mCoefficientsNumber + 1) * sizeof(double));
- double *_c = _r + (_mCoefficientsNumber + 1);
- double *_deltaRAndAProduct = _c + (_mCoefficientsNumber + 1);
- double *_g = _deltaRAndAProduct + (_mCoefficientsNumber + 1);
- memset(_g, 0, (_mCoefficientsNumber + 2) * sizeof(double));
- double *tmp = _g + (_mCoefficientsNumber + 2);
- double *forwardState = tmp + (_mCoefficientsNumber + 2);
- double *backwardState = forwardState + (_mCoefficientsNumber + 1);
-
- // Initializes i_iterationCounter and vectors. For details see step 0 of algorithm on page 3 of the paper
- /// Calculates autocorrelations. For details see step 0 of algorithm on page 3 of the paper
- for (j = 0; j <= _mCoefficientsNumber; j++)
- {
- _c[j] = 0.0;
- for (i = 0; i < xLen - j; i++)
- _c[j] += xn[i] * xn[i + j];
- }
- unsigned int _iIterationCounter = 0;
- predictionCoefficients[0] = 1.0;
- _g[0] = 2.0 * _c[0] - fabs(xn[0]) * fabs(xn[0]) - fabs(xn[lenM1]) * fabs(xn[lenM1]);
- _g[1] = 2.0 * _c[1];
- // the paper says r[1], error in paper?
- _r[0] = 2.0 * _c[1];
-
- while (_iIterationCounter <= _mCoefficientsNumber)
- {
- // Computes vector of reflection coefficients. For details see step 1 of algorithm on page 3 of the paper
- double nominator = 0.0;
- double denominator = (double)FLT_EPSILON;
- for (i = 0; i <= _iIterationCounter + 1; i++)
- {
- nominator += predictionCoefficients[i] * _g[(_iIterationCounter + 1) - i];
- denominator += predictionCoefficients[i] * _g[i];
- }
- reflectionCoefficient[_iIterationCounter] = -nominator / denominator;
- // Updates vector of prediction coefficients. For details see step 2 of algorithm on page 3 of the paper
- memcpy(tmp, predictionCoefficients, (_mCoefficientsNumber + 1) * sizeof(double));
- for (i = 0; i <= _iIterationCounter + 1; i++)
- predictionCoefficients[i] = tmp[i] + reflectionCoefficient[_iIterationCounter] * tmp[(_iIterationCounter + 1) - i];
- _iIterationCounter++;
- if (_iIterationCounter == _mCoefficientsNumber)
- {
- if (getPredictionState)
- {
- memset(forwardState, 0, (_mCoefficientsNumber + 1) * sizeof(double));
- memset(backwardState, 0, (_mCoefficientsNumber + 1) * sizeof(double));
- for (i = 0; i < xLen; i++)
- {
- runStateArburg(forwardState, predictionCoefficients, xn[i], _mCoefficientsNumber); // Forward
- runStateArburg(backwardState, predictionCoefficients, xn[lenM1 - i], _mCoefficientsNumber); // Backward
- }
- }
- break;
- }
- // Updates vector r. For details see step 5 of algorithm on page 3 of the paper
- memcpy(tmp, _r, (_mCoefficientsNumber + 1) * sizeof(double));
- for (i = 0; i <= _iIterationCounter - 1; i++)
- _r[i + 1] = tmp[i] - xn[i] * xn[_iIterationCounter] - xn[lenM1 - i] * xn[lenM1 - _iIterationCounter];
- _r[0] = 2.0 * _c[_iIterationCounter + 1];
-
- // Calculates vector deltaRAndAProduct. For details see step 6 of algorithm on page 3 of the paper
- unsigned int posEnd = lenM1 - _iIterationCounter;
- unsigned int _iIterationCounterA1 = _iIterationCounter + 1;
- for (i = 0; i <= _iIterationCounter; i++)
- {
- double innerProduct1 = 0.0;
- double innerProduct2 = 0.0;
- for (j = 0; j <= _iIterationCounter; j++)
- {
- innerProduct1 += xn[_iIterationCounter - j] * predictionCoefficients[j];
- innerProduct2 += xn[posEnd + j] * predictionCoefficients[j];
- }
- _deltaRAndAProduct[i] = -xn[_iIterationCounter - i] * innerProduct1 - xn[posEnd + i] * innerProduct2;
- }
- // Updates vector g. For details see step 7 of algorithm on page 3 of the paper
- memcpy(tmp, _g, (_mCoefficientsNumber + 2) * sizeof(double));
- // g.Length is i_iterationCounter + 1
- for (i = 0; i <= _iIterationCounter; i++)
- _g[i] = tmp[i] + reflectionCoefficient[_iIterationCounter - 1] * tmp[_iIterationCounter - i] + _deltaRAndAProduct[i];
- for (i = 0; i <= _iIterationCounter; i++)
- _g[_iIterationCounter + 1] += _r[i] * predictionCoefficients[i];
- }
-}
-static float NSEEL_CGEN_CALL arburgCheckMemoryRequirement(float *blocks, float *parm0, float *parm1)
-{
- unsigned int coefficientsNumber = (unsigned int)(*parm0 + NSEEL_CLOSEFACTOR);
- char getPredictionState = (char)(*parm1 + NSEEL_CLOSEFACTOR);
- size_t totalMemSize = sizeof(unsigned int) + ((coefficientsNumber + 1) * (getPredictionState == 1 ? 7 : 5) + (coefficientsNumber + 2) * 2) * sizeof(double);
- return (float)((totalMemSize / sizeof(float) + 1));
-}
-static float NSEEL_CGEN_CALL arburgTrainModel(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- char *burg = (char*)__NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- int32_t offs1 = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *xn = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- *burg = (char)(*parms[2] + NSEEL_CLOSEFACTOR);
- unsigned int *flag = (unsigned int*)(burg + 1);
- *flag = (unsigned int)(*parms[1] + NSEEL_CLOSEFACTOR);
- uint32_t xLen = (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- TrainArburg(burg, xn, xLen);
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL arburgGetPredictionReflectionCoeff(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- char *bg = (char*)__NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- int32_t offs1 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *pdC = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *rfC = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- unsigned int *flag = (unsigned int*)(bg + 1);
- const unsigned int _mCoefficientsNumber = *flag;
- double *predictionCoefficients = (double*)(flag + 1);
- double *reflectionCoefficient = predictionCoefficients + (_mCoefficientsNumber + 1);
- for (unsigned int i = 0; i < _mCoefficientsNumber + 1; i++)
- {
- pdC[i] = (float)predictionCoefficients[i];
- rfC[i] = (float)reflectionCoefficient[i];
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL arburgPredictBackward(float *blocks, float *start)
-{
- int32_t offs = (int32_t)(*start + NSEEL_CLOSEFACTOR);
- char *burg = (char*)__NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- unsigned int *flag = (unsigned int*)(burg + 1);
- double *predictionCoefficients = (double*)(flag + 1);
- double *backwardState = ((double*)(flag + 1)) + (*flag + 1) * 5 + (*flag + 2) * 2 + (*flag + 1);
- double output = predictArburg(backwardState, predictionCoefficients, *flag);
- return (float)output;
-}
-static float NSEEL_CGEN_CALL arburgPredictForward(float *blocks, float *start)
-{
- int32_t offs = (int32_t)(*start + NSEEL_CLOSEFACTOR);
- char *burg = (char*)__NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- unsigned int *flag = (unsigned int*)(burg + 1);
- double *predictionCoefficients = (double*)(flag + 1);
- double *forwardState = ((double*)(flag + 1)) + (*flag + 1) * 5 + (*flag + 2) * 2;
- double output = predictArburg(forwardState, predictionCoefficients, *flag);
- return (float)output;
-}
-void reverse(float *arr, int32_t start, int32_t end)
-{
- while (start < end)
- {
- float tmp = arr[start];
- arr[start] = arr[end];
- arr[end] = tmp;
- start++;
- end--;
- }
-}
-void shift(float *arr, int32_t k, int32_t n)
-{
- k = k % n;
- reverse(arr, 0, n - 1);
- reverse(arr, 0, n - k - 1);
- reverse(arr, n - k, n - 1);
-}
-float * NSEEL_CGEN_CALL __NSEEL_circshift(float *blocks, float *offptr, float *shiftptr, float *lenptr)
-{
- uint32_t offs = (uint32_t)(*offptr + NSEEL_CLOSEFACTOR);
- float *arr = __NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- int32_t k = (int32_t)*shiftptr;
- int32_t n = (int32_t)*lenptr;
- k < 0 ? shift(arr, -k, n) : shift(arr, n - k, n);
- return offptr;
-}
-static float NSEEL_CGEN_CALL _eel_vectorizeAssignScalar(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t resultPtr = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *result = __NSEEL_RAMAlloc(blocks, (uint64_t)resultPtr);
- int32_t numElements = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- for (int32_t i = 0; i < numElements; i++)
- result[i] = *parms[2];
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_vectorizeAdd(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t resultPtr = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *result = __NSEEL_RAMAlloc(blocks, (uint64_t)resultPtr);
- int32_t numElements = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- int32_t APtr = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *A = __NSEEL_RAMAlloc(blocks, (uint64_t)APtr);
- int32_t BPtr = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *B = __NSEEL_RAMAlloc(blocks, (uint64_t)BPtr);
- for (int32_t i = 0; i < numElements; i++)
- result[i] = A[i] + B[i];
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_vectorizeMinus(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t resultPtr = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *result = __NSEEL_RAMAlloc(blocks, (uint64_t)resultPtr);
- int32_t numElements = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- int32_t APtr = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *A = __NSEEL_RAMAlloc(blocks, (uint64_t)APtr);
- int32_t BPtr = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *B = __NSEEL_RAMAlloc(blocks, (uint64_t)BPtr);
- for (int32_t i = 0; i < numElements; i++)
- result[i] = A[i] - B[i];
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_vectorizeMultiply(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t resultPtr = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *result = __NSEEL_RAMAlloc(blocks, (uint64_t)resultPtr);
- int32_t numElements = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- int32_t APtr = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *A = __NSEEL_RAMAlloc(blocks, (uint64_t)APtr);
- int32_t BPtr = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *B = __NSEEL_RAMAlloc(blocks, (uint64_t)BPtr);
- for (int32_t i = 0; i < numElements; i++)
- result[i] = A[i] * B[i];
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_vectorizeDivide(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t resultPtr = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *result = __NSEEL_RAMAlloc(blocks, (uint64_t)resultPtr);
- int32_t numElements = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- int32_t APtr = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *A = __NSEEL_RAMAlloc(blocks, (uint64_t)APtr);
- int32_t BPtr = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *B = __NSEEL_RAMAlloc(blocks, (uint64_t)BPtr);
- for (int32_t i = 0; i < numElements; i++)
- result[i] = A[i] / B[i];
- return 1;
-}
-float expint(float x)
-{
- if (x <= 1.0f)
- return -0.57721566490153286060651209f - logf(x) + x * (-x / 4.0f + 1.0f);
- float term = 0.0f;
- for (int32_t k = 1 + (int32_t)floorf(80.0f / x); k >= 1; k--)
- term = k / (1.0f + k / (x + term));
- return expf(-x) / (x + term);
-}
-// Domain: 0.001 ~ 0.5f
-static const float ExpintTable1[500] = { 6.33153936413615f, 5.63939143396494f, 5.23492507691165f, 4.94824125651360f, 4.72609545858444f, 4.54477115683906f, 4.39161723405586f, 4.25908210080260f, 4.14229482717614f, 4.03792957653811f, 3.94361416507444f, 3.85759706007702f, 3.77854812837773f, 3.70543343651052f, 3.63743334995231f, 3.57388711871546f, 3.51425429210118f, 3.45808717909408f, 3.40501076461633f, 3.35470778330971f, 3.30690743883812f, 3.26137674984624f, 3.21791382119158f, 3.17634254828989f, 3.13650840321517f, 3.09827504776313f, 3.06152158606426f, 3.02614031708686f, 2.99203488170511f, 2.95911872402128f, 2.92731380507851f, 2.89654952085833f, 2.86676178682571f, 2.83789225917520f, 2.80988766899124f, 2.78269925022877f, 2.75628224608441f, 2.73059548120986f, 2.70560098950218f, 2.68126368902528f, 2.65755109707773f, 2.63443307960029f, 2.61188163007365f, 2.58987067383731f, 2.56837589440108f, 2.54737457884799f, 2.52684547986474f, 2.50676869229857f, 2.48712554244313f, 2.46789848850997f, 2.44907103095643f, 2.43062763152119f, 2.41255363997231f, 2.39483522770240f, 2.37745932741712f, 2.36041357825803f, 2.34368627578265f, 2.32726632629475f, 2.31114320507867f, 2.29530691814378f, 2.27974796713116f, 2.26445731707363f, 2.24942636673543f, 2.23464692128761f, 2.22011116710190f, 2.20581164846892f, 2.19174124606712f, 2.17789315702680f, 2.16426087644945f, 2.15083818025680f, 2.13761910925637f, 2.12459795432145f, 2.11176924259316f, 2.09912772462139f, 2.08666836236871f, 2.07438631800884f, 2.06227694345737f, 2.05033577057783f, 2.03855850201183f, 2.02694100258574f, 2.01547929125139f, 2.00416953352107f, 1.99300803436109f, 1.98199123151100f, 1.97111568919802f, 1.96037809221915f, 1.94977524036537f, 1.93930404316446f, 1.92896151492086f, 1.91874477003266f, 1.90865101856733f, 1.89867756207924f, 1.88882178965323f, 1.87908117415985f, 1.86945326870865f, 1.85993570328723f, 1.85052618157445f, 1.84122247791703f, 1.83202243445968f, 1.82292395841939f, 1.81392501949540f, 1.80502364740671f, 1.79621792954979f, 1.78750600876935f, 1.77888608123583f, 1.77035639442354f, 1.76191524518360f, 1.75356097790666f, 1.74529198277014f, 1.73710669406567f, 1.72900358860208f, 1.72098118418005f, 1.71303803813460f, 1.70517274594176f, 1.69738393988603f, 1.68967028778564f, 1.68203049177242f, 1.67446328712364f, 1.66696744114317f, 1.65954175208938f, 1.65218504814758f, 1.64489618644475f, 1.63767405210444f, 1.63051755734000f, 1.62342564058417f, 1.61639726565340f, 1.60943142094514f, 1.60252711866667f, 1.59568339409389f, 1.58889930485880f, 1.58217393026415f, 1.57550637062431f, 1.56889574663089f, 1.56234119874219f, 1.55584188659529f, 1.54939698843990f, 1.54300570059289f, 1.53666723691273f, 1.53038082829278f, 1.52414572217289f, 1.51796118206826f, 1.51182648711501f, 1.50574093163171f, 1.49970382469613f, 1.49371448973666f, 1.48777226413783f, 1.48187649885916f, 1.47602655806709f, 1.47022181877919f, 1.46446167052028f, 1.45874551499005f, 1.45307276574158f, 1.44744284787039f, 1.44185519771371f, 1.43630926255935f, 1.43080450036407f, 1.42534037948083f, 1.41991637839478f, 1.41453198546754f, 1.40918669868949f, 1.40388002543983f, 1.39861148225397f, 1.39338059459819f, 1.38818689665114f, 1.38302993109194f, 1.37790924889475f, 1.37282440912947f, 1.36777497876843f, 1.36276053249873f, 1.35778065254024f, 1.35283492846881f, 1.34792295704476f, 1.34304434204620f, 1.33819869410729f, 1.33338563056104f, 1.32860477528666f, 1.32385575856114f, 1.31913821691513f, 1.31445179299275f, 1.30979613541537f, 1.30517089864914f, 1.30057574287617f, 1.29601033386927f, 1.29147434287001f, 1.28696744647023f, 1.28248932649660f, 1.27803966989839f, 1.27361816863814f, 1.26922451958530f, 1.26485842441262f, 1.26051958949533f, 1.25620772581287f, 1.25192254885323f, 1.24766377851975f, 1.24343113904031f, 1.23922435887882f, 1.23504317064902f, 1.23088731103039f, 1.22675652068626f, 1.22265054418389f, 1.21856912991660f, 1.21451203002782f, 1.21047900033696f, 1.20646980026724f, 1.20248419277510f, 1.19852194428150f, 1.19458282460475f, 1.19066660689505f, 1.18677306757053f, 1.18290198625489f, 1.17905314571646f, 1.17522633180872f, 1.17142133341224f, 1.16763794237793f, 1.16387595347169f, 1.16013516432024f, 1.15641537535834f, 1.15271638977706f, 1.14903801347337f, 1.14538005500082f, 1.14174232552131f, 1.13812463875802f, 1.13452681094936f, 1.13094866080393f, 1.12739000945649f, 1.12385068042499f, 1.12033049956838f, 1.11682929504554f, 1.11334689727494f, 1.10988313889530f, 1.10643785472705f, 1.10301088173459f, 1.09960205898947f, 1.09621122763424f, 1.09283823084711f, 1.08948291380742f, 1.08614512366176f, 1.08282470949081f, 1.07952152227697f, 1.07623541487250f, 1.07296624196851f, 1.06971386006443f, 1.06647812743823f, 1.06325890411715f, 1.06005605184912f, 1.05686943407471f, 1.05369891589963f, 1.05054436406786f, 1.04740564693527f, 1.04428263444374f, 1.04117519809585f, 1.03808321093007f, 1.03500654749642f, 1.03194508383258f, 1.02889869744056f, 1.02586726726374f, 1.02285067366439f, 1.01984879840164f, 1.01686152460984f, 1.01388873677738f, 1.01093032072589f, 1.00798616358984f, 1.00505615379652f, 1.00214018104644f, 0.999238136294059f, 0.996349911728865f, 0.993475400756876f, 0.990614497982423f, 0.987767099190299f, 0.984933101328234f, 0.982112402489699f, 0.979304901897022f, 0.976510499884809f, 0.973729097883682f, 0.970960598404302f, 0.968204905021682f, 0.965461922359790f, 0.962731556076425f, 0.960013712848367f, 0.957308300356788f, 0.954615227272931f, 0.951934403244034f, 0.949265738879512f, 0.946609145737375f, 0.943964536310890f, 0.941331824015476f, 0.938710923175825f, 0.936101749013249f, 0.933504217633244f, 0.930918246013275f, 0.928343751990763f, 0.925780654251284f, 0.923228872316966f, 0.920688326535087f, 0.918158938066864f, 0.915640628876432f, 0.913133321720014f, 0.910636940135260f, 0.908151408430781f, 0.905676651675847f, 0.903212595690257f, 0.900759167034383f, 0.898316292999373f, 0.895883901597516f, 0.893461921552770f, 0.891050282291436f, 0.888648913932996f, 0.886257747281089f, 0.883876713814638f, 0.881505745679123f, 0.879144775677990f, 0.876793737264197f, 0.874452564531905f, 0.872121192208285f, 0.869799555645474f, 0.867487590812641f, 0.865185234288193f, 0.862892423252093f, 0.860609095478304f, 0.858335189327350f, 0.856070643738996f, 0.853815398225033f, 0.851569392862186f, 0.849332568285124f, 0.847104865679583f, 0.844886226775585f, 0.842676593840777f, 0.840475909673856f, 0.838284117598100f, 0.836101161455002f, 0.833926985597995f, 0.831761534886266f, 0.829604754678678f, 0.827456590827773f, 0.825316989673861f, 0.823185898039208f, 0.821063263222303f, 0.818949032992211f, 0.816843155583011f, 0.814745579688315f, 0.812656254455868f, 0.810575129482225f, 0.808502154807510f, 0.806437280910244f, 0.804380458702259f, 0.802331639523674f, 0.800290775137951f, 0.798257817727021f, 0.796232719886476f, 0.794215434620836f, 0.792205915338876f, 0.790204115849027f, 0.788209990354839f, 0.786223493450506f, 0.784244580116458f, 0.782273205715011f, 0.780309325986082f, 0.778352897042962f, 0.776403875368148f, 0.774462217809232f, 0.772527881574849f, 0.770600824230679f, 0.768681003695509f, 0.766768378237340f, 0.764862906469556f, 0.762964547347142f, 0.761073260162954f, 0.759189004544038f, 0.757311740448002f, 0.755441428159437f, 0.753578028286381f, 0.751721501756837f, 0.749871809815336f, 0.748028914019544f, 0.746192776236916f, 0.744363358641393f, 0.742540623710147f, 0.740724534220363f, 0.738915053246067f, 0.737112144154998f, 0.735315770605516f, 0.733525896543553f, 0.731742486199606f, 0.729965504085765f, 0.728194914992784f, 0.726430683987183f, 0.724672776408401f, 0.722921157865967f, 0.721175794236724f, 0.719436651662080f, 0.717703696545296f, 0.715976895548810f, 0.714256215591593f, 0.712541623846539f, 0.710833087737889f, 0.709130574938690f, 0.707434053368279f, 0.705743491189805f, 0.704058856807781f, 0.702380118865662f, 0.700707246243463f, 0.699040208055393f, 0.697378973647534f, 0.695723512595532f, 0.694073794702333f, 0.692429789995936f, 0.690791468727175f, 0.689158801367534f, 0.687531758606980f, 0.685910311351833f, 0.684294430722649f, 0.682684088052144f, 0.681079254883129f, 0.679479902966478f, 0.677886004259118f, 0.676297530922046f, 0.674714455318365f, 0.673136750011346f, 0.671564387762516f, 0.669997341529763f, 0.668435584465468f, 0.666879089914658f, 0.665327831413178f, 0.663781782685891f, 0.662240917644895f, 0.660705210387756f, 0.659174635195774f, 0.657649166532257f, 0.656128779040825f, 0.654613447543725f, 0.653103147040173f, 0.651597852704708f, 0.650097539885575f, 0.648602184103115f, 0.647111761048182f, 0.645626246580576f, 0.644145616727490f, 0.642669847681983f, 0.641198915801459f, 0.639732797606177f, 0.638271469777766f, 0.636814909157763f, 0.635363092746164f, 0.633915997699998f, 0.632473601331907f, 0.631035881108752f, 0.629602814650226f, 0.628174379727492f, 0.626750554261822f, 0.625331316323269f, 0.623916644129338f, 0.622506516043683f, 0.621100910574808f, 0.619699806374795f, 0.618303182238032f, 0.616911017099967f, 0.615523290035870f, 0.614139980259605f, 0.612761067122424f, 0.611386530111769f, 0.610016348850085f, 0.608650503093652f, 0.607288972731423f, 0.605931737783878f, 0.604578778401895f, 0.603230074865621f, 0.601885607583366f, 0.600545357090505f, 0.599209304048392f, 0.597877429243282f, 0.596549713585273f, 0.595226138107252f, 0.593906683963851f, 0.592591332430423f, 0.591280064902018f, 0.589972862892376f, 0.588669708032933f, 0.587370582071829f, 0.586075466872932f, 0.584784344414874f, 0.583497196790091f, 0.582214006203880f, 0.580934754973459f, 0.579659425527039f, 0.578388000402911f, 0.577120462248533f, 0.575856793819634f, 0.574596977979323f, 0.573340997697209f, 0.572088836048530f, 0.570840476213289f, 0.569595901475400f, 0.568355095221847f, 0.567118040941839f, 0.565884722225992f, 0.564655122765501f, 0.563429226351332f, 0.562207016873418f, 0.560988478319864f, 0.559773594776161f };
-// Domain: 0.5f ~ 1.5
-static const float ExpintTable2[251] = { 0.559773594776161f, 0.554950295774654f, 0.550184228566447f, 0.545474419724144f, 0.540819918846431f, 0.536219797845636f, 0.531673150262605f, 0.527179090607617f, 0.522736753726183f, 0.518345294188611f, 0.514003885702249f, 0.509711720545442f, 0.505468009022217f, 0.501271978936804f, 0.497122875087133f, 0.493019958776493f, 0.488962507342567f, 0.484949813703121f, 0.480981185917635f, 0.477055946764210f, 0.473173433331126f, 0.469332996622433f, 0.465534001177009f, 0.461775824700544f, 0.458057857709903f, 0.454379503189402f, 0.450740176258502f, 0.447139303850470f, 0.443576324401589f, 0.440050687550483f, 0.436561853847192f, 0.433109294471587f, 0.429692490960805f, 0.426310934945320f, 0.422964127893360f, 0.419651580863333f, 0.416372814263966f, 0.413127357621880f, 0.409914749356315f, 0.406734536560751f, 0.403586274791166f, 0.400469527860700f, 0.397383867640485f, 0.394328873866420f, 0.391304133951693f, 0.388309242804826f, 0.385343802653065f, 0.382407422870921f, 0.379499719813686f, 0.376620316655740f, 0.373768843233509f, 0.370944935892892f, 0.368148237341009f, 0.365378396502136f, 0.362635068377678f, 0.359917913910035f, 0.357226599850257f, 0.354560798629336f, 0.351920188233033f, 0.349304452080114f, 0.346713278903895f, 0.344146362636973f, 0.341603402299064f, 0.339084101887818f, 0.336588170272547f, 0.334115321090748f, 0.331665272647358f, 0.329237747816627f, 0.326832473946554f, 0.324449182765786f, 0.322087610292923f, 0.319747496748133f, 0.317428586467031f, 0.315130627816727f, 0.312853373114005f, 0.310596578545543f, 0.308360004090134f, 0.306143413442834f, 0.303946573940985f, 0.301769256492064f, 0.299611235503289f, 0.297472288812947f, 0.295352197623386f, 0.293250746435620f, 0.291167722985511f, 0.289102918181468f, 0.287056126043634f, 0.285027143644513f, 0.283015771050992f, 0.281021811267725f, 0.279045070181840f, 0.277085356508928f, 0.275142481740288f, 0.273216260091375f, 0.271306508451441f, 0.269413046334320f, 0.267535695830332f, 0.265674281559272f, 0.263828630624464f, 0.261998572567834f, 0.260183939326000f, 0.258384565187321f, 0.256600286749911f, 0.254830942880567f, 0.253076374674603f, 0.251336425416562f, 0.249610940541772f, 0.247899767598750f, 0.246202756212403f, 0.244519758048025f, 0.242850626776061f, 0.241195218037623f, 0.239553389410736f, 0.237925000377293f, 0.236309912290710f, 0.234707988344255f, 0.233119093540036f, 0.231543094658634f, 0.229979860229366f, 0.228429260501155f, 0.226891167414003f, 0.225365454571042f, 0.223851997211154f, 0.222350672182151f, 0.220861357914491f, 0.219383934395520f, 0.217918283144238f, 0.216464287186559f, 0.215021831031070f, 0.213590800645265f, 0.212171083432249f, 0.210762568207898f, 0.209365145178468f, 0.207978705918639f, 0.206603143349984f, 0.205238351719856f, 0.203884226580681f, 0.202540664769647f, 0.201207564388785f, 0.199884824785426f, 0.198572346533028f, 0.197270031412369f, 0.195977782393090f, 0.194695503615591f, 0.193423100373256f, 0.192160479095018f, 0.190907547328241f, 0.189664213721924f, 0.188430388010206f, 0.187205980996190f, 0.185990904536040f, 0.184785071523391f, 0.183588395874023f, 0.182400792510829f, 0.181222177349038f, 0.180052467281716f, 0.178891580165522f, 0.177739434806718f, 0.176595950947427f, 0.175461049252136f, 0.174334651294438f, 0.173216679544007f, 0.172107057353797f, 0.171005708947475f, 0.169912559407060f, 0.168827534660787f, 0.167750561471176f, 0.166681567423308f, 0.165620480913305f, 0.164567231136999f, 0.163521748078805f, 0.162483962500777f, 0.161453805931852f, 0.160431210657273f, 0.159416109708196f, 0.158408436851462f, 0.157408126579554f, 0.156415114100704f, 0.155429335329182f, 0.154450726875736f, 0.153479226038189f, 0.152514770792199f, 0.151557299782162f, 0.150606752312267f, 0.149663068337703f, 0.148726188455997f, 0.147796053898504f, 0.146872606522027f, 0.145955788800575f, 0.145045543817253f, 0.144141815256283f, 0.143244547395151f, 0.142353685096878f, 0.141469173802417f, 0.140590959523164f, 0.139718988833596f, 0.138853208864020f, 0.137993567293430f, 0.137140012342489f, 0.136292492766605f, 0.135450957849129f, 0.134615357394647f, 0.133785641722382f, 0.132961761659695f, 0.132143668535687f, 0.131331314174900f, 0.130524650891108f, 0.129723631481212f, 0.128928209219219f, 0.128138337850319f, 0.127353971585044f, 0.126575065093524f, 0.125801573499819f, 0.125033452376345f, 0.124270657738376f, 0.123513146038632f, 0.122760874161947f, 0.122013799420013f, 0.121271879546203f, 0.120535072690475f, 0.119803337414337f, 0.119076632685907f, 0.118354917875021f, 0.117638152748432f, 0.116926297465068f, 0.116219312571358f, 0.115517158996635f, 0.114819798048592f, 0.114127191408815f, 0.113439301128373f, 0.112756089623470f, 0.112077519671165f, 0.111403554405148f, 0.110734157311576f, 0.110069292224971f, 0.109408923324170f, 0.108753015128340f, 0.108101532493039f, 0.107454440606342f, 0.106811704985010f, 0.106173291470726f, 0.105539166226369f, 0.104909295732348f, 0.104283646782986f, 0.103662186482950f, 0.103044882243734f, 0.102431701780185f, 0.101822613107082f, 0.101217584535761f, 0.100616584670779f, 0.100019582406633f };
-// Domain 1.5 ~ 3.5
-static const float ExpintTable3[126] = { 0.100019582406633f, 0.0976709372158198f, 0.0953838384149070f, 0.0931564276459467f, 0.0909869129830044f, 0.0888735660844122f, 0.0868147194907422f, 0.0848087640597390f, 0.0828541465300625f, 0.0809493672062480f, 0.0790929777578066f, 0.0772835791258635f, 0.0755198195311743f, 0.0738003925777604f, 0.0721240354467908f, 0.0704895271756689f, 0.0688956870176292f, 0.0673413728774234f, 0.0658254798189725f, 0.0643469386411095f, 0.0629047145177793f, 0.0614978056992866f, 0.0601252422713888f, 0.0587860849692256f, 0.0574794240432553f, 0.0562043781745348f, 0.0549600934368431f, 0.0537457423032842f, 0.0525605226951504f, 0.0514036570709528f, 0.0502743915536392f, 0.0491719950941388f, 0.0480957586694767f, 0.0470449945137897f, 0.0460190353806841f, 0.0450172338354382f, 0.0440389615756621f, 0.0430836087790745f, 0.0421505834771471f, 0.0412393109534225f, 0.0403492331653865f, 0.0394798081888161f, 0.0386305096836003f, 0.0378008263800681f, 0.0369902615849173f, 0.0361983327058716f, 0.0354245707942568f, 0.0346685201047068f, 0.0339297376712618f, 0.0332077928991558f, 0.0325022671716214f, 0.0318127534710799f, 0.0311388560141009f, 0.0304801898995688f, 0.0298363807694920f, 0.0292070644819443f, 0.0285918867956309f, 0.0279905030656117f, 0.0274025779497217f, 0.0268277851252616f, 0.0262658070155479f, 0.0257163345259216f, 0.0251790667888503f, 0.0246537109177589f, 0.0241399817692477f, 0.0236376017133719f, 0.0231463004116726f, 0.0226658146026547f, 0.0221958878944312f, 0.0217362705642599f, 0.0212867193647089f, 0.0208469973362054f, 0.0204168736257225f, 0.0199961233113807f, 0.0195845272327421f, 0.0191818718265862f, 0.0187879489679693f, 0.0184025558163696f, 0.0180254946667384f, 0.0176565728052777f, 0.0172956023697725f, 0.0169424002143170f, 0.0165967877782784f, 0.0162585909593461f, 0.0159276399905230f, 0.0156037693209245f, 0.0152868175002407f, 0.0149766270667522f, 0.0146730444387568f, 0.0143759198093052f, 0.0140851070441270f, 0.0138004635826326f, 0.0135218503418941f, 0.0132491316235018f, 0.0129821750231990f, 0.0127208513432019f, 0.0124650345071144f, 0.0122146014773545f, 0.0119694321750053f, 0.0117294094020133f, 0.0114944187656559f, 0.0112643486052043f, 0.0110390899207104f, 0.0108185363038491f, 0.0106025838707484f, 0.0103911311967455f, 0.0101840792530053f, 0.00998133134494335f, 0.00978279305239503f, 0.00958837217147620f, 0.00939797865808188f, 0.00921152457297160f, 0.00902892402839181f, 0.00885009313618758f, 0.00867494995735709f, 0.00850341445300474f, 0.00833540843664957f, 0.00817085552784730f, 0.00800968110708622f, 0.00785181227191778f, 0.00769717779428456f, 0.00754570807900947f, 0.00739733512341117f, 0.00725199247801176f, 0.00710961520830429f, 0.00697013985754840f };
-// Domain 3.5 ~ 11.436
-static const float ExpintTable4[63] = { 0.00697013985754843f, 0.00595165118439979f, 0.00508661641561241f, 0.00435102957490895f, 0.00372481546087525f, 0.00319115004588169f, 0.00273590601139406f, 0.00234719870089483f, 0.00201501303487467f, 0.00173089598574009f, 0.00148770235377602f, 0.00127938403852772f, 0.00110081492605982f, 0.000947645033184157f, 0.000816178756486768f, 0.000703273036244310f, 0.000606252016086186f, 0.000522835399236460f, 0.000451078202821178f, 0.000389320017508240f, 0.000336142209771689f, 0.000290331773353231f, 0.000250850756880151f, 0.000216810375484428f, 0.000187449063132408f, 0.000162113845196945f, 0.000140244512382263f, 0.000121360161310043f, 0.000105047737015578f, 9.09522708167131e-05f, 7.87685555639048e-05f, 6.82340408359011e-05f, 5.91227645848651e-05f, 5.12401661828662e-05f, 4.44186497036028e-05f, 3.85137863511616e-05f, 3.34010618509128e-05f, 2.89730888669951e-05f, 2.51372165380621e-05f, 2.18134793867002e-05f, 1.89328364567230e-05f, 1.64356588152578e-05f, 1.42704297310207e-05f, 1.23926270802452e-05f, 1.07637619830281e-05f, 9.35055145753116e-06f, 8.12420610016641e-06f, 7.05981654290921e-06f, 6.13582477694144e-06f, 5.33356842622777e-06f, 4.63688775713486e-06f, 4.03178666455650e-06f, 3.50614011821845e-06f, 3.04944161624825e-06f, 2.65258510327885e-06f, 2.30767658985817e-06f, 2.00787137790676e-06f, 1.74723336968152e-06f, 1.52061342901041e-06f, 1.32354418525242e-06f, 1.15214903255314e-06f, 1.00306338807548e-06f, 8.73366540296160e-07f };
-float linear_value(float Start, float Step, float Input, const float *Space)
-{
- int32_t Index = (int32_t)((Input - Start) / Step);
- float X1 = Start + Step * Index;
- return Space[Index] + (Space[Index + 1] - Space[Index]) / (Start + Step * (Index + 1) - X1) * (Input - X1);
-}
-float expint_interpolation(float x)
-{
- if (x < 0.001f)
- return 6.33153936413615f;
- else if (x < 0.5f)
- return (float)linear_value(0.001f, 0.001f, (float)x, ExpintTable1);// 0.001:0.001:0.5f
- else if (x < 1.5f)
- return (float)linear_value(0.5f, 0.004f, (float)x, ExpintTable2); // 0.5f:0.004:1.5
- else if (x < 3.5f)
- return (float)linear_value(1.5f, 0.016f, (float)x, ExpintTable3);// 1.5:0.016:3.5
- else if (x < 11.436f)
- return (float)linear_value(3.5f, 0.128f, (float)x, ExpintTable4);// 3.5:0.128:11.5
- else
- return 8.73366540296160e-07f;
-}
-float invsqrt(float x)
-{
- return 1.0f / sqrtf(x);
-}
-#include "fft.h"
-static void fft_reorder_buffer(int32_t bitsz, WDL_FFT_COMPLEX *data, int32_t fwd)
-{
- const int32_t *tab = fft_reorder_table_for_bitsize(bitsz);
- if (!fwd)
- {
- while (*tab)
- {
- const int32_t sidx = *tab++;
- WDL_FFT_COMPLEX a = data[sidx];
- for (;;)
- {
- WDL_FFT_COMPLEX ta;
- const int32_t idx = *tab++;
- if (!idx) break;
- ta = data[idx];
- data[idx] = a;
- a = ta;
- }
- data[sidx] = a;
- }
- }
- else
- {
- while (*tab)
- {
- const int32_t sidx = *tab++;
- int32_t lidx = sidx;
- const WDL_FFT_COMPLEX sta = data[lidx];
- for (;;)
- {
- const int32_t idx = *tab++;
- if (!idx) break;
- data[lidx] = data[idx];
- lidx = idx;
- }
- data[lidx] = sta;
- }
- }
-}
-// 0=fw, 1=iv, 2=fwreal, 3=ireal, 4=permutec, 6=permuter
-// low bit: is inverse
-// second bit: was isreal, but no longer used
-// third bit: is permute
-static void FFT(int32_t sizebits, float *data, int32_t dir)
-{
- if (dir >= 4 && dir < 8)
- {
- if (dir == 4 || dir == 5)
- fft_reorder_buffer(sizebits, (WDL_FFT_COMPLEX*)data, dir == 4);
- }
- else if (dir >= 0 && dir < 2)
- WDL_fft((WDL_FFT_COMPLEX*)data, 1 << sizebits, dir & 1);
- else if (dir >= 2 && dir < 4)
- WDL_real_fft((float*)data, 1 << sizebits, dir & 1);
-}
-static float * fft_func(int32_t dir, float *blocks, float *start, float *length)
-{
- const int32_t offs = (uint32_t)(*start + NSEEL_CLOSEFACTOR);
- const int32_t itemSizeShift = (dir & 2) ? 0 : 1;
- int32_t l = (uint32_t)(*length + NSEEL_CLOSEFACTOR);
- int32_t bitl = 0;
- int32_t ilen;
- float *ptr;
- while (l > 1 && bitl < EEL_FFT_MAXBITLEN)
- {
- bitl++;
- l >>= 1;
- }
- if (bitl < ((dir & 4) ? EEL_FFT_MINBITLEN_REORDER : EEL_FFT_MINBITLEN)) // smallest FFT is 16 item, smallest reorder is 8 item
- return start;
- ilen = 1 << bitl;
- // check to make sure we don't cross a boundary
- if (offs / NSEEL_RAM_ITEMSPERBLOCK != (offs + (ilen << itemSizeShift) - 1) / NSEEL_RAM_ITEMSPERBLOCK)
- {
- return start;
- }
- ptr = __NSEEL_RAMAlloc(blocks, (uint64_t)offs);
- FFT(bitl, ptr, dir);
- return start;
-}
-static float NSEEL_CGEN_CALL eel_max(float *blocks, float *start, float *length)
-{
- float *ptr = __NSEEL_RAMAlloc(blocks, (uint32_t)(*start + NSEEL_CLOSEFACTOR));
- float ma = ptr[0];
- for (uint32_t i = 1; i < (uint32_t)(*length + NSEEL_CLOSEFACTOR); i++)
- {
- if (ptr[i] > ma)
- ma = ptr[i];
- }
- return ma;
-}
-static float NSEEL_CGEN_CALL eel_min(float *blocks, float *start, float *length)
-{
- float *ptr = __NSEEL_RAMAlloc(blocks, (uint32_t)(*start + NSEEL_CLOSEFACTOR));
- float mi = ptr[0];
- for (uint32_t i = 1; i < (uint32_t)(*length + NSEEL_CLOSEFACTOR); i++)
- {
- if (ptr[i] < mi)
- mi = ptr[i];
- }
- return mi;
-}
-static float NSEEL_CGEN_CALL eel_mean(float *blocks, float *start, float *length)
-{
- float *ptr = __NSEEL_RAMAlloc(blocks, (uint32_t)(*start + NSEEL_CLOSEFACTOR));
- float mm = ptr[0];
- for (uint32_t i = 1; i < (uint32_t)(*length + NSEEL_CLOSEFACTOR); i++)
- mm += ptr[i];
- return mm / *length;
-}
-#define ELEM_SWAP(a,b) { register float t=(a);(a)=(b);(b)=t; }
-/*---------------------------------------------------------------------------
- Function : kth_smallest()
- In : array of elements, # of elements in the array, rank k
- Out : one element
- Job : find the kth smallest element in the array
- Notice : use the median() macro defined below to get the median.
-
- Reference:
-
- Author: Wirth, Niklaus
- Title: Algorithms + data structures = programs
- Publisher: Englewood Cliffs: Prentice-Hall, 1976
- Physical description: 366 p.
- Series: Prentice-Hall Series in Automatic Computation
-
- ---------------------------------------------------------------------------*/
-float kth_smallest(float a[], int n, int k)
-{
- register i, j, l, m;
- register float x;
-
- l = 0; m = n - 1;
- while (l < m) {
- x = a[k];
- i = l;
- j = m;
- do {
- while (a[i] < x) i++;
- while (x < a[j]) j--;
- if (i <= j) {
- ELEM_SWAP(a[i], a[j]);
- i++; j--;
- }
- } while (i <= j);
- if (j < k) l = i;
- if (k < i) m = j;
- }
- if (n % 2)
- return a[k];
- else
- return (a[k] + a[k + 1]) * 0.5f;
-}
-#define median_wirth(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
-static float NSEEL_CGEN_CALL eel_median(float *blocks, float *start, float *length)
-{
- float *ptr = __NSEEL_RAMAlloc(blocks, (uint32_t)(*start + NSEEL_CLOSEFACTOR));
- uint32_t n = (uint32_t)(*length + NSEEL_CLOSEFACTOR);
- float *tmp = (float*)malloc(n * sizeof(float));
- memcpy(tmp, ptr, n * sizeof(float));
- float med = median_wirth(tmp, n);
- free(tmp);
- return med;
-}
-static float * NSEEL_CGEN_CALL eel_fft(float *blocks, float *start, float *length)
-{
- return fft_func(0, blocks, start, length);
-}
-static float * NSEEL_CGEN_CALL eel_ifft(float *blocks, float *start, float *length)
-{
- return fft_func(1, blocks, start, length);
-}
-static float * NSEEL_CGEN_CALL eel_fft_real(float *blocks, float *start, float *length)
-{
- return fft_func(2, blocks, start, length);
-}
-static float * NSEEL_CGEN_CALL eel_ifft_real(float *blocks, float *start, float *length)
-{
- return fft_func(3, blocks, start, length);
-}
-static float * NSEEL_CGEN_CALL eel_fft_permute(float *blocks, float *start, float *length)
-{
- return fft_func(4, blocks, start, length);
-}
-static float * NSEEL_CGEN_CALL eel_ifft_permute(float *blocks, float *start, float *length)
-{
- return fft_func(5, blocks, start, length);
-}
-static float * NSEEL_CGEN_CALL eel_convolve_c(float *blocks, float *dest, float *src, float *lenptr)
-{
- const int32_t dest_offs = (int32_t)(*dest + NSEEL_CLOSEFACTOR);
- const int32_t src_offs = (int32_t)(*src + NSEEL_CLOSEFACTOR);
- const int32_t len = ((int32_t)(*lenptr + NSEEL_CLOSEFACTOR)) * 2;
- float *srcptr, *destptr;
- if (len < 1 || len > NSEEL_RAM_ITEMSPERBLOCK || dest_offs < 0 || src_offs < 0 ||
- dest_offs >= NSEEL_RAM_ITEMSPERBLOCK || src_offs >= NSEEL_RAM_ITEMSPERBLOCK) return dest;
- if ((dest_offs&(NSEEL_RAM_ITEMSPERBLOCK - 1)) + len > NSEEL_RAM_ITEMSPERBLOCK) return dest;
- if ((src_offs&(NSEEL_RAM_ITEMSPERBLOCK - 1)) + len > NSEEL_RAM_ITEMSPERBLOCK) return dest;
- srcptr = __NSEEL_RAMAlloc(blocks, (uint64_t)src_offs);
- destptr = __NSEEL_RAMAlloc(blocks, (uint64_t)dest_offs);
- WDL_fft_complexmul((WDL_FFT_COMPLEX*)destptr, (WDL_FFT_COMPLEX*)srcptr, (len / 2)&~1);
- return dest;
-}
-int32_t nseel_stringsegments_tobuf(char *bufOut, int32_t bufout_sz, eelStringSegmentRec *list) // call with NULL to calculate size, or non-null to generate to buffer (returning size used)
-{
- int32_t pos = 0;
- while (list)
- {
- if (!bufOut)
- pos += list->str_len;
- else if (list->str_len > 1)
- {
- if (pos >= bufout_sz) break;
- pos += nseel_filter_escaped_string(bufOut + pos, bufout_sz - pos, list->str_start + 1, list->str_len - 1, list->str_start[0]);
- }
- list = list->_next;
- }
- return pos;
-}
-void Initeel_string_context_state(eel_string_context_state *st)
-{
- st->inuse = 0;
- st->slot = 2;
- st->map = (int32_t*)malloc(st->slot * sizeof(s_str));
- st->m_literal_strings = (s_str*)malloc(st->slot * sizeof(s_str));
- for (int32_t i = 0; i < st->slot; i++)
- {
- st->map[i] = 0;
- st->m_literal_strings[i] = 0;
- }
-}
-void Freeel_string_context_state(eel_string_context_state *st)
-{
- for (int32_t i = 0; i < st->slot; i++)
- s_str_destroy(&st->m_literal_strings[i]);
- free(st->map);
- free(st->m_literal_strings);
- st->slot = 0;
- st->inuse = 0;
-}
-int32_t arySearch(int32_t *array, int32_t N, int32_t x)
-{
- for (int32_t i = 0; i < N; i++)
- {
- if (array[i] == x)
- return i;
- }
- return -1;
-}
-#define FLOIDX 20000
-void* GetStringForIndex(eel_string_context_state *st, float val, int32_t write)
-{
- int32_t castedValue = (int32_t)(val + 0.5f);
- if (castedValue < FLOIDX)
- return 0;
- int32_t idx = arySearch(st->map, st->slot, castedValue);
- if (idx < 0)
- return 0;
- if (!write)
- {
- s_str *tmp = &st->m_literal_strings[idx];
- const char *s = s_str_c_str(tmp);
- return (void*)s;
- }
- else
- return (void*)&st->m_literal_strings[idx];
-}
-int32_t AddString(eel_string_context_state *st, char *ns)
-{
- const int32_t l = strlen(ns);
- int32_t x;
- for (x = 0; x < st->inuse; x++)
- {
- s_str *tmp = &st->m_literal_strings[x];
- const char *s = s_str_c_str(tmp);
- if (strlen(s) == l && !strcmp(s, ns))
- break;
- }
- if (x < st->inuse)
- free(ns);
- else
- {
- int32_t currentSlot = st->inuse;
- if (currentSlot > (st->slot - 1))
- {
- st->slot++;
- st->m_literal_strings = (s_str*)realloc(st->m_literal_strings, st->slot * sizeof(s_str));
- st->m_literal_strings[st->inuse] = 0;
- st->map = (int32_t*)realloc(st->map, st->slot * sizeof(int32_t));
- st->map[st->inuse] = 0;
- }
- st->m_literal_strings[st->inuse] = s_str_create_from_c_str(ns);
- st->map[st->inuse] = x + FLOIDX;
- st->inuse++;
- free(ns);
- }
- return x + FLOIDX;
-}
-static float addStringCallback(void *opaque, eelStringSegmentRec *list)
-{
- compileContext *c = (compileContext*)opaque;
- eel_string_context_state *_this = c->m_string_context;
- // could probably do a faster implementation using AddRaw() etc but this should also be OK
- int32_t sz = nseel_stringsegments_tobuf(NULL, 0, list);
- char *ns = (char*)malloc(sz + 32);
- memset(ns, 0, sz + 32);
- sz = nseel_stringsegments_tobuf(ns, sz, list) + 1;
- ns = (char*)realloc(ns, sz);
- int32_t id = AddString(_this, ns);
- return (float)id;
-}
-static int32_t eel_string_match(compileContext *c, const char *fmt, const char *msg, int32_t match_fmt_pos, int32_t ignorecase, const char *fmt_endptr, const char *msg_endptr, int32_t num_fmt_parms, float **fmt_parms)
-{
- // %d=12345
- // %f=12345[.678]
- // %c=any nonzero char, ascii value
- // %x=12354ab
- // %*, %?, %+, %% literals
- // * ? + match minimal groups of 0+,1, or 1+ chars
- for (;;)
- {
- if (fmt >= fmt_endptr)
- {
- if (msg >= msg_endptr) return 1;
- return 0; // format ends before matching string
- }
-
- // if string ends and format is not on a wildcard, early-out to 0
- if (msg >= msg_endptr && *fmt != '*' && *fmt != '%') return 0;
-
- switch (*fmt)
- {
- case '*':
- case '+':
- // if last char of search pattern, we're done!
- if (fmt + 1 >= fmt_endptr || (fmt[1] == '?' && fmt + 2 >= fmt_endptr)) return *fmt == '*' || msg < msg_endptr;
-
- if (fmt[0] == '+') msg++; // skip a character for + . Note that in this case msg[1] is valid, because of the !*msg && *fmt != '*' check above
-
- fmt++;
- if (*fmt == '?')
- {
- // *? or +? are lazy matches
- fmt++;
-
- while (msg < msg_endptr && !eel_string_match(c, fmt, msg, match_fmt_pos, ignorecase, fmt_endptr, msg_endptr, num_fmt_parms, fmt_parms)) msg++;
- return msg < msg_endptr;
- }
- else
- {
- // greedy match
- int32_t len = (int32_t)(msg_endptr - msg);
- while (len >= 0 && !eel_string_match(c, fmt, msg + len, match_fmt_pos, ignorecase, fmt_endptr, msg_endptr, num_fmt_parms, fmt_parms)) len--;
- return len >= 0;
- }
- break;
- case '?':
- fmt++;
- msg++;
- break;
- case '%':
- {
- fmt++;
- unsigned short fmt_minlen = 1, fmt_maxlen = 0;
- if (*fmt >= '0' && *fmt <= '9')
- {
- fmt_minlen = *fmt++ - '0';
- while (*fmt >= '0' && *fmt <= '9') fmt_minlen = fmt_minlen * 10 + (*fmt++ - '0');
- fmt_maxlen = fmt_minlen;
- }
- if (*fmt == '-')
- {
- fmt++;
- fmt_maxlen = 0;
- while (*fmt >= '0' && *fmt <= '9') fmt_maxlen = fmt_maxlen * 10 + (*fmt++ - '0');
- }
- const char *dest_varname = NULL;
- if (*fmt == '{')
- {
- dest_varname = ++fmt;
- while (*fmt && fmt < fmt_endptr && *fmt != '}') fmt++;
- if (fmt >= fmt_endptr - 1 || *fmt != '}') return 0; // malformed %{var}s
- fmt++; // skip '}'
- }
- char fmt_char = *fmt++;
- if (!fmt_char) return 0; // malformed
- if (fmt_char == '*' || fmt_char == '?' || fmt_char == '+' || fmt_char == '%')
- {
- if (*msg++ != fmt_char) return 0;
- }
- else if (fmt_char == 'c')
- {
- float *varOut = NULL;
- float vv = 0.0f;
- if (!dest_varname)
- {
- if (match_fmt_pos < num_fmt_parms)
- varOut = fmt_parms[match_fmt_pos];
- match_fmt_pos++;
- }
- if (msg >= msg_endptr) return 0; // out of chars
- if (varOut)
- {
- if (varOut == &vv) // %{#foo}c
- {
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, vv, 1);
- if (wr)
- s_str_destroy(wr);
- *wr = s_str_create_from_c_str(msg);
- }
- else
- {
- *varOut = (float)*(unsigned char *)msg;
- }
- }
- msg++;
- }
- else
- {
- int32_t len = 0;
- int32_t lazy = 0;
- if (fmt_char >= 'A'&&fmt_char <= 'Z') { lazy = 1; fmt_char += 'a' - 'A'; }
- if (fmt_char == 's')
- {
- len = (int32_t)(msg_endptr - msg);
- }
- else if (fmt_char == 'x')
- {
- while ((msg[len] >= '0' && msg[len] <= '9') || (msg[len] >= 'A' && msg[len] <= 'F') || (msg[len] >= 'a' && msg[len] <= 'f'))
- len++;
- }
- else if (fmt_char == 'f')
- {
- if (msg[len] == '-') len++;
- while (msg[len] >= '0' && msg[len] <= '9') len++;
- if (msg[len] == '.')
- {
- len++;
- while (msg[len] >= '0' && msg[len] <= '9') len++;
- }
- }
- else if (fmt_char == 'd' || fmt_char == 'u' || fmt_char == 'i')
- {
- if (fmt_char != 'u' && msg[len] == '-') len++;
- while (msg[len] >= '0' && msg[len] <= '9') len++;
- }
- else
- {
- // bad format
- return 0;
- }
- if (fmt_maxlen > 0 && len > fmt_maxlen) len = fmt_maxlen;
- if (!dest_varname) match_fmt_pos++;
- if (lazy)
- {
- if (fmt_maxlen<1 || fmt_maxlen>len) fmt_maxlen = len;
- len = fmt_minlen;
- while (len <= fmt_maxlen && !eel_string_match(c, fmt, msg + len, match_fmt_pos, ignorecase, fmt_endptr, msg_endptr, num_fmt_parms, fmt_parms)) len++;
- if (len > fmt_maxlen) return 0;
- }
- else
- {
- while (len >= fmt_minlen && !eel_string_match(c, fmt, msg + len, match_fmt_pos, ignorecase, fmt_endptr, msg_endptr, num_fmt_parms, fmt_parms)) len--;
- if (len < fmt_minlen) return 0;
- }
- float vv = 0.0f;
- float *varOut = NULL;
- if (!dest_varname)
- {
- if (match_fmt_pos > 0 && match_fmt_pos - 1 < num_fmt_parms)
- varOut = fmt_parms[match_fmt_pos - 1];
- }
- if (varOut)
- {
- if (fmt_char == 's')
- {
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, *varOut, 1);
- if (wr)
- s_str_destroy(wr);
- if (wr)
- {
- const char *strS = s_str_c_str(wr);
- int32_t le = strlen(strS);
- if (msg_endptr >= strS && msg_endptr <= strS + le)
- {
-#ifdef EEL_STRING_DEBUGOUT
- EEL_STRING_DEBUGOUT("match: destination specifier passed is also haystack, will not update");
-#endif
- }
- else if (fmt_endptr >= strS && fmt_endptr <= strS + le)
- {
-#ifdef EEL_STRING_DEBUGOUT
- EEL_STRING_DEBUGOUT("match: destination specifier passed is also format, will not update");
-#endif
- }
- else
- {
- *wr = s_str_create_from_c_str(msg);
- }
- }
- else
- {
-#ifdef EEL_STRING_DEBUGOUT
- EEL_STRING_DEBUGOUT("match: bad destination specifier passed as %d: %f", match_fmt_pos, *varOut);
-#endif
- }
- }
- else
- {
- char tmp[128];
- lstrcpyn_safe(tmp, msg, min(len + 1, (int32_t)sizeof(tmp)));
- if (varOut == &vv)
- {
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, vv, 1);
- if (wr)
- s_str_destroy(wr);
- *wr = s_str_create_from_c_str(tmp);
- }
- else
- {
- char *bl = (char*)msg;
- if (fmt_char == 'u')
- *varOut = (float)strtoul(tmp, &bl, 10);
- else if (fmt_char == 'x')
- *varOut = (float)strtoul(msg, &bl, 16);
- else
- *varOut = (float)atof(tmp);
- }
- }
- }
- return 1;
- }
- }
- break;
- default:
- if (ignorecase ? (toupper(*fmt) != toupper(*msg)) : (*fmt != *msg)) return 0;
- fmt++;
- msg++;
- break;
- }
- }
-}
-static float NSEEL_CGEN_CALL _eel_match(void *opaque, INT_PTR num_parms, float **parms)
-{
- if (num_parms >= 2)
- {
- compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- const char *msg = (const char*)GetStringForIndex(c->m_string_context, *parms[1], 0);
- if (fmt && msg)
- return eel_string_match(c, fmt, msg, 0, 0, fmt + strlen(fmt), msg + strlen(msg), (int32_t)num_parms - 2, parms + 2) ? 1.0f : 0.0f;
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_matchi(void *opaque, INT_PTR num_parms, float **parms)
-{
- if (num_parms >= 2)
- {
- compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- const char *msg = (const char*)GetStringForIndex(c->m_string_context, *parms[1], 0);
- if (fmt && msg)
- return eel_string_match(opaque, fmt, msg, 0, 1, fmt + strlen(fmt), msg + strlen(msg), (int32_t)num_parms - 2, parms + 2) ? 1.0f : 0.0f;
- }
- return 0.0f;
-}
-static int32_t eel_validate_format_specifier(const char *fmt_in, char *typeOut, char *fmtOut, int32_t fmtOut_sz, char *varOut, int32_t varOut_sz)
-{
- const char *fmt = fmt_in + 1;
- int32_t state = 0;
- if (fmt_in[0] != '%') return 0; // ugh passed a non-
- *varOut = 0;
- if (fmtOut_sz-- < 2) return 0;
- *fmtOut++ = '%';
- while (*fmt)
- {
- const char c = *fmt++;
- if (fmtOut_sz < 2) return 0;
- if (c == 'f' || c == 'e' || c == 'E' || c == 'g' || c == 'G' || c == 'd' || c == 'u' || c == 'x' || c == 'X' || c == 'c' || c == 'C' || c == 's' || c == 'S' || c == 'i')
- {
- *typeOut = c;
- fmtOut[0] = c;
- fmtOut[1] = 0;
- return (int32_t)(fmt - fmt_in);
- }
- else if (c == '.')
- {
- *fmtOut++ = c; fmtOut_sz--;
- if (state&(2)) break;
- state |= 2;
- }
- else if (c == '+')
- {
- *fmtOut++ = c; fmtOut_sz--;
- if (state&(32 | 16 | 8 | 4)) break;
- state |= 8;
- }
- else if (c == '-' || c == ' ')
- {
- *fmtOut++ = c; fmtOut_sz--;
- if (state&(32 | 16 | 8 | 4)) break;
- state |= 16;
- }
- else if (c >= '0' && c <= '9')
- {
- *fmtOut++ = c; fmtOut_sz--;
- state |= 4;
- }
- else
- break;
- }
- return 0;
-}
-int32_t eel_format_strings(void *opaque, const char *fmt, const char *fmt_end, char *buf, uint32_t buf_sz, int32_t num_fmt_parms, float **fmt_parms)
-{
- int32_t fmt_parmpos = 0;
- char *op = buf;
- while ((fmt_end ? fmt < fmt_end : *fmt) && op < buf + buf_sz - 128)
- {
- if (fmt[0] == '%' && fmt[1] == '%')
- {
- *op++ = '%';
- fmt += 2;
- }
- else if (fmt[0] == '%')
- {
- char ct = 0;
- char fs[128];
- char varname[128];
- const int32_t l = eel_validate_format_specifier(fmt, &ct, fs, sizeof(fs), varname, sizeof(varname));
- if (!l || !ct)
- {
- *op = 0;
- return -1;
- }
- const float *varptr = NULL;
- if (fmt_parmpos < num_fmt_parms)
- varptr = fmt_parms[fmt_parmpos];
- fmt_parmpos++;
- float v = varptr ? (float)*varptr : 0.0f;
- if (ct == 'x' || ct == 'X' || ct == 'd' || ct == 'u' || ct == 'i')
- {
- stbsp_snprintf(op, 64, fs, (int32_t)(v));
- }
- else if (ct == 's' || ct == 'S')
- {
- compileContext *c = (compileContext*)opaque;
- const char *str = (const char*)GetStringForIndex(c->m_string_context, v, 0);
- const size_t maxl = (size_t)(buf + buf_sz - 2u - op);
- stbsp_snprintf(op, maxl, fs, str ? str : "");
- }
- else if (ct == 'c')
- {
- *op++ = (char)(int32_t)v;
- *op = 0;
- }
- else if (ct == 'C')
- {
- const uint32_t iv = (uint32_t)v;
- int32_t bs = 0;
- if (iv & 0xff000000) bs = 24;
- else if (iv & 0x00ff0000) bs = 16;
- else if (iv & 0x0000ff00) bs = 8;
- while (bs >= 0)
- {
- const char c = (char)(iv >> bs);
- *op++ = c ? c : ' ';
- bs -= 8;
- }
- *op = 0;
- }
- else
- stbsp_snprintf(op, 64, fs, v);
- while (*op) op++;
- fmt += l;
- }
- else
- *op++ = *fmt++;
- }
- *op = 0;
- return (int32_t)(op - buf);
-}
-float NSEEL_CGEN_CALL _eel_printf(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param > 0)
- {
- compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *(parms[0]), 0);
- if (fmt)
- {
- int32_t stringLength = strlen(fmt);
- const int32_t len = eel_format_strings(opaque, fmt, fmt ? (fmt + stringLength) : NULL, c->printfbuf, sizeof(c->printfbuf), num_param - 1, parms + 1);
- if (len > 0)
- {
- EEL_STRING_STDOUT_WRITE(c->printfbuf, len);
- return 1.0f;
- }
- else
- {
- const char *badStr = "printf: bad format string";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- }
- else
- {
- const char *badStr = "printf: bad format specifier passed";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- }
- return 0.0f;
-}
-float NSEEL_CGEN_CALL _eel_sprintf(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param > 0)
- {
- compileContext *c = (compileContext*)opaque;
- s_str *wr = (s_str*)GetStringForIndex(c->m_string_context, *(parms[0]), 1);
- if (wr)
- s_str_destroy(wr);
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *(parms[1]), 0);
- if (wr && fmt)
- {
- int32_t stringLength = strlen(fmt);
- const int32_t len = eel_format_strings(opaque, fmt, fmt ? (fmt + stringLength) : NULL, c->printfbuf, sizeof(c->printfbuf), num_param - 2, parms + 2);
- if (len > 0)
- {
- *wr = s_str_create_from_c_str(c->printfbuf);
- return 1.0f;
- }
- else
- {
- const char *badStr = "printf: bad format string";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- }
- else
- {
- const char *badStr = "printf: bad format specifier passed";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- }
- return 0.0f;
-}
-static float _eel_strcmp_int(const char *a, int32_t a_len, const char *b, int32_t b_len, int32_t ml, int32_t ignorecase)
-{
- // binary-safe comparison (at least if a_len>=0 etc)
- int32_t pos = 0;
- for (;;)
- {
- if (ml > 0 && pos == ml) return 0.0f;
- const int32_t a_end = a_len >= 0 ? pos == a_len : !a[pos];
- const int32_t b_end = b_len >= 0 ? pos == b_len : !b[pos];
- if (a_end || b_end)
- {
- if (!b_end) return -1.0f; // b[pos] is nonzero, a[pos] is zero
- if (!a_end) return 1.0f;
- return 0.0f;
- }
- char av = a[pos];
- char bv = b[pos];
- if (ignorecase)
- {
- av = toupper(av);
- bv = toupper(bv);
- }
- if (bv > av) return -1.0f;
- if (av > bv) return 1.0f;
- pos++;
- }
-}
-static float NSEEL_CGEN_CALL _eel_strncmp(void *opaque, float *aa, float *bb, float *maxlen)
-{
- compileContext *c = (compileContext*)opaque;
- const char *a = (const char*)GetStringForIndex(c->m_string_context, *aa, 0);
- const char *b = (const char*)GetStringForIndex(c->m_string_context, *bb, 0);
- if (!a || !b)
- {
- const char *badStr = "strncmp: bad specifier(s)";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- else
- {
- const int32_t ml = maxlen ? (int32_t)(*maxlen + NSEEL_CLOSEFACTOR) : -1;
- if (!ml || a == b) return 0; // strncmp(x,y,0) == 0
- return _eel_strcmp_int(a, a ? strlen(a) : -1, b, b ? strlen(b) : -1, ml, 0);
- }
- return -1.0f;
-}
-static float NSEEL_CGEN_CALL _eel_strnicmp(void *opaque, float *aa, float *bb, float *maxlen)
-{
- compileContext *c = (compileContext*)opaque;
- const char *a = (const char*)GetStringForIndex(c->m_string_context, *aa, 0);
- const char *b = (const char*)GetStringForIndex(c->m_string_context, *bb, 0);
- if (!a || !b)
- {
- const char *badStr = "strnicmp: bad specifier(s)";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- else
- {
- const int32_t ml = maxlen ? (int32_t)(*maxlen + NSEEL_CLOSEFACTOR) : -1;
- if (!ml || a == b) return 0; // strncmp(x,y,0) == 0
- return _eel_strcmp_int(a, a ? strlen(a) : -1, b, b ? strlen(b) : -1, ml, 1);
- }
- return -1.0f;
-}
-static float NSEEL_CGEN_CALL _eel_strcmp(void *opaque, float *strOut, float *fmt_index)
-{
- return _eel_strncmp(opaque, strOut, fmt_index, NULL);
-}
-static float NSEEL_CGEN_CALL _eel_stricmp(void *opaque, float *strOut, float *fmt_index)
-{
- return _eel_strnicmp(opaque, strOut, fmt_index, NULL);
-}
-static float NSEEL_CGEN_CALL _eel_strlen(void *opaque, float *fmt_index)
-{
- compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *fmt_index, 0);
- if (fmt)
- return (float)strlen(fmt);
- return 0.0f;
-}
-#ifdef _WIN32
-#include
-#include "dirent.h"
-#else
-#include
-#include
-#endif
-static float NSEEL_CGEN_CALL _eel_ls(void *opaque, float *fmt_index)
-{
- DIR *dir;
- struct dirent *ent;
- char badStr[128];
- if ((dir = opendir(".")) != NULL)
- {
- while ((ent = readdir(dir)) != NULL)
- {
- stbsp_snprintf(badStr, 128, "%s\n", ent->d_name);
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- closedir(dir);
- }
- else
- return -1;
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_cd(void *opaque, float *fmt_index)
-{
- if (opaque)
- {
- compileContext *c = (compileContext*)opaque;
- const char *fmt = (const char*)GetStringForIndex(c->m_string_context, *fmt_index, 0);
- if (fmt)
-#ifdef _WIN32
- return (float)_chdir(fmt);
-#else
- return chdir(fmt);
-#endif
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_eval(void *opaque, float *s)
-{
- compileContext *r = (compileContext*)opaque;
- NSEEL_CODEHANDLE ch = NULL;
- if (r)
- {
- const char *str = (const char*)GetStringForIndex(r->m_string_context, *s, 0);
- if (!str)
- {
- const char *badStr = "eval() passed invalid string handle\n";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- else
- {
- if (!ch) ch = NSEEL_code_compile(r, str, 0);
- if (ch)
- {
- NSEEL_code_execute(ch);
- NSEEL_code_free(ch);
- return 1.0f;
- }
- else
- {
- const char *err = NSEEL_code_getcodeerror(r);
- if (err)
- {
- // EEL_STRING_DEBUGOUT("eval() error: %s", err);
- }
- }
- }
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_evalFile(void *opaque, float *s)
-{
- compileContext *r = (compileContext*)opaque;
- if (r)
- {
- const char *str = (const char*)GetStringForIndex(r->m_string_context, *s, 0);
- if (!str)
- {
- const char *badStr = "eval() passed invalid string handle\n";
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- else
- {
- FILE *fp = fopen(str, "rb");
- NSEEL_CODEHANDLE ch;
- if (fp)
- {
- s_str code = s_str_create();
- s_str_clear(&code);
- char line[4096];
- for (;;)
- {
- line[0] = 0;
- fgets(line, sizeof(line), fp);
- if (!line[0]) break;
- s_str_append_c_str(&code, line);
- }
- fclose(fp);
- const char *codetext = s_str_c_str(&code);
- ch = NSEEL_code_compile(r, codetext, 0);
- s_str_destroy(&code);
- if (ch)
- {
- NSEEL_code_execute(ch);
- NSEEL_code_free(ch);
- return 1.0f;
- }
- else
- {
- const char *err = NSEEL_code_getcodeerror(r);
- if (err)
- {
- EEL_STRING_STDOUT_WRITE(err, strlen(err));
- }
- }
- }
- }
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_base64_encode(void *opaque, float *destination, float *source, float *maxlen)
-{
- if (opaque)
- {
- compileContext *c = (compileContext*)opaque;
- s_str *dest = (s_str*)GetStringForIndex(c->m_string_context, *destination, 1);
- if (dest)
- s_str_destroy(dest);
- s_str *srcClass = (s_str*)GetStringForIndex(c->m_string_context, *source, 1);
- size_t len = (size_t)(*maxlen + NSEEL_CLOSEFACTOR);
- if (len > s_str_capacity(srcClass))
- return -1;
- const char *src = s_str_c_str(srcClass);
- if (dest && src)
- {
- unsigned char *out, *pos;
- const unsigned char *end, *in;
- size_t olen;
- int32_t line_len;
- olen = len * 4 / 3 + 4; // 3-byte blocks to 4-byte
- olen += olen / 72; // line feeds
- olen++; // nul termination
- if (olen < len)
- return 0; // integer overflow
- out = (unsigned char*)malloc(olen);
- if (out == 0)
- return 0;
- end = src + len;
- in = src;
- pos = out;
- line_len = 0;
- while (end - in >= 3)
- {
- *pos++ = base64_table[in[0] >> 2];
- *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
- *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)];
- *pos++ = base64_table[in[2] & 0x3f];
- in += 3;
- line_len += 4;
- if (line_len >= 72)
- {
- *pos++ = '\n';
- line_len = 0;
- }
- }
- if (end - in)
- {
- *pos++ = base64_table[in[0] >> 2];
- if (end - in == 1) {
- *pos++ = base64_table[(in[0] & 0x03) << 4];
- *pos++ = '=';
- }
- else
- {
- *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
- *pos++ = base64_table[(in[1] & 0x0f) << 2];
- }
- *pos++ = '=';
- line_len += 4;
- }
- if (line_len)
- *pos++ = '\n';
- *pos = '\0';
- size_t out_len = pos - out;
- *dest = s_str_create_from_c_str(out);
- free(out);
- return (float)out_len;
- }
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_base64_encodeBinaryToTextFile(void *opaque, float *destination, float *source)
-{
- if (opaque)
- {
- compileContext *c = (compileContext*)opaque;
- const char *dest = (const char*)GetStringForIndex(c->m_string_context, *destination, 0);
- const char *src = (const char *)GetStringForIndex(c->m_string_context, *source, 0);
- if (dest && src)
- {
- unsigned char *buffer = 0;
- long length;
- FILE *textFile = fopen(src, "rb");
- if (textFile)
- {
- fseek(textFile, 0, SEEK_END);
- length = ftell(textFile);
- fseek(textFile, 0, SEEK_SET);
- buffer = (unsigned char*)malloc(length + 1);
- if (buffer)
- fread((void*)buffer, 1, length, textFile);
- fclose(textFile);
- buffer[length] = '\0';
- }
- size_t outLen = 0;
- unsigned char *out;
- if (buffer)
- {
- out = base64_encode(buffer, length, &outLen);
- free(buffer);
- FILE *fp = fopen(dest, "w");
- if (fp)
- {
- fwrite(out, 1, outLen, fp);
- fclose(fp);
- }
- free(out);
- }
- return (float)outLen;
- }
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_base64_decode(void *opaque, float *destination, float *source, float *maxlen)
-{
- if (opaque)
- {
- compileContext *c = (compileContext*)opaque;
- s_str *dest = (s_str*)GetStringForIndex(c->m_string_context, *destination, 1);
- if (dest)
- s_str_destroy(dest);
- s_str *srcClass = (s_str*)GetStringForIndex(c->m_string_context, *source, 1);
- size_t len = (size_t)(*maxlen + NSEEL_CLOSEFACTOR);
- if (len > s_str_capacity(srcClass))
- return -1;
- const char *src = s_str_c_str(srcClass);
- if (dest && src)
- {
- unsigned char dtable[256], *out, *pos, block[4], tmp;
- size_t i, count, olen;
- int32_t pad = 0;
- memset(dtable, 0x80, 256);
- for (i = 0; i < sizeof(base64_table) - 1; i++)
- dtable[base64_table[i]] = (unsigned char)i;
- dtable['='] = 0;
- count = 0;
- for (i = 0; i < len; i++)
- if (dtable[src[i]] != 0x80)
- count++;
- if (count == 0 || count % 4)
- return 0;
- olen = count / 4 * 3;
- pos = out = (unsigned char*)malloc(olen);
- if (out == NULL)
- return 0;
- count = 0;
- for (i = 0; i < len; i++)
- {
- tmp = dtable[src[i]];
- if (tmp == 0x80)
- continue;
- if (src[i] == '=')
- pad++;
- block[count] = tmp;
- count++;
- if (count == 4)
- {
- *pos++ = (block[0] << 2) | (block[1] >> 4);
- *pos++ = (block[1] << 4) | (block[2] >> 2);
- *pos++ = (block[2] << 6) | block[3];
- count = 0;
- if (pad)
- {
- if (pad == 1)
- pos--;
- else if (pad == 2)
- pos -= 2;
- else
- {
- // Invalid padding
- free(out);
- return 0;
- }
- break;
- }
- }
- }
- size_t out_len = pos - out;
- *dest = s_str_create_from_c_str_0Inc(out, out_len);
- free(out);
- return (float)out_len;
- }
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_base64_decodeBinaryToTextFile(void *opaque, float *destination, float *source)
-{
- if (opaque)
- {
- compileContext *c = (compileContext*)opaque;
- const char *dest = (const char*)GetStringForIndex(c->m_string_context, *destination, 0);
- const char *src = (const char *)GetStringForIndex(c->m_string_context, *source, 0);
- if (dest && src)
- {
- unsigned char *buffer = 0;
- long length;
- FILE *textFile = fopen(src, "r");
- if (textFile)
- {
- fseek(textFile, 0, SEEK_END);
- length = ftell(textFile);
- fseek(textFile, 0, SEEK_SET);
- buffer = (unsigned char*)malloc(length + 1);
- if (buffer)
- fread(buffer, 1, length, textFile);
- fclose(textFile);
- buffer[length] = '\0';
- }
- size_t outLen = 0;
- unsigned char *out;
- if (buffer)
- {
- out = base64_decode(buffer, length, &outLen);
- free(buffer);
- FILE *fp = fopen(dest, "wb");
- if (fp)
- {
- fwrite(out, 1, outLen, fp);
- fclose(fp);
- }
- free(out);
- }
- return (float)outLen;
- }
- }
- return 0.0f;
-}
-static float NSEEL_CGEN_CALL _eel_delete_all_strings(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- eel_string_context_state *state = c->m_string_context;
- Freeel_string_context_state(state);
- Initeel_string_context_state(state);
- return 0.0f;
-}
-int32_t get_float(char *val, float *F)
-{
- char *eptr;
- errno = 0;
- float f = strtof(val, &eptr);
- if (eptr != val && errno != ERANGE)
- {
- *F = f;
- return 1;
- }
- return 0;
-}
-float* string2FloatArray(char *frArbitraryEqString, int32_t *elements)
-{
- char *p = frArbitraryEqString;
- char *counter = frArbitraryEqString;
- int32_t i = 0, count = 0;
- float number;
- while (*p)
- {
- if (get_float(p, &number))
- {
- strtod(p, &p);
- count++;
- }
- else
- p++;
- }
- *elements = count;
- float *arrayF = (float*)malloc(count * sizeof(float));
- while (*counter)
- {
- if (get_float(counter, &number))
- {
- arrayF[i] = (float)strtod(counter, &counter);
- i++;
- }
- else
- counter++;
- }
- return arrayF;
-}
-static float NSEEL_CGEN_CALL _eel_importFloatArrayFromString(void *opaque, float *fn_index, float *pointer)
-{
- compileContext *c = (compileContext*)opaque;
- const char *FLTBuf = (const char*)GetStringForIndex(c->m_string_context, *fn_index, 0);
- uint32_t offs1 = (uint32_t)(*pointer + NSEEL_CLOSEFACTOR);
- float *userspaceFLT = __NSEEL_RAMAlloc(c->ram_state, offs1);
- int32_t elements;
- float *convertedFLT = string2FloatArray((char*)FLTBuf, &elements);
- memcpy(userspaceFLT, convertedFLT, elements * sizeof(float));
- free(convertedFLT);
- return (float)elements;
-}
-void fractionalDelayLine_clear(float *fdl)
-{
- for (int32_t i = 0; i < (int32_t)fdl[2]; i++)
- fdl[5 + i] = 0.;
-}
-static float NSEEL_CGEN_CALL fractionalDelayLineInit(float *blocks, float *start, float *length)
-{
- int32_t offs1 = (int32_t)(*start + NSEEL_CLOSEFACTOR);
- int32_t max_length = (int32_t)(*length + NSEEL_CLOSEFACTOR);
- float *fdl = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- fdl[0] = 0;
- fdl[1] = 0;
- fdl[2] = (float)max_length;
- fractionalDelayLine_clear(fdl);
- return (float)(max_length + 5);
-}
-static float NSEEL_CGEN_CALL fractionalDelayLineClear(float *blocks, float *start)
-{
- int32_t offs1 = (int32_t)(*start + NSEEL_CLOSEFACTOR);
- float *fdl = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- fractionalDelayLine_clear(fdl);
- return 1;
-}
-static float NSEEL_CGEN_CALL fractionalDelayLineSetDelay(float *blocks, float *start, float *lg)
-{
- uint32_t offs1 = (uint32_t)(*start + NSEEL_CLOSEFACTOR);
- float lag = *lg;
- float *fdl = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float outPointer;
- if (lag > fdl[2] - 1.0f)
- outPointer = fdl[0] + 1.0f; // force delay to max_length
- else
- outPointer = fdl[0] - lag; // read chases write
- while (outPointer < 0)
- outPointer += fdl[2]; // modulo maximum length
- fdl[1] = (float)((int32_t)outPointer); // integer part
- fdl[3] = outPointer - fdl[1]; // fractional part
- fdl[4] = 1.0f - fdl[3]; // 1.0f - fractional part (more efficient)
- return 1;
-}
-static float NSEEL_CGEN_CALL fractionalDelayLineProcess(float *blocks, float *start, float *x)
-{
- uint32_t offs1 = (uint32_t)(*start + NSEEL_CLOSEFACTOR);
- float *fdl = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t inPtr = (int32_t)(fdl[0] + NSEEL_CLOSEFACTOR);
- fdl[5 + inPtr++] = *x;
- int32_t len = (int32_t)(fdl[2] + NSEEL_CLOSEFACTOR);
- if (inPtr == len) // Check for end condition
- inPtr -= len;
- fdl[0] = (float)inPtr;
- int32_t outPtr = (int32_t)(fdl[1] + NSEEL_CLOSEFACTOR);
- float lastOutput = fdl[5 + outPtr++] * fdl[4]; // first 1/2 of interpolation
- if (outPtr < len) // Check for end condition
- lastOutput += fdl[5 + outPtr] * fdl[3]; // second 1/2 of interpolation
- else
- {
- lastOutput += fdl[5] * fdl[3]; // second 1/2 of interpolation
- outPtr -= len;
- }
- fdl[1] = (float)outPtr;
- return lastOutput;
-}
-static float NSEEL_CGEN_CALL FIRInit(float *blocks, float *start, float *length)
-{
- uint32_t offs1 = (uint32_t)(*start + NSEEL_CLOSEFACTOR);
- int32_t hlen = (int32_t)(*length + NSEEL_CLOSEFACTOR);
- float *fir = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- memset(fir, 0, (hlen + 2) * sizeof(float));
- fir[1] = (float)hlen;
- return (float)(hlen + 2);
-}
-static float NSEEL_CGEN_CALL FIRProcess(float *blocks, float *start, float *x, float *coe)
-{
- int32_t offs1 = (int32_t)(*start + NSEEL_CLOSEFACTOR);
- float *fir = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*coe + NSEEL_CLOSEFACTOR);
- float *coeffs = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- float *coeff = coeffs;
- int32_t coeffslength = (int32_t)(fir[1] + NSEEL_CLOSEFACTOR);
- float *coeff_end = coeffs + coeffslength;
- int32_t pos = (int32_t)(fir[0] + NSEEL_CLOSEFACTOR);
- float *dline = &fir[2];
- float *buf_val = dline + pos;
- *buf_val = *x;
- float y = 0.0f;
- while (buf_val >= dline)
- y += *buf_val-- * *coeff++;
- buf_val = dline + coeffslength - 1;
- while (coeff < coeff_end)
- y += *buf_val-- * *coeff++;
- if (++pos >= coeffslength)
- fir[0] = (float)0;
- else
- fir[0] = (float)pos;
- return y;
-}
-#define NRAND 624
-#define MRAND 397
-#define MATRIX_A 0x9908b0dfUL /* constant vector a */
-#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
-#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
-float NSEEL_CGEN_CALL nseel_int_rand(float amplitude)
-{
- uint32_t y;
- static uint32_t mag01[2] = { 0x0UL, MATRIX_A };
- /* mag01[x] = x * MATRIX_A for x=0,1 */
- static uint32_t mt[NRAND]; /* the array for the state vector */
- static uint32_t __idx;
- uint32_t mti = __idx;
- if (!mti)
- {
- uint32_t s = 0x4141f00d;
- mt[0] = s & 0xffffffffUL;
- for (mti = 1; mti < NRAND; mti++)
- {
- mt[mti] =
- (1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti);
- /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
- /* In the previous versions, MSBs of the seed affect */
- /* only MSBs of the array mt[]. */
- /* 2002/01/09 modified by Makoto Matsumoto */
- mt[mti] &= 0xffffffffUL;
- /* for >32 bit machines */
- }
- __idx = NRAND; // mti = N (from loop)
- }
- if (mti >= NRAND) { /* generate N words at one time */
- int32_t kk;
- __idx = 1;
-
- for (kk = 0; kk < NRAND - MRAND; kk++) {
- y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
- mt[kk] = mt[kk + MRAND] ^ (y >> 1) ^ mag01[y & 0x1UL];
- }
- for (; kk < NRAND - 1; kk++) {
- y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
- mt[kk] = mt[kk + (MRAND - NRAND)] ^ (y >> 1) ^ mag01[y & 0x1UL];
- }
- y = (mt[NRAND - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
- mt[NRAND - 1] = mt[MRAND - 1] ^ (y >> 1) ^ mag01[y & 0x1UL];
-
- mti = 0;
- }
- else
- __idx++;
- y = mt[mti];
- /* Tempering */
- y ^= (y >> 11);
- y ^= (y << 7) & 0x9d2c5680UL;
- y ^= (y << 15) & 0xefc60000UL;
- y ^= (y >> 18);
- return (float)(y*(1.0f / (float)0xFFFFFFFF) * fabsf(amplitude));
-}
-// Calculate pseudo-random 32 bit number based on linear congruential method.
-static unsigned long GenerateRandomNumber(void)
-{
- static unsigned long randSeed = 22222; // Change this for different random sequences.
- randSeed = (randSeed * 196314165) + 907633515;
- return randSeed;
-}
-#define PINK_MAX_RANDOM_ROWS 31
-#define PINK_RANDOM_BITS 24
-#define PINK_RANDOM_SHIFT ((sizeof(long)*8)-PINK_RANDOM_BITS)
-typedef struct
-{
- long pink_Rows[PINK_MAX_RANDOM_ROWS];
- long pink_RunningSum; // Used to optimize summing of generators
- int pink_Index; // Incremented each sample
- int pink_IndexMask; // Index wrapped by ANDing with this mask
- float pink_Scalar; // Used to scale within range of -1.0f to +1.0f
-} PinkNoise;
-// EEL_SETUP PinkNoise structure for N rows of generators
-void InitializePinkNoise(PinkNoise *pink, unsigned int numRows)
-{
- unsigned int i;
- long pmax;
- pink->pink_Index = 0;
- pink->pink_IndexMask = (1 << numRows) - 1;
- // Calculate maximum possible signed random value. Extra 1 for white noise always added
- pmax = (numRows + 1) * (1 << (PINK_RANDOM_BITS - 1));
- pink->pink_Scalar = 1.0f / pmax;
- // Initialize rows
- for (i = 0; i < numRows; i++) pink->pink_Rows[i] = 0;
- pink->pink_RunningSum = 0;
-}
-// Generate Pink noise values between -1.0f and +1.0f
-float GeneratePinkNoise(PinkNoise *pink)
-{
- long newRandom;
- // Increment and mask index
- pink->pink_Index = (pink->pink_Index + 1) & pink->pink_IndexMask;
- // If index is zero, don't update any random values
- if (pink->pink_Index)
- {
- // Determine how many trailing zeros in PinkIndex
- // This algorithm will hang if n==0 so test first
- int numZeros = 0;
- int n = pink->pink_Index;
- while ((n & 1) == 0)
- {
- n = n >> 1;
- numZeros++;
- }
- // Replace the indexed ROWS random value.
- // Subtract and add back to RunningSum instead of adding all the random
- // values together. Only one changes each time.
- pink->pink_RunningSum -= pink->pink_Rows[numZeros];
- newRandom = ((long)GenerateRandomNumber()) >> PINK_RANDOM_SHIFT;
- pink->pink_RunningSum += newRandom;
- pink->pink_Rows[numZeros] = newRandom;
- }
- // Add extra white noise value
- newRandom = ((long)GenerateRandomNumber()) >> PINK_RANDOM_SHIFT;
- return pink->pink_Scalar * (float)(pink->pink_RunningSum + newRandom);
-}
-static float NSEEL_CGEN_CALL pinkNoiseInit(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 2)
- return 0;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int pinkness = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- if (pinkness < 1)
- pinkness = 1;
- if (pinkness > 30)
- pinkness = 30;
- memset(indexer, 0, sizeof(PinkNoise));
- InitializePinkNoise(((PinkNoise*)indexer), pinkness);
- return sizeof(PinkNoise) / sizeof(float) + 1;
-}
-static float NSEEL_CGEN_CALL pinkNoiseGen(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- PinkNoise *noiseStruct = (PinkNoise*)indexer;
- return GeneratePinkNoise(noiseStruct) * *parms[1];
-}
-#include "numericSys/FilterDesign/polyphaseFilterbank.h"
-static float NSEEL_CGEN_CALL PolyphaseFilterbankInit(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 4)
- return 0;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- float fs = *parms[0];
- unsigned int N = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- if (N < 2)
- {
- *parms[1] = 2;
- N = 2;
- char badStr[128];
- stbsp_snprintf(badStr, 128, "Number of subbands cannot be less than 2\n");
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- unsigned int m = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- size_t requiredMemSize = getMemSizeWarpedPFB(N, m);
- size_t aligned = requiredMemSize / sizeof(float) + 1;
- int32_t offs1 = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = 0;
- float *indexer2 = 0;
- if (num_param == 5)
- {
- indexer2 = __NSEEL_RAMAlloc(blocks, offs1 + aligned);
- *parms[4] = offs1 + aligned;
- }
- WarpedPFB *pfbPtr = (WarpedPFB*)indexer;
- WarpedPFB *pfbPtr2 = (WarpedPFB*)indexer2;
- initWarpedPFB(pfbPtr, fs, N, m);
- if (pfbPtr2)
- assignPtrWarpedPFB(pfbPtr2, N, m);
- return (float)requiredMemSize;
-}
-static float NSEEL_CGEN_CALL PolyphaseFilterbankChangeWarpingFactor(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 3)
- return 0;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float fs = *parms[1];
- float warpFact = *parms[2];
- WarpedPFB *pfbPtr = (WarpedPFB*)indexer;
- changeWarpingFactorWarpedPFB(pfbPtr, fs, warpFact);
- return 0;
-}
-static float NSEEL_CGEN_CALL PolyphaseFilterbankGetPhaseCorrector(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 3)
- return 0;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float corrFact = *parms[1];
- int32_t offs2 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *phaseCorr = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- WarpedPFB *pfbPtr = (WarpedPFB*)indexer;
- unsigned int CFiltLen;
- float *filter = getPhaseCorrFilterWarpedPFB(pfbPtr, corrFact, &CFiltLen);
- for (int32_t i = 0; i < CFiltLen; i++)
- phaseCorr[i] = filter[i];
- free(filter);
- return CFiltLen;
-}
-static float NSEEL_CGEN_CALL PolyphaseFilterbankGetDecimationFactor(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 2)
- return 0;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *decF = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- WarpedPFB *pfbPtr = (WarpedPFB*)indexer;
- for (int32_t i = 0; i < pfbPtr->N; i++)
- decF[i] = pfbPtr->Sk[i];
- return 0;
-}
-static float NSEEL_CGEN_CALL PolyphaseFilterbankAnalysisMono(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 4)
- return 0;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *subbandDat = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t offs3 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *decimationCounter = __NSEEL_RAMAlloc(blocks, (uint64_t)offs3);
- float xn = *parms[3];
- WarpedPFB *pfbPtr = (WarpedPFB*)indexer;
- analysisWarpedPFB(pfbPtr, xn);
- getSubbandDatWarpedPFB(pfbPtr, subbandDat, decimationCounter);
- return 0;
-}
-static float NSEEL_CGEN_CALL PolyphaseFilterbankSynthesisMono(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 2)
- return 0;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *subbandDat = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- WarpedPFB *pfbPtr = (WarpedPFB*)indexer;
- writeSubbandDatWarpedPFB(pfbPtr, subbandDat);
- float y = synthesisWarpedPFB(pfbPtr);
- return y;
-}
-static float NSEEL_CGEN_CALL PolyphaseFilterbankAnalysisStereo(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 7)
- return -1;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer1 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *indexer2 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t offs3 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *subbandDat1 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs3);
- int32_t offs4 = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *subbandDat2 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs4);
- int32_t offs5 = (int32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- float *decimationCounter = __NSEEL_RAMAlloc(blocks, (uint64_t)offs5);
- WarpedPFB *pfb1Ptr = (WarpedPFB*)indexer1;
- WarpedPFB *pfb2Ptr = (WarpedPFB*)indexer2;
- analysisWarpedPFBStereo(pfb1Ptr, pfb2Ptr, parms[5], parms[6]);
- getSubbandDatWarpedPFBStereo(pfb1Ptr, pfb2Ptr, subbandDat1, subbandDat2, decimationCounter);
- return 0;
-}
-static float NSEEL_CGEN_CALL PolyphaseFilterbankSynthesisStereo(void *opaque, INT_PTR num_param, float **parms)
-{
- if (num_param < 6)
- return -1;
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- int32_t offs1 = (int32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float *indexer1 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- int32_t offs2 = (int32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *indexer2 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- int32_t offs3 = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *subbandDat1 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs3);
- int32_t offs4 = (int32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *subbandDat2 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs4);
- WarpedPFB *pfb1Ptr = (WarpedPFB*)indexer1;
- WarpedPFB *pfb2Ptr = (WarpedPFB*)indexer2;
- writeSubbandDatWarpedPFBStereo(pfb1Ptr, pfb2Ptr, subbandDat1, subbandDat2);
- synthesisWarpedPFBStereo(pfb1Ptr, pfb2Ptr, parms[4], parms[5]);
- return 0;
-}
-#include "numericSys/FilterDesign/fdesign.h"
-static float NSEEL_CGEN_CALL _eel_iirBandSplitterInit(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- uint32_t offs1 = (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- float fs = *parms[1];
- float *tdsbStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- if (num_param > 9)
- return -1;
- size_t requireMemSize;
- void *ptr = 0;
- if (num_param == 3)
- {
- requireMemSize = sizeof(LinkwitzRileyCrossover);
- LinkwitzRileyCrossover *lr = (LinkwitzRileyCrossover*)malloc(requireMemSize);
- LWZRClearStateVariable(lr);
- LWZRCalculateCoefficients(lr, fs, *parms[2], 0);
- ptr = lr;
- }
- else if (num_param == 4)
- {
- requireMemSize = sizeof(ThreeBandsCrossover);
- ThreeBandsCrossover *bps = (ThreeBandsCrossover*)malloc(requireMemSize);
- memset(bps, 0, sizeof(ThreeBandsCrossover));
- init3BandsCrossover(bps, fs, *parms[2], *parms[3]);
- ptr = bps;
- }
- else if (num_param == 5)
- {
- requireMemSize = sizeof(FourBandsCrossover);
- FourBandsCrossover *bps = (FourBandsCrossover*)malloc(requireMemSize);
- memset(bps, 0, sizeof(FourBandsCrossover));
- init4BandsCrossover(bps, fs, *parms[2], *parms[3], *parms[4]);
- ptr = bps;
- }
- else if (num_param == 6)
- {
- requireMemSize = sizeof(FiveBandsCrossover);
- FiveBandsCrossover *bps = (FiveBandsCrossover*)malloc(requireMemSize);
- memset(bps, 0, sizeof(FiveBandsCrossover));
- init5BandsCrossover(bps, fs, *parms[2], *parms[3], *parms[4], *parms[5]);
- ptr = bps;
- }
- else if (num_param == 7)
- {
- requireMemSize = sizeof(SixBandsCrossover);
- SixBandsCrossover *bps = (SixBandsCrossover*)malloc(requireMemSize);
- memset(bps, 0, sizeof(SixBandsCrossover));
- init6BandsCrossover(bps, fs, *parms[2], *parms[3], *parms[4], *parms[5], *parms[6]);
- ptr = bps;
- }
- else if (num_param == 8)
- {
- requireMemSize = sizeof(SevenBandsCrossover);
- SevenBandsCrossover *bps = (SevenBandsCrossover*)malloc(requireMemSize);
- memset(bps, 0, sizeof(SevenBandsCrossover));
- init7BandsCrossover(bps, fs, *parms[2], *parms[3], *parms[4], *parms[5], *parms[6], *parms[7]);
- ptr = bps;
- }
- else if (num_param == 9)
- {
- requireMemSize = sizeof(EightBandsCrossover);
- EightBandsCrossover *bps = (EightBandsCrossover*)malloc(requireMemSize);
- memset(bps, 0, sizeof(EightBandsCrossover));
- init8BandsCrossover(bps, fs, *parms[2], *parms[3], *parms[4], *parms[5], *parms[6], *parms[7], *parms[8]);
- ptr = bps;
- }
- tdsbStruct[0] = (float)(num_param - 1);
- memcpy(tdsbStruct + 1, ptr, requireMemSize);
- free(ptr);
- return (float)(1 + requireMemSize / sizeof(float));
-}
-static float NSEEL_CGEN_CALL _eel_iirBandSplitterClearState(float *blocks, float *start)
-{
- float *tdsbStruct = __NSEEL_RAMAlloc(blocks, (uint64_t)(uint32_t)(*start + NSEEL_CLOSEFACTOR));
- int32_t bands = (int32_t)(tdsbStruct[0] + NSEEL_CLOSEFACTOR);
- switch (bands)
- {
- case 2:
- LWZRClearStateVariable((LinkwitzRileyCrossover*)(tdsbStruct + 1));
- break;
- case 3:
- clearState3BandsCrossover((ThreeBandsCrossover*)(tdsbStruct + 1));
- break;
- case 4:
- clearState4BandsCrossover((FourBandsCrossover*)(tdsbStruct + 1));
- break;
- case 5:
- clearState5BandsCrossover((FiveBandsCrossover*)(tdsbStruct + 1));
- break;
- case 6:
- clearState6BandsCrossover((SixBandsCrossover*)(tdsbStruct + 1));
- break;
- case 7:
- clearState7BandsCrossover((SevenBandsCrossover*)(tdsbStruct + 1));
- break;
- case 8:
- clearState8BandsCrossover((EightBandsCrossover*)(tdsbStruct + 1));
- break;
- }
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_iirBandSplitterProcess(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *tdsbStruct = __NSEEL_RAMAlloc(c->ram_state, (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR));
- int32_t bands = (int32_t)(tdsbStruct[0] + NSEEL_CLOSEFACTOR);
- double out[8];
- switch (bands)
- {
- case 2:
- LWZRProcessSample((LinkwitzRileyCrossover*)(tdsbStruct + 1), *parms[1], &out[0], &out[1]);
- *parms[2] = (float)out[0];
- *parms[3] = (float)-out[1];
- break;
- case 3:
- process3BandsCrossover((ThreeBandsCrossover*)(tdsbStruct + 1), *parms[1], &out[0], &out[1], &out[2]);
- *parms[2] = (float)out[0];
- *parms[3] = (float)-out[1];
- *parms[4] = (float)out[2];
- break;
- case 4:
- process4BandsCrossover((FourBandsCrossover*)(tdsbStruct + 1), *parms[1], &out[0], &out[1], &out[2], &out[3]);
- *parms[2] = (float)out[0];
- *parms[3] = (float)-out[1];
- *parms[4] = (float)out[2];
- *parms[5] = (float)-out[3];
- break;
- case 5:
- process5BandsCrossover((FiveBandsCrossover*)(tdsbStruct + 1), *parms[1], &out[0], &out[1], &out[2], &out[3], &out[4]);
- *parms[2] = (float)out[0];
- *parms[3] = (float)-out[1];
- *parms[4] = (float)out[2];
- *parms[5] = (float)-out[3];
- *parms[6] = (float)out[4];
- break;
- case 6:
- process6BandsCrossover((SixBandsCrossover*)(tdsbStruct + 1), *parms[1], &out[0], &out[1], &out[2], &out[3], &out[4], &out[5]);
- *parms[2] = (float)out[0];
- *parms[3] = (float)-out[1];
- *parms[4] = (float)out[2];
- *parms[5] = (float)-out[3];
- *parms[6] = (float)out[4];
- *parms[7] = (float)-out[5];
- break;
- case 7:
- process7BandsCrossover((SevenBandsCrossover*)(tdsbStruct + 1), *parms[1], &out[0], &out[1], &out[2], &out[3], &out[4], &out[5], &out[6]);
- *parms[2] = (float)out[0];
- *parms[3] = (float)-out[1];
- *parms[4] = (float)out[2];
- *parms[5] = (float)-out[3];
- *parms[6] = (float)out[4];
- *parms[7] = (float)-out[5];
- *parms[8] = (float)out[6];
- break;
- case 8:
- process8BandsCrossover((EightBandsCrossover*)(tdsbStruct + 1), *parms[1], &out[0], &out[1], &out[2], &out[3], &out[4], &out[5], &out[6], &out[7]);
- *parms[2] = (float)out[0];
- *parms[3] = (float)-out[1];
- *parms[4] = (float)out[2];
- *parms[5] = (float)-out[3];
- *parms[6] = (float)out[4];
- *parms[7] = (float)-out[5];
- *parms[8] = (float)out[6];
- *parms[9] = (float)-out[7];
- break;
- }
- return 1;
-}
-#include "eel_matrix.h"
-#include "numericSys/FFTConvolver.h"
-static float NSEEL_CGEN_CALL _eel_initfftconv1d(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- if (c->numberOfConvolver > 1024 - 1)
- return -1;
- uint32_t ranN;
- while (1)
- {
- ranN = (uint32_t)(nseel_int_rand(1.0f) * 1024.0);
- uint32_t counter = 0;
- for (uint32_t i = 0; i < c->numberOfConvolver; i++)
- {
- if (ranN == c->convolverMap[i])
- {
- counter++;
- break;
- }
- }
- if (!counter)
- break;
- }
- void *ptr = 0;
- uint32_t convType;
- if (num_param == 3)
- convType = 1;
- else if (num_param == 4)
- convType = 2;
- else if (num_param == 6)
- convType = 4;
- else
- return -2;
- uint32_t latency = (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR);
- uint32_t irLen = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- if (convType == 1)
- {
- int32_t offs1 = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *impulseresponse = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- FFTConvolver1x1 *conv = (FFTConvolver1x1*)malloc(sizeof(FFTConvolver1x1));
- FFTConvolver1x1Init(conv);
- FFTConvolver1x1LoadImpulseResponse(conv, latency, impulseresponse, irLen);
- ptr = (void*)conv;
- }
- if (convType == 2)
- {
- uint32_t offs1 = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- uint32_t offs2 = (uint32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- float *leftImp = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *rightImp = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- FFTConvolver2x2 *conv = (FFTConvolver2x2*)malloc(sizeof(FFTConvolver2x2));
- FFTConvolver2x2Init(conv);
- FFTConvolver2x2LoadImpulseResponse(conv, latency, leftImp, rightImp, irLen);
- ptr = (void*)conv;
- }
- if (convType == 4)
- {
- uint32_t offs1 = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- uint32_t offs2 = (uint32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- uint32_t offs3 = (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- uint32_t offs4 = (uint32_t)(*parms[5] + NSEEL_CLOSEFACTOR);
- float *LL = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *LR = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- float *RL = __NSEEL_RAMAlloc(blocks, (uint64_t)offs3);
- float *RR = __NSEEL_RAMAlloc(blocks, (uint64_t)offs4);
- FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2*)malloc(sizeof(FFTConvolver2x4x2));
- FFTConvolver2x4x2Init(conv);
- FFTConvolver2x4x2LoadImpulseResponse(conv, latency, LL, LR, RL, RR, irLen);
- ptr = (void*)conv;
- }
- c->numberOfConvolver++;
- int32_t idx = c->numberOfConvolver - 1;
- if (idx)
- {
- c->convolverMap = (uint32_t*)realloc(c->convolverMap, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverType = (uint32_t*)realloc(c->convolverType, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverSink = (void**)realloc(c->convolverSink, c->numberOfConvolver * sizeof(void*));
- }
- else
- {
- c->convolverMap = (uint32_t*)malloc(c->numberOfConvolver * sizeof(uint32_t));
- c->convolverType = (uint32_t*)malloc(c->numberOfConvolver * sizeof(uint32_t));
- c->convolverSink = (void**)malloc(c->numberOfConvolver * sizeof(void*));
- }
- c->convolverMap[idx] = ranN;
- c->convolverType[idx] = convType;
- c->convolverSink[idx] = ptr;
- return (float)ranN;
-}
-static float NSEEL_CGEN_CALL _eel_deletefftconv1d(void *opaque, float *v)
-{
- compileContext *c = (compileContext*)opaque;
- if (!c->convolverMap)
- return -1;
- int32_t idx = arySearch(c->convolverMap, c->numberOfConvolver, (int32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return -2;
- void *ptr = c->convolverSink[idx];
- int32_t convType = c->convolverType[idx];
- if (convType == 1)
- {
- FFTConvolver1x1 *conv = (FFTConvolver1x1*)ptr;
- FFTConvolver1x1Free(conv);
- free(conv);
- }
- if (convType == 2)
- {
- FFTConvolver2x2 *conv = (FFTConvolver2x2*)ptr;
- FFTConvolver2x2Free(conv);
- free(conv);
- }
- if (convType == 4)
- {
- FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2*)ptr;
- FFTConvolver2x4x2Free(conv);
- free(conv);
- }
- for (uint32_t i = idx; i < c->numberOfConvolver - 1; i++)
- {
- c->convolverMap[i] = c->convolverMap[i + 1];
- c->convolverType[i] = c->convolverType[i + 1];
- c->convolverSink[i] = c->convolverSink[i + 1];
- }
- c->numberOfConvolver--;
- if (c->numberOfConvolver)
- {
- c->convolverMap = (uint32_t*)realloc(c->convolverMap, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverType = (uint32_t*)realloc(c->convolverType, c->numberOfConvolver * sizeof(uint32_t));
- c->convolverSink = (void**)realloc(c->convolverSink, c->numberOfConvolver * sizeof(void*));
- }
- else
- {
- free(c->convolverMap);
- free(c->convolverType);
- free(c->convolverSink);
- c->convolverMap = 0;
- c->convolverType = 0;
- c->convolverSink = 0;
- }
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_processfftconv1d(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- if (!c->convolverMap)
- return -1;
- int32_t idx = arySearch(c->convolverMap, c->numberOfConvolver, (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return 0;
- void *ptr = c->convolverSink[idx];
- int32_t convType = c->convolverType[idx];
- if (convType == 1)
- {
- FFTConvolver1x1 *conv = (FFTConvolver1x1*)ptr;
- uint32_t offs1 = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float *x = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- FFTConvolver1x1Process(conv, x, x, conv->_blockSize);
- }
- if (convType == 2)
- {
- FFTConvolver2x2 *conv = (FFTConvolver2x2*)ptr;
- uint32_t offs1 = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- uint32_t offs2 = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *x1 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *x2 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- FFTConvolver2x2Process(conv, x1, x2, x1, x2, conv->_blockSize);
- }
- if (convType == 4)
- {
- FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2*)ptr;
- uint32_t offs1 = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- uint32_t offs2 = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float *x1 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs1);
- float *x2 = __NSEEL_RAMAlloc(blocks, (uint64_t)offs2);
- FFTConvolver2x4x2Process(conv, x1, x2, x1, x2, conv->_blockSize);
- }
- return 1;
-}
-
-void *task_user_created(void *arg)
-{
- abstractThreads *info = (abstractThreads *)arg;
- // cond_wait mutex must be locked before we can wait
- pthread_mutex_lock(&(info->work_mtx));
- // ensure boss is waiting
- pthread_mutex_lock(&(info->boss_mtx));
- // signal to boss that EEL_SETUP is complete
- info->state = EEL_IDLE;
- // wake-up signal
- pthread_cond_signal(&(info->boss_cond));
- pthread_mutex_unlock(&(info->boss_mtx));
- while (1)
- {
- pthread_cond_wait(&(info->work_cond), &(info->work_mtx));
- if (EEL_GET_OFF_FROM_WORK == info->state)
- break; // kill thread
- if (EEL_IDLE == info->state)
- continue; // accidental wake-up
- // do blocking task
- NSEEL_code_execute(info->codePtr);
- // ensure boss is waiting
- pthread_mutex_lock(&(info->boss_mtx));
- // indicate that job is done
- info->state = EEL_IDLE;
- // wake-up signal
- pthread_cond_signal(&(info->boss_cond));
- pthread_mutex_unlock(&(info->boss_mtx));
- }
- pthread_mutex_unlock(&(info->work_mtx));
- pthread_exit(NULL);
- return 0;
-}
-void eelThread_start(compileContext *st, size_t task)
-{
- abstractThreads *info = st->codePtrThreadSink[task];
- // ensure worker is waiting
- pthread_mutex_lock(&(info->work_mtx));
- // set job information & state
- info->state = EEL_WORKING;
- // wake-up signal
- pthread_cond_signal(&(info->work_cond));
- pthread_mutex_unlock(&(info->work_mtx));
-}
-void eelThread_wait(compileContext *st, size_t task)
-{
- abstractThreads *info = st->codePtrThreadSink[task];
- while (1)
- {
- pthread_cond_wait(&(info->boss_cond), &(info->boss_mtx));
- if (EEL_IDLE == info->state)
- break;
- }
-}
-void thread_init(compileContext *st, int task)
-{
- abstractThreads *info = st->codePtrThreadSink[task];
- info->state = EEL_SETUP;
- pthread_cond_init(&(info->work_cond), NULL);
- pthread_mutex_init(&(info->work_mtx), NULL);
- pthread_cond_init(&(info->boss_cond), NULL);
- pthread_mutex_init(&(info->boss_mtx), NULL);
- pthread_mutex_lock(&(info->boss_mtx));
- pthread_create(&info->threadID, NULL, task_user_created, (void *)info);
- eelThread_wait(st, task);
-}
-void thread_delete(compileContext *st, int task)
-{
- abstractThreads *info = st->codePtrThreadSink[task];
- // ensure the worker is waiting
- if (info->state == EEL_WORKING)
- eelThread_wait(st, task);
- pthread_mutex_lock(&(info->work_mtx));
- info->state = EEL_GET_OFF_FROM_WORK;
- // wake-up signal
- pthread_cond_signal(&(info->work_cond));
- pthread_mutex_unlock(&(info->work_mtx));
- // wait for thread to exit
- pthread_join(info->threadID, NULL);
- pthread_mutex_destroy(&(info->work_mtx));
- pthread_cond_destroy(&(info->work_cond));
- pthread_mutex_unlock(&(info->boss_mtx));
- pthread_mutex_destroy(&(info->boss_mtx));
- pthread_cond_destroy(&(info->boss_cond));
- NSEEL_code_free(info->codePtr);
-}
-static float NSEEL_CGEN_CALL _eel_initthread(void *opaque, float *stringID)
-{
- compileContext *c = (compileContext*)opaque;
- const char *codePtr = (const char*)GetStringForIndex(c->m_string_context, *stringID, 0);
- NSEEL_CODEHANDLE compiledCode = NSEEL_code_compile_ex(c, codePtr, 0, 1);
- char *err;
- char badStr[128];
- if (!compiledCode && (err = NSEEL_code_getcodeerror(c)))
- {
- stbsp_snprintf(badStr, 128, "Error when compiling code for thread: %s\n", err);
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- return -2;
- }
- float *blocks = c->ram_state;
- if (c->numberOfThreads > 1024 - 1)
- return -1;
- uint32_t ranN;
- while (1)
- {
- ranN = (uint32_t)(nseel_int_rand(1.0f) * 1024.0);
- uint32_t counter = 0;
- for (uint32_t i = 0; i < c->numberOfThreads; i++)
- {
- if (ranN == c->threadMap[i])
- {
- counter++;
- break;
- }
- }
- if (!counter)
- break;
- }
- c->numberOfThreads++;
- int32_t idx = c->numberOfThreads - 1;
- c->codePtrThreadSink[idx] = (abstractThreads*)malloc(sizeof(abstractThreads));
- thread_init(c, idx);
- c->codePtrThreadSink[idx]->codePtr = compiledCode;
- c->threadMap[idx] = ranN;
- return (float)ranN;
-}
-static float NSEEL_CGEN_CALL _eel_deletethread(void *opaque, float *v)
-{
- compileContext *c = (compileContext*)opaque;
- if (!c->threadMap)
- return -1;
- int32_t idx = arySearch(c->threadMap, c->numberOfThreads, (int32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return -2;
- thread_delete(c, idx);
- free(c->codePtrThreadSink[idx]);
- for (uint32_t i = idx; i < c->numberOfThreads - 1; i++)
- {
- c->threadMap[i] = c->threadMap[i + 1];
- c->codePtrThreadSink[i] = c->codePtrThreadSink[i + 1];
- }
- c->numberOfThreads--;
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_createThread(void *opaque, float *v)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- if (!c->threadMap)
- return -1;
- int32_t idx = arySearch(c->threadMap, c->numberOfThreads, (uint32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return 0;
- eelThread_start(c, idx);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_joinThread(void *opaque, float *v)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- if (!c->threadMap)
- return -1;
- int32_t idx = arySearch(c->threadMap, c->numberOfThreads, (uint32_t)(*v + NSEEL_CLOSEFACTOR));
- if (idx < 0)
- return 0;
- eelThread_wait(c, idx);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_lockThread(void *opaque, float *v)
-{
- compileContext *c = (compileContext*)opaque;
- pthread_mutex_lock(&c->globalLocker);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_unlockThread(void *opaque, float *v)
-{
- compileContext *c = (compileContext*)opaque;
- pthread_mutex_unlock(&c->globalLocker);
- return 1;
-}
-
-static void channel_split(float *buffer, uint64_t num_frames, float **chan_buffers, uint32_t num_channels)
-{
- uint64_t i, samples = num_frames * num_channels;
- for (i = 0; i < samples; i++)
- chan_buffers[i % num_channels][i / num_channels] = buffer[i];
-}
-static void channel_join(float **chan_buffers, uint32_t num_channels, float *buffer, uint64_t num_frames)
-{
- uint64_t i, samples = num_frames * num_channels;
- for (i = 0; i < samples; i++)
- buffer[i] = (float)(chan_buffers[i % num_channels][i / num_channels]);
-}
-static const double compressedCoeffMQ[701] = { 0.919063234986138511, 0.913619994199411201, 0.897406560667438402, 0.870768836078722797, 0.834273523109754001, 0.788693711602254766, 0.734989263333015286, 0.674282539592362951, 0.607830143521649657, 0.536991457245508341, 0.463194839157173466, 0.387902406850539450, 0.312574364478514499, 0.238633838900749129, 0.167433166845669668, 0.100222526262645231, 0.038121730693097225, -0.017904091793426027, -0.067064330735278010, -0.108757765594775291, -0.142582153044975485, -0.168338357500518510, -0.186029009837402531, -0.195851834439330574, -0.198187933840591440, -0.193585458951914369, -0.182739217157973949, -0.166466876941489483, -0.145682513177707279, -0.121368299577954988, -0.094545192393702127, -0.066243461643369750, -0.037473912797399318, -0.009200603832691301, 0.017684198632122932, 0.042382162574711987, 0.064207571946511041, 0.082602100079150684, 0.097145355203635028, 0.107561011406507381, 0.113718474453852247, 0.115630166683615837, 0.113444644504459249, 0.107435882084395071, 0.097989162055837783, 0.085584105452548076, 0.070775446120293309, 0.054172207614333223, 0.036415971885660689, 0.018158938330246815, 0.000042459196338912, -0.017323296238410713, -0.033377949403731559, -0.047627263300716267, -0.059656793081079629, -0.069142490141500798, -0.075858019256578396, -0.079678658979652428, -0.080581767609623323, -0.078643906863599317, -0.074034819562284179, -0.067008552930955145, -0.057892102695980191, -0.047072022601671190, -0.034979497375161483, -0.022074413174279148, -0.008828977400685476, 0.004288560713652965, 0.016829555699174666, 0.028379479813981756, 0.038570858162652835, 0.047094241683417769, 0.053706909605020871, 0.058239076113395197, 0.060597464446319166, 0.060766202425508065, 0.058805083502616720, 0.054845323789501445, 0.049083025498695095, 0.041770628243703020, 0.033206689594802247, 0.023724383421121997, 0.013679137601712221, 0.003435850879130631, -0.006643868309165797, -0.016214010012738603, -0.024955612937682017, -0.032586990530198853, -0.038872417226545809, -0.043629018879643239, -0.046731678346964158, -0.048115839004410917, -0.047778163016171563, -0.045775074997070689, -0.042219292770236193, -0.037274512912134725, -0.031148477572630149, -0.024084698830208532, -0.016353156105483747, -0.008240309809337577, -0.000038789761018515, 0.007962880277736915, 0.015490170167632772, 0.022291712611484882, 0.028147455724642705, 0.032875542265754551, 0.036337708303315903, 0.038443049556812471, 0.039150063091460026, 0.038466933347880143, 0.036450092517807633, 0.033201143952433128, 0.028862291652591764, 0.023610467168487866, 0.017650385903971395, 0.011206796641134264, 0.004516210167813600, -0.002181595351151269, -0.008651993358287469, -0.014673562407359826, -0.020045503214184583, -0.024594176093158650, -0.028178551235573571, -0.030694406321622035, -0.032077152831841031, -0.032303222419993387, -0.031389996039150381, -0.029394309376722470, -0.026409616804964359, -0.022561940854659814, -0.018004773700230153, -0.012913130046223239, -0.007476976122050557, -0.001894276500050309, 0.003636091270827173, 0.008921304789011335, 0.013781207467236415, 0.018054338893886482, 0.021603186795815136, 0.024318493648450956, 0.026122487293166251, 0.026970945047679402, 0.026854043263213976, 0.025795987570079431, 0.023853461640206807, 0.021112972713804853, 0.017687209024348168, 0.013710556397414673, 0.009333947668859192, 0.004719238361448204, 0.000033314715823999, -0.004557854609777880, -0.008895014112733140, -0.012831064739959125, -0.016235971633599879, -0.019000975419769615, -0.021041973670496809, -0.022301970824562707, -0.022752529440111541, -0.022394191906072568, -0.021255878361951062, -0.019393302279828196, -0.016886478718542881, -0.013836430536684995, -0.010361223853106050, -0.006591484944463394, -0.002665565936317155, 0.001275464342459697, 0.005092825309417521, 0.008654850008311749, 0.011841465274590917, 0.014548176385701671, 0.016689426206986688, 0.018201223316688792, 0.019042961289876651, 0.019198381208357294, 0.018675660452129358, 0.017506641810096972, 0.015745246837337051, 0.013465145155917528, 0.010756776112709417, 0.007723840062309154, 0.004479392878420811, 0.001141688626311485, -0.002170078649346380, -0.005339982462341837, -0.008259373919338373, -0.010830557217282604, -0.012970007990380254, -0.014611030342508765, -0.015705770153788771, -0.016226526478563909, -0.016166328657139784, -0.015538773207899238, -0.014377140707818779, -0.012732837794565421, -0.010673232279050818, -0.008278969379415602, -0.005640873626063710, -0.002856553527664500, -0.000026834265658038, 0.002747852704083721, 0.005370995258360709, 0.007753319014958258, 0.009815785813909824, 0.011492173003678219, 0.012731150958433296, 0.013497795530424229, 0.013774493273929109, 0.013561219484126362, 0.012875191572278549, 0.011749922250546383, 0.010233717662138146, 0.008387684262046795, 0.006283324310867826, 0.003999812773708582, 0.001621057822818793, -0.000767347236997687, -0.003081171091507831, -0.005240483245491547, -0.007172383140908554, -0.008813427537033921, -0.010111676574189758, -0.011028293954650051, -0.011538653669060464, -0.011632924035784708, -0.011316118830412747, -0.010607624279109693, -0.009540229002217340, -0.008158700990423423, -0.006517970800651516, -0.004680992876389242, -0.002716366825287035, -0.000695807329823454, 0.001308445056270027, 0.003226179724201707, 0.004991648959431359, 0.006545794666321473, 0.007838194454033614, 0.008828664063258869, 0.009488466505815606, 0.009801093167340614, 0.009762597931815446, 0.009381481548192093, 0.008678139395534967, 0.007683900954968532, 0.006439703144240938, 0.004994451750326167, 0.003403135115410580, 0.001724761684323746, 0.000020197792912962, -0.001650015947868542, -0.003227792151864713, -0.004659494079420105, -0.005897735119564774, -0.006902920847777659, -0.007644484483944344, -0.008101778413755888, -0.008264597354555087, -0.008133322264400958, -0.007718687720230902, -0.007041188742854554, -0.006130155461650219, -0.005022535167821778, -0.003761430832691131, -0.002394452762763960, -0.000971945496911797, 0.000454844825025831, 0.001835596641714852, 0.003122668316617104, 0.004272722114380925, 0.005248162177843576, 0.006018339594106877, 0.006560486855847911, 0.006860354383749922, 0.006912532886871314, 0.006720456790559610, 0.006296095343184246, 0.005659348921651181, 0.004837178114662079, 0.003862502033291890, 0.002772909691220670, 0.001609233980906675, 0.000414041581645497, -0.000769906024675906, -0.001901165407831948, -0.002941044990442539, -0.003854910802244932, -0.004613320774623974, -0.005192951162290093, -0.005577286818932973, -0.005757056020769449, -0.005730399990410974, -0.005502776877353867, -0.005086609356845171, -0.004500693886508907, -0.003769397706347888, -0.002921676615038254, -0.001989952181071211, -0.001008891180284735, -0.000014132577398601, 0.000958991766382216, 0.001876697269289887, 0.002707904681562794, 0.003425276863778077, 0.004006100299408528, 0.004432983601002821, 0.004694352366032693, 0.004784727410211850, 0.004704781367912914, 0.004461176612085595, 0.004066195127045020, 0.003537178100163921, 0.002895799341758980, 0.002167201988627001, 0.001379032128141500, 0.000560405874095270, -0.000259152041390146, -0.001050759947470964, -0.001787184184342184, -0.002443762818329620, -0.002999217281793143, -0.003436325772772713, -0.003742437746853627, -0.003909814939345641, -0.003935790838753386, -0.003822747153675574, -0.003577912336230492, -0.003212993416401785, -0.002743658050835511, -0.002188888608264336, -0.001570234143874397, -0.000910989133812205, -0.000235329764723561, 0.000432560641279413, 0.001069345839998360, 0.001653340745377959, 0.002165238082962834, 0.002588733711954676, 0.002911030869493576, 0.003123208352342977, 0.003220442832479460, 0.003202080909987641, 0.003071561941475896, 0.002836197950977609, 0.002506821849485185, 0.002097319592184942, 0.001624065644771860, 0.001105284094542681, 0.000560359841433201, 0.000009125484808694, -0.000528850236297424, -0.001034947274672293, -0.001492128764321782, -0.001885503916298735, -0.002202801129643487, -0.002434736758218434, -0.002575269035034838, -0.002621730990172647, -0.002574840645573092, -0.002438591168737718, -0.002220027862259672, -0.001928922712789991, -0.001577360593112676, -0.001179253996234489, -0.000749805296090004, -0.000304936916893765, 0.000139289578942291, 0.000567244609490058, 0.000964271897894877, 0.001317181565737385, 0.001614678737960774, 0.001847714105275549, 0.002009746006742852, 0.002096907004167219, 0.002108071492117578, 0.002044824491385029, 0.001911335280223238, 0.001714142804308648, 0.001461862761483392, 0.001164828784166054, 0.000834682161765550, 0.000483925998593740, 0.000125460552453497, -0.000227883269383389, -0.000563795658925073, -0.000870909262856999, -0.001139175997920627, -0.001360187135536317, -0.001527426803455576, -0.001636451679881492, -0.001684992470943874, -0.001672975660262524, -0.001602466894019970, -0.001477540114542411, -0.001304079085075351, -0.001089520173828018, -0.000842547115162114, -0.000572749884052837, -0.000290260767615715, -0.000005381173403155, 0.000271787324682131, 0.000531694720882059, 0.000765665077860444, 0.000966179147256847, 0.001127108176071712, 0.001243891947014572, 0.001313656276814221, 0.001335267482640161, 0.001309323638539731, 0.001238084697878249, 0.001125345675261167, 0.000976258990458714, 0.000797113715033597, 0.000595080778704776, 0.000377934148912837, 0.000153758569481225, -0.000069345376995143, -0.000283548328671139, -0.000481561352316614, -0.000656878246049437, -0.000803983100343503, -0.000918516742461215, -0.000997397336828164, -0.001038892182663637, -0.001042639573678904, -0.001009621396079384, -0.000942088876021349, -0.000843445486235168, -0.000718092430499951, -0.000571243299133416, -0.000408715393446694, -0.000236705827693455, -0.000061560820167541, 0.000110453421068778, 0.000273370118506192, 0.000421724138601977, 0.000550730322629083, 0.000656432310144007, 0.000735817450677950, 0.000786894740519778, 0.000808734131933592, 0.000801466989262860, 0.000766248858509478, 0.000705187025332569, 0.000621236516650982, 0.000518069214751335, 0.000399921568730665, 0.000271426983019702, 0.000137439322056229, 0.000002854088234340, -0.000127566289796932, -0.000249356967950712, -0.000358499459727905, -0.000451549869015331, -0.000525742663600061, -0.000579067066332711, -0.000610314210246149, -0.000619094306052033, -0.000605824164738963, -0.000571686465475047, -0.000518563123569660, -0.000448945962885840, -0.000365828604967228, -0.000272584032349123, -0.000172832651673869, -0.000070305865763902, 0.000031289837955523, 0.000128403456337462, 0.000217760218406138, 0.000296468531144650, 0.000362109765670523, 0.000412808249833617, 0.000447279627497663, 0.000464856578836417, 0.000465491738613502, 0.000449738470059130, 0.000418710921836804, 0.000374025488711351, 0.000317726390511799, 0.000252198560764628, 0.000180071382714710, 0.000104117018254314, 0.000027147141711448, -0.000048088182130861, -0.000118995940709898, -0.000183226726188442, -0.000238749615318076, -0.000283913107803554, -0.000317490431754438, -0.000338708143110164, -0.000347257581417331, -0.000343289373546324, -0.000327391777412823, -0.000300554208881314, -0.000264117778630104, -0.000219715066774411, -0.000169201669906033, -0.000114582260151285, -0.000057933995063949, -0.000001330110803372, 0.000053233576939992, 0.000103906741924272, 0.000149044949497856, 0.000187260510974094, 0.000217462319983746, 0.000238883649294571, 0.000251097355835207, 0.000254018413730855, 0.000247894152903089, 0.000233283008194432, 0.000211022966716673, 0.000182191226994878, 0.000148056842795767, 0.000110028310364557, 0.000069598166140896, 0.000028286691831679, -0.000012413223177511, -0.000051088131137235, -0.000086451240238396, -0.000117383287411682, -0.000142965848616867, -0.000162506184310969, -0.000175553056891817, -0.000181903303379713, -0.000181599287597338, -0.000174917679492114, -0.000162350303974188, -0.000144578058136870, -0.000122439106161612, -0.000096892719738482, -0.000068980234721197, -0.000039784640417051, -0.000010390306964679, 0.000018155708707897, 0.000044879452343343, 0.000068911789142910, 0.000089515073669816, 0.000106104020030281, 0.000118260259226232, 0.000125740319217347, 0.000128477011389261, 0.000126574445796332, 0.000120297118433995, 0.000110053709582710, 0.000096376396848920, 0.000079896615190895, 0.000061318285745045, 0.000041389584008291, 0.000020874325790195, 0.000000524017729422, -0.000018948449136533, -0.000036892585232981, -0.000052740818819573, -0.000066025144314650, -0.000076389469747209, -0.000083597404911355, -0.000087535408131387, -0.000088211381288728, -0.000085748963835814, -0.000080377921496540, -0.000072421149619506, -0.000062278911057702, -0.000050411001395778, -0.000037317578835504, -0.000023519411693731, -0.000009538283954733, 0.000004121739654397, 0.000016991550435446, 0.000028652179052461, 0.000038747470023706, 0.000046993903986995, 0.000053187343852112, 0.000057206603209622, 0.000059013855762422, 0.000058652018744224, 0.000056239347370971, 0.000051961567969763, 0.000046061951828715, 0.000038829788015541, 0.000030587750191730, 0.000021678669346899, 0.000012452221695327, 0.000003252019725938, -0.000005596443768274, -0.000013796601731427, -0.000021090036946349, -0.000027263866219030, -0.000032156106624670, -0.000035658928433894, -0.000037719781474555, -0.000038340460301533, -0.000037574245901964, -0.000035521325378456, -0.000032322744186229, -0.000028153186597604, -0.000023212908194301, -0.000017719158939021, -0.000011897436866734, -0.000005972901266780, -0.000000162251446552, 0.000005333655793588, 0.000010336218246169, 0.000014694346087313, 0.000018288433744639, 0.000021032968627464, 0.000022877753957232, 0.000023807775391314, 0.000023841789731823, 0.000023029757133319, 0.000021449274538926, 0.000019201196577477, 0.000016404650185715, 0.000013191660473528, 0.000009701607868611, 0.000006075730729441, 0.000002451874068818, -0.000001040335292299, -0.000004283732788372, -0.000007177155365100, -0.000009638185206925, -0.000011605042076524, -0.000013037603419542, -0.000013917565218600, -0.000014247788012456, -0.000014050900469913, -0.000013367256554309, -0.000012252360976939, -0.000010773890887184, -0.000009008449384796, -0.000007038188493661, -0.000004947435946560, -0.000002819451929447, -0.000000733429418017, 0.000001238164361723, 0.000003031826677860, 0.000004594780305705, 0.000005886220575305, 0.000006878033995645, 0.000007554995005623, 0.000007914466875845, 0.000007965650064675, 0.000007728435880102, 0.000007231934716903, 0.000006512756173231, 0.000005613122895949, 0.000004578901096601, 0.000003457628489583, 0.000002296615219305, 0.000001141185552533, 0.000000033118183302, -0.000000990668545558, -0.000001899152803076, -0.000002667946210802, -0.000003279724008567, -0.000003724353373815, -0.000003998736284580, -0.000004106393367485, -0.000004056823505075, -0.000003864680371659, -0.000003548811395079, -0.000003131206866384, -0.000002635907089885, -0.000002087913711897, -0.000001512147886406, -0.000000932492985725, -0.000000370953442845, 0.000000153045653294, 0.000000623201057861, 0.000001026706448750, 0.000001354458044511, 0.000001601095747237, 0.000001764891111188, 0.000001847498832724, 0.000001853592772907, 0.000001790410657756, 0.000001667233505382, 0.000001494826511430, 0.000001284867642241, 0.000001049388641653, 0.000000800250692844, 0.000000548673760673, 0.000000304834862491, 0.000000077546377014, -0.000000125978796206, -0.000000300272674786, -0.000000441669721214, -0.000000548281621807, -0.000000619897641839, -0.000000657821438861, -0.000000664657100282, -0.000000644058349094, -0.000000600455333568, -0.000000538773213853, -0.000000464155939282, -0.000000381707256690, -0.000000296259201847, -0.000000212176215381, -0.000000133200709942, -0.000000062343516559, 0.0 };
-void decompressResamplerMQ(const double y[701], float *yi)
-{
- double breaks[701];
- double coefs[2800];
- int k;
- double s[701];
- double dx[700];
- double dvdf[700];
- double r, dzzdx, dzdxdx;
- for (k = 0; k < 700; k++)
- {
- r = 0.0014285714285714286 * ((double)k + 1.0) - 0.0014285714285714286 * (double)k;
- dx[k] = r;
- dvdf[k] = (y[k + 1] - y[k]) / r;
- }
- s[0] = ((dx[0] + 0.0057142857142857143) * dx[1] * dvdf[0] + dx[0] * dx[0] * dvdf[1]) / 0.0028571428571428571;
- s[700] = ((dx[699] + 0.0057142857142857828) * dx[698] * dvdf[699] + dx[699] * dx[699] * dvdf[698]) / 0.0028571428571428914;
- breaks[0] = dx[1];
- breaks[700] = dx[698];
- for (k = 0; k < 699; k++)
- {
- r = dx[k + 1];
- s[k + 1] = 3.0 * (r * dvdf[k] + dx[k] * dvdf[k + 1]);
- breaks[k + 1] = 2.0 * (r + dx[k]);
- }
- r = dx[1] / breaks[0];
- breaks[1] -= r * 0.0028571428571428571;
- s[1] -= r * s[0];
- for (k = 0; k < 698; k++)
- {
- r = dx[k + 2] / breaks[k + 1];
- breaks[k + 2] -= r * dx[k];
- s[k + 2] -= r * s[k + 1];
- }
- r = 0.0028571428571428914 / breaks[699];
- breaks[700] -= r * dx[698];
- s[700] -= r * s[699];
- s[700] /= breaks[700];
- for (k = 698; k >= 0; k--)
- s[k + 1] = (s[k + 1] - dx[k] * s[k + 2]) / breaks[k + 1];
- s[0] = (s[0] - 0.0028571428571428571 * s[1]) / breaks[0];
- for (k = 0; k < 701; k++)
- breaks[k] = 0.0014285714285714286 * (double)k;
- for (k = 0; k < 700; k++)
- {
- r = 1.0 / dx[k];
- dzzdx = (dvdf[k] - s[k]) * r;
- dzdxdx = (s[k + 1] - dvdf[k]) * r;
- coefs[k] = (dzdxdx - dzzdx) * r;
- coefs[k + 700] = 2.0 * dzzdx - dzdxdx;
- coefs[k + 1400] = s[k];
- coefs[k + 2100] = y[k];
- }
- double d = 1.0 / 22437.0;
- int low_i, low_ip1, high_i, mid_i;
- for (k = 0; k < 22438; k++)
- {
- low_i = 0;
- low_ip1 = 2;
- high_i = 701;
- r = k * d;
- while (high_i > low_ip1)
- {
- mid_i = ((low_i + high_i) + 1) >> 1;
- if (r >= breaks[mid_i - 1])
- {
- low_i = mid_i - 1;
- low_ip1 = mid_i + 1;
- }
- else
- high_i = mid_i;
- }
- double xloc = r - breaks[low_i];
- yi[k] = (float)(xloc * (xloc * (xloc * coefs[low_i] + coefs[low_i + 700]) + coefs[low_i + 1400]) + coefs[low_i + 2100]);
- }
-}
-#include "numericSys/libsamplerate/samplerate.h"
-void JamesDSPOfflineResampling(float const *in, float *out, size_t lenIn, size_t lenOut, int channels, double src_ratio)
-{
- if (lenOut == lenIn && lenIn == 1)
- {
- memcpy(out, in, channels * sizeof(float));
- return;
- }
- SRC_DATA src_data;
- memset(&src_data, 0, sizeof(src_data));
- src_data.data_in = in;
- src_data.data_out = out;
- src_data.input_frames = (long)lenIn;
- src_data.output_frames = (long)lenOut;
- src_data.src_ratio = src_ratio;
- int error;
- if ((error = src_simple(&src_data, 0, channels)))
- {
- printf("\n%s\n\n", src_strerror(error));
- }
-}
-float *decompressedCoefficients = 0;
-#define DR_FLAC_IMPLEMENTATION
-#include "dr_flac.h"
-#define DR_WAV_IMPLEMENTATION
-#include "dr_wav.h"
-static float NSEEL_CGEN_CALL _eel_flacDecodeFile(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- const char *filename = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- uint32_t channels, fs;
- uint64_t frameCount;
- float *signal = drflac_open_file_and_read_pcm_frames_f32(filename, &channels, &fs, &frameCount, 0);
- float targetFs = *parms[2];
- if (targetFs > FLT_EPSILON)
- {
- double ratio = targetFs / (double)fs;
- if (ratio != 1.0)
- {
- int compressedLen = (int)ceil(frameCount * ratio);
- float *tmpBuf = (float*)malloc(compressedLen * channels * sizeof(float));
- memset(tmpBuf, 0, compressedLen * channels * sizeof(float));
- JamesDSPOfflineResampling(signal, tmpBuf, frameCount, compressedLen, channels, ratio);
- frameCount = compressedLen;
- free(signal);
- signal = tmpBuf;
- }
- }
- else
- *parms[2] = (float)fs;
- uint32_t channel1BasePointer = (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- frameCount = (frameCount + channel1BasePointer) > NSEEL_RAM_ITEMSPERBLOCK ? (NSEEL_RAM_ITEMSPERBLOCK - channel1BasePointer) : frameCount;
- *parms[1] = (float)channels;
- *parms[3] = (float)frameCount;
- if ((num_param - 4) < (int32_t)channels)
- {
- free(signal);
- return -1;
- }
- float **ptr = (float**)malloc(channels * sizeof(float*));
- ptr[0] = __NSEEL_RAMAlloc(blocks, (uint64_t)channel1BasePointer);
- uint64_t pointer = channel1BasePointer;
- uint64_t count = pointer;
- int resetCnt = 0;
- for (uint32_t i = 1; i < channels; i++)
- {
- if (count + frameCount * 2 < NSEEL_RAM_ITEMSPERBLOCK)
- {
- pointer += frameCount;
- count = pointer;
- resetCnt++;
- }
- else
- {
- pointer = NSEEL_RAM_ITEMSPERBLOCK * resetCnt;
- count = 0;
- }
- *parms[i + 4] = (float)pointer;
- ptr[i] = __NSEEL_RAMAlloc(blocks, (uint64_t)pointer);
- }
- channel_split(signal, frameCount, ptr, channels);
- free(signal);
- free(ptr);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_flacDecodeMemory(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- const char *base64String = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- size_t actualSize;
- unsigned char *memoryBlk = base64_decode((const unsigned char*)base64String, strlen(base64String), &actualSize);
- uint32_t channels, fs;
- uint64_t frameCount;
- float *signal = drflac_open_memory_and_read_pcm_frames_f32(memoryBlk, actualSize, &channels, &fs, &frameCount, 0);
- float targetFs = *parms[2];
- if (targetFs > FLT_EPSILON)
- {
- double ratio = targetFs / (double)fs;
- if (ratio != 1.0)
- {
- int compressedLen = (int)ceil(frameCount * ratio);
- float *tmpBuf = (float*)malloc(compressedLen * channels * sizeof(float));
- memset(tmpBuf, 0, compressedLen * channels * sizeof(float));
- JamesDSPOfflineResampling(signal, tmpBuf, frameCount, compressedLen, channels, ratio);
- frameCount = compressedLen;
- free(signal);
- signal = tmpBuf;
- }
- }
- else
- *parms[2] = (float)fs;
- free(memoryBlk);
- uint32_t channel1BasePointer = (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- frameCount = (frameCount + channel1BasePointer) > NSEEL_RAM_ITEMSPERBLOCK ? (NSEEL_RAM_ITEMSPERBLOCK - channel1BasePointer) : frameCount;
- *parms[1] = (float)channels;
- *parms[3] = (float)frameCount;
- if ((num_param - 4) < (int32_t)channels)
- {
- free(signal);
- return -1;
- }
- float **ptr = (float**)malloc(channels * sizeof(float*));
- ptr[0] = __NSEEL_RAMAlloc(blocks, (uint64_t)channel1BasePointer);
- uint64_t pointer = channel1BasePointer;
- uint64_t count = pointer;
- int resetCnt = 0;
- for (uint32_t i = 1; i < channels; i++)
- {
- if (count + frameCount * 2 < NSEEL_RAM_ITEMSPERBLOCK)
- {
- pointer += frameCount;
- count = pointer;
- resetCnt++;
- }
- else
- {
- pointer = NSEEL_RAM_ITEMSPERBLOCK * resetCnt;
- count = 0;
- }
- *parms[i + 4] = (float)pointer;
- ptr[i] = __NSEEL_RAMAlloc(blocks, (uint64_t)pointer);
- }
- channel_split(signal, frameCount, ptr, channels);
- free(signal);
- free(ptr);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_wavDecodeFile(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- const char *filename = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- uint32_t channels, fs;
- uint64_t frameCount;
- float *signal = drwav_open_file_and_read_pcm_frames_f32(filename, &channels, &fs, &frameCount, 0);
- float targetFs = *parms[2];
- if (targetFs > FLT_EPSILON)
- {
- double ratio = targetFs / (double)fs;
- if (ratio != 1.0)
- {
- int compressedLen = (int)ceil(frameCount * ratio);
- float *tmpBuf = (float*)malloc(compressedLen * channels * sizeof(float));
- memset(tmpBuf, 0, compressedLen * channels * sizeof(float));
- JamesDSPOfflineResampling(signal, tmpBuf, frameCount, compressedLen, channels, ratio);
- frameCount = compressedLen;
- free(signal);
- signal = tmpBuf;
- }
- }
- else
- *parms[2] = (float)fs;
- uint32_t channel1BasePointer = (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- frameCount = (frameCount + channel1BasePointer) > NSEEL_RAM_ITEMSPERBLOCK ? (NSEEL_RAM_ITEMSPERBLOCK - channel1BasePointer) : frameCount;
- *parms[1] = (float)channels;
- *parms[3] = (float)frameCount;
- if ((num_param - 4) < (int32_t)channels)
- {
- free(signal);
- return -1;
- }
- float **ptr = (float**)malloc(channels * sizeof(float*));
- ptr[0] = __NSEEL_RAMAlloc(blocks, (uint64_t)channel1BasePointer);
- uint64_t pointer = channel1BasePointer;
- uint64_t count = pointer;
- int resetCnt = 0;
- for (uint32_t i = 1; i < channels; i++)
- {
- if (count + frameCount * 2 < NSEEL_RAM_ITEMSPERBLOCK)
- {
- pointer += frameCount;
- count = pointer;
- resetCnt++;
- }
- else
- {
- pointer = NSEEL_RAM_ITEMSPERBLOCK * resetCnt;
- count = 0;
- }
- *parms[i + 4] = (float)pointer;
- ptr[i] = __NSEEL_RAMAlloc(blocks, (uint64_t)pointer);
- }
- channel_split(signal, frameCount, ptr, channels);
- free(signal);
- free(ptr);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_wavDecodeMemory(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- const char *base64String = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- size_t actualSize;
- unsigned char *memoryBlk = base64_decode((const unsigned char*)base64String, strlen(base64String), &actualSize);
- uint32_t channels, fs;
- uint64_t frameCount;
- float *signal = drwav_open_memory_and_read_pcm_frames_f32(memoryBlk, actualSize, &channels, &fs, &frameCount, 0);
- float targetFs = *parms[2];
- if (targetFs > FLT_EPSILON)
- {
- double ratio = targetFs / (double)fs;
- if (ratio != 1.0)
- {
- int compressedLen = (int)ceil(frameCount * ratio);
- float *tmpBuf = (float*)malloc(compressedLen * channels * sizeof(float));
- memset(tmpBuf, 0, compressedLen * channels * sizeof(float));
- JamesDSPOfflineResampling(signal, tmpBuf, frameCount, compressedLen, channels, ratio);
- frameCount = compressedLen;
- free(signal);
- signal = tmpBuf;
- }
- }
- else
- *parms[2] = (float)fs;
- free(memoryBlk);
- uint32_t channel1BasePointer = (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR);
- frameCount = (frameCount + channel1BasePointer) > NSEEL_RAM_ITEMSPERBLOCK ? (NSEEL_RAM_ITEMSPERBLOCK - channel1BasePointer) : frameCount;
- *parms[1] = (float)channels;
- *parms[3] = (float)frameCount;
- if ((num_param - 4) < (int32_t)channels)
- {
- free(signal);
- return -1;
- }
- float **ptr = (float**)malloc(channels * sizeof(float*));
- ptr[0] = __NSEEL_RAMAlloc(blocks, (uint64_t)channel1BasePointer);
- uint64_t pointer = channel1BasePointer;
- uint64_t count = pointer;
- int resetCnt = 0;
- for (uint32_t i = 1; i < channels; i++)
- {
- if (count + frameCount * 2 < NSEEL_RAM_ITEMSPERBLOCK)
- {
- pointer += frameCount;
- count = pointer;
- resetCnt++;
- }
- else
- {
- pointer = NSEEL_RAM_ITEMSPERBLOCK * resetCnt;
- count = 0;
- }
- *parms[i + 4] = (float)pointer;
- ptr[i] = __NSEEL_RAMAlloc(blocks, (uint64_t)pointer);
- }
- channel_split(signal, frameCount, ptr, channels);
- free(signal);
- free(ptr);
- return 1;
-}
-unsigned int peakfinder(unsigned int elements, const float *input, float sel, unsigned int extrema, float *peakInds)
-{
- unsigned int i, j, k, foundPeak;
- unsigned int eleMinus1 = elements - 1;
- unsigned int eleMinus2 = elements - 2;
- float work, minMag, leftMin, tempMag;
- unsigned int *ind = (unsigned int*)malloc((eleMinus2 < 4 ? 4 : eleMinus2) * sizeof(unsigned int));
- float *b_x = (float*)malloc((eleMinus1 < 4 ? 4 : eleMinus1) * sizeof(float));
- unsigned int *peakLoc = (unsigned int*)malloc((eleMinus2 < 4 ? 4 : eleMinus2) * sizeof(unsigned int));
- // Adjust threshold according to extrema
- i = 1;
- k = 0;
- if (extrema)
- {
- work = input[0];
- for (j = 0; j < eleMinus1; j++)
- {
- minMag = work;
- work = input[i];
- b_x[k] = input[i] - minMag;
- i++;
- k++;
- }
- }
- else
- {
- work = -input[0];
- for (j = 0; j < eleMinus1; j++)
- {
- minMag = work;
- work = -input[i];
- b_x[k] = -input[i] - minMag;
- i++;
- k++;
- }
- }
- // Find derivative
- for (i = 0; i < eleMinus1; i++)
- {
- if (b_x[i] == 0.0f)
- b_x[i] = -DBL_EPSILON;
- }
- i = 0;
- j = 0;
- while (j < eleMinus2)
- {
- if (b_x[j] * b_x[j + 1] < 0.0f)// This is so we find the first of repeated values
- {
- i++;
- ind[i] = j + 1;
- if (i >= eleMinus2)
- break;
- else
- j++;
- }
- else
- j++;
- }
- ind[0] = 0;
- ind[i + 1] = elements - 1;
- // Find where the derivative changes sign
- // Include endpoints in potential peaks and valleys as desired
- unsigned int indSize = i + 2;
- if (extrema)
- {
- b_x[0] = input[0];
- for (j = 0; j < indSize - 1; j++)
- b_x[j + 1] = input[ind[j + 1]];
- b_x[indSize + 1] = input[eleMinus1];
- }
- else
- {
- b_x[0] = -input[0];
- for (j = 0; j < indSize - 1; j++)
- b_x[j + 1] = -input[ind[j + 1]];
- b_x[indSize + 1] = -input[eleMinus1];
- }
- if (indSize <= 2)
- {
- if (b_x[0] > b_x[1])
- minMag = b_x[1];
- else
- minMag = b_x[0];
- }
- else
- {
- minMag = b_x[0];
- for (k = 2; k <= indSize; k++)
- {
- work = b_x[k - 1];
- if (minMag > work)
- minMag = work;
- }
- }
- leftMin = minMag;
- // x only has the peaks, valleys, and possibly endpoints
- if (indSize > 2)
- {
- // Function with peaks and valleys, set initial parameters for loop
- tempMag = minMag;
- foundPeak = 0;
- // Skip the first point if it is smaller so we always start on a maxima
- if (b_x[0] >= b_x[1])
- j = -1;
- else
- j = 0;
- k = 0;
- i = 1;
- // Loop through extrema which should be peaks and then valleys
- while (j + 1 < indSize)
- {
- j += 2;
- // This is a peak
- // Reset peak finding if we had a peak and the next peak is bigger
- // than the last or the left min was small enough to reset.
- if (foundPeak)
- {
- tempMag = minMag;
- foundPeak = 0;
- }
- // Found new peak that was lager than temp mag and selectivity larger
- // than the minimum to its left.
- work = b_x[j - 1];
- if ((work > tempMag) && (work > leftMin + sel))
- {
- i = j;
- tempMag = work;
- }
- // Make sure we don't iterate past the length of our vector
- if (j == indSize)
- break;
- else
- {
- // Move onto the valley, come down at least sel from peak
- if (tempMag > sel + b_x[j])
- {
- foundPeak = 1;
- // We have found a peak
- leftMin = b_x[j];
- peakLoc[k] = i;
- k++;
- }
- else
- {
- if (b_x[j] < leftMin) // New left minima
- leftMin = b_x[j];
- }
- }
- }
- // Check end point
- if ((b_x[indSize - 1] > tempMag) && (b_x[indSize - 1] > leftMin + sel))
- {
- peakLoc[k] = indSize;
- k++;
- }
- else
- {
- if ((!foundPeak) && (tempMag > minMag))
- {
- // Check if we still need to add the last point
- peakLoc[k] = i;
- k++;
- }
- }
- // Create output
- if (k + 1 > 1)
- {
- for (j = 0; j < k; j++)
- peakInds[j] = (float)ind[peakLoc[j] - 1];
- }
- }
- else
- {
- // This is a monotone function where an endpoint is the only peak
- if (b_x[0] < b_x[1])
- {
- work = b_x[1];
- i = 1;
- }
- else
- {
- work = b_x[0];
- i = 0;
- }
- if (work > minMag + sel)
- {
- peakInds[0] = (float)ind[i];
- k = 1;
- }
- }
- free(ind);
- free(b_x);
- free(peakLoc);
- return k;
-}
-static float NSEEL_CGEN_CALL _eel_peakFinder(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- float *input = __NSEEL_RAMAlloc(c->ram_state, (uint32_t)(*parms[0] + NSEEL_CLOSEFACTOR));
- float *output = __NSEEL_RAMAlloc(c->ram_state, (uint32_t)(*parms[4] + NSEEL_CLOSEFACTOR));
- uint32_t n = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- float sel = *parms[2];
- uint32_t maximaMinima = (uint32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- return (float)peakfinder(n, input, sel, maximaMinima, output);
-}
-static float NSEEL_CGEN_CALL _eel_writeWavFile(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- const char *filename = (const char*)GetStringForIndex(c->m_string_context, *parms[0], 0);
- uint32_t channels = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- uint32_t fs = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- uint64_t frameCount = (uint64_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- if ((num_param - 4) < (int32_t)channels)
- return -1;
- float *signal = (float*)malloc((size_t)(channels * frameCount * sizeof(float)));
- float **ptr = (float**)malloc(channels * sizeof(float*));
- for (uint32_t i = 0; i < channels; i++)
- ptr[i] = __NSEEL_RAMAlloc(blocks, (uint64_t)(uint32_t)(*parms[i + 4] + NSEEL_CLOSEFACTOR));
- channel_join(ptr, channels, signal, frameCount);
- drwav pWav;
- drwav_data_format format;
- format.container = drwav_container_riff;
- format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
- format.channels = channels;
- format.sampleRate = fs;
- format.bitsPerSample = 32;
- uint32_t fail = drwav_init_file_write(&pWav, filename, &format, 0);
- drwav_uint64 framesWritten = drwav_write_pcm_frames(&pWav, frameCount, signal);
- drwav_uninit(&pWav);
- free(signal);
- free(ptr);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_writeWavMemory(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- s_str *dest = (s_str*)GetStringForIndex(c->m_string_context, *parms[0], 1);
- uint32_t channels = (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR);
- uint32_t fs = (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- uint64_t frameCount = (uint64_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- if ((num_param - 4) < (int32_t)channels)
- return -1;
- float *signal = (float*)malloc((size_t)(channels * frameCount * sizeof(float)));
- float **ptr = (float**)malloc(channels * sizeof(float*));
- for (uint32_t i = 0; i < channels; i++)
- ptr[i] = __NSEEL_RAMAlloc(blocks, (uint64_t)(uint32_t)(*parms[i + 4] + NSEEL_CLOSEFACTOR));
- channel_join(ptr, channels, signal, frameCount);
- free(ptr);
- drwav pWav;
- drwav_data_format format;
- format.container = drwav_container_riff;
- format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
- format.channels = channels;
- format.sampleRate = fs;
- format.bitsPerSample = 32;
- size_t blkSize;
- void *memoryBlk;
- uint32_t fail = drwav_init_memory_write(&pWav, &memoryBlk, &blkSize, &format, 0);
- drwav_uint64 framesWritten = drwav_write_pcm_frames(&pWav, frameCount, signal);
- drwav_uninit(&pWav);
- free(signal);
- size_t outLen;
- unsigned char *base64String = base64_encode((unsigned char*)memoryBlk, blkSize, &outLen);
- free(memoryBlk);
- if (dest)
- s_str_destroy(dest);
- *dest = s_str_create_from_c_str(base64String);
- free(base64String);
- return 1;
-}
-static float NSEEL_CGEN_CALL _eel_listSystemVariable(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *blocks = c->ram_state;
- char badStr[128];
- stbsp_snprintf(badStr, 128, "Listing system variables\n");
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- char isString[16];
- for (int i = 0; i < c->varTable_numBlocks; i++)
- {
- for (int j = 0; j < NSEEL_VARS_PER_BLOCK; j++)
- {
- char *valid = GetStringForIndex(c->m_string_context, c->varTable_Values[i][j], 1);
- if (!valid)
- strncpy(isString, "Is not string", 16);
- else
- strncpy(isString, "Could be string", 16);
- if (c->varTable_Names[i][j])
- {
- stbsp_snprintf(badStr, 128, "%s %1.18lf %s\n", c->varTable_Names[i][j], c->varTable_Values[i][j], isString);
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
- }
- }
- stbsp_snprintf(badStr, 128, "All variables has been printed\n");
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- return 0;
-}
-static float NSEEL_CGEN_CALL _eel_linspace(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *vec = __NSEEL_RAMAlloc(c->ram_state, (uint32_t)(*parms[3] + NSEEL_CLOSEFACTOR));
- int32_t n = (int32_t)(*parms[2] + NSEEL_CLOSEFACTOR);
- float d = (*parms[1] - *parms[0]) / (float)(n - 1);
- for (int32_t i = 0; i < n; i++)
- vec[i] = *parms[0] + i * d;
- return 0;
-}
-size_t choose(float *a, float *b, size_t src1, size_t src2)
-{
- return (*b >= *a) ? src2 : src1;
-}
-size_t fast_upper_bound4(float *vec, size_t n, float *value)
-{
- size_t size = n;
- size_t low = 0;
- while (size >= 8)
- {
- size_t half = size / 2;
- size_t other_half = size - half;
- size_t probe = low + half;
- size_t other_low = low + other_half;
- size = half;
- low = choose(&vec[probe], value, low, other_low);
-
- half = size / 2;
- other_half = size - half;
- probe = low + half;
- other_low = low + other_half;
- size = half;
- low = choose(&vec[probe], value, low, other_low);
-
- half = size / 2;
- other_half = size - half;
- probe = low + half;
- other_low = low + other_half;
- size = half;
- low = choose(&vec[probe], value, low, other_low);
- }
- while (size > 0) {
- size_t half = size / 2;
- size_t other_half = size - half;
- size_t probe = low + half;
- size_t other_low = low + other_half;
- size = half;
- low = choose(&vec[probe], value, low, other_low);
- }
- return low;
-}
-static float _eel_lerp(void *opaque, INT_PTR num_param, float **parms)
-{
- compileContext *c = (compileContext*)opaque;
- float *x = __NSEEL_RAMAlloc(c->ram_state, (uint32_t)(*parms[1] + NSEEL_CLOSEFACTOR));
- float *y = __NSEEL_RAMAlloc(c->ram_state, (uint32_t)(*parms[2] + NSEEL_CLOSEFACTOR));
- uint32_t pts = (uint32_t)(*parms[3] + NSEEL_CLOSEFACTOR);
- if (*parms[0] == x[0])
- return y[0];
- if (*parms[0] == x[pts - 1])
- return y[pts - 1];
- size_t j = fast_upper_bound4(x, pts, parms[0]);
- if (j <= 0)
- return (*parms[0] - x[1]) / (x[0] - x[1]) * (y[0] - y[1]) + y[1]; // Extrapolation to leftmost
- else if (j >= pts)
- return (*parms[0] - x[pts - 2]) / (x[pts - 1] - x[pts - 2]) * (y[pts - 1] - y[pts - 2]) + y[pts - 2]; // Extrapolation to rightmost
- else
- return (*parms[0] - x[j - 1]) / (x[j] - x[j - 1]) * (y[j] - y[j - 1]) + y[j - 1]; // Interpolation
-}
-#define redirect(x) static float redirect_##x(float _input1){return x(_input1); }
-#define redirect2(x) static float redirect_##x(float _input1, float _input2){return x(_input1, _input2); }
-redirect(sinf);
-redirect(cosf);
-redirect(tanf);
-redirect(asinf);
-redirect(acosf);
-redirect(atanf);
-redirect2(atan2f);
-redirect(asinhf);
-redirect(acoshf);
-redirect(coshf);
-redirect(sinhf);
-redirect(sqrtf);
-redirect(tanhf);
-redirect(atanhf)
-redirect(logf)
-redirect(log10f)
-redirect2(hypotf)
-redirect2(powf)
-redirect(expf)
-redirect(roundf)
-redirect(floorf)
-redirect(ceilf)
-static functionType fnTable1[] = {
- { "sin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sinf} },
- { "cos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_cosf} },
- { "tan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_tanf} },
- { "sqrt", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sqrtf}, },
- { "asin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_asinf}, },
- { "acos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_acosf}, },
- { "atan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_atanf}, },
- { "atan2", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_atan2f}, },
- { "sinh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL, {(void**)&redirect_sinhf} },
- { "cosh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_coshf} },
- { "tanh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_tanhf} },
- { "asinh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_asinhf}, },
- { "acosh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_acoshf}, },
- { "atanh", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_atanhf}, },
- { "log", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_logf} },
- { "log10", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_log10f} },
- { "hypot", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_hypotf}, },
- { "pow", nseel_asm_2pdd,nseel_asm_2pdd_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK, {(void**)&redirect_powf}, },
- { "exp", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&redirect_expf}, },
- { "abs", nseel_asm_abs,nseel_asm_abs_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(0) | BIF_WONTMAKEDENORMAL },
- { "sqr", nseel_asm_sqr,nseel_asm_sqr_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(1) },
- { "min", nseel_asm_min,nseel_asm_min_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_FPSTACKUSE(3) | BIF_WONTMAKEDENORMAL },
- { "max", nseel_asm_max,nseel_asm_max_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_FPSTACKUSE(3) | BIF_WONTMAKEDENORMAL },
- { "sign", nseel_asm_sign,nseel_asm_sign_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL, },
- { "rand", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&nseel_int_rand}, },
- { "round", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_roundf} },
- { "floor", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_floorf} },
- { "ceil", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&redirect_ceilf} },
- { "expint", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&expint} },
- { "expintFast",nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL, {(void**)&expint_interpolation} },
- { "invsqrt",nseel_asm_1pdd,nseel_asm_1pdd_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(3), {(void**)&invsqrt} },
- { "invsqrtFast",nseel_asm_invsqrt,nseel_asm_invsqrt_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(3), },
- { "circshift",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&__NSEEL_circshift},NSEEL_PProc_RAM},
- { "convolve_c",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&eel_convolve_c},NSEEL_PProc_RAM},
- { "maxVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_max},NSEEL_PProc_RAM},
- { "minVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_min},NSEEL_PProc_RAM},
- { "meanVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_mean},NSEEL_PProc_RAM},
- { "medianVec",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&eel_median},NSEEL_PProc_RAM},
- { "fft",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft},NSEEL_PProc_RAM},
- { "ifft",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft},NSEEL_PProc_RAM},
- { "fft_real",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft_real},NSEEL_PProc_RAM},
- { "ifft_real",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft_real},NSEEL_PProc_RAM},
- { "fft_permute",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_fft_permute},NSEEL_PProc_RAM},
- { "fft_ipermute",_asm_generic2parm,_asm_generic2parm_end,2,{(void**)&eel_ifft_permute},NSEEL_PProc_RAM},
- {"memcpy",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&__NSEEL_RAM_MemCpy},NSEEL_PProc_RAM},
- {"memset",_asm_generic3parm,_asm_generic3parm_end,3,{(void**)&__NSEEL_RAM_MemSet},NSEEL_PProc_RAM},
- {"sleep",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK,{(void**)&_eel_sleep}},
- {"time",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK,{(void**)&_eel_time},NSEEL_PProc_THIS},
- {"time_precise",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK,{(void**)&_eel_time_precise},NSEEL_PProc_THIS},
- {"strlen",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_strlen},NSEEL_PProc_THIS},
- {"base64_encode",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&_eel_base64_encode},NSEEL_PProc_THIS},
- {"base64_encodeF2F",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&_eel_base64_encodeBinaryToTextFile},NSEEL_PProc_THIS},
- {"base64_decode",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&_eel_base64_decode},NSEEL_PProc_THIS},
- {"base64_decodeF2F",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&_eel_base64_decodeBinaryToTextFile},NSEEL_PProc_THIS},
- {"strcmp",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&_eel_strcmp},NSEEL_PProc_THIS},
- {"match",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_match},NSEEL_PProc_THIS},
- {"matchi",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_matchi},NSEEL_PProc_THIS},
- {"stricmp",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&_eel_stricmp},NSEEL_PProc_THIS},
- {"strncmp",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&_eel_strncmp},NSEEL_PProc_THIS},
- {"strnicmp",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&_eel_strnicmp},NSEEL_PProc_THIS},
- {"printf",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_printf},NSEEL_PProc_THIS},
- {"sprintf",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_sprintf},NSEEL_PProc_THIS},
- {"resetStringContainers",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_delete_all_strings},NSEEL_PProc_THIS},
- {"importFLTFromStr",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&_eel_importFloatArrayFromString},NSEEL_PProc_THIS},
- {"arburgCheckMemoryRequirement",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&arburgCheckMemoryRequirement},NSEEL_PProc_RAM},
- {"arburgTrainModel",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&arburgTrainModel},NSEEL_PProc_THIS},
- {"arburgGetPredictionReflectionCoeff",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&arburgGetPredictionReflectionCoeff},NSEEL_PProc_THIS},
- {"arburgPredictBackward",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&arburgPredictBackward},NSEEL_PProc_RAM},
- {"arburgPredictForward",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&arburgPredictForward},NSEEL_PProc_RAM},
- {"stftCheckMemoryRequirement",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftCheckMemoryRequirement},NSEEL_PProc_THIS},
- {"stftInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftInit},NSEEL_PProc_THIS},
- {"stftGetWindowPower",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftGetWindowPower},NSEEL_PProc_THIS},
- {"stftForward",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftForward},NSEEL_PProc_THIS},
- {"stftBackward",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&stftBackward},NSEEL_PProc_THIS},
- {"InitPinkNoise",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&pinkNoiseInit},NSEEL_PProc_THIS},
- {"GeneratePinkNoise",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&pinkNoiseGen},NSEEL_PProc_THIS},
- {"InitPolyphaseFilterbank",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankInit},NSEEL_PProc_THIS},
- {"PolyphaseFilterbankChangeWarpingFactor",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankChangeWarpingFactor},NSEEL_PProc_THIS},
- {"PolyphaseFilterbankGetPhaseCorrector",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankGetPhaseCorrector},NSEEL_PProc_THIS},
- {"PolyphaseFilterbankGetDecimationFactor",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankGetDecimationFactor},NSEEL_PProc_THIS},
- {"PolyphaseFilterbankAnalysisMono",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankAnalysisMono},NSEEL_PProc_THIS},
- {"PolyphaseFilterbankSynthesisMono",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankSynthesisMono},NSEEL_PProc_THIS},
- {"PolyphaseFilterbankAnalysisStereo",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankAnalysisStereo},NSEEL_PProc_THIS},
- {"PolyphaseFilterbankSynthesisStereo",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&PolyphaseFilterbankSynthesisStereo},NSEEL_PProc_THIS},
- {"FIRInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&FIRInit},NSEEL_PProc_RAM},
- {"FIRProcess",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&FIRProcess},NSEEL_PProc_RAM},
- {"fractionalDelayLineInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&fractionalDelayLineInit},NSEEL_PProc_RAM},
- {"fractionalDelayLineClear",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&fractionalDelayLineClear},NSEEL_PProc_RAM},
- {"fractionalDelayLineSetDelay",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&fractionalDelayLineSetDelay},NSEEL_PProc_RAM},
- {"fractionalDelayLineProcess",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_RETURNSONSTACK,{(void**)&fractionalDelayLineProcess},NSEEL_PProc_RAM},
- {"linspace",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_linspace},NSEEL_PProc_THIS},
- {"rank",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&_eel_matRank},NSEEL_PProc_RAM},
- {"det",_asm_generic3parm_retd,_asm_generic3parm_retd_end,3 | BIF_RETURNSONSTACK,{(void**)&_eel_matDeterminant},NSEEL_PProc_RAM},
- {"transpose",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_matTranspose},NSEEL_PProc_THIS},
- {"cholesky",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_cholesky},NSEEL_PProc_THIS},
- {"inv_chol",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_inv_chol},NSEEL_PProc_THIS},
- {"inv",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_matInv},NSEEL_PProc_THIS},
- {"pinv_svd",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_matPinv},NSEEL_PProc_THIS},
- {"pinv_fast",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_matPinvFast},NSEEL_PProc_THIS},
- {"mldivide",_asm_generic2parm_retd,_asm_generic2parm_retd_end,8 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_mldivide},NSEEL_PProc_THIS},
- {"mrdivide",_asm_generic2parm_retd,_asm_generic2parm_retd_end,8 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_mrdivide},NSEEL_PProc_THIS},
- {"quadprog",_asm_generic2parm_retd,_asm_generic2parm_retd_end,12 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_quadprog},NSEEL_PProc_THIS},
- {"lsqlin",_asm_generic2parm_retd,_asm_generic2parm_retd_end,13 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_lsqlin},NSEEL_PProc_THIS},
- {"firls",_asm_generic2parm_retd,_asm_generic2parm_retd_end,7 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_firls},NSEEL_PProc_THIS},
- {"eqnerror",_asm_generic2parm_retd,_asm_generic2parm_retd_end,10 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_eqnerror},NSEEL_PProc_THIS},
- {"unwrap",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_unwrap},NSEEL_PProc_THIS},
- {"zp2sos",_asm_generic2parm_retd,_asm_generic2parm_retd_end,7 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_zp2sos},NSEEL_PProc_THIS},
- {"tf2sos",_asm_generic2parm_retd,_asm_generic2parm_retd_end,6 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_tf2sos},NSEEL_PProc_THIS},
- {"roots",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_roots},NSEEL_PProc_THIS},
- {"cplxpair",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM_EX | BIF_RETURNSONSTACK,{(void**)&_eel_cplxpair},NSEEL_PProc_THIS},
- {"IIRBandSplitterInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_iirBandSplitterInit},NSEEL_PProc_THIS},
- {"IIRBandSplitterClearState",_asm_generic1parm_retd,_asm_generic1parm_retd_end, 1 | BIF_RETURNSONSTACK,{(void**)&_eel_iirBandSplitterClearState},NSEEL_PProc_RAM},
- {"IIRBandSplitterProcess",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_iirBandSplitterProcess},NSEEL_PProc_THIS},
- {"Conv1DInit",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_initfftconv1d},NSEEL_PProc_THIS},
- {"Conv1DProcess",_asm_generic2parm_retd,_asm_generic2parm_retd_end,2 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_processfftconv1d},NSEEL_PProc_THIS},
- {"Conv1DFree",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_deletefftconv1d},NSEEL_PProc_THIS},
- {"decodeFLACFromFile",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_flacDecodeFile},NSEEL_PProc_THIS},
- {"decodeFLACFromMemory",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_flacDecodeMemory},NSEEL_PProc_THIS},
- {"decodeWavFromFile",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_wavDecodeFile},NSEEL_PProc_THIS},
- {"decodeWavFromMemory",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_wavDecodeMemory},NSEEL_PProc_THIS},
- {"writeWavToFile",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_writeWavFile},NSEEL_PProc_THIS},
- {"writeWavToBase64String",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_writeWavMemory},NSEEL_PProc_THIS},
- {"peakFinder",_asm_generic2parm_retd,_asm_generic2parm_retd_end,5 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_peakFinder},NSEEL_PProc_THIS },
- {"listSystemVariable",_asm_generic2parm_retd,_asm_generic2parm_retd_end,1 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_listSystemVariable},NSEEL_PProc_THIS },
- {"vectorizeAssignScalar",_asm_generic2parm_retd,_asm_generic2parm_retd_end,3 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeAssignScalar},NSEEL_PProc_THIS },
- {"vectorizeAdd",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeAdd},NSEEL_PProc_THIS },
- {"vectorizeMinus",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeMinus},NSEEL_PProc_THIS },
- {"vectorizeMultiply",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeMultiply},NSEEL_PProc_THIS },
- {"vectorizeDivide",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_vectorizeDivide},NSEEL_PProc_THIS },
- {"ls",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_ls},NSEEL_PProc_THIS },
- {"cd",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_cd},NSEEL_PProc_THIS },
- {"eval",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_eval},NSEEL_PProc_THIS },
- {"evalFile",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_evalFile},NSEEL_PProc_THIS },
- {"ThreadInit",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_initthread},NSEEL_PProc_THIS },
- {"ThreadCreate",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_createThread},NSEEL_PProc_THIS },
- {"ThreadJoin",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_joinThread},NSEEL_PProc_THIS },
- {"ThreadDelete",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_deletethread},NSEEL_PProc_THIS },
- {"ThreadMutexLock",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_lockThread},NSEEL_PProc_THIS },
- {"ThreadMutexUnlock",_asm_generic1parm_retd,_asm_generic1parm_retd_end,1 | BIF_RETURNSONSTACK,{(void**)&_eel_unlockThread},NSEEL_PProc_THIS },
- {"lerpAt",_asm_generic2parm_retd,_asm_generic2parm_retd_end,4 | BIF_TAKES_VARPARM | BIF_RETURNSONSTACK,{(void**)&_eel_lerp},NSEEL_PProc_THIS },
-};
-void printFunctions()
-{
- char badStr[128];
- for (int i = 0; i < sizeof(fnTable1) / sizeof(fnTable1[0]); i++)
- {
- stbsp_snprintf(badStr, 128, "%s\n", fnTable1[i].name);
- EEL_STRING_STDOUT_WRITE(badStr, strlen(badStr));
- }
-}
-
-void NSEEL_start()
-{
- // Global memory
- if (decompressedCoefficients)
- free(decompressedCoefficients);
- decompressedCoefficients = (float*)malloc(22438 * sizeof(float));
- decompressResamplerMQ(compressedCoeffMQ, decompressedCoefficients);
- initFFTData();
- srand((uint32_t)time(NULL));
-}
-void NSEEL_quit()
-{
- if (decompressedCoefficients)
- free(decompressedCoefficients);
- decompressedCoefficients = 0;
-}
-//---------------------------------------------------------------------------------------------------------------
-static void freeBlocks(llBlock **start)
-{
- llBlock *s = *start;
- *start = 0;
- while (s)
- {
- llBlock *llB = s->next;
- free(s);
- s = llB;
- }
-}
-//---------------------------------------------------------------------------------------------------------------
-static void *__newBlock(llBlock **start, int32_t size)
-{
- llBlock *llb;
- int32_t alloc_size;
- if (*start && (LLB_DSIZE - (*start)->sizeused) >= size)
- {
- void *t = (*start)->block + (*start)->sizeused;
- (*start)->sizeused += (size + 7)&~7;
- return t;
- }
- alloc_size = sizeof(llBlock);
- if ((int32_t)size > LLB_DSIZE) alloc_size += size - LLB_DSIZE;
- llb = (llBlock *)malloc(alloc_size); // grab bigger block if absolutely necessary (heh)
- if (!llb) return NULL;
- llb->sizeused = (size + 7)&~7;
- llb->next = *start;
- *start = llb;
- return llb->block;
-}
-//---------------------------------------------------------------------------------------------------------------
-opcodeRec *nseel_createCompiledValue(compileContext *ctx, float value)
-{
- opcodeRec *r = newOpCode(ctx, NULL, OPCODETYPE_DIRECTVALUE);
- if (r)
- {
- r->parms.dv.directValue = value;
- }
- return r;
-}
-opcodeRec *nseel_createCompiledValuePtr(compileContext *ctx, float *addrValue, const char *namestr)
-{
- opcodeRec *r = newOpCode(ctx, namestr, OPCODETYPE_VARPTR);
- if (!r) return 0;
- r->parms.dv.valuePtr = addrValue;
- return r;
-}
-static int32_t validate_varname_for_function(compileContext *ctx, const char *name)
-{
- if (!ctx->function_curName || !ctx->function_globalFlag) return 1;
- if (ctx->function_localTable_Size[2] > 0 && ctx->function_localTable_Names[2])
- {
- char * const * const namelist = ctx->function_localTable_Names[2];
- const int32_t namelist_sz = ctx->function_localTable_Size[2];
- int32_t i;
- const size_t name_len = strlen(name);
- for (i = 0; i < namelist_sz; i++)
- {
- const char *nmchk = namelist[i];
- const size_t l = strlen(nmchk);
- if (l > 1 && nmchk[l - 1] == '*')
- {
- if (name_len >= l && !strncmp(nmchk, name, l - 1) && name[l - 1] == '.') return 1;
- }
- else
- {
- if (name_len == l && !strcmp(nmchk, name)) return 1;
- }
- }
- }
- return 0;
-}
-opcodeRec *nseel_resolve_named_symbol(compileContext *ctx, opcodeRec *rec, int32_t parmcnt, int32_t *errOut)
-{
- const int32_t isFunctionMode = parmcnt >= 0;
- int32_t rel_prefix_len = 0;
- int32_t rel_prefix_idx = -2;
- int32_t i;
- char match_parmcnt[4] = { -1,-1,-1,-1 }; // [3] is guess
- unsigned char match_parmcnt_pos = 0;
- char *sname = (char *)rec->relname;
- const char *prevent_function_calls = NULL;
- if (errOut) *errOut = 0;
- if (rec->opcodeType != OPCODETYPE_VARPTR || !sname || !sname[0]) return NULL;
- if (ctx->function_curName)
- {
- if (!strncmp(sname, "this.", 5))
- {
- rel_prefix_len = 5;
- rel_prefix_idx = -1;
- }
- else if (!strcmp(sname, "this"))
- {
- rel_prefix_len = 4;
- rel_prefix_idx = -1;
- }
- // scan for parameters/local variables before user functions
- if (rel_prefix_idx < -1 && ctx->function_localTable_Size[0] > 0 && ctx->function_localTable_Names[0] && ctx->function_localTable_ValuePtrs)
- {
- char * const * const namelist = ctx->function_localTable_Names[0];
- const int32_t namelist_sz = ctx->function_localTable_Size[0];
- for (i = 0; i < namelist_sz; i++)
- {
- const char *p = namelist[i];
- if (p)
- {
- if (!isFunctionMode && !strncmp(p, sname, NSEEL_MAX_VARIABLE_NAMELEN))
- {
- rec->opcodeType = OPCODETYPE_VARPTRPTR;
- rec->parms.dv.valuePtr = (float *)(ctx->function_localTable_ValuePtrs + i);
- rec->parms.dv.directValue = 0.0f;
- return rec;
- }
- else
- {
- const size_t plen = strlen(p);
- if (plen > 1 && p[plen - 1] == '*' && !strncmp(p, sname, plen - 1) && ((sname[plen - 1] == '.'&&sname[plen]) || !sname[plen - 1]))
- {
- rel_prefix_len = (int32_t)(sname[plen - 1] ? plen : plen - 1);
- rel_prefix_idx = i;
- break;
- }
- }
- }
- }
- }
- // if instance name set, translate sname or sname.* into "this.sname.*"
- if (rel_prefix_idx < -1 && ctx->function_localTable_Size[1] > 0 && ctx->function_localTable_Names[1])
- {
- char * const * const namelist = ctx->function_localTable_Names[1];
- const int32_t namelist_sz = ctx->function_localTable_Size[1];
- const char *full_sname = rec->relname; // include # in checks
- for (i = 0; i < namelist_sz; i++)
- {
- const char *p = namelist[i];
- if (p && *p)
- {
- const size_t tl = strlen(p);
- if (!strncmp(p, full_sname, tl) && (full_sname[tl] == 0 || full_sname[tl] == '.'))
- {
- rel_prefix_len = 0; // treat as though this. prefixes is present
- rel_prefix_idx = -1;
- break;
- }
- }
- }
- }
- if (rel_prefix_idx >= -1)
- {
- ctx->function_usesNamespaces = 1;
- }
- } // ctx->function_curName
- if (!isFunctionMode)
- {
- // instance variables
- if (rel_prefix_idx >= -1)
- {
- rec->opcodeType = OPCODETYPE_VALUE_FROM_NAMESPACENAME;
- rec->namespaceidx = rel_prefix_idx;
- if (rel_prefix_len > 0)
- {
- memmove(sname, sname + rel_prefix_len, strlen(sname + rel_prefix_len) + 1);
- }
- }
- else
- {
- // no namespace index, so it must be a global
- if (!validate_varname_for_function(ctx, rec->relname))
- {
- if (errOut) *errOut = 1;
- if (ctx->last_error_string[0]) lstrcatn(ctx->last_error_string, ", ", sizeof(ctx->last_error_string));
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "global '%s' inaccessible", rec->relname);
- return NULL;
- }
- }
- return rec;
- }
- if (ctx->func_check)
- prevent_function_calls = ctx->func_check(sname, ctx->func_check_user);
- ////////// function mode
- // first off, while() and loop() are special and can't be overridden
- //
- if (parmcnt == 1 && !strcmp("while", sname) && !prevent_function_calls)
- {
- rec->opcodeType = OPCODETYPE_FUNC1;
- rec->fntype = FN_WHILE;
- return rec;
- }
- if (parmcnt == 2 && !strcmp("loop", sname) && !prevent_function_calls)
- {
- rec->opcodeType = OPCODETYPE_FUNC2;
- rec->fntype = FN_LOOP;
- return rec;
- }
- //
- // resolve user function names before builtin functions -- this allows the user to override default functions
- {
- _codeHandleFunctionRec *best = NULL;
- size_t bestlen = 0;
- const char * const ourcall = sname + rel_prefix_len;
- const size_t ourcall_len = strlen(ourcall);
- int32_t pass;
- for (pass = 0; pass < 2; pass++)
- {
- _codeHandleFunctionRec *fr = pass ? ctx->functions_common : ctx->functions_local;
- // sname is [namespace.[ns.]]function, find best match of function that matches the right end
- while (fr)
- {
- int32_t this_np = fr->num_params;
- const char *thisfunc = fr->fname;
- const size_t thisfunc_len = strlen(thisfunc);
- if (this_np < 1) this_np = 1;
- if (thisfunc_len == ourcall_len && !strcmp(thisfunc, ourcall))
- {
- if (this_np == parmcnt)
- {
- bestlen = thisfunc_len;
- best = fr;
- break; // found exact match, finished
- }
- else
- {
- if (match_parmcnt_pos < 3) match_parmcnt[match_parmcnt_pos++] = fr->num_params;
- }
- }
- if (thisfunc_len > bestlen && thisfunc_len < ourcall_len && ourcall[ourcall_len - thisfunc_len - 1] == '.' && !strcmp(thisfunc, ourcall + ourcall_len - thisfunc_len))
- {
- if (this_np == parmcnt)
- {
- bestlen = thisfunc_len;
- best = fr;
- }
- else
- if (match_parmcnt[3] < 0) match_parmcnt[3] = fr->num_params;
- }
- fr = fr->next;
- }
- if (fr) break; // found exact match, finished
- }
- if (best)
- {
- switch (parmcnt)
- {
- case 0:
- case 1: rec->opcodeType = OPCODETYPE_FUNC1; break;
- case 2: rec->opcodeType = OPCODETYPE_FUNC2; break;
- case 3: rec->opcodeType = OPCODETYPE_FUNC3; break;
- default: rec->opcodeType = OPCODETYPE_FUNCX; break;
- }
- if (ourcall != rec->relname) memmove((char *)rec->relname, ourcall, strlen(ourcall) + 1);
- if (ctx->function_curName && rel_prefix_idx < 0)
- {
- // if no namespace specified, and this.commonprefix.func() called, remove common prefixes and set prefixidx to be this
- const char *p = ctx->function_curName;
- if (*p) p++;
- while (*p && *p != '.') p++;
- if (*p && p[1]) // we have a dot!
- {
- while (p[1]) p++; // go to last char of string, which doesn't allow possible trailing dot to be checked
- while (--p > ctx->function_curName) // do not check possible leading dot
- {
- if (*p == '.')
- {
- const size_t cmplen = p + 1 - ctx->function_curName;
- if (!strncmp(rec->relname, ctx->function_curName, cmplen) && rec->relname[cmplen])
- {
- const char *src = rec->relname + cmplen;
- memmove((char *)rec->relname, src, strlen(src) + 1);
- rel_prefix_idx = -1;
- ctx->function_usesNamespaces = 1;
- break;
- }
- }
- }
- }
- }
- if (ctx->function_curName && rel_prefix_idx < -1 &&
- strchr(rec->relname, '.') && !validate_varname_for_function(ctx, rec->relname))
- {
- if (errOut) *errOut = 1;
- if (ctx->last_error_string[0]) lstrcatn(ctx->last_error_string, ", ", sizeof(ctx->last_error_string));
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "namespaced function '%s' inaccessible", rec->relname);
- return NULL;
- }
- rec->namespaceidx = rel_prefix_idx;
- rec->fntype = FUNCTYPE_EELFUNC;
- rec->fn = best;
- return rec;
- }
- }
- if (prevent_function_calls)
- {
- if (ctx->last_error_string[0]) lstrcatn(ctx->last_error_string, ", ", sizeof(ctx->last_error_string));
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "'%.30s': %s", sname, prevent_function_calls);
- if (errOut) *errOut = 0;
- return NULL;
- }
- // convert legacy pow() to FN_POW
- if (!strcmp("pow", sname))
- {
- if (parmcnt == 2)
- {
- rec->opcodeType = OPCODETYPE_FUNC2;
- rec->fntype = FN_POW;
- return rec;
- }
- if (match_parmcnt_pos < 3) match_parmcnt[match_parmcnt_pos++] = 2;
- }
- else if (!strcmp("__denormal_likely", sname) || !strcmp("__denormal_unlikely", sname))
- {
- if (parmcnt == 1)
- {
- rec->opcodeType = OPCODETYPE_FUNC1;
- rec->fntype = !strcmp("__denormal_likely", sname) ? FN_DENORMAL_LIKELY : FN_DENORMAL_UNLIKELY;
- return rec;
- }
- }
- for (i = 0; fnTable1 + i; i++)
- {
- if (i >= (int32_t)(sizeof(fnTable1) / sizeof(fnTable1[0])))
- break;
- functionType *f = fnTable1 + i;
- if (!strcmp(f->name, sname))
- {
- const int32_t pc_needed = (f->nParams&FUNCTIONTYPE_PARAMETERCOUNTMASK);
- if ((f->nParams&BIF_TAKES_VARPARM_EX) == BIF_TAKES_VARPARM ? (parmcnt >= pc_needed) : (parmcnt == pc_needed))
- {
- rec->fntype = FUNCTYPE_FUNCTIONTYPEREC;
- rec->fn = (void *)f;
- switch (parmcnt)
- {
- case 0:
- case 1: rec->opcodeType = OPCODETYPE_FUNC1; break;
- case 2: rec->opcodeType = OPCODETYPE_FUNC2; break;
- case 3: rec->opcodeType = OPCODETYPE_FUNC3; break;
- default: rec->opcodeType = OPCODETYPE_FUNCX; break;
- }
- return rec;
- }
- if (match_parmcnt_pos < 3) match_parmcnt[match_parmcnt_pos++] = (f->nParams&FUNCTIONTYPE_PARAMETERCOUNTMASK);
- }
- }
- if (ctx->last_error_string[0]) lstrcatn(ctx->last_error_string, ", ", sizeof(ctx->last_error_string));
- if (match_parmcnt[3] >= 0)
- {
- if (match_parmcnt_pos < 3) match_parmcnt[match_parmcnt_pos] = match_parmcnt[3];
- match_parmcnt_pos++;
- }
- if (!match_parmcnt_pos)
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "'%.30s' undefined", sname);
- else
- {
- int32_t x;
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "'%.30s' needs ", sname);
- for (x = 0; x < match_parmcnt_pos; x++)
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "%s%d", x == 0 ? "" : x == match_parmcnt_pos - 1 ? " or " : ",", match_parmcnt[x]);
- lstrcatn(ctx->last_error_string, " parms", sizeof(ctx->last_error_string));
- }
- if (errOut) *errOut = match_parmcnt_pos > 0 ? parmcnt < match_parmcnt[0] ? 2 : (match_parmcnt[0] < 2 ? 4 : 1) : 0;
- return NULL;
-}
-opcodeRec *nseel_setCompiledFunctionCallParameters(compileContext *ctx, opcodeRec *fn, opcodeRec *code1, opcodeRec *code2, opcodeRec *code3, opcodeRec *postCode, int32_t *errOut)
-{
- opcodeRec *r;
- int32_t np = 0, x;
- if (!fn || fn->opcodeType != OPCODETYPE_VARPTR || !fn->relname || !fn->relname[0])
- {
- return NULL;
- }
- fn->parms.parms[0] = code1;
- fn->parms.parms[1] = code2;
- fn->parms.parms[2] = code3;
- for (x = 0; x < 3; x++)
- {
- opcodeRec *prni = fn->parms.parms[x];
- while (prni && np < NSEEL_MAX_EELFUNC_PARAMETERS)
- {
- const int32_t isMP = prni->opcodeType == OPCODETYPE_MOREPARAMS;
- np++;
- if (!isMP) break;
- prni = prni->parms.parms[1];
- }
- }
- r = nseel_resolve_named_symbol(ctx, fn, np < 1 ? 1 : np, errOut);
- if (postCode && r)
- {
- if (code1 && r->opcodeType == OPCODETYPE_FUNC1 && r->fntype == FN_WHILE)
- {
- // change while(x) (postcode) to be
- // while ((x) ? (postcode;1) : 0);
- r->parms.parms[0] =
- nseel_createIfElse(ctx, r->parms.parms[0],
- nseel_createSimpleCompiledFunction(ctx, FN_JOIN_STATEMENTS, 2, postCode, nseel_createCompiledValue(ctx, 1.0f)),
- NULL); // NULL defaults to 0.0f
- }
- else
- {
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "syntax error following function");
- *errOut = -1;
- return NULL;
- }
- }
- return r;
-}
-eelStringSegmentRec *nseel_createStringSegmentRec(compileContext *ctx, const char *str, int32_t len)
-{
- eelStringSegmentRec *r = newTmpBlock(ctx, sizeof(eelStringSegmentRec));
- if (r)
- {
- r->_next = 0;
- r->str_start = str;
- r->str_len = len;
- }
- return r;
-}
-opcodeRec *nseel_eelMakeOpcodeFromStringSegments(compileContext *ctx, eelStringSegmentRec *rec)
-{
- if (ctx && ctx->onString)
- {
- return nseel_createCompiledValue(ctx, ctx->onString(ctx->caller_this, rec));
- }
- return NULL;
-}
-opcodeRec *nseel_createMoreParametersOpcode(compileContext *ctx, opcodeRec *code1, opcodeRec *code2)
-{
- opcodeRec *r = code1 && code2 ? newOpCode(ctx, NULL, OPCODETYPE_MOREPARAMS) : NULL;
- if (r)
- {
- r->parms.parms[0] = code1;
- r->parms.parms[1] = code2;
- }
- return r;
-}
-opcodeRec *nseel_createIfElse(compileContext *ctx, opcodeRec *code1, opcodeRec *code2, opcodeRec *code3)
-{
- opcodeRec *r = code1 ? newOpCode(ctx, NULL, OPCODETYPE_FUNC3) : NULL;
- if (r)
- {
- if (!code2) code2 = nseel_createCompiledValue(ctx, 0.0f);
- if (!code3) code3 = nseel_createCompiledValue(ctx, 0.0f);
- if (!code2 || !code3) return NULL;
- r->fntype = FN_IF_ELSE;
- r->parms.parms[0] = code1;
- r->parms.parms[1] = code2;
- r->parms.parms[2] = code3;
- }
- return r;
-}
-opcodeRec *nseel_createMemoryAccess(compileContext *ctx, opcodeRec *code1, opcodeRec *code2)
-{
- if (code2 && (code2->opcodeType != OPCODETYPE_DIRECTVALUE || code2->parms.dv.directValue != 0.0f))
- {
- code1 = nseel_createSimpleCompiledFunction(ctx, FN_ADD, 2, code1, code2);
- }
- return nseel_createSimpleCompiledFunction(ctx, FN_MEMORY, 1, code1, 0);
-}
-opcodeRec *nseel_createSimpleCompiledFunction(compileContext *ctx, int32_t fn, int32_t np, opcodeRec *code1, opcodeRec *code2)
-{
- opcodeRec *r = code1 && (np < 2 || code2) ? newOpCode(ctx, NULL, np >= 2 ? OPCODETYPE_FUNC2 : OPCODETYPE_FUNC1) : NULL;
- if (r)
- {
- r->fntype = fn;
- r->parms.parms[0] = code1;
- r->parms.parms[1] = code2;
- if (fn == FN_JOIN_STATEMENTS)
- {
- r->fn = r; // for joins, fn is temporarily used for tail pointers
- if (code1 && code1->opcodeType == OPCODETYPE_FUNC2 && code1->fntype == fn)
- {
- opcodeRec *t = (opcodeRec *)code1->fn;
- // keep joins in the form of dosomething->morestuff.
- // in this instance, code1 is previous stuff to do, code2 is new stuff to do
- r->parms.parms[0] = t->parms.parms[1];
- code1->fn = (t->parms.parms[1] = r);
- return code1;
- }
- }
- }
- return r;
-}
-// these are bitmasks; on request you can tell what is supported, and compileOpcodes will return one of them
-#define RETURNVALUE_IGNORE 0 // ignore return value
-#define RETURNVALUE_NORMAL 1 // pointer
-#define RETURNVALUE_FPSTACK 2
-#define RETURNVALUE_BOOL 4 // P1 is nonzero if true
-#define RETURNVALUE_BOOL_REVERSED 8 // P1 is zero if true
-static int32_t compileOpcodes(compileContext *ctx, opcodeRec *op, unsigned char *bufOut, int32_t bufOut_len, int32_t *computTable, const namespaceInformation *namespacePathToThis,
- int32_t supportedReturnValues, int32_t *rvType, int32_t *fpStackUsage, int32_t *canHaveDenormalOutput);
-static unsigned char *compileCodeBlockWithRet(compileContext *ctx, opcodeRec *rec, int32_t *computTableSize, const namespaceInformation *namespacePathToThis,
- int32_t supportedReturnValues, int32_t *rvType, int32_t *fpStackUse, int32_t *canHaveDenormalOutput);
-_codeHandleFunctionRec *eel_createFunctionNamespacedInstance(compileContext *ctx, _codeHandleFunctionRec *fr, const char *nameptr)
-{
- size_t n;
- _codeHandleFunctionRec *subfr =
- fr->isCommonFunction ?
- ctx->isSharedFunctions ? newDataBlock(sizeof(_codeHandleFunctionRec), 8) :
- newCtxDataBlock(sizeof(_codeHandleFunctionRec), 8) : // if common function, but derived version is in non-common context, set ownership to VM rather than us
- newTmpBlock(ctx, sizeof(_codeHandleFunctionRec));
- if (!subfr) return 0;
- // fr points to functionname()'s rec, nameptr to blah.functionname()
- *subfr = *fr;
- n = strlen(nameptr);
- if (n > sizeof(subfr->fname) - 1) n = sizeof(subfr->fname) - 1;
- memcpy(subfr->fname, nameptr, n);
- subfr->fname[n] = 0;
- subfr->next = NULL;
- subfr->startptr = 0; // make sure this code gets recompiled (with correct member ptrs) for this instance!
- // subfr->derivedCopies already points to the right place
- fr->derivedCopies = subfr;
- return subfr;
-}
-static void combineNamespaceFields(char *nm, const namespaceInformation *namespaceInfo, const char *relname, int32_t thisctx) // nm must be NSEEL_MAX_VARIABLE_NAMELEN+1 bytes
-{
- const char *prefix = namespaceInfo ?
- thisctx < 0 ? (thisctx == -1 ? namespaceInfo->namespacePathToThis : NULL) : (thisctx < MAX_SUB_NAMESPACES ? namespaceInfo->subParmInfo[thisctx] : NULL)
- : NULL;
- int32_t lfp = 0, lrn = relname ? (int32_t)strlen(relname) : 0;
- if (prefix) while (prefix[lfp] && prefix[lfp] != ':' && lfp < NSEEL_MAX_VARIABLE_NAMELEN) lfp++;
- if (!relname) relname = "";
- while (*relname == '.') // if relname begins with ., then remove a chunk of context from prefix
- {
- relname++;
- while (lfp > 0 && prefix[lfp - 1] != '.') lfp--;
- if (lfp > 0) lfp--;
- }
- if (lfp > NSEEL_MAX_VARIABLE_NAMELEN - 3) lfp = NSEEL_MAX_VARIABLE_NAMELEN - 3;
- if (lfp > 0) memcpy(nm, prefix, lfp);
- if (lrn > NSEEL_MAX_VARIABLE_NAMELEN - lfp - (lfp > 0)) lrn = NSEEL_MAX_VARIABLE_NAMELEN - lfp - (lfp > 0);
- if (lrn > 0)
- {
- if (lfp > 0) nm[lfp++] = '.';
- memcpy(nm + lfp, relname, lrn);
- lfp += lrn;
- }
- nm[lfp++] = 0;
-}
-//---------------------------------------------------------------------------------------------------------------
-static void *nseel_getBuiltinFunctionAddress(compileContext *ctx,
- int32_t fntype, void *fn,
- NSEEL_PPPROC *pProc, void ***replList,
- void **endP, int32_t *abiInfo, int32_t preferredReturnValues, const float *hasConstParm1, const float *hasConstParm2)
-{
- const float *firstConstParm = hasConstParm1 ? hasConstParm1 : hasConstParm2;
- static void *pow_replptrs[4] = { (void**)&redirect_powf, };
- switch (fntype)
- {
-#define RF(x) *endP = nseel_asm_##x##_end; return (void*)nseel_asm_##x
- case FN_MUL_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(mul_op);
- case FN_DIV_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(div_op);
- case FN_OR_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(or_op);
- case FN_XOR_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(xor_op);
- case FN_AND_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(and_op);
- case FN_MOD_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(mod_op);
- case FN_ADD_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(add_op);
- case FN_SUB_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(sub_op);
- case FN_POW_OP:
- *abiInfo = BIF_LASTPARMONSTACK | BIF_CLEARDENORMAL;
- *replList = pow_replptrs;
- RF(2pdds);
- case FN_POW:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK;//BIF_FPSTACKUSE(2) might be safe, need to look at pow()'s implementation, but safer bet is to disallow fp stack caching for this expression
- *replList = pow_replptrs;
- RF(2pdd);
- case FN_ADD:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK_LAZY | BIF_FPSTACKUSE(2) | BIF_WONTMAKEDENORMAL;
- // for x +- non-denormal-constant, we can set BIF_CLEARDENORMAL
- if (firstConstParm && fabsf(*firstConstParm) > 1.0e-10) *abiInfo |= BIF_CLEARDENORMAL;
- RF(add);
- case FN_SUB:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK | BIF_FPSTACKUSE(2) | BIF_WONTMAKEDENORMAL;
- // for x +- non-denormal-constant, we can set BIF_CLEARDENORMAL
- if (firstConstParm && fabsf(*firstConstParm) > 1.0e-10) *abiInfo |= BIF_CLEARDENORMAL;
- RF(sub);
- case FN_MULTIPLY:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK_LAZY | BIF_FPSTACKUSE(2);
- // for x*constant-greater-than-eq-1, we can set BIF_WONTMAKEDENORMAL
- if (firstConstParm && fabsf(*firstConstParm) >= 1.0f) *abiInfo |= BIF_WONTMAKEDENORMAL;
- RF(mul);
- case FN_DIVIDE:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK | BIF_FPSTACKUSE(2);
- // for x/constant-less-than-eq-1, we can set BIF_WONTMAKEDENORMAL
- if (firstConstParm && fabsf(*firstConstParm) <= 1.0f) *abiInfo |= BIF_WONTMAKEDENORMAL;
- RF(div);
- case FN_MOD:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK | BIF_FPSTACKUSE(1) | BIF_CLEARDENORMAL;
- RF(mod);
- case FN_ASSIGN:
- *abiInfo = BIF_FPSTACKUSE(1) | BIF_CLEARDENORMAL;
- RF(assign);
- case FN_AND: *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK_LAZY | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL; RF(and);
- case FN_OR: *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK_LAZY | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL; RF(or );
- case FN_XOR:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK_LAZY | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(xor);
- case FN_SHR:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(shr);
- case FN_SHL:
- *abiInfo = BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK | BIF_FPSTACKUSE(2) | BIF_CLEARDENORMAL;
- RF(shl);
- case FN_NOTNOT: *abiInfo = BIF_LASTPARM_ASBOOL | BIF_RETURNSBOOL | BIF_FPSTACKUSE(1); RF(bnotnot);
- case FN_UMINUS: *abiInfo = BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_WONTMAKEDENORMAL; RF(uminus);
- case FN_NOT: *abiInfo = BIF_LASTPARM_ASBOOL | BIF_RETURNSBOOL | BIF_FPSTACKUSE(1); RF(bnot);
- case FN_EQ:
- *abiInfo = BIF_TWOPARMSONFPSTACK_LAZY | BIF_RETURNSBOOL | BIF_FPSTACKUSE(2);
- RF(equal);
- case FN_EQ_EXACT:
- *abiInfo = BIF_TWOPARMSONFPSTACK_LAZY | BIF_RETURNSBOOL | BIF_FPSTACKUSE(2);
- RF(equal_exact);
- case FN_NE:
- *abiInfo = BIF_TWOPARMSONFPSTACK_LAZY | BIF_RETURNSBOOL | BIF_FPSTACKUSE(2);
- RF(notequal);
- case FN_NE_EXACT:
- *abiInfo = BIF_TWOPARMSONFPSTACK_LAZY | BIF_RETURNSBOOL | BIF_FPSTACKUSE(2);
- RF(notequal_exact);
- case FN_LOGICAL_AND:
- *abiInfo = BIF_RETURNSBOOL;
- RF(band);
- case FN_LOGICAL_OR:
- *abiInfo = BIF_RETURNSBOOL;
- RF(bor);
-#ifdef GLUE_HAS_FXCH
- case FN_GT:
- *abiInfo = BIF_TWOPARMSONFPSTACK | BIF_RETURNSBOOL | BIF_FPSTACKUSE(2);
- RF(above);
- case FN_GTE:
- *abiInfo = BIF_TWOPARMSONFPSTACK | BIF_RETURNSBOOL | BIF_REVERSEFPORDER | BIF_FPSTACKUSE(2);
- RF(beloweq);
- case FN_LT:
- *abiInfo = BIF_TWOPARMSONFPSTACK | BIF_RETURNSBOOL | BIF_REVERSEFPORDER | BIF_FPSTACKUSE(2);
- RF(above);
- case FN_LTE:
- *abiInfo = BIF_TWOPARMSONFPSTACK | BIF_RETURNSBOOL | BIF_FPSTACKUSE(2);
- RF(beloweq);
-#else
- case FN_GT:
- *abiInfo = BIF_RETURNSBOOL | BIF_LASTPARMONSTACK;
- RF(above);
- case FN_GTE:
- *abiInfo = BIF_RETURNSBOOL | BIF_LASTPARMONSTACK;
- RF(aboveeq);
- case FN_LT:
- *abiInfo = BIF_RETURNSBOOL | BIF_LASTPARMONSTACK;
- RF(below);
- case FN_LTE:
- *abiInfo = BIF_RETURNSBOOL | BIF_LASTPARMONSTACK;
- RF(beloweq);
-#endif
-#undef RF
-#define RF(x) *endP = _asm_##x##_end; return (void*)_asm_##x
- case FN_MEMORY:
- {
- //static void *replptrs[4] = { (void**)&__NSEEL_RAMAlloc, };
- //*replList = replptrs;
- *abiInfo = BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(1) | BIF_CLEARDENORMAL;
-//#ifdef GLUE_MEM_NEEDS_PPROC
-// *pProc = NSEEL_PProc_RAM;
-//#endif
- RF(megabuf);
- }
- break;
-#undef RF
- case FUNCTYPE_FUNCTIONTYPEREC:
- if (fn)
- {
- functionType *p = (functionType *)fn;
- // if prefers fpstack or int32_t, or ignoring value, then use fp-stack versions
- if ((preferredReturnValues&(RETURNVALUE_BOOL | RETURNVALUE_FPSTACK)) || !preferredReturnValues)
- {
- static functionType min2 = { "min", nseel_asm_min_fp,nseel_asm_min_fp_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK_LAZY | BIF_FPSTACKUSE(2) | BIF_WONTMAKEDENORMAL };
- static functionType max2 = { "max", nseel_asm_max_fp,nseel_asm_max_fp_end, 2 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_TWOPARMSONFPSTACK_LAZY | BIF_FPSTACKUSE(2) | BIF_WONTMAKEDENORMAL };
- if (p->afunc == (void*)nseel_asm_min) p = &min2;
- else if (p->afunc == (void*)nseel_asm_max) p = &max2;
- }
- *replList = p->replptrs;
- *pProc = p->pProc;
- *endP = p->func_e;
- *abiInfo = p->nParams & BIF_NPARAMS_MASK;
- if (firstConstParm)
- {
- const char *name = p->name;
- if (!strcmp(name, "min") && *firstConstParm < -1.0e-10) *abiInfo |= BIF_CLEARDENORMAL;
- else if (!strcmp(name, "max") && *firstConstParm > 1.0e-10) *abiInfo |= BIF_CLEARDENORMAL;
- }
- return p->afunc;
- }
- break;
- }
- return 0;
-}
-static void *nseel_getEELFunctionAddress(compileContext *ctx,
- opcodeRec *op,
- int32_t *customFuncParmSize, int32_t *customFuncLocalStorageSize,
- float ***customFuncLocalStorage, int32_t *computTableTop,
- void **endP, int32_t *isRaw, int32_t wantCodeGenerated,
- const namespaceInformation *namespacePathToThis, int32_t *rvMode, int32_t *fpStackUse, int32_t *canHaveDenormalOutput,
- opcodeRec **ordered_parmptrs, int32_t num_ordered_parmptrs
-) // if wantCodeGenerated is false, can return bogus pointers in raw mode
-{
- _codeHandleFunctionRec *fn = (_codeHandleFunctionRec*)op->fn;
- namespaceInformation local_namespace = { NULL };
- char prefix_buf[NSEEL_MAX_VARIABLE_NAMELEN + 1], nm[NSEEL_MAX_FUNCSIG_NAME + 1];
- if (!fn) return NULL;
- // op->relname ptr is [whatever.]funcname
- if (fn->parameterAsNamespaceMask || fn->usesNamespaces)
- {
- if (wantCodeGenerated)
- {
- char *p = prefix_buf;
- combineNamespaceFields(nm, namespacePathToThis, op->relname, op->namespaceidx);
- lstrcpyn_safe(prefix_buf, nm, sizeof(prefix_buf));
- local_namespace.namespacePathToThis = prefix_buf;
- // nm is full path of function, prefix_buf will be the path not including function name (unless function name only)
- while (*p) p++;
- while (p >= prefix_buf && *p != '.') p--;
- if (p > prefix_buf) *p = 0;
- }
- if (fn->parameterAsNamespaceMask)
- {
- int32_t x;
- for (x = 0; x < MAX_SUB_NAMESPACES && x < fn->num_params; x++)
- {
- if (fn->parameterAsNamespaceMask & (((uint32_t)1) << x))
- {
- if (wantCodeGenerated)
- {
- const char *rn = NULL;
- char tmp[NSEEL_MAX_VARIABLE_NAMELEN + 1];
- if (x < num_ordered_parmptrs && ordered_parmptrs[x])
- {
- if (ordered_parmptrs[x]->opcodeType == OPCODETYPE_VARPTR)
- {
- rn = ordered_parmptrs[x]->relname;
- }
- else if (ordered_parmptrs[x]->opcodeType == OPCODETYPE_VALUE_FROM_NAMESPACENAME)
- {
- const char *p = ordered_parmptrs[x]->relname;
- if (*p == '#') p++;
- combineNamespaceFields(tmp, namespacePathToThis, p, ordered_parmptrs[x]->namespaceidx);
- rn = tmp;
- }
- }
- if (!rn)
- {
- // todo: figure out how to give correct line number/offset (ugh)
- stbsp_snprintf(ctx->last_error_string, sizeof(ctx->last_error_string), "parameter %d to %s() must be namespace", x + 1, fn->fname);
- return NULL;
- }
- lstrcatn(nm, ":", sizeof(nm));
- local_namespace.subParmInfo[x] = nm + strlen(nm);
- lstrcatn(nm, rn, sizeof(nm));
- }
- ordered_parmptrs[x] = NULL; // prevent caller from bothering generating parameters
- }
- }
- }
- if (wantCodeGenerated)
- {
- _codeHandleFunctionRec *fr = fn;
- // find namespace-adjusted function (if generating code, otherwise assume size is the same)
- fn = 0; // if this gets re-set, it will be the new function
- while (fr && !fn)
- {
- if (!strcmp(fr->fname, nm)) fn = fr;
- fr = fr->derivedCopies;
- }
- if (!fn) // generate copy of function
- {
- fn = eel_createFunctionNamespacedInstance(ctx, (_codeHandleFunctionRec*)op->fn, nm);
- }
- }
- }
- if (!fn) return NULL;
- if (!fn->startptr && fn->opcodes && fn->startptr_size > 0)
- {
- int32_t sz;
- fn->tmpspace_req = 0;
- fn->rvMode = RETURNVALUE_IGNORE;
- fn->canHaveDenormalOutput = 0;
- sz = compileOpcodes(ctx, fn->opcodes, NULL, 128 * 1024 * 1024, &fn->tmpspace_req, wantCodeGenerated ? &local_namespace : NULL, RETURNVALUE_NORMAL | RETURNVALUE_FPSTACK, &fn->rvMode, &fn->fpStackUsage, &fn->canHaveDenormalOutput);
- if (!wantCodeGenerated)
- {
- // don't compile anything for now, just give stats
- if (computTableTop) *computTableTop += fn->tmpspace_req;
- *customFuncParmSize = fn->num_params;
- *customFuncLocalStorage = fn->localstorage;
- *customFuncLocalStorageSize = fn->localstorage_size;
- *rvMode = fn->rvMode;
- *fpStackUse = fn->fpStackUsage;
- if (canHaveDenormalOutput) *canHaveDenormalOutput = fn->canHaveDenormalOutput;
- if (sz <= NSEEL_MAX_FUNCTION_SIZE_FOR_INLINE && !(0 & OPTFLAG_NO_INLINEFUNC))
- {
- *isRaw = 1;
- *endP = ((char *)1) + sz;
- return (char *)1;
- }
- *endP = (void*)nseel_asm_fcall_end;
- return (void*)nseel_asm_fcall;
- }
- if (sz <= NSEEL_MAX_FUNCTION_SIZE_FOR_INLINE && !(0 & OPTFLAG_NO_INLINEFUNC))
- {
- void *p = newTmpBlock(ctx, sz);
- fn->tmpspace_req = 0;
- if (p)
- {
- fn->canHaveDenormalOutput = 0;
- if (fn->isCommonFunction) ctx->isGeneratingCommonFunction++;
- sz = compileOpcodes(ctx, fn->opcodes, (unsigned char*)p, sz, &fn->tmpspace_req, &local_namespace, RETURNVALUE_NORMAL | RETURNVALUE_FPSTACK, &fn->rvMode, &fn->fpStackUsage, &fn->canHaveDenormalOutput);
- if (fn->isCommonFunction) ctx->isGeneratingCommonFunction--;
- // recompile function with native context pointers
- if (sz > 0)
- {
- fn->startptr_size = sz;
- fn->startptr = p;
- }
- }
- }
- else
- {
- unsigned char *codeCall;
- fn->tmpspace_req = 0;
- fn->fpStackUsage = 0;
- fn->canHaveDenormalOutput = 0;
- if (fn->isCommonFunction) ctx->isGeneratingCommonFunction++;
- codeCall = compileCodeBlockWithRet(ctx, fn->opcodes, &fn->tmpspace_req, &local_namespace, RETURNVALUE_NORMAL | RETURNVALUE_FPSTACK, &fn->rvMode, &fn->fpStackUsage, &fn->canHaveDenormalOutput);
- if (fn->isCommonFunction) ctx->isGeneratingCommonFunction--;
- if (codeCall)
- {
- void *f = GLUE_realAddress(nseel_asm_fcall, nseel_asm_fcall_end, &sz);
- fn->startptr = newTmpBlock(ctx, sz);
- if (fn->startptr)
- {
- memcpy(fn->startptr, f, sz);
- EEL_GLUE_set_immediate(fn->startptr, (INT_PTR)codeCall);
- fn->startptr_size = sz;
- }
- }
- }
- }
- if (fn->startptr)
- {
- if (computTableTop) *computTableTop += fn->tmpspace_req;
- *customFuncParmSize = fn->num_params;
- *customFuncLocalStorage = fn->localstorage;
- *customFuncLocalStorageSize = fn->localstorage_size;
- *rvMode = fn->rvMode;
- *fpStackUse = fn->fpStackUsage;
- if (canHaveDenormalOutput) *canHaveDenormalOutput = fn->canHaveDenormalOutput;
- *endP = (char*)fn->startptr + fn->startptr_size;
- *isRaw = 1;
- return fn->startptr;
- }
- return 0;
-}
-// returns true if does something (other than calculating and throwing away a value)
-static char optimizeOpcodes(compileContext *ctx, opcodeRec *op, int32_t needsResult)
-{
- opcodeRec *lastJoinOp = NULL;
- char retv, retv_parm[3], joined_retv = 0;
- while (op && op->opcodeType == OPCODETYPE_FUNC2 && op->fntype == FN_JOIN_STATEMENTS)
- {
- if (!optimizeOpcodes(ctx, op->parms.parms[0], 0) || OPCODE_IS_TRIVIAL(op->parms.parms[0]))
- {
- // direct value, can skip ourselves
- memcpy(op, op->parms.parms[1], sizeof(*op));
- }
- else
- {
- joined_retv |= 1;
- lastJoinOp = op;
- op = op->parms.parms[1];
- }
- }
- goto start_over;
-#define RESTART_DIRECTVALUE(X) { op->parms.dv.directValue = (X); goto start_over_directvalue; }
-start_over_directvalue:
- op->opcodeType = OPCODETYPE_DIRECTVALUE;
- op->parms.dv.valuePtr = NULL;
-start_over: // when an opcode changed substantially in optimization, goto here to reprocess it
- retv = retv_parm[0] = retv_parm[1] = retv_parm[2] = 0;
- if (!op || // should never really happen
- OPCODE_IS_TRIVIAL(op) || // should happen often (vars)
- op->opcodeType < 0 || op->opcodeType >= OPCODETYPE_INVALID // should never happen (assert would be appropriate heh)
- ) return joined_retv;
- if (!needsResult)
- {
- if (op->fntype == FUNCTYPE_EELFUNC)
- {
- needsResult = 1; // assume eel functions are non-const for now
- }
- else if (op->fntype == FUNCTYPE_FUNCTIONTYPEREC)
- {
- functionType *pfn = (functionType *)op->fn;
- if (!pfn || !(pfn->nParams&NSEEL_NPARAMS_FLAG_CONST)) needsResult = 1;
- }
- else if (op->fntype >= FN_NONCONST_BEGIN && op->fntype < FUNCTYPE_SIMPLEMAX)
- {
- needsResult = 1;
- }
- }
- if (op->opcodeType >= OPCODETYPE_FUNC2) retv_parm[1] = optimizeOpcodes(ctx, op->parms.parms[1], needsResult);
- if (op->opcodeType >= OPCODETYPE_FUNC3) retv_parm[2] = optimizeOpcodes(ctx, op->parms.parms[2], needsResult);
- retv_parm[0] = optimizeOpcodes(ctx, op->parms.parms[0], needsResult ||
- (FNPTR_HAS_CONDITIONAL_EXEC(op) && (retv_parm[1] || retv_parm[2] || op->opcodeType <= OPCODETYPE_FUNC1)));
- if (op->opcodeType != OPCODETYPE_MOREPARAMS)
- {
- if (op->fntype >= 0 && op->fntype < FUNCTYPE_SIMPLEMAX)
- {
- if (op->opcodeType == OPCODETYPE_FUNC1) // within FUNCTYPE_SIMPLE
- {
- if (op->parms.parms[0]->opcodeType == OPCODETYPE_DIRECTVALUE)
- {
- switch (op->fntype)
- {
- case FN_NOTNOT: RESTART_DIRECTVALUE(fabsf(op->parms.parms[0]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR ? 1.0f : 0.0f);
- case FN_NOT: RESTART_DIRECTVALUE(fabsf(op->parms.parms[0]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR ? 0.0f : 1.0f);
- case FN_UMINUS: RESTART_DIRECTVALUE(-op->parms.parms[0]->parms.dv.directValue);
- }
- }
- else if (op->fntype == FN_NOT || op->fntype == FN_NOTNOT)
- {
- if (op->parms.parms[0]->opcodeType == OPCODETYPE_FUNC1)
- {
- switch (op->parms.parms[0]->fntype)
- {
- case FN_UMINUS:
- case FN_NOTNOT: // ignore any NOTNOTs UMINUS or UPLUS, they would have no effect anyway
- op->parms.parms[0] = op->parms.parms[0]->parms.parms[0];
- goto start_over;
- case FN_NOT:
- op->fntype = op->fntype == FN_NOT ? FN_NOTNOT : FN_NOT; // switch between FN_NOT and FN_NOTNOT
- op->parms.parms[0] = op->parms.parms[0]->parms.parms[0];
- goto start_over;
- }
- }
- else if (op->parms.parms[0]->opcodeType == OPCODETYPE_FUNC2)
- {
- int32_t repl_type = -1;
- switch (op->parms.parms[0]->fntype)
- {
- case FN_EQ: repl_type = FN_NE; break;
- case FN_NE: repl_type = FN_EQ; break;
- case FN_EQ_EXACT: repl_type = FN_NE_EXACT; break;
- case FN_NE_EXACT: repl_type = FN_EQ_EXACT; break;
- case FN_LT: repl_type = FN_GTE; break;
- case FN_LTE: repl_type = FN_GT; break;
- case FN_GT: repl_type = FN_LTE; break;
- case FN_GTE: repl_type = FN_LT; break;
- }
- if (repl_type != -1)
- {
- const int32_t oldtype = op->fntype;
- memcpy(op, op->parms.parms[0], sizeof(*op));
- if (oldtype == FN_NOT) op->fntype = repl_type;
- goto start_over;
- }
- }
- }
- }
- else if (op->opcodeType == OPCODETYPE_FUNC2) // within FUNCTYPE_SIMPLE
- {
- const int32_t dv0 = op->parms.parms[0]->opcodeType == OPCODETYPE_DIRECTVALUE;
- const int32_t dv1 = op->parms.parms[1]->opcodeType == OPCODETYPE_DIRECTVALUE;
- if (dv0 && dv1)
- {
- int32_t reval = -1;
- switch (op->fntype)
- {
- case FN_MOD:
- {
- int32_t a = (int32_t)op->parms.parms[1]->parms.dv.directValue;
- if (a)
- {
- a = (int32_t)op->parms.parms[0]->parms.dv.directValue % a;
- if (a < 0) a = -a;
- }
- RESTART_DIRECTVALUE((float)a);
- }
- break;
- case FN_SHL: RESTART_DIRECTVALUE(((int32_t)op->parms.parms[0]->parms.dv.directValue) << ((int32_t)op->parms.parms[1]->parms.dv.directValue));
- case FN_SHR: RESTART_DIRECTVALUE(((int32_t)op->parms.parms[0]->parms.dv.directValue) >> ((int32_t)op->parms.parms[1]->parms.dv.directValue));
- case FN_POW: RESTART_DIRECTVALUE(powf(op->parms.parms[0]->parms.dv.directValue, op->parms.parms[1]->parms.dv.directValue));
- case FN_DIVIDE: RESTART_DIRECTVALUE(op->parms.parms[0]->parms.dv.directValue / op->parms.parms[1]->parms.dv.directValue);
- case FN_MULTIPLY: RESTART_DIRECTVALUE(op->parms.parms[0]->parms.dv.directValue * op->parms.parms[1]->parms.dv.directValue);
- case FN_ADD: RESTART_DIRECTVALUE(op->parms.parms[0]->parms.dv.directValue + op->parms.parms[1]->parms.dv.directValue);
- case FN_SUB: RESTART_DIRECTVALUE(op->parms.parms[0]->parms.dv.directValue - op->parms.parms[1]->parms.dv.directValue);
- case FN_AND: RESTART_DIRECTVALUE((float)(((WDL_INT64)op->parms.parms[0]->parms.dv.directValue) & ((WDL_INT64)op->parms.parms[1]->parms.dv.directValue)));
- case FN_OR: RESTART_DIRECTVALUE((float)(((WDL_INT64)op->parms.parms[0]->parms.dv.directValue) | ((WDL_INT64)op->parms.parms[1]->parms.dv.directValue)));
- case FN_XOR: RESTART_DIRECTVALUE((float)(((WDL_INT64)op->parms.parms[0]->parms.dv.directValue) ^ ((WDL_INT64)op->parms.parms[1]->parms.dv.directValue)));
- case FN_EQ: reval = fabsf(op->parms.parms[0]->parms.dv.directValue - op->parms.parms[1]->parms.dv.directValue) < NSEEL_CLOSEFACTOR; break;
- case FN_NE: reval = fabsf(op->parms.parms[0]->parms.dv.directValue - op->parms.parms[1]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR; break;
- case FN_EQ_EXACT: reval = op->parms.parms[0]->parms.dv.directValue == op->parms.parms[1]->parms.dv.directValue; break;
- case FN_NE_EXACT: reval = op->parms.parms[0]->parms.dv.directValue != op->parms.parms[1]->parms.dv.directValue; break;
- case FN_LT: reval = op->parms.parms[0]->parms.dv.directValue < op->parms.parms[1]->parms.dv.directValue; break;
- case FN_LTE: reval = op->parms.parms[0]->parms.dv.directValue <= op->parms.parms[1]->parms.dv.directValue; break;
- case FN_GT: reval = op->parms.parms[0]->parms.dv.directValue > op->parms.parms[1]->parms.dv.directValue; break;
- case FN_GTE: reval = op->parms.parms[0]->parms.dv.directValue >= op->parms.parms[1]->parms.dv.directValue; break;
- case FN_LOGICAL_AND: reval = fabsf(op->parms.parms[0]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR && fabsf(op->parms.parms[1]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR; break;
- case FN_LOGICAL_OR: reval = fabsf(op->parms.parms[0]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR || fabsf(op->parms.parms[1]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR; break;
- }
- if (reval >= 0) RESTART_DIRECTVALUE((float)reval);
- }
- else if (dv0 || dv1)
- {
- float dvalue = op->parms.parms[!dv0]->parms.dv.directValue;
- switch (op->fntype)
- {
- case FN_OR:
- case FN_XOR:
- if (!(WDL_INT64)dvalue)
- {
- // replace with or0
- static functionType fr = { "or0",nseel_asm_or0, nseel_asm_or0_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_LASTPARMONSTACK | BIF_RETURNSONSTACK | BIF_CLEARDENORMAL, {0}, NULL };
- op->opcodeType = OPCODETYPE_FUNC1;
- op->fntype = FUNCTYPE_FUNCTIONTYPEREC;
- op->fn = &fr;
- if (dv0) op->parms.parms[0] = op->parms.parms[1];
- goto start_over;
- }
- break;
- case FN_SUB:
- if (dv0)
- {
- if (dvalue == 0.0f)
- {
- op->opcodeType = OPCODETYPE_FUNC1;
- op->fntype = FN_UMINUS;
- op->parms.parms[0] = op->parms.parms[1];
- goto start_over;
- }
- break;
- }
- // fall through, if dv1 we can remove +0.0f
- case FN_ADD:
- if (dvalue == 0.0f)
- {
- memcpy(op, op->parms.parms[!!dv0], sizeof(*op));
- goto start_over;
- }
- break;
- case FN_AND:
- if ((WDL_INT64)dvalue) break;
- dvalue = 0.0f; // treat x&0 as x*0, which optimizes to 0
- // fall through
- case FN_MULTIPLY:
- if (dvalue == 0.0f) // remove multiply by 0.0f (using 0.0f direct value as replacement), unless the nonzero side did something
- {
- if (!retv_parm[!!dv0])
- {
- memcpy(op, op->parms.parms[!dv0], sizeof(*op)); // set to 0 if other action wouldn't do anything
- goto start_over;
- }
- else
- {
- // this is 0.0f * oldexpressionthatmustbeprocessed or oldexpressionthatmustbeprocessed*0.0f
- op->fntype = FN_JOIN_STATEMENTS;
- if (dv0) // 0.0f*oldexpression, reverse the order so that 0 is returned
- {
- // set to (oldexpression;0)
- opcodeRec *tmp = op->parms.parms[1];
- op->parms.parms[1] = op->parms.parms[0];
- op->parms.parms[0] = tmp;
- }
- goto start_over;
- }
- }
- else if (dvalue == 1.0f) // remove multiply by 1.0f (using non-1.0f value as replacement)
- {
- memcpy(op, op->parms.parms[!!dv0], sizeof(*op));
- goto start_over;
- }
- break;
- case FN_POW:
- if (dv1)
- {
- // x^0 = 1
- if (fabsf(dvalue) < 1e-15f)
- {
- RESTART_DIRECTVALUE(1.0f);
- }
- // x^1 = x
- if (fabsf(dvalue - 1.0f) < 1e-15f)
- {
- memcpy(op, op->parms.parms[0], sizeof(*op));
- goto start_over;
- }
- }
- else if (dv0)
- {
- // pow(constant, x) = exp((x) * ln(constant)), if constant>0
- // opcodeRec *parm0 = op->parms.parms[0];
- if (dvalue > 0.0f)
- {
- static functionType expcpy = { "exp", nseel_asm_1pdd,nseel_asm_1pdd_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK, {(void**)&exp}, };
- // 1^x = 1
- if (fabsf(dvalue - 1.0f) < 1e-15f)
- {
- RESTART_DIRECTVALUE(1.0f);
- }
- dvalue = logf(dvalue);
- if (fabsf(dvalue - 1.0f) < FLT_EPSILON)
- {
- // caller wanted e^x
- op->parms.parms[0] = op->parms.parms[1];
- }
- else
- {
- // it would be nice to replace 10^x with exp(log(10)*x) or 2^x with exp(log(2),x), but
- // doing so breaks rounding. we could maybe only allow 10^x, which is used for dB conversion,
- // but for now we should just force the programmer do it exp(log(10)*x) themselves.
- break;
- /*
- parm0->opcodeType = OPCODETYPE_FUNC2;
- parm0->fntype = FN_MULTIPLY;
- parm0->parms.parms[0] = nseel_createCompiledValue(ctx,dvalue);
- parm0->parms.parms[1] = op->parms.parms[1];
- */
- }
- op->opcodeType = OPCODETYPE_FUNC1;
- op->fntype = FUNCTYPE_FUNCTIONTYPEREC;
- op->fn = &expcpy;
- goto start_over;
- }
- }
- break;
- case FN_MOD:
- if (dv1)
- {
- const int32_t a = (int32_t)dvalue;
- if (!a)
- {
- RESTART_DIRECTVALUE(0.0f);
- }
- }
- break;
- case FN_DIVIDE:
- if (dv1)
- {
- if (dvalue == 1.0f) // remove divide by 1.0f (using non-1.0f value as replacement)
- {
- memcpy(op, op->parms.parms[!!dv0], sizeof(*op));
- goto start_over;
- }
- else
- {
- // change to a multiply
- if (dvalue == 0.0f)
- {
- op->fntype = FN_MULTIPLY;
- goto start_over;
- }
- else
- {
- op->fntype = FN_MULTIPLY;
- op->parms.parms[1]->parms.dv.directValue = 1.0f / dvalue;
- op->parms.parms[1]->parms.dv.valuePtr = NULL;
- goto start_over;
- }
- }
- }
- else if (dvalue == 0.0f)
- {
- if (!retv_parm[!!dv0])
- {
- // if 0/x set to always 0.
- // this is 0.0f / (oldexpression that can be eliminated)
- memcpy(op, op->parms.parms[!dv0], sizeof(*op)); // set to 0 if other action wouldn't do anything
- }
- else
- {
- opcodeRec *tmp;
- // this is 0.0f / oldexpressionthatmustbeprocessed
- op->fntype = FN_JOIN_STATEMENTS;
- tmp = op->parms.parms[1];
- op->parms.parms[1] = op->parms.parms[0];
- op->parms.parms[0] = tmp;
- // set to (oldexpression;0)
- }
- goto start_over;
- }
- break;
- case FN_EQ:
- if (dvalue == 0.0f)
- {
- // convert x == 0.0f to !x
- op->opcodeType = OPCODETYPE_FUNC1;
- op->fntype = FN_NOT;
- if (dv0) op->parms.parms[0] = op->parms.parms[1];
- goto start_over;
- }
- break;
- case FN_NE:
- if (dvalue == 0.0f)
- {
- // convert x != 0.0f to !!
- op->opcodeType = OPCODETYPE_FUNC1;
- op->fntype = FN_NOTNOT;
- if (dv0) op->parms.parms[0] = op->parms.parms[1];
- goto start_over;
- }
- break;
- case FN_LOGICAL_AND:
- if (dv0)
- {
- // dvalue && expr
- if (fabsf(dvalue) < NSEEL_CLOSEFACTOR)
- {
- // 0 && expr, replace with 0
- RESTART_DIRECTVALUE(0.0f);
- }
- else
- {
- // 1 && expr, replace with 0 != expr
- op->fntype = FN_NE;
- op->parms.parms[0]->parms.dv.valuePtr = NULL;
- op->parms.parms[0]->parms.dv.directValue = 0.0f;
- }
- }
- else
- {
- // expr && dvalue
- if (fabsf(dvalue) < NSEEL_CLOSEFACTOR)
- {
- // expr && 0
- if (!retv_parm[0])
- {
- // expr has no consequence, drop it
- RESTART_DIRECTVALUE(0.0f);
- }
- else
- {
- // replace with (expr; 0)
- op->fntype = FN_JOIN_STATEMENTS;
- op->parms.parms[1]->parms.dv.valuePtr = NULL;
- op->parms.parms[1]->parms.dv.directValue = 0.0f;
- }
- }
- else
- {
- // expr && 1, replace with expr != 0
- op->fntype = FN_NE;
- op->parms.parms[1]->parms.dv.valuePtr = NULL;
- op->parms.parms[1]->parms.dv.directValue = 0.0f;
- }
- }
- goto start_over;
- case FN_LOGICAL_OR:
- if (dv0)
- {
- // dvalue || expr
- if (fabsf(dvalue) >= NSEEL_CLOSEFACTOR)
- {
- // 1 || expr, replace with 1
- RESTART_DIRECTVALUE(1.0f);
- }
- else
- {
- // 0 || expr, replace with 0 != expr
- op->fntype = FN_NE;
- op->parms.parms[0]->parms.dv.valuePtr = NULL;
- op->parms.parms[0]->parms.dv.directValue = 0.0f;
- }
- }
- else
- {
- // expr || dvalue
- if (fabsf(dvalue) >= NSEEL_CLOSEFACTOR)
- {
- // expr || 1
- if (!retv_parm[0])
- {
- // expr has no consequence, drop it and return 1
- RESTART_DIRECTVALUE(1.0f);
- }
- else
- {
- // replace with (expr; 1)
- op->fntype = FN_JOIN_STATEMENTS;
- op->parms.parms[1]->parms.dv.valuePtr = NULL;
- op->parms.parms[1]->parms.dv.directValue = 1.0f;
- }
- }
- else
- {
- // expr || 0, replace with expr != 0
- op->fntype = FN_NE;
- op->parms.parms[1]->parms.dv.valuePtr = NULL;
- op->parms.parms[1]->parms.dv.directValue = 0.0f;
- }
- }
- goto start_over;
- }
- } // dv0 || dv1
- // general optimization of two parameters
- switch (op->fntype)
- {
- case FN_MULTIPLY:
- {
- opcodeRec *first_parm = op->parms.parms[0], *second_parm = op->parms.parms[1];
- if (second_parm->opcodeType == first_parm->opcodeType)
- {
- switch (first_parm->opcodeType)
- {
- case OPCODETYPE_VALUE_FROM_NAMESPACENAME:
- if (first_parm->namespaceidx != second_parm->namespaceidx) break;
- // fall through
- case OPCODETYPE_VARPTR:
- if (first_parm->relname && second_parm->relname && !strcmp(second_parm->relname, first_parm->relname)) second_parm = NULL;
- break;
- case OPCODETYPE_VARPTRPTR:
- if (first_parm->parms.dv.valuePtr && first_parm->parms.dv.valuePtr == second_parm->parms.dv.valuePtr) second_parm = NULL;
- break;
- }
- if (!second_parm) // switch from x*x to sqr(x)
- {
- static functionType sqrcpy = { "sqr", nseel_asm_sqr,nseel_asm_sqr_end, 1 | NSEEL_NPARAMS_FLAG_CONST | BIF_RETURNSONSTACK | BIF_LASTPARMONSTACK | BIF_FPSTACKUSE(1) };
- op->opcodeType = OPCODETYPE_FUNC1;
- op->fntype = FUNCTYPE_FUNCTIONTYPEREC;
- op->fn = &sqrcpy;
- goto start_over;
- }
- }
- }
- break;
- case FN_POW:
- {
- opcodeRec *first_parm = op->parms.parms[0];
- if (first_parm->opcodeType == op->opcodeType && first_parm->fntype == FN_POW)
- {
- // since first_parm is a pow too, we can multiply the exponents.
- // set our base to be the base of the inner pow
- op->parms.parms[0] = first_parm->parms.parms[0];
- // make the old extra pow be a multiply of the exponents
- first_parm->fntype = FN_MULTIPLY;
- first_parm->parms.parms[0] = op->parms.parms[1];
- // put that as the exponent
- op->parms.parms[1] = first_parm;
- goto start_over;
- }
- }
- break;
- case FN_LOGICAL_AND:
- case FN_LOGICAL_OR:
- if (op->parms.parms[0]->fntype == FN_NOTNOT)
- {
- // remove notnot, unnecessary for input to &&/|| operators
- op->parms.parms[0] = op->parms.parms[0]->parms.parms[0];
- goto start_over;
- }
- if (op->parms.parms[1]->fntype == FN_NOTNOT)
- {
- // remove notnot, unnecessary for input to &&/|| operators
- op->parms.parms[1] = op->parms.parms[1]->parms.parms[0];
- goto start_over;
- }
- break;
- }
- }
- else if (op->opcodeType == OPCODETYPE_FUNC3) // within FUNCTYPE_SIMPLE
- {
- if (op->fntype == FN_IF_ELSE)
- {
- if (op->parms.parms[0]->opcodeType == OPCODETYPE_DIRECTVALUE)
- {
- int32_t s = fabsf(op->parms.parms[0]->parms.dv.directValue) >= NSEEL_CLOSEFACTOR;
- memcpy(op, op->parms.parms[s ? 1 : 2], sizeof(opcodeRec));
- goto start_over;
- }
- if (op->parms.parms[0]->opcodeType == OPCODETYPE_FUNC1)
- {
- if (op->parms.parms[0]->fntype == FN_NOTNOT)
- {
- // remove notnot, unnecessary for input to ? operator
- op->parms.parms[0] = op->parms.parms[0]->parms.parms[0];
- goto start_over;
- }
- }
- }
- }
- if (op->fntype >= FN_NONCONST_BEGIN && op->fntype < FUNCTYPE_SIMPLEMAX) retv |= 1;
- // FUNCTYPE_SIMPLE
- }
- else if (op->fntype == FUNCTYPE_FUNCTIONTYPEREC && op->fn)
- {
- /*
- probably worth doing reduction on:
- _divop (constant change to multiply)
- _and
- _or
- abs
- maybe:
- min
- max
- also, optimize should (recursively or maybe iteratively?) search transitive functions (mul/div) for more constant reduction possibilities
- */
- functionType *pfn = (functionType *)op->fn;
- if (!(pfn->nParams&NSEEL_NPARAMS_FLAG_CONST)) retv |= 1;
- if (op->opcodeType == OPCODETYPE_FUNC1) // within FUNCTYPE_FUNCTIONTYPEREC
- {
- if (op->parms.parms[0]->opcodeType == OPCODETYPE_DIRECTVALUE)
- {
- int32_t suc = 1;
- float v = op->parms.parms[0]->parms.dv.directValue;
-#define DOF(x) if (!strcmp(pfn->name,#x)) v = x(v); else
-#define DOF2(x,y) if (!strcmp(pfn->name,#x)) v = x(y); else
- DOF(sinf)
- DOF(cosf)
- DOF(tanf)
- DOF(asinf)
- DOF(acosf)
- DOF(atanf)
- DOF2(sqrtf, fabsf(v))
- DOF(expf)
- DOF(logf)
- DOF(log10f)
- /* else */ suc = 0;
-#undef DOF
-#undef DOF2
- if (suc)
- {
- RESTART_DIRECTVALUE(v);
- }
- }
- }
- else if (op->opcodeType == OPCODETYPE_FUNC2) // within FUNCTYPE_FUNCTIONTYPEREC
- {
- const int32_t dv0 = op->parms.parms[0]->opcodeType == OPCODETYPE_DIRECTVALUE;
- const int32_t dv1 = op->parms.parms[1]->opcodeType == OPCODETYPE_DIRECTVALUE;
- if (dv0 && dv1)
- {
- if (!strcmp(pfn->name, "atan2"))
- {
- RESTART_DIRECTVALUE(atan2f(op->parms.parms[0]->parms.dv.directValue, op->parms.parms[1]->parms.dv.directValue));
- }
- }
- }
- // FUNCTYPE_FUNCTIONTYPEREC
- }
- else
- {
- // unknown or eel func, assume non-const
- retv |= 1;
- }
- }
- // if we need results, or our function has effects itself, then finish
- if (retv || needsResult)
- {
- return retv || joined_retv || retv_parm[0] || retv_parm[1] || retv_parm[2];
- }
- // we don't need results here, and our function is const, which means we can remove it
- {
- int32_t cnt = 0, idx1 = 0, idx2 = 0, x;
- for (x = 0; x < 3; x++) if (retv_parm[x]) { if (!cnt++) idx1 = x; else idx2 = x; }
- if (!cnt) // none of the parameters do anything, remove this opcode
- {
- if (lastJoinOp)
- {
- // replace previous join with its first linked opcode, removing this opcode completely
- memcpy(lastJoinOp, lastJoinOp->parms.parms[0], sizeof(*lastJoinOp));
- }
- else if (op->opcodeType != OPCODETYPE_DIRECTVALUE)
- {
- // allow caller to easily detect this as trivial and remove it
- op->opcodeType = OPCODETYPE_DIRECTVALUE;
- op->parms.dv.valuePtr = NULL;
- op->parms.dv.directValue = 0.0f;
- }
- // return joined_retv below
- }
- else
- {
- // if parameters are non-const, and we're a conditional, preserve our function
- if (FNPTR_HAS_CONDITIONAL_EXEC(op)) return 1;
- // otherwise, condense into either the non-const statement, or a join
- if (cnt == 1)
- {
- memcpy(op, op->parms.parms[idx1], sizeof(*op));
- }
- else if (cnt == 2)
- {
- op->opcodeType = OPCODETYPE_FUNC2;
- op->fntype = FN_JOIN_STATEMENTS;
- op->fn = op;
- op->parms.parms[0] = op->parms.parms[idx1];
- op->parms.parms[1] = op->parms.parms[idx2];
- op->parms.parms[2] = NULL;
- }
- else
- {
- // todo need to create a new opcodeRec here, for now just leave as is
- // (non-conditional const 3 parameter functions are rare anyway)
- }
- return 1;
- }
- }
- return joined_retv;
-}
-static int32_t generateValueToReg(compileContext *ctx, opcodeRec *op, unsigned char *bufOut, int32_t whichReg, const namespaceInformation *functionPrefix, int32_t allowCache)
-{
- float *b = NULL;
- if (op->opcodeType == OPCODETYPE_VALUE_FROM_NAMESPACENAME)
- {
- char nm[NSEEL_MAX_VARIABLE_NAMELEN + 1];
- const char *p = op->relname;
- combineNamespaceFields(nm, functionPrefix, p + (*p == '#'), op->namespaceidx);
- if (!nm[0]) return -1;
- b = nseel_int_register_var(ctx, nm, 0, NULL);
- if (!b) RET_MINUS1_FAIL("error registering var")
- }
- else
- {
- if (op->opcodeType != OPCODETYPE_DIRECTVALUE) allowCache = 0;
- b = op->parms.dv.valuePtr;
- if (!b && op->opcodeType == OPCODETYPE_VARPTR && op->relname && op->relname[0])
- {
- op->parms.dv.valuePtr = b = nseel_int_register_var(ctx, op->relname, 0, NULL);
- }
- if (b && op->opcodeType == OPCODETYPE_VARPTRPTR) b = *(float **)b;
- if (!b && allowCache)
- {
- int32_t n = 50; // only scan last X items
- opcodeRec *r = ctx->directValueCache;
- while (r && n--)
- {
- if (r->parms.dv.directValue == op->parms.dv.directValue && (b = r->parms.dv.valuePtr)) break;
- r = (opcodeRec*)r->fn;
- }
- }
- if (!b)
- {
- ctx->l_stats[3]++;
- if (ctx->isGeneratingCommonFunction)
- b = newCtxDataBlock(sizeof(float), sizeof(float));
- else
- b = newDataBlock(sizeof(float), sizeof(float));
- if (!b) RET_MINUS1_FAIL("error allocating data block")
- if (op->opcodeType != OPCODETYPE_VARPTRPTR) op->parms.dv.valuePtr = b;
- *b = op->parms.dv.directValue;
- if (allowCache)
- {
- op->fn = ctx->directValueCache;
- ctx->directValueCache = op;
- }
- }
- }
- GLUE_MOV_PX_DIRECTVALUE_GEN(bufOut, (INT_PTR)b, whichReg);
- return GLUE_MOV_PX_DIRECTVALUE_SIZE;
-}
-unsigned char *compileCodeBlockWithRet(compileContext *ctx, opcodeRec *rec, int32_t *computTableSize, const namespaceInformation *namespacePathToThis,
- int32_t supportedReturnValues, int32_t *rvType, int32_t *fpStackUsage, int32_t *canHaveDenormalOutput)
-{
- unsigned char *p, *newblock2;
- // generate code call
- int32_t funcsz = compileOpcodes(ctx, rec, NULL, 1024 * 1024 * 128, NULL, namespacePathToThis, supportedReturnValues, rvType, fpStackUsage, NULL);
- if (funcsz < 0) return NULL;
- p = newblock2 = newCodeBlock(funcsz + sizeof(GLUE_RET), 32);
- if (!newblock2) return NULL;
- *fpStackUsage = 0;
- funcsz = compileOpcodes(ctx, rec, p, funcsz, computTableSize, namespacePathToThis, supportedReturnValues, rvType, fpStackUsage, canHaveDenormalOutput);
- if (funcsz < 0) return NULL;
- p += funcsz;
- memcpy(p, &GLUE_RET, sizeof(GLUE_RET)); p += sizeof(GLUE_RET);
-#ifdef __arm__
- __clear_cache(newblock2, p);
-#endif
- ctx->l_stats[2] += funcsz + 2;
- return newblock2;
-}
-static int32_t compileNativeFunctionCall(compileContext *ctx, opcodeRec *op, unsigned char *bufOut, int32_t bufOut_len, int32_t *computTableSize, const namespaceInformation *namespacePathToThis,
- int32_t *rvMode, int32_t *fpStackUsage, int32_t preferredReturnValues, int32_t *canHaveDenormalOutput)
-{
- // builtin function generation
- int32_t func_size = 0;
- int32_t cfunc_abiinfo = 0;
- int32_t local_fpstack_use = 0; // how many items we have pushed onto the fp stack
- int32_t parm_size = 0;
- int32_t restore_stack_amt = 0;
- void *func_e = NULL;
- NSEEL_PPPROC preProc = 0;
- void **repl = NULL;
- int32_t n_params = 1 + op->opcodeType - OPCODETYPE_FUNC1;
- const int32_t parm0_dv = op->parms.parms[0]->opcodeType == OPCODETYPE_DIRECTVALUE;
- const int32_t parm1_dv = n_params > 1 && op->parms.parms[1]->opcodeType == OPCODETYPE_DIRECTVALUE;
- void *func = nseel_getBuiltinFunctionAddress(ctx, op->fntype, op->fn, &preProc, &repl, &func_e, &cfunc_abiinfo, preferredReturnValues,
- parm0_dv ? &op->parms.parms[0]->parms.dv.directValue : NULL,
- parm1_dv ? &op->parms.parms[1]->parms.dv.directValue : NULL
- );
- if (!func) RET_MINUS1_FAIL("error getting funcaddr")
- *fpStackUsage = BIF_GETFPSTACKUSE(cfunc_abiinfo);
- *rvMode = RETURNVALUE_NORMAL;
- if (cfunc_abiinfo & BIF_TAKES_VARPARM)
- {
-#if defined(__arm__) || defined(__ppc__) || (defined (_M_ARM) && _M_ARM == 7)
- const int32_t max_params = 4096; // 32kb max offset addressing for stack, so 4096*4 = 16384, should be safe
-#else
- const int32_t max_params = 32768; // sanity check, the stack is free to grow on x86/x86-64
-#endif
- int32_t x;
- // this mode is less efficient in that it creates a list of pointers on the stack to pass to the function
- // but it is more flexible and works for >3 parameters.
- if (op->opcodeType == OPCODETYPE_FUNCX)
- {
- n_params = 0;
- for (x = 0; x < 3; x++)
- {
- opcodeRec *prni = op->parms.parms[x];
- while (prni)
- {
- const int32_t isMP = prni->opcodeType == OPCODETYPE_MOREPARAMS;
- n_params++;
- if (!isMP || n_params >= max_params) break;
- prni = prni->parms.parms[1];
- }
- }
- }
- restore_stack_amt = (sizeof(void *) * n_params + 15)&~15;
- if (restore_stack_amt)
- {
- int32_t offs = restore_stack_amt;
- while (offs > 0)
- {
- int32_t amt = offs;
- if (amt > 4096) amt = 4096;
- if ((size_t)bufOut_len < ((size_t)(parm_size)+GLUE_MOVE_STACK_SIZE)) RET_MINUS1_FAIL("insufficient size for varparm")
- if (bufOut) GLUE_MOVE_STACK(bufOut + parm_size, -amt);
- parm_size += GLUE_MOVE_STACK_SIZE;
- offs -= amt;
- if (offs > 0) // make sure this page is in memory
- {
- if ((size_t)bufOut_len < ((size_t)(parm_size)+GLUE_STORE_P1_TO_STACK_AT_OFFS_SIZE))
- RET_MINUS1_FAIL("insufficient size for varparm stackchk")
- if (bufOut) GLUE_STORE_P1_TO_STACK_AT_OFFS(bufOut + parm_size, 0);
- parm_size += GLUE_STORE_P1_TO_STACK_AT_OFFS_SIZE;
- }
- }
- }
- if (op->opcodeType == OPCODETYPE_FUNCX)
- {
- n_params = 0;
- for (x = 0; x < 3; x++)
- {
- opcodeRec *prni = op->parms.parms[x];
- while (prni)
- {
- const int32_t isMP = prni->opcodeType == OPCODETYPE_MOREPARAMS;
- opcodeRec *r = isMP ? prni->parms.parms[0] : prni;
- if (r)
- {
- int32_t canHaveDenorm = 0;
- int32_t rvt = RETURNVALUE_NORMAL;
- int32_t subfpstackuse = 0;
- int32_t lsz = compileOpcodes(ctx, r, bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, rvt, &rvt, &subfpstackuse, &canHaveDenorm);
- if (canHaveDenorm && canHaveDenormalOutput) *canHaveDenormalOutput = 1;
- if (lsz < 0) RET_MINUS1_FAIL("call coc for varparmX failed")
- if (rvt != RETURNVALUE_NORMAL) RET_MINUS1_FAIL("call coc for varparmX gave bad type back");
- parm_size += lsz;
- if ((size_t)bufOut_len < ((size_t)(parm_size)+GLUE_STORE_P1_TO_STACK_AT_OFFS_SIZE)) RET_MINUS1_FAIL("call coc for varparmX size");
- if (bufOut) GLUE_STORE_P1_TO_STACK_AT_OFFS(bufOut + parm_size, n_params * sizeof(void *));
- parm_size += GLUE_STORE_P1_TO_STACK_AT_OFFS_SIZE;
- if (subfpstackuse + local_fpstack_use > *fpStackUsage) *fpStackUsage = subfpstackuse + local_fpstack_use;
- }
- else RET_MINUS1_FAIL("zero parameter varparmX")
- n_params++;
- if (!isMP || n_params >= max_params) break;
- prni = prni->parms.parms[1];
- }
- }
- }
- else for (x = 0; x < n_params; x++)
- {
- opcodeRec *r = op->parms.parms[x];
- if (r)
- {
- int32_t canHaveDenorm = 0;
- int32_t subfpstackuse = 0;
- int32_t rvt = RETURNVALUE_NORMAL;
- int32_t lsz = compileOpcodes(ctx, r, bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, rvt, &rvt, &subfpstackuse, &canHaveDenorm);
- if (canHaveDenorm && canHaveDenormalOutput) *canHaveDenormalOutput = 1;
- if (lsz < 0) RET_MINUS1_FAIL("call coc for varparm123 failed")
- if (rvt != RETURNVALUE_NORMAL) RET_MINUS1_FAIL("call coc for varparm123 gave bad type back");
- parm_size += lsz;
- if ((size_t)bufOut_len < ((size_t)(parm_size)+GLUE_STORE_P1_TO_STACK_AT_OFFS_SIZE)) RET_MINUS1_FAIL("call coc for varparm123 size");
- if (bufOut) GLUE_STORE_P1_TO_STACK_AT_OFFS(bufOut + parm_size, x * sizeof(void *));
- parm_size += GLUE_STORE_P1_TO_STACK_AT_OFFS_SIZE;
- if (subfpstackuse + local_fpstack_use > *fpStackUsage) *fpStackUsage = subfpstackuse + local_fpstack_use;
- }
- else RET_MINUS1_FAIL("zero parameter for varparm123");
- }
- if ((size_t)bufOut_len < ((size_t)(parm_size)+GLUE_MOV_PX_DIRECTVALUE_SIZE + GLUE_MOVE_PX_STACKPTR_SIZE)) RET_MINUS1_FAIL("insufficient size for varparm p1")
- if (bufOut) GLUE_MOV_PX_DIRECTVALUE_GEN(bufOut + parm_size, (INT_PTR)n_params, 1);
- parm_size += GLUE_MOV_PX_DIRECTVALUE_SIZE;
- if (bufOut) GLUE_MOVE_PX_STACKPTR_GEN(bufOut + parm_size, 0);
- parm_size += GLUE_MOVE_PX_STACKPTR_SIZE;
- }
- else // not varparm
- {
- int32_t pn;
-#ifdef GLUE_HAS_FXCH
- int32_t need_fxch = 0;
-#endif
- int32_t last_nt_parm = -1, last_nt_parm_type;
- if (op->opcodeType == OPCODETYPE_FUNCX)
- {
- // this is not yet supported (calling conventions will need to be sorted, among other things)
- RET_MINUS1_FAIL("funcx for native functions requires BIF_TAKES_VARPARM or BIF_TAKES_VARPARM_EX")
- }
- // end of built-in function specific special casing
- // first pass, calculate any non-trivial parameters
- for (pn = 0; pn < n_params; pn++)
- {
- if (!OPCODE_IS_TRIVIAL(op->parms.parms[pn]))
- {
- int32_t canHaveDenorm = 0;
- int32_t subfpstackuse = 0;
- int32_t lsz = 0;
- int32_t rvt = RETURNVALUE_NORMAL;
- int32_t may_need_fppush = -1;
- if (last_nt_parm >= 0)
- {
- if (last_nt_parm_type == RETURNVALUE_FPSTACK)
- {
- may_need_fppush = parm_size;
- }
- else
- {
- // push last result
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_PUSH_P1)) RET_MINUS1_FAIL("failed on size, pushp1")
- if (bufOut) memcpy(bufOut + parm_size, &GLUE_PUSH_P1, sizeof(GLUE_PUSH_P1));
- parm_size += sizeof(GLUE_PUSH_P1);
- }
- }
- if (func == nseel_asm_bnot) rvt = RETURNVALUE_BOOL_REVERSED | RETURNVALUE_BOOL;
- else if (pn == n_params - 1)
- {
- if (cfunc_abiinfo&BIF_LASTPARMONSTACK) rvt = RETURNVALUE_FPSTACK;
- else if (cfunc_abiinfo&BIF_LASTPARM_ASBOOL) rvt = RETURNVALUE_BOOL;
- else if (func == nseel_asm_assign) rvt = RETURNVALUE_FPSTACK | RETURNVALUE_NORMAL;
- }
- else if (pn == n_params - 2 && (cfunc_abiinfo&BIF_SECONDLASTPARMST))
- {
- rvt = RETURNVALUE_FPSTACK;
- }
- lsz = compileOpcodes(ctx, op->parms.parms[pn], bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, rvt, &rvt, &subfpstackuse, &canHaveDenorm);
- if (lsz < 0) RET_MINUS1_FAIL("call coc failed")
- if (func == nseel_asm_bnot && rvt == RETURNVALUE_BOOL_REVERSED)
- {
- // remove bnot, compileOpcodes() used fptobool_rev
- func = nseel_asm_bnotnot;
- func_e = nseel_asm_bnotnot_end;
- rvt = RETURNVALUE_BOOL;
- }
- if (canHaveDenorm && canHaveDenormalOutput) *canHaveDenormalOutput = 1;
- parm_size += lsz;
- if (may_need_fppush >= 0)
- {
- if (local_fpstack_use + subfpstackuse >= (GLUE_MAX_FPSTACK_SIZE - 1) || (0 & OPTFLAG_NO_FPSTACK))
- {
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_POP_FPSTACK_TOSTACK))
- RET_MINUS1_FAIL("failed on size, popfpstacktostack")
- if (bufOut)
- {
- memmove(bufOut + may_need_fppush + sizeof(GLUE_POP_FPSTACK_TOSTACK), bufOut + may_need_fppush, parm_size - may_need_fppush);
- memcpy(bufOut + may_need_fppush, &GLUE_POP_FPSTACK_TOSTACK, sizeof(GLUE_POP_FPSTACK_TOSTACK));
- }
- parm_size += sizeof(GLUE_POP_FPSTACK_TOSTACK);
- }
- else
- {
- local_fpstack_use++;
- }
- }
- if (subfpstackuse + local_fpstack_use > *fpStackUsage)
- *fpStackUsage = subfpstackuse + local_fpstack_use;
- last_nt_parm = pn;
- last_nt_parm_type = rvt;
- if (pn == n_params - 1 && func == nseel_asm_assign)
- {
- if (!canHaveDenorm)
- {
- if (rvt == RETURNVALUE_FPSTACK)
- {
- cfunc_abiinfo |= BIF_LASTPARMONSTACK;
- func = nseel_asm_assign_fast_fromfp;
- func_e = nseel_asm_assign_fast_fromfp_end;
- }
- else
- {
- func = nseel_asm_assign_fast;
- func_e = nseel_asm_assign_fast_end;
- }
- }
- else
- {
- if (rvt == RETURNVALUE_FPSTACK)
- {
- cfunc_abiinfo |= BIF_LASTPARMONSTACK;
- func = nseel_asm_assign_fromfp;
- func_e = nseel_asm_assign_fromfp_end;
- }
- }
- }
- }
- }
- pn = last_nt_parm;
- if (pn >= 0) // if the last thing executed doesn't go to the last parameter, move it there
- {
- if ((cfunc_abiinfo&BIF_SECONDLASTPARMST) && pn == n_params - 2)
- {
- // do nothing, things are in the right place
- }
- else if (pn != n_params - 1)
- {
- // generate mov p1->pX
- if ((size_t)bufOut_len < ((size_t)(parm_size)+GLUE_SET_PX_FROM_P1_SIZE)) RET_MINUS1_FAIL("size, pxfromp1")
- if (bufOut) GLUE_SET_PX_FROM_P1(bufOut + parm_size, n_params - 1 - pn);
- parm_size += GLUE_SET_PX_FROM_P1_SIZE;
- }
- }
- // pop any pushed parameters
- while (--pn >= 0)
- {
- if (!OPCODE_IS_TRIVIAL(op->parms.parms[pn]))
- {
- if ((cfunc_abiinfo&BIF_SECONDLASTPARMST) && pn == n_params - 2)
- {
- if (!local_fpstack_use)
- {
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_POP_STACK_TO_FPSTACK)) RET_MINUS1_FAIL("size, popstacktofpstack 2")
- if (bufOut) memcpy(bufOut + parm_size, GLUE_POP_STACK_TO_FPSTACK, sizeof(GLUE_POP_STACK_TO_FPSTACK));
- parm_size += sizeof(GLUE_POP_STACK_TO_FPSTACK);
-#ifdef GLUE_HAS_FXCH
- need_fxch = 1;
-#endif
- }
- else
- {
- local_fpstack_use--;
- }
- }
- else
- {
- if ((size_t)bufOut_len < (size_t)(parm_size)+GLUE_POP_PX_SIZE) RET_MINUS1_FAIL("size, poppx")
- if (bufOut) GLUE_POP_PX(bufOut + parm_size, n_params - 1 - pn);
- parm_size += GLUE_POP_PX_SIZE;
- }
- }
- }
- // finally, set trivial pointers
- for (pn = 0; pn < n_params; pn++)
- {
- if (OPCODE_IS_TRIVIAL(op->parms.parms[pn]))
- {
- if (pn == n_params - 2 && (cfunc_abiinfo&(BIF_SECONDLASTPARMST))) // second to last parameter
- {
- int32_t a = compileOpcodes(ctx, op->parms.parms[pn], bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis,
- RETURNVALUE_FPSTACK, NULL, NULL, canHaveDenormalOutput);
- if (a < 0) RET_MINUS1_FAIL("coc call here 2")
- parm_size += a;
-#ifdef GLUE_HAS_FXCH
- need_fxch = 1;
-#endif
- }
- else if (pn == n_params - 1) // last parameter, but we should call compileOpcodes to get it in the right format (compileOpcodes can optimize that process if it needs to)
- {
- int32_t rvt = 0, a;
- int32_t wantFpStack = func == nseel_asm_assign;
-#ifdef GLUE_PREFER_NONFP_DV_ASSIGNS // x86-64, and maybe others, prefer to avoid the fp stack for a simple copy
- if (wantFpStack &&
- (op->parms.parms[pn]->opcodeType != OPCODETYPE_DIRECTVALUE ||
- (op->parms.parms[pn]->parms.dv.directValue != 1.0f && op->parms.parms[pn]->parms.dv.directValue != 0.0f)))
- {
- wantFpStack = 0;
- }
-#endif
- a = compileOpcodes(ctx, op->parms.parms[pn], bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis,
- func == nseel_asm_bnot ? (RETURNVALUE_BOOL_REVERSED | RETURNVALUE_BOOL) :
- (cfunc_abiinfo & BIF_LASTPARMONSTACK) ? RETURNVALUE_FPSTACK :
- (cfunc_abiinfo & BIF_LASTPARM_ASBOOL) ? RETURNVALUE_BOOL :
- wantFpStack ? (RETURNVALUE_FPSTACK | RETURNVALUE_NORMAL) :
- RETURNVALUE_NORMAL,
- &rvt, NULL, canHaveDenormalOutput);
- if (a < 0) RET_MINUS1_FAIL("coc call here 3")
- if (func == nseel_asm_bnot && rvt == RETURNVALUE_BOOL_REVERSED)
- {
- // remove bnot, compileOpcodes() used fptobool_rev
- func = nseel_asm_bnotnot;
- func_e = nseel_asm_bnotnot_end;
- rvt = RETURNVALUE_BOOL;
- }
- parm_size += a;
-#ifdef GLUE_HAS_FXCH
- need_fxch = 0;
-#endif
- if (func == nseel_asm_assign)
- {
- if (rvt == RETURNVALUE_FPSTACK)
- {
- func = nseel_asm_assign_fast_fromfp;
- func_e = nseel_asm_assign_fast_fromfp_end;
- }
- else
- {
- // assigning a value (from a variable or other non-computer), can use a fast assign (no denormal/result checking)
- func = nseel_asm_assign_fast;
- func_e = nseel_asm_assign_fast_end;
- }
- }
- }
- else
- {
- if ((size_t)bufOut_len < ((size_t)(parm_size)+GLUE_MOV_PX_DIRECTVALUE_SIZE)) RET_MINUS1_FAIL("size, pxdvsz")
- if (bufOut)
- {
- if (generateValueToReg(ctx, op->parms.parms[pn], bufOut + parm_size, n_params - 1 - pn, namespacePathToThis, 0/*nocaching, function gets pointer*/) < 0) RET_MINUS1_FAIL("gvtr")
- }
- parm_size += GLUE_MOV_PX_DIRECTVALUE_SIZE;
- }
- }
- }
-#ifdef GLUE_HAS_FXCH
- if ((cfunc_abiinfo&(BIF_SECONDLASTPARMST)) && !(cfunc_abiinfo&(BIF_LAZYPARMORDERING)) &&
- ((!!need_fxch) ^ !!(cfunc_abiinfo&BIF_REVERSEFPORDER))
- )
- {
- // emit fxch
- if ((size_t)bufOut_len < sizeof(GLUE_FXCH)) RET_MINUS1_FAIL("len,fxch")
- if (bufOut)
- {
- memcpy(bufOut + parm_size, GLUE_FXCH, sizeof(GLUE_FXCH));
- }
- parm_size += sizeof(GLUE_FXCH);
- }
-#endif
- if (!*canHaveDenormalOutput)
- {
- // if add_op or sub_op, and non-denormal input, safe to omit denormal checks
- if (func == (void*)nseel_asm_add_op)
- {
- func = nseel_asm_add_op_fast;
- func_e = nseel_asm_add_op_fast_end;
- }
- else if (func == (void*)nseel_asm_sub_op)
- {
- func = nseel_asm_sub_op_fast;
- func_e = nseel_asm_sub_op_fast_end;
- }
- // or if mul/div by a fixed value of >= or <= 1.0f
- else if (func == (void *)nseel_asm_mul_op && parm1_dv && fabsf(op->parms.parms[1]->parms.dv.directValue) >= 1.0f)
- {
- func = nseel_asm_mul_op_fast;
- func_e = nseel_asm_mul_op_fast_end;
- }
- else if (func == (void *)nseel_asm_div_op && parm1_dv && fabsf(op->parms.parms[1]->parms.dv.directValue) <= 1.0f)
- {
- func = nseel_asm_div_op_fast;
- func_e = nseel_asm_div_op_fast_end;
- }
- }
- } // not varparm
- if (cfunc_abiinfo & (BIF_CLEARDENORMAL | BIF_RETURNSBOOL)) *canHaveDenormalOutput = 0;
- else if (!(cfunc_abiinfo & BIF_WONTMAKEDENORMAL)) *canHaveDenormalOutput = 1;
- func = GLUE_realAddress(func, func_e, &func_size);
- if (!func) RET_MINUS1_FAIL("failrealladdrfunc")
- if (bufOut_len < parm_size + func_size) RET_MINUS1_FAIL("funcsz")
- if (bufOut)
- {
- unsigned char *p = bufOut + parm_size;
- memcpy(p, func, func_size);
- if (preProc) p = preProc(p, func_size, ctx);
- if (repl)
- {
- if (repl[0]) p = EEL_GLUE_set_immediate(p, (INT_PTR)repl[0]);
- if (repl[1]) p = EEL_GLUE_set_immediate(p, (INT_PTR)repl[1]);
- if (repl[2]) p = EEL_GLUE_set_immediate(p, (INT_PTR)repl[2]);
- if (repl[3]) p = EEL_GLUE_set_immediate(p, (INT_PTR)repl[3]);
- }
- }
- if (restore_stack_amt)
- {
- if ((size_t)bufOut_len < ((size_t)(parm_size + func_size) + GLUE_MOVE_STACK_SIZE)) RET_MINUS1_FAIL("insufficient size for varparm")
- if (bufOut) GLUE_MOVE_STACK(bufOut + parm_size + func_size, restore_stack_amt);
- parm_size += GLUE_MOVE_STACK_SIZE;
- }
- if (cfunc_abiinfo&BIF_RETURNSONSTACK) *rvMode = RETURNVALUE_FPSTACK;
- else if (cfunc_abiinfo&BIF_RETURNSBOOL) *rvMode = RETURNVALUE_BOOL;
- return parm_size + func_size;
-}
-static int32_t compileEelFunctionCall(compileContext *ctx, opcodeRec *op, unsigned char *bufOut, int32_t bufOut_len, int32_t *computTableSize, const namespaceInformation *namespacePathToThis,
- int32_t *rvMode, int32_t *fpStackUse, int32_t *canHaveDenormalOutput)
-{
- int32_t func_size = 0, parm_size = 0;
- int32_t pn;
- int32_t last_nt_parm = -1, last_nt_parm_mode = 0;
- void *func_e = NULL;
- int32_t n_params;
- opcodeRec *parmptrs[NSEEL_MAX_EELFUNC_PARAMETERS];
- int32_t cfp_numparams = -1;
- int32_t cfp_statesize = 0;
- float **cfp_ptrs = NULL;
- int32_t func_raw = 0;
- int32_t do_parms;
- int32_t x;
- void *func;
- for (x = 0; x < 3; x++) parmptrs[x] = op->parms.parms[x];
- if (op->opcodeType == OPCODETYPE_FUNCX)
- {
- n_params = 0;
- for (x = 0; x < 3; x++)
- {
- opcodeRec *prni = op->parms.parms[x];
- while (prni && n_params < NSEEL_MAX_EELFUNC_PARAMETERS)
- {
- const int32_t isMP = prni->opcodeType == OPCODETYPE_MOREPARAMS;
- parmptrs[n_params++] = isMP ? prni->parms.parms[0] : prni;
- if (!isMP) break;
- prni = prni->parms.parms[1];
- }
- }
- }
- else
- {
- n_params = 1 + op->opcodeType - OPCODETYPE_FUNC1;
- }
- *fpStackUse = 0;
- func = nseel_getEELFunctionAddress(ctx, op,
- &cfp_numparams, &cfp_statesize, &cfp_ptrs,
- computTableSize,
- &func_e, &func_raw,
- !!bufOut, namespacePathToThis, rvMode, fpStackUse, canHaveDenormalOutput, parmptrs, n_params);
- if (func_raw) func_size = (int32_t)((char*)func_e - (char*)func);
- else if (func) func = GLUE_realAddress(func, func_e, &func_size);
- if (!func) RET_MINUS1_FAIL("eelfuncaddr")
- *fpStackUse += 1;
- if (cfp_numparams > 0 && n_params != cfp_numparams)
- {
- RET_MINUS1_FAIL("eelfuncnp")
- }
- // user defined function
- do_parms = cfp_numparams > 0 && cfp_ptrs && cfp_statesize > 0;
- // if function local/parameter state is zero, we need to allocate storage for it
- if (cfp_statesize > 0 && cfp_ptrs && !cfp_ptrs[0])
- {
- float *pstate = newDataBlock(sizeof(float)*cfp_statesize, 8);
- if (!pstate) RET_MINUS1_FAIL("eelfuncdb")
- for (pn = 0; pn < cfp_statesize; pn++)
- {
- pstate[pn] = 0;
- cfp_ptrs[pn] = pstate + pn;
- }
- }
- // first process parameters that are non-trivial
- for (pn = 0; pn < n_params; pn++)
- {
- int32_t needDenorm = 0;
- int32_t lsz, sUse = 0;
- if (!parmptrs[pn] || OPCODE_IS_TRIVIAL(parmptrs[pn])) continue; // skip and process after
- if (last_nt_parm >= 0 && do_parms)
- {
- if (last_nt_parm_mode == RETURNVALUE_FPSTACK)
- {
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_POP_FPSTACK_TOSTACK)) RET_MINUS1_FAIL("eelfunc_size popfpstacktostack")
- if (bufOut) memcpy(bufOut + parm_size, GLUE_POP_FPSTACK_TOSTACK, sizeof(GLUE_POP_FPSTACK_TOSTACK));
- parm_size += sizeof(GLUE_POP_FPSTACK_TOSTACK);
- }
- else
- {
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_PUSH_P1PTR_AS_VALUE)) RET_MINUS1_FAIL("eelfunc_size pushp1ptrasval")
- // push
- if (bufOut) memcpy(bufOut + parm_size, &GLUE_PUSH_P1PTR_AS_VALUE, sizeof(GLUE_PUSH_P1PTR_AS_VALUE));
- parm_size += sizeof(GLUE_PUSH_P1PTR_AS_VALUE);
- }
- }
- last_nt_parm_mode = 0;
- lsz = compileOpcodes(ctx, parmptrs[pn], bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis,
- do_parms ? (RETURNVALUE_FPSTACK | RETURNVALUE_NORMAL) : RETURNVALUE_IGNORE, &last_nt_parm_mode, &sUse, &needDenorm);
- // todo: if needDenorm, denorm convert when copying parameter
- if (lsz < 0) RET_MINUS1_FAIL("eelfunc, coc fail")
- if (last_nt_parm_mode == RETURNVALUE_FPSTACK) sUse++;
- if (sUse > *fpStackUse) *fpStackUse = sUse;
- parm_size += lsz;
- last_nt_parm = pn;
- }
- // pop non-trivial results into place
- if (last_nt_parm >= 0 && do_parms)
- {
- while (--pn >= 0)
- {
- if (!parmptrs[pn] || OPCODE_IS_TRIVIAL(parmptrs[pn])) continue; // skip and process after
- if (pn == last_nt_parm)
- {
- if (last_nt_parm_mode == RETURNVALUE_FPSTACK)
- {
- // pop to memory directly
- const int32_t cpsize = GLUE_POP_FPSTACK_TO_PTR(NULL, NULL);
- if (bufOut_len < parm_size + cpsize) RET_MINUS1_FAIL("eelfunc size popfpstacktoptr")
- if (bufOut) GLUE_POP_FPSTACK_TO_PTR((unsigned char *)bufOut + parm_size, cfp_ptrs[pn]);
- parm_size += cpsize;
- }
- else
- {
- // copy direct p1ptr to mem
- const int32_t cpsize = GLUE_COPY_VALUE_AT_P1_TO_PTR(NULL, NULL);
- if (bufOut_len < parm_size + cpsize) RET_MINUS1_FAIL("eelfunc size copyvalueatp1toptr")
- if (bufOut) GLUE_COPY_VALUE_AT_P1_TO_PTR((unsigned char *)bufOut + parm_size, cfp_ptrs[pn]);
- parm_size += cpsize;
- }
- }
- else
- {
- const int32_t popsize = GLUE_POP_VALUE_TO_ADDR(NULL, NULL);
- if (bufOut_len < parm_size + popsize) RET_MINUS1_FAIL("eelfunc size pop value to addr")
- if (bufOut) GLUE_POP_VALUE_TO_ADDR((unsigned char *)bufOut + parm_size, cfp_ptrs[pn]);
- parm_size += popsize;
- }
- }
- }
- // finally, set any trivial parameters
- if (do_parms)
- {
- const int32_t cpsize = GLUE_MOV_PX_DIRECTVALUE_SIZE + GLUE_COPY_VALUE_AT_P1_TO_PTR(NULL, NULL);
- for (pn = 0; pn < n_params; pn++)
- {
- if (!parmptrs[pn] || !OPCODE_IS_TRIVIAL(parmptrs[pn])) continue; // set trivial values, we already set nontrivials
- if (bufOut_len < parm_size + cpsize) RET_MINUS1_FAIL("eelfunc size trivial set")
- if (bufOut)
- {
- if (generateValueToReg(ctx, parmptrs[pn], bufOut + parm_size, 0, namespacePathToThis, 1) < 0) RET_MINUS1_FAIL("eelfunc gvr fail")
- GLUE_COPY_VALUE_AT_P1_TO_PTR(bufOut + parm_size + GLUE_MOV_PX_DIRECTVALUE_SIZE, cfp_ptrs[pn]);
- }
- parm_size += cpsize;
- }
- }
- if (bufOut_len < parm_size + func_size) RET_MINUS1_FAIL("eelfunc size combined")
- if (bufOut) memcpy(bufOut + parm_size, func, func_size);
- return parm_size + func_size;
- // end of EEL function generation
-}
-#define CHECK_SIZE_FORJMP(x,y)
-#define RET_MINUS1_FAIL_FALLBACK(err,j) RET_MINUS1_FAIL(err)
-static int32_t compileOpcodesInternal(compileContext *ctx, opcodeRec *op, unsigned char *bufOut, int32_t bufOut_len, int32_t *computTableSize, const namespaceInformation *namespacePathToThis, int32_t *calledRvType, int32_t preferredReturnValues, int32_t *fpStackUse, int32_t *canHaveDenormalOutput)
-{
- int32_t rv_offset = 0, denormal_force = -1;
- if (!op) RET_MINUS1_FAIL("coi !op")
- *fpStackUse = 0;
- for (;;)
- {
- // special case: statement delimiting means we can process the left side into place, and iteratively do the second parameter without recursing
- // also we don't need to save/restore anything to the stack (which the normal 2 parameter function processing does)
- if (op->opcodeType == OPCODETYPE_FUNC2 && op->fntype == FN_JOIN_STATEMENTS)
- {
- int32_t fUse1;
- int32_t parm_size = compileOpcodes(ctx, op->parms.parms[0], bufOut, bufOut_len, computTableSize, namespacePathToThis, RETURNVALUE_IGNORE, NULL, &fUse1, NULL);
- if (parm_size < 0) RET_MINUS1_FAIL("coc join fail")
- op = op->parms.parms[1];
- if (!op) RET_MINUS1_FAIL("join got to null")
- if (fUse1 > *fpStackUse) *fpStackUse = fUse1;
- if (bufOut) bufOut += parm_size;
- bufOut_len -= parm_size;
- rv_offset += parm_size;
- denormal_force = -1;
- }
- // special case: __denormal_likely(), __denormal_unlikely()
- else if (op->opcodeType == OPCODETYPE_FUNC1 && (op->fntype == FN_DENORMAL_LIKELY || op->fntype == FN_DENORMAL_UNLIKELY))
- {
- denormal_force = op->fntype == FN_DENORMAL_LIKELY;
- op = op->parms.parms[0];
- }
- else
- {
- break;
- }
- }
- if (denormal_force >= 0 && canHaveDenormalOutput)
- {
- *canHaveDenormalOutput = denormal_force;
- canHaveDenormalOutput = &denormal_force; // prevent it from being changed by functions below
- }
- // special case: BAND/BOR
- if (op->opcodeType == OPCODETYPE_FUNC2 && (op->fntype == FN_LOGICAL_AND || op->fntype == FN_LOGICAL_OR))
- {
- int32_t fUse1 = 0;
- int32_t parm_size;
- int32_t retType = RETURNVALUE_IGNORE;
- if (preferredReturnValues != RETURNVALUE_IGNORE) retType = RETURNVALUE_BOOL;
- *calledRvType = retType;
- parm_size = compileOpcodes(ctx, op->parms.parms[0], bufOut, bufOut_len, computTableSize, namespacePathToThis, RETURNVALUE_BOOL, NULL, &fUse1, NULL);
- if (parm_size < 0) RET_MINUS1_FAIL("loop band/bor coc fail")
- if (fUse1 > *fpStackUse) *fpStackUse = fUse1;
- {
- int32_t sz2, fUse2 = 0;
- unsigned char *destbuf;
- const int32_t testsz = op->fntype == FN_LOGICAL_OR ? sizeof(GLUE_JMP_IF_P1_NZ) : sizeof(GLUE_JMP_IF_P1_Z);
- if (bufOut_len < parm_size + testsz) RET_MINUS1_FAIL_FALLBACK("band/bor size fail", doNonInlinedAndOr_)
- if (bufOut) memcpy(bufOut + parm_size, op->fntype == FN_LOGICAL_OR ? GLUE_JMP_IF_P1_NZ : GLUE_JMP_IF_P1_Z, testsz);
- parm_size += testsz;
- destbuf = bufOut + parm_size;
- sz2 = compileOpcodes(ctx, op->parms.parms[1], bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, retType, NULL, &fUse2, NULL);
- CHECK_SIZE_FORJMP(sz2, doNonInlinedAndOr_)
- if (sz2 < 0) RET_MINUS1_FAIL("band/bor coc fail")
- parm_size += sz2;
- if (bufOut) GLUE_JMP_SET_OFFSET(destbuf, (bufOut + parm_size) - destbuf);
- if (fUse2 > *fpStackUse) *fpStackUse = fUse2;
- return rv_offset + parm_size;
- }
- }
- if (op->opcodeType == OPCODETYPE_FUNC3 && op->fntype == FN_IF_ELSE) // special case: IF
- {
- int32_t fUse1 = 0;
- int32_t use_rv = RETURNVALUE_IGNORE;
- int32_t rvMode = 0;
- int32_t parm_size = compileOpcodes(ctx, op->parms.parms[0], bufOut, bufOut_len, computTableSize, namespacePathToThis, RETURNVALUE_BOOL | RETURNVALUE_BOOL_REVERSED, &rvMode, &fUse1, NULL);
- if (parm_size < 0) RET_MINUS1_FAIL("if coc fail")
- if (fUse1 > *fpStackUse) *fpStackUse = fUse1;
- if (preferredReturnValues & RETURNVALUE_NORMAL) use_rv = RETURNVALUE_NORMAL;
- else if (preferredReturnValues & RETURNVALUE_FPSTACK) use_rv = RETURNVALUE_FPSTACK;
- else if (preferredReturnValues & RETURNVALUE_BOOL) use_rv = RETURNVALUE_BOOL;
- *calledRvType = use_rv;
- {
- int32_t csz, hasSecondHalf;
- if (rvMode & RETURNVALUE_BOOL_REVERSED)
- {
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_JMP_IF_P1_NZ)) RET_MINUS1_FAIL_FALLBACK("if size fail", doNonInlineIf_)
- if (bufOut) memcpy(bufOut + parm_size, GLUE_JMP_IF_P1_NZ, sizeof(GLUE_JMP_IF_P1_NZ));
- parm_size += sizeof(GLUE_JMP_IF_P1_NZ);
- }
- else
- {
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_JMP_IF_P1_Z)) RET_MINUS1_FAIL_FALLBACK("if size fail", doNonInlineIf_)
- if (bufOut) memcpy(bufOut + parm_size, GLUE_JMP_IF_P1_Z, sizeof(GLUE_JMP_IF_P1_Z));
- parm_size += sizeof(GLUE_JMP_IF_P1_Z);
- }
- csz = compileOpcodes(ctx, op->parms.parms[1], bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, use_rv, NULL, &fUse1, canHaveDenormalOutput);
- if (fUse1 > *fpStackUse) *fpStackUse = fUse1;
- hasSecondHalf = preferredReturnValues || !OPCODE_IS_TRIVIAL(op->parms.parms[2]);
- CHECK_SIZE_FORJMP(csz, doNonInlineIf_)
- if (csz < 0) RET_MINUS1_FAIL("if coc fial")
- if (bufOut) GLUE_JMP_SET_OFFSET(bufOut + parm_size, csz + (hasSecondHalf ? sizeof(GLUE_JMP_NC) : 0));
- parm_size += csz;
- if (hasSecondHalf)
- {
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_JMP_NC)) RET_MINUS1_FAIL_FALLBACK("if len fail", doNonInlineIf_)
- if (bufOut) memcpy(bufOut + parm_size, GLUE_JMP_NC, sizeof(GLUE_JMP_NC));
- parm_size += sizeof(GLUE_JMP_NC);
- csz = compileOpcodes(ctx, op->parms.parms[2], bufOut ? bufOut + parm_size : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, use_rv, NULL, &fUse1, canHaveDenormalOutput);
- CHECK_SIZE_FORJMP(csz, doNonInlineIf_)
- if (csz < 0) RET_MINUS1_FAIL("if coc 2 fail")
- // update jump address
- if (bufOut) GLUE_JMP_SET_OFFSET(bufOut + parm_size, csz);
- parm_size += csz;
- if (fUse1 > *fpStackUse) *fpStackUse = fUse1;
- }
- return rv_offset + parm_size;
- }
- }
- {
- // special case: while
- if (op->opcodeType == OPCODETYPE_FUNC1 && op->fntype == FN_WHILE)
- {
- *calledRvType = RETURNVALUE_BOOL;
- {
- unsigned char *jzoutpt;
- unsigned char *looppt;
- int32_t parm_size = 0, subsz;
- if (bufOut_len < parm_size + (int32_t)(GLUE_WHILE_SETUP_SIZE + sizeof(GLUE_WHILE_BEGIN))) RET_MINUS1_FAIL("while size fail 1")
- if (bufOut) memcpy(bufOut + parm_size, GLUE_WHILE_SETUP, GLUE_WHILE_SETUP_SIZE);
- parm_size += GLUE_WHILE_SETUP_SIZE;
- looppt = bufOut + parm_size;
- if (bufOut) memcpy(bufOut + parm_size, GLUE_WHILE_BEGIN, sizeof(GLUE_WHILE_BEGIN));
- parm_size += sizeof(GLUE_WHILE_BEGIN);
- subsz = compileOpcodes(ctx, op->parms.parms[0], bufOut ? (bufOut + parm_size) : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, RETURNVALUE_BOOL, NULL, fpStackUse, NULL);
- if (subsz < 0) RET_MINUS1_FAIL("while coc fail")
- if (bufOut_len < parm_size + (int32_t)(sizeof(GLUE_WHILE_END) + sizeof(GLUE_WHILE_CHECK_RV))) RET_MINUS1_FAIL("which size fial 2")
- parm_size += subsz;
- if (bufOut) memcpy(bufOut + parm_size, GLUE_WHILE_END, sizeof(GLUE_WHILE_END));
- parm_size += sizeof(GLUE_WHILE_END);
- jzoutpt = bufOut + parm_size;
- if (bufOut) memcpy(bufOut + parm_size, GLUE_WHILE_CHECK_RV, sizeof(GLUE_WHILE_CHECK_RV));
- parm_size += sizeof(GLUE_WHILE_CHECK_RV);
- if (bufOut)
- {
- GLUE_JMP_SET_OFFSET(bufOut + parm_size, (looppt - (bufOut + parm_size)));
- GLUE_JMP_SET_OFFSET(jzoutpt, (bufOut + parm_size) - jzoutpt);
- }
- return rv_offset + parm_size;
- }
- }
- // special case: loop
- if (op->opcodeType == OPCODETYPE_FUNC2 && op->fntype == FN_LOOP)
- {
- int32_t fUse1;
- int32_t parm_size = compileOpcodes(ctx, op->parms.parms[0], bufOut, bufOut_len, computTableSize, namespacePathToThis, RETURNVALUE_FPSTACK, NULL, &fUse1, NULL);
- if (parm_size < 0) RET_MINUS1_FAIL("loop coc fail")
- *calledRvType = RETURNVALUE_BOOL;
- if (fUse1 > *fpStackUse) *fpStackUse = fUse1;
- {
- int32_t subsz;
- int32_t fUse2 = 0;
- unsigned char *skipptr1, *loopdest;
- if (bufOut_len < parm_size + (int32_t)(sizeof(GLUE_LOOP_LOADCNT) + GLUE_LOOP_CLAMPCNT_SIZE + GLUE_LOOP_BEGIN_SIZE)) RET_MINUS1_FAIL("loop size fail")
- // store, convert to int32_t, compare against 1, if less than, skip to end
- if (bufOut) memcpy(bufOut + parm_size, GLUE_LOOP_LOADCNT, sizeof(GLUE_LOOP_LOADCNT));
- parm_size += sizeof(GLUE_LOOP_LOADCNT);
- skipptr1 = bufOut + parm_size;
- // compare aginst max loop length, jump to loop start if not above it
- if (bufOut) memcpy(bufOut + parm_size, GLUE_LOOP_CLAMPCNT, GLUE_LOOP_CLAMPCNT_SIZE);
- parm_size += GLUE_LOOP_CLAMPCNT_SIZE;
- // loop code:
- loopdest = bufOut + parm_size;
- if (bufOut) memcpy(bufOut + parm_size, GLUE_LOOP_BEGIN, GLUE_LOOP_BEGIN_SIZE);
- parm_size += GLUE_LOOP_BEGIN_SIZE;
- subsz = compileOpcodes(ctx, op->parms.parms[1], bufOut ? (bufOut + parm_size) : NULL, bufOut_len - parm_size, computTableSize, namespacePathToThis, RETURNVALUE_IGNORE, NULL, &fUse2, NULL);
- if (subsz < 0) RET_MINUS1_FAIL("loop coc fail")
- if (fUse2 > *fpStackUse) *fpStackUse = fUse2;
- parm_size += subsz;
- if (bufOut_len < parm_size + (int32_t)sizeof(GLUE_LOOP_END)) RET_MINUS1_FAIL("loop size fail 2")
- if (bufOut) memcpy(bufOut + parm_size, GLUE_LOOP_END, sizeof(GLUE_LOOP_END));
- parm_size += sizeof(GLUE_LOOP_END);
- if (bufOut)
- {
- GLUE_JMP_SET_OFFSET(bufOut + parm_size, loopdest - (bufOut + parm_size));
- GLUE_JMP_SET_OFFSET(skipptr1, (bufOut + parm_size) - skipptr1);
- }
- return rv_offset + parm_size;
- }
- }
- }
- switch (op->opcodeType)
- {
- case OPCODETYPE_DIRECTVALUE:
- if (preferredReturnValues == RETURNVALUE_BOOL)
- {
- int32_t w = fabsf(op->parms.dv.directValue) >= NSEEL_CLOSEFACTOR;
- int32_t wsz = (w ? sizeof(GLUE_SET_P1_NZ) : sizeof(GLUE_SET_P1_Z));
- *calledRvType = RETURNVALUE_BOOL;
- if (bufOut_len < wsz) RET_MINUS1_FAIL("direct int32_t size fail3")
- if (bufOut) memcpy(bufOut, w ? GLUE_SET_P1_NZ : GLUE_SET_P1_Z, wsz);
- return rv_offset + wsz;
- }
- else if (preferredReturnValues & RETURNVALUE_FPSTACK)
- {
-#ifdef GLUE_HAS_FLDZ
- if (op->parms.dv.directValue == 0.0f)
- {
- *fpStackUse = 1;
- *calledRvType = RETURNVALUE_FPSTACK;
- if (bufOut_len < sizeof(GLUE_FLDZ)) RET_MINUS1_FAIL("direct fp fail 1")
- if (bufOut) memcpy(bufOut, GLUE_FLDZ, sizeof(GLUE_FLDZ));
- return rv_offset + sizeof(GLUE_FLDZ);
- }
-#endif
-#ifdef GLUE_HAS_FLD1
- if (op->parms.dv.directValue == 1.0f)
- {
- *fpStackUse = 1;
- *calledRvType = RETURNVALUE_FPSTACK;
- if (bufOut_len < sizeof(GLUE_FLD1)) RET_MINUS1_FAIL("direct fp fail 1")
- if (bufOut) memcpy(bufOut, GLUE_FLD1, sizeof(GLUE_FLD1));
- return rv_offset + sizeof(GLUE_FLD1);
- }
-#endif
- }
- // fall through
- case OPCODETYPE_DIRECTVALUE_TEMPSTRING:
- case OPCODETYPE_VALUE_FROM_NAMESPACENAME:
- case OPCODETYPE_VARPTR:
- case OPCODETYPE_VARPTRPTR:
-#ifdef GLUE_MOV_PX_DIRECTVALUE_TOSTACK_SIZE
- if (OPCODE_IS_TRIVIAL(op))
- {
- if (preferredReturnValues & RETURNVALUE_FPSTACK)
- {
- *fpStackUse = 1;
- if (bufOut_len < GLUE_MOV_PX_DIRECTVALUE_TOSTACK_SIZE) RET_MINUS1_FAIL("direct fp fail 2")
- if (bufOut)
- {
- if (generateValueToReg(ctx, op, bufOut, -1, namespacePathToThis, 1 /*allow caching*/) < 0) RET_MINUS1_FAIL("direct fp fail gvr")
- }
- *calledRvType = RETURNVALUE_FPSTACK;
- return rv_offset + GLUE_MOV_PX_DIRECTVALUE_TOSTACK_SIZE;
- }
- }
-#endif
- if (bufOut_len < GLUE_MOV_PX_DIRECTVALUE_SIZE)
- {
- RET_MINUS1_FAIL("direct value fail 1")
- }
- if (bufOut)
- {
- if (generateValueToReg(ctx, op, bufOut, 0, namespacePathToThis, !!(preferredReturnValues&RETURNVALUE_FPSTACK)/*cache if going to the fp stack*/) < 0) RET_MINUS1_FAIL("direct value gvr fail3")
- }
- return rv_offset + GLUE_MOV_PX_DIRECTVALUE_SIZE;
- case OPCODETYPE_FUNCX:
- case OPCODETYPE_FUNC1:
- case OPCODETYPE_FUNC2:
- case OPCODETYPE_FUNC3:
- if (op->fntype == FUNCTYPE_EELFUNC)
- {
- int32_t a;
- a = compileEelFunctionCall(ctx, op, bufOut, bufOut_len, computTableSize, namespacePathToThis, calledRvType, fpStackUse, canHaveDenormalOutput);
- if (a < 0) return a;
- rv_offset += a;
- }
- else
- {
- int32_t a;
- a = compileNativeFunctionCall(ctx, op, bufOut, bufOut_len, computTableSize, namespacePathToThis, calledRvType, fpStackUse, preferredReturnValues, canHaveDenormalOutput);
- if (a < 0)return a;
- rv_offset += a;
- }
- return rv_offset;
- }
- RET_MINUS1_FAIL("default opcode fail")
-}
-int32_t compileOpcodes(compileContext *ctx, opcodeRec *op, unsigned char *bufOut, int32_t bufOut_len, int32_t *computTableSize, const namespaceInformation *namespacePathToThis,
- int32_t supportedReturnValues, int32_t *rvType, int32_t *fpStackUse, int32_t *canHaveDenormalOutput)
-{
- int32_t code_returns = RETURNVALUE_NORMAL;
- int32_t fpsu = 0;
- int32_t codesz;
- int32_t denorm = 0;
- codesz = compileOpcodesInternal(ctx, op, bufOut, bufOut_len, computTableSize, namespacePathToThis, &code_returns, supportedReturnValues, &fpsu, &denorm);
- if (denorm && canHaveDenormalOutput) *canHaveDenormalOutput = 1;
- if (codesz < 0) return codesz;
- if (fpStackUse) *fpStackUse = fpsu;
- if (bufOut) bufOut += codesz;
- bufOut_len -= codesz;
- if (code_returns == RETURNVALUE_BOOL && !(supportedReturnValues & RETURNVALUE_BOOL) && supportedReturnValues)
- {
- int32_t stubsize;
- void *stub = GLUE_realAddress(nseel_asm_booltofp, nseel_asm_booltofp_end, &stubsize);
- if (!stub || bufOut_len < stubsize) RET_MINUS1_FAIL(stub ? "booltofp size" : "booltfp addr")
- if (bufOut)
- {
- memcpy(bufOut, stub, stubsize);
- bufOut += stubsize;
- }
- codesz += stubsize;
- bufOut_len -= stubsize;
- code_returns = RETURNVALUE_FPSTACK;
- }
- // default processing of code_returns to meet return value requirements
- if (supportedReturnValues & code_returns)
- {
- if (rvType) *rvType = code_returns;
- return codesz;
- }
- if (rvType) *rvType = RETURNVALUE_IGNORE;
- if (code_returns == RETURNVALUE_NORMAL)
- {
- if (supportedReturnValues & (RETURNVALUE_FPSTACK | RETURNVALUE_BOOL))
- {
- if (bufOut_len < GLUE_PUSH_VAL_AT_PX_TO_FPSTACK_SIZE) RET_MINUS1_FAIL("pushvalatpxtofpstack,size")
- if (bufOut)
- {
- GLUE_PUSH_VAL_AT_PX_TO_FPSTACK(bufOut, 0); // always fld qword [eax] but we might change that later
- bufOut += GLUE_PUSH_VAL_AT_PX_TO_FPSTACK_SIZE;
- }
- codesz += GLUE_PUSH_VAL_AT_PX_TO_FPSTACK_SIZE;
- bufOut_len -= GLUE_PUSH_VAL_AT_PX_TO_FPSTACK_SIZE;
- if (supportedReturnValues & RETURNVALUE_BOOL)
- {
- code_returns = RETURNVALUE_FPSTACK;
- }
- else
- {
- if (rvType) *rvType = RETURNVALUE_FPSTACK;
- }
- }
- }
- if (code_returns == RETURNVALUE_FPSTACK)
- {
- if (supportedReturnValues & (RETURNVALUE_BOOL | RETURNVALUE_BOOL_REVERSED))
- {
- int32_t stubsize;
- void *stub;
- if (supportedReturnValues & RETURNVALUE_BOOL_REVERSED)
- {
- if (rvType) *rvType = RETURNVALUE_BOOL_REVERSED;
- stub = GLUE_realAddress(nseel_asm_fptobool_rev, nseel_asm_fptobool_rev_end, &stubsize);
- }
- else
- {
- if (rvType) *rvType = RETURNVALUE_BOOL;
- stub = GLUE_realAddress(nseel_asm_fptobool, nseel_asm_fptobool_end, &stubsize);
- }
- if (!stub || bufOut_len < stubsize) RET_MINUS1_FAIL(stub ? "fptobool size" : "fptobool addr")
- if (bufOut)
- {
- memcpy(bufOut, stub, stubsize);
- bufOut += stubsize;
- }
- codesz += stubsize;
- bufOut_len -= stubsize;
- }
- else if (supportedReturnValues & RETURNVALUE_NORMAL)
- {
- if (computTableSize) (*computTableSize)++;
- if (bufOut_len < GLUE_POP_FPSTACK_TO_WTP_TO_PX_SIZE) RET_MINUS1_FAIL("popfpstacktowtptopxsize")
- // generate fp-pop to temp space
- if (bufOut) GLUE_POP_FPSTACK_TO_WTP_TO_PX(bufOut, 0);
- codesz += GLUE_POP_FPSTACK_TO_WTP_TO_PX_SIZE;
- if (rvType) *rvType = RETURNVALUE_NORMAL;
- }
- else
- {
- // toss return value that will be ignored
- if (bufOut_len < GLUE_POP_FPSTACK_SIZE) RET_MINUS1_FAIL("popfpstack size")
- if (bufOut) memcpy(bufOut, GLUE_POP_FPSTACK, GLUE_POP_FPSTACK_SIZE);
- codesz += GLUE_POP_FPSTACK_SIZE;
- }
- }
- return codesz;
-}
-//------------------------------------------------------------------------------
-NSEEL_CODEHANDLE NSEEL_code_compile(NSEEL_VMCTX _ctx, const char *_expression, int32_t lineoffs)
-{
- return NSEEL_code_compile_ex(_ctx, _expression, lineoffs, 0);
-}
-typedef struct topLevelCodeSegmentRec {
- struct topLevelCodeSegmentRec *_next;
- void *code;
- int32_t codesz;
- int32_t tmptable_use;
-} topLevelCodeSegmentRec;
-NSEEL_CODEHANDLE NSEEL_code_compile_ex(NSEEL_VMCTX _ctx, const char *_expression, int32_t lineoffs, int32_t compile_flags)
-{
- compileContext *ctx = (compileContext*)_ctx;
- const char *endptr;
- const char *_expression_end;
- codeHandleType *handle;
- topLevelCodeSegmentRec *startpts_tail = NULL;
- topLevelCodeSegmentRec *startpts = NULL;
- _codeHandleFunctionRec *oldCommonFunctionList;
- int32_t curtabptr_sz = 0;
- void *curtabptr = NULL;
- int32_t had_err = 0;
- if (!ctx) return 0;
- ctx->directValueCache = 0;
- ctx->gotEndOfInput = 0;
- if (compile_flags & NSEEL_CODE_COMPILE_FLAG_COMMONFUNCS_RESET)
- {
- ctx->functions_common = NULL; // reset common function list
- }
- else
- {
- // reset common compiled function code, forcing a recompile if shared
- _codeHandleFunctionRec *a = ctx->functions_common;
- while (a)
- {
- _codeHandleFunctionRec *b = a->derivedCopies;
- if (a->localstorage)
- {
- // force local storage actual values to be reallocated if used again
- memset(a->localstorage, 0, sizeof(float *) * a->localstorage_size);
- }
- a->startptr = NULL; // force this copy to be recompiled
- while (b)
- {
- b->startptr = NULL; // force derived copies to get recompiled
- // no need to reset b->localstorage, since it points to a->localstorage
- b = b->derivedCopies;
- }
- a = a->next;
- }
- }
- ctx->last_error_string[0] = 0;
- if (!_expression || !*_expression) return 0;
- _expression_end = _expression + strlen(_expression);
- oldCommonFunctionList = ctx->functions_common;
- ctx->isGeneratingCommonFunction = 0;
- ctx->isSharedFunctions = !!(compile_flags & NSEEL_CODE_COMPILE_FLAG_COMMONFUNCS);
- ctx->functions_local = NULL;
- freeBlocks(&ctx->tmpblocks_head); // free blocks
- freeBlocks(&ctx->blocks_head); // free blocks
- freeBlocks(&ctx->blocks_head_data); // free blocks
- memset(ctx->l_stats, 0, sizeof(ctx->l_stats));
- handle = (codeHandleType*)newDataBlock(sizeof(codeHandleType), 8);
- if (!handle)
- {
- return 0;
- }
- memset(handle, 0, sizeof(codeHandleType));
- ctx->l_stats[0] += (int32_t)(_expression_end - _expression);
- ctx->tmpCodeHandle = handle;
- endptr = _expression;
- while (*endptr)
- {
- int32_t computTableTop = 0;
- int32_t startptr_size = 0;
- void *startptr = NULL;
- opcodeRec *start_opcode = NULL;
- const char *expr = endptr;
- int32_t function_numparms = 0;
- char is_fname[NSEEL_MAX_VARIABLE_NAMELEN + 1];
- is_fname[0] = 0;
- memset(ctx->function_localTable_Size, 0, sizeof(ctx->function_localTable_Size));
- memset(ctx->function_localTable_Names, 0, sizeof(ctx->function_localTable_Names));
- ctx->function_localTable_ValuePtrs = 0;
- ctx->function_usesNamespaces = 0;
- ctx->function_curName = NULL;
- ctx->function_globalFlag = 0;
- ctx->errVar = 0;
- // single out top level segment
- {
- int32_t had_something = 0, pcnt = 0, pcnt2 = 0;
- int32_t state = 0;
- for (;;)
- {
- int32_t l;
- const char *p = nseel_simple_tokenizer(&endptr, _expression_end, &l, &state);
- if (!p)
- {
- if (pcnt || pcnt2) ctx->gotEndOfInput |= 4;
- break;
- }
- if (*p == ';')
- {
- if (had_something && !pcnt && !pcnt2) break;
- }
- else if (*p == '/' && l > 1 && (p[1] == '/' || p[1] == '*'))
- {
- if (l > 19 && !strncmp(p, "//#eel-no-optimize:", 19))
- {
- //0 = atoi(p + 19);
- }
- }
- else
- {
- if (!had_something)
- {
- expr = p;
- had_something = 1;
- }
- if (*p == '(') pcnt++;
- else if (*p == ')') { if (--pcnt < 0) pcnt = 0; }
- else if (*p == '[') pcnt2++;
- else if (*p == ']') { if (--pcnt2 < 0) pcnt2 = 0; }
- }
- }
- if (!*expr || !had_something) break;
- }
- // parse
- {
- int32_t tmplen, funcname_len;
- const char *p = expr;
- const char *tok1 = nseel_simple_tokenizer(&p, endptr, &tmplen, NULL);
- const char *funcname = nseel_simple_tokenizer(&p, endptr, &funcname_len, NULL);
- if (tok1 && funcname && tmplen == 8 && !strncmp(tok1, "function", 8) && (isalpha(funcname[0]) || funcname[0] == '_'))
- {
- int32_t had_parms_locals = 0;
- if (funcname_len > (int32_t)(sizeof(is_fname) - 1))
- funcname_len = (int32_t)(sizeof(is_fname) - 1);
- memcpy(is_fname, funcname, funcname_len);
- is_fname[funcname_len] = 0;
- ctx->function_curName = is_fname; // only assigned for the duration of the loop, cleared later //-V507
- while (NULL != (tok1 = nseel_simple_tokenizer(&p, endptr, &tmplen, NULL)))
- {
- int32_t is_parms = 0, localTableContext = 0;
- int32_t maxcnt = 0;
- const char *sp_save;
- if (tok1[0] == '(')
- {
- if (had_parms_locals)
- {
- expr = p - 1; // begin compilation at this code!
- break;
- }
- is_parms = 1;
- }
- else
- {
- if (tmplen == 5 && !strncmp(tok1, "local", tmplen)) localTableContext = 0;
- else if (tmplen == 6 && !strncmp(tok1, "static", tmplen)) localTableContext = 0;
- else if (tmplen == 8 && !strncmp(tok1, "instance", tmplen)) localTableContext = 1;
- else if ((tmplen == 7 && !strncmp(tok1, "globals", tmplen)) ||
- (tmplen == 6 && !strncmp(tok1, "global", tmplen)))
- {
- ctx->function_globalFlag = 1;
- localTableContext = 2;
- }
- else break; // unknown token!
- tok1 = nseel_simple_tokenizer(&p, endptr, &tmplen, NULL);
- if (!tok1 || tok1[0] != '(') break;
- }
- had_parms_locals = 1;
- sp_save = p;
- while (NULL != (tok1 = nseel_simple_tokenizer(&p, endptr, &tmplen, NULL)))
- {
- if (tok1[0] == ')') break;
- if (*tok1 == '#' && localTableContext != 1 && localTableContext != 2)
- {
- ctx->errVar = (int32_t)(tok1 - _expression);
- lstrcpyn_safe(ctx->last_error_string, "#string can only be in instance() or globals()", sizeof(ctx->last_error_string));
- goto had_error;
- }
- if (isalpha(*tok1) || *tok1 == '_' || *tok1 == '#')
- {
- maxcnt++;
- if (p < endptr && *p == '*')
- {
- if (!is_parms && localTableContext != 2)
- {
- ctx->errVar = (int32_t)(p - _expression);
- lstrcpyn_safe(ctx->last_error_string, "namespace* can only be used in parameters or globals()", sizeof(ctx->last_error_string));
- goto had_error;
- }
- p++;
- }
- }
- else if (*tok1 != ',')
- {
- ctx->errVar = (int32_t)(tok1 - _expression);
- lstrcpyn_safe(ctx->last_error_string, "unknown character in function parameters", sizeof(ctx->last_error_string));
- goto had_error;
- }
- }
- if (tok1 && maxcnt > 0)
- {
- char **ot = ctx->function_localTable_Names[localTableContext];
- const int32_t osz = ctx->function_localTable_Size[localTableContext];
- maxcnt += osz;
- ctx->function_localTable_Names[localTableContext] = (char **)newTmpBlock(ctx, sizeof(char *) * maxcnt);
- if (ctx->function_localTable_Names[localTableContext])
- {
- int32_t i = osz;
- if (osz && ot) memcpy(ctx->function_localTable_Names[localTableContext], ot, sizeof(char *) * osz);
- p = sp_save;
- while (NULL != (tok1 = nseel_simple_tokenizer(&p, endptr, &tmplen, NULL)))
- {
- if (tok1[0] == ')') break;
- if (isalpha(*tok1) || *tok1 == '_' || *tok1 == '#')
- {
- char *newstr;
- int32_t l = tmplen;
- if (*p == '*') // xyz* for namespace
- {
- p++;
- l++;
- }
- if (l > NSEEL_MAX_VARIABLE_NAMELEN) l = NSEEL_MAX_VARIABLE_NAMELEN;
- newstr = newTmpBlock(ctx, l + 1);
- if (newstr)
- {
- memcpy(newstr, tok1, l);
- newstr[l] = 0;
- ctx->function_localTable_Names[localTableContext][i++] = newstr;
- }
- }
- }
- ctx->function_localTable_Size[localTableContext] = i;
- if (is_parms) function_numparms = i;
- }
- }
- }
- }
- }
- if (ctx->function_localTable_Size[0] > 0)
- {
- ctx->function_localTable_ValuePtrs =
- ctx->isSharedFunctions ? newDataBlock(ctx->function_localTable_Size[0] * sizeof(float *), 8) :
- newTmpBlock(ctx, ctx->function_localTable_Size[0] * sizeof(float *));
- if (!ctx->function_localTable_ValuePtrs)
- {
- ctx->function_localTable_Size[0] = 0;
- function_numparms = 0;
- }
- else
- {
- memset(ctx->function_localTable_ValuePtrs, 0, sizeof(float *) * ctx->function_localTable_Size[0]); // force values to be allocated
- }
- }
- {
- int32_t nseelparse(compileContext* context);
- void nseelrestart(void *input_file, void *yyscanner);
- ctx->rdbuf_start = _expression;
- ctx->rdbuf = expr;
- ctx->rdbuf_end = endptr;
- if (!nseelparse(ctx) && !ctx->errVar)
- start_opcode = ctx->result;
- ctx->rdbuf = NULL;
- }
- if (start_opcode)
- {
- int32_t rvMode = 0, fUse = 0;
- optimizeOpcodes(ctx, start_opcode, is_fname[0] ? 1 : 0);
- startptr_size = compileOpcodes(ctx, start_opcode, NULL, 1024 * 1024 * 256, NULL, NULL,
- is_fname[0] ? (RETURNVALUE_NORMAL | RETURNVALUE_FPSTACK) : RETURNVALUE_IGNORE, &rvMode, &fUse, NULL); // if not a function, force return value as address (avoid having to pop it ourselves
- // if a function, allow the code to decide how return values are generated
- if (is_fname[0])
- {
- _codeHandleFunctionRec *fr = ctx->isSharedFunctions ? newDataBlock(sizeof(_codeHandleFunctionRec), 8) :
- newTmpBlock(ctx, sizeof(_codeHandleFunctionRec));
- if (fr)
- {
- memset(fr, 0, sizeof(_codeHandleFunctionRec));
- fr->startptr_size = startptr_size;
- fr->opcodes = start_opcode;
- fr->rvMode = rvMode;
- fr->fpStackUsage = fUse;
- fr->tmpspace_req = computTableTop;
- if (ctx->function_localTable_Size[0] > 0 && ctx->function_localTable_ValuePtrs)
- {
- if (ctx->function_localTable_Names[0])
- {
- int32_t i;
- for (i = 0; i < function_numparms; i++)
- {
- const char *nptr = ctx->function_localTable_Names[0][i];
- if (nptr && *nptr && nptr[strlen(nptr) - 1] == '*')
- {
- fr->parameterAsNamespaceMask |= ((uint32_t)1) << i;
- }
- }
- }
- fr->num_params = function_numparms;
- fr->localstorage = ctx->function_localTable_ValuePtrs;
- fr->localstorage_size = ctx->function_localTable_Size[0];
- }
- fr->usesNamespaces = ctx->function_usesNamespaces;
- fr->isCommonFunction = ctx->isSharedFunctions;
- lstrcpyn_safe(fr->fname, is_fname, sizeof(fr->fname));
- if (ctx->isSharedFunctions)
- {
- fr->next = ctx->functions_common;
- ctx->functions_common = fr;
- }
- else
- {
- fr->next = ctx->functions_local;
- ctx->functions_local = fr;
- }
- }
- continue;
- }
- if (!startptr_size) continue; // optimized away
- if (startptr_size > 0)
- {
- startptr = newTmpBlock(ctx, startptr_size);
- if (startptr)
- {
- startptr_size = compileOpcodes(ctx, start_opcode, (unsigned char*)startptr, startptr_size, &computTableTop, NULL, RETURNVALUE_IGNORE, NULL, NULL, NULL);
- if (startptr_size <= 0) startptr = NULL;
- }
- }
- }
- if (!startptr)
- {
- had_error:
- //if (!ctx->last_error_string[0])
- {
- int32_t byteoffs = ctx->errVar;
- int32_t linenumber;
- char cur_err[sizeof(ctx->last_error_string)];
- lstrcpyn_safe(cur_err, ctx->last_error_string, sizeof(cur_err));
- if (cur_err[0]) lstrcatn(cur_err, ": ", sizeof(cur_err));
- else lstrcpyn_safe(cur_err, "syntax error: ", sizeof(cur_err));
- if (_expression + byteoffs >= _expression_end)
- {
- if (ctx->gotEndOfInput & 4) byteoffs = (int32_t)(expr - _expression);
- else byteoffs = (int32_t)(_expression_end - _expression);
- }
- if (byteoffs < 0) byteoffs = 0;
- linenumber = findLineNumber(_expression, byteoffs) + 1;
- if (ctx->gotEndOfInput & 4)
- {
- stbsp_snprintf(ctx->last_error_string, sizeof(ctx->last_error_string), "%d: %smissing ) or ]", linenumber + lineoffs, cur_err);
- }
- else
- {
- const char *p = _expression + byteoffs;
- int32_t x = 0, right_amt_nospace = 0, left_amt_nospace = 0;
- while (x < 32 && p - x > _expression && p[-x] != '\r' && p[-x] != '\n')
- {
- if (!isspace(p[-x])) left_amt_nospace = x;
- x++;
- }
- x = 0;
- while (x < 60 && p[x] && p[x] != '\r' && p[x] != '\n')
- {
- if (!isspace(p[x])) right_amt_nospace = x;
- x++;
- }
- if (right_amt_nospace < 1) right_amt_nospace = 1;
- // display left_amt >>>> right_amt_nospace
- if (left_amt_nospace > 0)
- stbsp_snprintf(ctx->last_error_string, sizeof(ctx->last_error_string), "%d: %s'%.*s %.*s'", linenumber + lineoffs, cur_err,
- left_amt_nospace, p - left_amt_nospace,
- right_amt_nospace, p);
- else
- stbsp_snprintf(ctx->last_error_string, sizeof(ctx->last_error_string), "%d: %s'%.*s'", linenumber + lineoffs, cur_err, right_amt_nospace, p);
- }
- }
- startpts = NULL;
- startpts_tail = NULL;
- had_err = 1;
- break;
- }
- if (!is_fname[0]) // redundant check (if is_fname[0] is set and we succeeded, it should continue)
- // but we'll be on the safe side
- {
- topLevelCodeSegmentRec *p = newTmpBlock(ctx, sizeof(topLevelCodeSegmentRec));
- p->_next = 0;
- p->code = startptr;
- p->codesz = startptr_size;
- p->tmptable_use = computTableTop;
- if (!startpts_tail) startpts_tail = startpts = p;
- else
- {
- startpts_tail->_next = p;
- startpts_tail = p;
- }
- if (curtabptr_sz < computTableTop)
- {
- curtabptr_sz = computTableTop;
- }
- }
- }
- memset(ctx->function_localTable_Size, 0, sizeof(ctx->function_localTable_Size));
- memset(ctx->function_localTable_Names, 0, sizeof(ctx->function_localTable_Names));
- ctx->function_localTable_ValuePtrs = 0;
- ctx->function_usesNamespaces = 0;
- ctx->function_curName = NULL;
- ctx->function_globalFlag = 0;
- ctx->tmpCodeHandle = NULL;
- if (startpts)
- {
- curtabptr_sz += 2; // many functions use the worktable for temporary storage of up to 2 float's
- handle->workTable_size = curtabptr_sz;
- handle->workTable = curtabptr = newDataBlock((curtabptr_sz + MIN_COMPUTABLE_SIZE + COMPUTABLE_EXTRA_SPACE) * sizeof(float), 32);
- if (!curtabptr) startpts = NULL;
- }
- if (startpts || (!had_err && (compile_flags & NSEEL_CODE_COMPILE_FLAG_COMMONFUNCS)))
- {
- unsigned char *writeptr;
- topLevelCodeSegmentRec *p = startpts;
- int32_t size = sizeof(GLUE_RET); // for ret at end :)
- int32_t wtpos = 0;
- // now we build one big code segment out of our list of them, inserting a mov esi, computable before each item as necessary
- while (p)
- {
- if (wtpos <= 0)
- {
- wtpos = MIN_COMPUTABLE_SIZE;
- size += GLUE_RESET_WTP(NULL, 0);
- }
- size += p->codesz;
- wtpos -= p->tmptable_use;
- p = p->_next;
- }
- handle->code = newCodeBlock(size, 32);
- if (handle->code)
- {
- writeptr = (unsigned char *)handle->code;
- p = startpts;
- wtpos = 0;
- while (p)
- {
- if (wtpos <= 0)
- {
- wtpos = MIN_COMPUTABLE_SIZE;
- writeptr += GLUE_RESET_WTP(writeptr, curtabptr);
- }
- memcpy(writeptr, (char*)p->code, p->codesz);
- writeptr += p->codesz;
- wtpos -= p->tmptable_use;
- p = p->_next;
- }
- memcpy(writeptr, &GLUE_RET, sizeof(GLUE_RET)); writeptr += sizeof(GLUE_RET);
- ctx->l_stats[1] = size;
- handle->code_size = (int32_t)(writeptr - (unsigned char *)handle->code);
-#ifdef __arm__
- //__clear_cache(handle->code, writeptr);
-#endif
- }
- handle->blocks = ctx->blocks_head;
- handle->blocks_data = ctx->blocks_head_data;
- ctx->blocks_head = 0;
- ctx->blocks_head_data = 0;
- }
- else
- {
- // failed compiling, or failed calloc()
- handle = NULL; // return NULL (after resetting blocks_head)
- }
- ctx->directValueCache = 0;
- ctx->functions_local = NULL;
- ctx->isGeneratingCommonFunction = 0;
- ctx->isSharedFunctions = 0;
- freeBlocks(&ctx->tmpblocks_head); // free blocks
- freeBlocks(&ctx->blocks_head); // free blocks of code (will be nonzero only on error)
- freeBlocks(&ctx->blocks_head_data); // free blocks of data (will be nonzero only on error)
- if (handle)
- {
- handle->ramPtr = ctx->ram_state;
- memcpy(handle->code_stats, ctx->l_stats, sizeof(ctx->l_stats));
- nseel_evallib_stats[0] += ctx->l_stats[0];
- nseel_evallib_stats[1] += ctx->l_stats[1];
- nseel_evallib_stats[2] += ctx->l_stats[2];
- nseel_evallib_stats[3] += ctx->l_stats[3];
- nseel_evallib_stats[4]++;
- }
- else
- {
- ctx->functions_common = oldCommonFunctionList; // failed compiling, remove any added common functions from the list
- // remove any derived copies of functions due to error, since we may have added some that have been freed
- while (oldCommonFunctionList)
- {
- oldCommonFunctionList->derivedCopies = NULL;
- oldCommonFunctionList = oldCommonFunctionList->next;
- }
- }
- memset(ctx->l_stats, 0, sizeof(ctx->l_stats));
- return (NSEEL_CODEHANDLE)handle;
-}
-//------------------------------------------------------------------------------
-void NSEEL_code_execute(NSEEL_CODEHANDLE code)
-{
- codeHandleType *h = (codeHandleType *)code;
- INT_PTR codeptr = (INT_PTR)h->code;
- INT_PTR tabptr = (INT_PTR)h->workTable;
- GLUE_CALL_CODE(tabptr, codeptr, (INT_PTR)h->ramPtr);
-}
-int32_t NSEEL_code_geterror_flag(NSEEL_VMCTX ctx)
-{
- compileContext *c = (compileContext*)ctx;
- if (c) return (c->gotEndOfInput ? 1 : 0);
- return 0;
-}
-char *NSEEL_code_getcodeerror(NSEEL_VMCTX ctx)
-{
- compileContext *c = (compileContext*)ctx;
- if (ctx && c->last_error_string[0]) return c->last_error_string;
- return 0;
-}
-//------------------------------------------------------------------------------
-void NSEEL_code_free(NSEEL_CODEHANDLE code)
-{
- codeHandleType *h = (codeHandleType *)code;
- if (h != NULL)
- {
- nseel_evallib_stats[0] -= h->code_stats[0];
- nseel_evallib_stats[1] -= h->code_stats[1];
- nseel_evallib_stats[2] -= h->code_stats[2];
- nseel_evallib_stats[3] -= h->code_stats[3];
- nseel_evallib_stats[4]--;
- freeBlocks(&h->blocks);
- freeBlocks(&h->blocks_data);
- }
-}
-//------------------------------------------------------------------------------
-void NSEEL_VM_freevars(NSEEL_VMCTX _ctx)
-{
- if (_ctx)
- {
- compileContext *ctx = (compileContext*)_ctx;
- free(ctx->varTable_Values);
- free(ctx->varTable_Names);
- ctx->varTable_Values = 0;
- ctx->varTable_Names = 0;
- ctx->varTable_numBlocks = 0;
- if (ctx->numberOfConvolver)
- {
- for (uint32_t i = 0; i < ctx->numberOfConvolver; i++)
- {
- void *ptr = ctx->convolverSink[i];
- int32_t convType = ctx->convolverType[i];
- if (convType == 1)
- {
- FFTConvolver1x1 *conv = (FFTConvolver1x1*)ptr;
- FFTConvolver1x1Free(conv);
- free(conv);
- }
- if (convType == 2)
- {
- FFTConvolver2x2 *conv = (FFTConvolver2x2*)ptr;
- FFTConvolver2x2Free(conv);
- free(conv);
- }
- if (convType == 4)
- {
- FFTConvolver2x4x2 *conv = (FFTConvolver2x4x2*)ptr;
- FFTConvolver2x4x2Free(conv);
- free(conv);
- }
- }
- if (ctx->convolverMap)
- free(ctx->convolverMap);
- if (ctx->convolverType)
- free(ctx->convolverType);
- if (ctx->convolverSink)
- free(ctx->convolverSink);
- ctx->convolverMap = 0;
- ctx->convolverType = 0;
- ctx->convolverSink = 0;
- ctx->numberOfConvolver = 0;
- }
- if (ctx->numberOfThreads)
- {
- for (uint32_t i = 0; i < ctx->numberOfThreads; i++)
- {
- thread_delete(ctx, i);
- free(ctx->codePtrThreadSink[i]);
- }
- ctx->numberOfThreads = 0;
- }
- if (ctx->m_string_context)
- {
- Freeel_string_context_state(ctx->m_string_context);
- free(ctx->m_string_context);
- ctx->m_string_context = 0;
- }
- }
-}
-void NSEEL_init_string(NSEEL_VMCTX _ctx)
-{
- if (_ctx)
- {
- compileContext *ctx = (compileContext*)_ctx;
- ctx->m_string_context = (eel_string_context_state*)malloc(sizeof(eel_string_context_state));
- Initeel_string_context_state(ctx->m_string_context);
- }
-}
-NSEEL_VMCTX NSEEL_VM_alloc() // return a handle
-{
- // Context
- compileContext *ctx = (compileContext*)calloc(1, sizeof(compileContext));
- if (ctx)
- {
- ctx->caller_this = ctx;
- ctx->scanner = ctx;
- ctx->onString = addStringCallback;
- NSEEL_init_string((NSEEL_VMCTX)ctx);
- }
- return ctx;
-}
-void NSEEL_VM_SetFunctionValidator(NSEEL_VMCTX _ctx, const char * (*validateFunc)(const char *fn_name, void *user), void *user)
-{
- if (_ctx)
- {
- compileContext *ctx = (compileContext*)_ctx;
- ctx->func_check = validateFunc;
- ctx->func_check_user = user;
- }
-}
-void NSEEL_VM_free(NSEEL_VMCTX _ctx) // free when done with a VM and ALL of its code have been freed, as well
-{
- if (_ctx)
- {
- compileContext *ctx = (compileContext*)_ctx;
- NSEEL_VM_freevars(_ctx);
- freeBlocks(&ctx->pblocks);
- // these should be 0 normally but just in case
- freeBlocks(&ctx->tmpblocks_head); // free blocks
- freeBlocks(&ctx->blocks_head); // free blocks
- freeBlocks(&ctx->blocks_head_data); // free blocks
- ctx->scanner = 0;
- free(ctx);
- }
-}
-int32_t *NSEEL_code_getstats(NSEEL_CODEHANDLE code)
-{
- codeHandleType *h = (codeHandleType *)code;
- if (h)
- {
- return h->code_stats;
- }
- return 0;
-}
-void NSEEL_VM_SetStringFunc(NSEEL_VMCTX ctx, float(*onString)(void *caller_this, eelStringSegmentRec *list))
-{
- if (ctx)
- {
- compileContext *c = (compileContext*)ctx;
- c->onString = onString;
- }
-}
-void *NSEEL_PProc_RAM(void *data, int32_t data_size, compileContext *ctx)
-{
- if (data_size > 0) data = EEL_GLUE_set_immediate(data, (INT_PTR)ctx->ram_state);
- return data;
-}
-void *NSEEL_PProc_THIS(void *data, int32_t data_size, compileContext *ctx)
-{
- if (data_size > 0) data = EEL_GLUE_set_immediate(data, (INT_PTR)ctx->caller_this);
- return data;
-}
-void NSEEL_VM_remove_unused_vars(NSEEL_VMCTX _ctx)
-{
- compileContext *ctx = (compileContext*)_ctx;
- int32_t wb;
- if (ctx) for (wb = 0; wb < ctx->varTable_numBlocks; wb++)
- {
- int32_t ti;
- char **plist = ctx->varTable_Names[wb];
- if (!plist) break;
- for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti++)
- {
- if (plist[ti])
- {
- varNameHdr *v = ((varNameHdr*)plist[ti]) - 1;
- if (!v->refcnt && !v->isreg)
- {
- plist[ti] = NULL;
- }
- }
- }
- }
-}
-void NSEEL_VM_remove_all_nonreg_vars(NSEEL_VMCTX _ctx)
-{
- compileContext *ctx = (compileContext*)_ctx;
- int32_t wb;
- if (ctx) for (wb = 0; wb < ctx->varTable_numBlocks; wb++)
- {
- int32_t ti;
- char **plist = ctx->varTable_Names[wb];
- if (!plist) break;
- for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti++)
- {
- if (plist[ti])
- {
- varNameHdr *v = ((varNameHdr*)plist[ti]) - 1;
- if (!v->isreg)
- {
- plist[ti] = NULL;
- }
- }
- }
- }
-}
-void NSEEL_VM_clear_var_refcnts(NSEEL_VMCTX _ctx)
-{
- compileContext *ctx = (compileContext*)_ctx;
- int32_t wb;
- if (ctx) for (wb = 0; wb < ctx->varTable_numBlocks; wb++)
- {
- int32_t ti;
- char **plist = ctx->varTable_Names[wb];
- if (!plist) break;
- for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti++)
- {
- if (plist[ti])
- {
- varNameHdr *v = ((varNameHdr*)plist[ti]) - 1;
- v->refcnt = 0;
- }
- }
- }
-}
-float *nseel_int_register_var(compileContext *ctx, const char *name, int32_t isReg, const char **namePtrOut)
-{
- int32_t match_wb = -1, match_ti = -1;
- int32_t wb;
- int32_t ti = 0;
- for (wb = 0; wb < ctx->varTable_numBlocks; wb++)
- {
- char **plist = ctx->varTable_Names[wb];
- if (!plist) return NULL; // error!
- for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti++)
- {
- if (!plist[ti])
- {
- if (match_wb < 0)
- {
- match_wb = wb;
- match_ti = ti;
- }
- }
- else if (!strncmp(plist[ti], name, NSEEL_MAX_VARIABLE_NAMELEN))
- {
- varNameHdr *v = ((varNameHdr*)plist[ti]) - 1;
- if (isReg < 0)
- {
- float *p;
- return (ctx->varTable_Values && NULL != (p = ctx->varTable_Values[wb])) ? p + ti : NULL;
- }
- v->refcnt++;
- if (isReg) v->isreg = isReg;
- if (namePtrOut) *namePtrOut = plist[ti];
- break;
- }
- }
- if (ti < NSEEL_VARS_PER_BLOCK) break;
- }
- if (isReg < 0) return NULL;
- if (wb == ctx->varTable_numBlocks && match_wb >= 0 && match_ti >= 0)
- {
- wb = match_wb;
- ti = match_ti;
- }
- if (wb == ctx->varTable_numBlocks)
- {
- ti = 0;
- // add new block
- if (!(ctx->varTable_numBlocks&(NSEEL_VARS_MALLOC_CHUNKSIZE - 1)) || !ctx->varTable_Values || !ctx->varTable_Names)
- {
- void *nv = realloc(ctx->varTable_Values, (ctx->varTable_numBlocks + NSEEL_VARS_MALLOC_CHUNKSIZE) * sizeof(float *));
- if (!nv) return NULL;
- ctx->varTable_Values = (float **)nv;
- nv = realloc(ctx->varTable_Names, (ctx->varTable_numBlocks + NSEEL_VARS_MALLOC_CHUNKSIZE) * sizeof(char **));
- if (!nv) return NULL;
- ctx->varTable_Names = (char ***)nv;
- }
- ctx->varTable_numBlocks++;
- ctx->varTable_Values[wb] = (float *)newCtxDataBlock(sizeof(float)*NSEEL_VARS_PER_BLOCK, 8);
- ctx->varTable_Names[wb] = (char **)newCtxDataBlock(sizeof(char *)*NSEEL_VARS_PER_BLOCK, 1);
- if (ctx->varTable_Values[wb])
- {
- memset(ctx->varTable_Values[wb], 0, sizeof(float)*NSEEL_VARS_PER_BLOCK);
- }
- if (ctx->varTable_Names[wb])
- {
- memset(ctx->varTable_Names[wb], 0, sizeof(char *)*NSEEL_VARS_PER_BLOCK);
- }
- }
- if (!ctx->varTable_Names[wb] || !ctx->varTable_Values[wb]) return NULL;
- if (!ctx->varTable_Names[wb][ti])
- {
- size_t l = strlen(name);
- char *b;
- varNameHdr *vh;
- if (l > NSEEL_MAX_VARIABLE_NAMELEN) l = NSEEL_MAX_VARIABLE_NAMELEN;
- b = newCtxDataBlock((int32_t)(sizeof(varNameHdr) + l + 1), 1);
- if (!b) return NULL; // malloc fail
- vh = (varNameHdr *)b;
- vh->refcnt = 1;
- vh->isreg = isReg;
- b += sizeof(varNameHdr);
- memcpy(b, name, l);
- b[l] = 0;
- ctx->varTable_Names[wb][ti] = b;
- ctx->varTable_Values[wb][ti] = 0.0f;
- if (namePtrOut) *namePtrOut = b;
- }
- return ctx->varTable_Values[wb] + ti;
-}
-//------------------------------------------------------------------------------
-void NSEEL_VM_enumallvars(NSEEL_VMCTX ctx, int32_t(*func)(const char *name, float *val, void *ctx), void *userctx)
-{
- compileContext *tctx = (compileContext*)ctx;
- int32_t wb;
- if (!tctx) return;
- for (wb = 0; wb < tctx->varTable_numBlocks; wb++)
- {
- int32_t ti;
- char **plist = tctx->varTable_Names[wb];
- if (!plist) break;
- for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti++)
- {
- if (plist[ti] && !func(plist[ti], tctx->varTable_Values[wb] + ti, userctx)) break;
- }
- if (ti < NSEEL_VARS_PER_BLOCK)
- break;
- }
-}
-//------------------------------------------------------------------------------
-float *NSEEL_VM_regvar(NSEEL_VMCTX _ctx, const char *var)
-{
- compileContext *ctx = (compileContext*)_ctx;
- if (!ctx) return 0;
- return nseel_int_register_var(ctx, var, 1, NULL);
-}
-float *NSEEL_VM_getvar(NSEEL_VMCTX _ctx, const char *var)
-{
- compileContext *ctx = (compileContext*)_ctx;
- if (!ctx) return 0;
- return nseel_int_register_var(ctx, var, -1, NULL);
-}
-int32_t NSEEL_VM_get_var_refcnt(NSEEL_VMCTX _ctx, const char *name)
-{
- compileContext *ctx = (compileContext*)_ctx;
- int32_t wb;
- if (!ctx) return -1;
- for (wb = 0; wb < ctx->varTable_numBlocks; wb++)
- {
- int32_t ti;
- if (!ctx->varTable_Values[wb] || !ctx->varTable_Names[wb]) break;
- for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti++)
- {
- if (ctx->varTable_Names[wb][ti] && !stricmp(ctx->varTable_Names[wb][ti], name))
- {
- varNameHdr *h = ((varNameHdr *)ctx->varTable_Names[wb][ti]) - 1;
- return h->refcnt;
- }
- }
- }
- return -1;
-}
-opcodeRec *nseel_createFunctionByName(compileContext *ctx, const char *name, int32_t np, opcodeRec *code1, opcodeRec *code2, opcodeRec *code3)
-{
- int32_t i;
- for (i = 0; fnTable1 + i; i++)
- {
- if (i >= (int32_t)(sizeof(fnTable1) / sizeof(fnTable1[0])))
- break;
- functionType *f = fnTable1 + i;
- if ((f->nParams&FUNCTIONTYPE_PARAMETERCOUNTMASK) == np && !strcmp(f->name, name))
- {
- opcodeRec *o = newOpCode(ctx, NULL, np == 3 ? OPCODETYPE_FUNC3 : np == 2 ? OPCODETYPE_FUNC2 : OPCODETYPE_FUNC1);
- if (o)
- {
- o->fntype = FUNCTYPE_FUNCTIONTYPEREC;
- o->fn = f;
- o->parms.parms[0] = code1;
- o->parms.parms[1] = code2;
- o->parms.parms[2] = code3;
- }
- return o;
- }
- }
- return NULL;
-}
-#include
-//------------------------------------------------------------------------------
-opcodeRec *nseel_translate(compileContext *ctx, const char *tmp, size_t tmplen) // tmplen 0 = null term
-{
- // this depends on the string being nul terminated eventually, tmplen is used more as a hint than anything else
- if ((tmp[0] == '0' || tmp[0] == '$') && toupper(tmp[1]) == 'X')
- {
- char *p;
- return nseel_createCompiledValue(ctx, (float)strtoul(tmp + 2, &p, 16));
- }
- else if (tmp[0] == '$')
- {
- if (tmp[1] == '~')
- {
- char *p = (char*)tmp + 2;
- uint32_t v = strtoul(tmp + 2, &p, 10);
- if (v > 53) v = 53;
- return nseel_createCompiledValue(ctx, (float)((((WDL_INT64)1) << v) - 1));
- }
- else if (!tmplen ? !stricmp(tmp, "$E") : (tmplen == 2 && !strnicmp(tmp, "$E", 2)))
- return nseel_createCompiledValue(ctx, (float)2.71828182845904523536);
- else if (!tmplen ? !stricmp(tmp, "$PI") : (tmplen == 3 && !strnicmp(tmp, "$PI", 3)))
- return nseel_createCompiledValue(ctx, (float)3.141592653589793238463);
- else if (!tmplen ? !stricmp(tmp, "$PHI") : (tmplen == 4 && !strnicmp(tmp, "$PHI", 4)))
- return nseel_createCompiledValue(ctx, (float)1.618033988749894848205);
- else if (!tmplen ? !stricmp(tmp, "$EPS") : (tmplen == 4 && !strnicmp(tmp, "$EPS", 4)))
- return nseel_createCompiledValue(ctx, (float)FLT_EPSILON);
- else if (!tmplen ? !stricmp(tmp, "$DBL_MAX") : (tmplen == 4 && !strnicmp(tmp, "$DBL_MAX", 4)))
- return nseel_createCompiledValue(ctx, (float)FLT_MAX);
- else if (!tmplen ? !stricmp(tmp, "$MEMBLKLIMIT") : (tmplen == 12 && !strnicmp(tmp, "$MEMBLKLIMIT", 12)))
- return nseel_createCompiledValue(ctx, (float)NSEEL_RAM_ITEMSPERBLOCK);
- else if ((!tmplen || tmplen == 4) && tmp[1] == '\'' && tmp[2] && tmp[3] == '\'')
- return nseel_createCompiledValue(ctx, (float)tmp[2]);
- else return NULL;
- }
- else if (tmp[0] == '\'')
- {
- char b[64];
- int32_t x, sz;
- uint32_t rv = 0;
- if (!tmplen) // nul terminated tmplen, calculate a workable length
- {
- // faster than strlen(tmp) if tmp is large, we'll never need more than ~18 chars anyway
- while (tmplen < 32 && tmp[tmplen]) tmplen++;
- }
- sz = tmplen > 0 ? nseel_filter_escaped_string(b, sizeof(b), tmp + 1, tmplen - 1, '\'') : 0;
- if (sz > 4)
- {
- if (ctx->last_error_string[0]) lstrcatn(ctx->last_error_string, ", ", sizeof(ctx->last_error_string));
- snprintf_append(ctx->last_error_string, sizeof(ctx->last_error_string), "multi-byte character '%.5s...' too long", b);
- return NULL; // do not allow 'xyzxy', limit to 4 bytes
- }
- for (x = 0; x < sz; x++) rv = (rv << 8) + ((unsigned char*)b)[x];
- return nseel_createCompiledValue(ctx, (float)rv);
- }
- return nseel_createCompiledValue(ctx, (float)atof(tmp));
-}
\ No newline at end of file
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/atox.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/atox.c
new file mode 100644
index 00000000..0909e3ce
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/atox.c
@@ -0,0 +1,210 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include "xpre.h"
+
+#define UPPER_BOUND (XMAX_10EX + 100)
+
+xpr
+strtox (const char *q, char **endptr)
+{
+ xpr s, f;
+ unsigned short pc[XDIM + 1];
+ unsigned short *pn, *pf, *pa, *pb;
+ unsigned short sfg, ibex, fbex;
+ unsigned long n;
+ long j;
+ int idex = 0, fdex = 0, c, m;
+ short noip, nofp;
+ const char *ptr;
+
+ pn = (unsigned short *) &s;
+ pf = (unsigned short *) &f;
+ for (j = 0; j <= XDIM; pn[j] = pf[j] = pc[j] = 0, ++j);
+ sfg = 0;
+ m = XDIM + 1;
+ if ((endptr))
+ *endptr = (char *) q;
+ /* Skip the leading spaces if there are some */
+ while ((isspace (*q)))
+ q++;
+ /* Sign */
+ if (*q == '+')
+ ++q;
+ else if (*q == '-')
+ {
+ sfg = 0x8000;
+ ++q;
+ }
+ /* Integer part */
+ for (ptr = q; (c = *q - '0') >= 0 && c <= 9; ++q)
+ {
+ if (pn[0])
+ ++idex;
+ else
+ {
+ xlshift (1, pn, m);
+ for (j = 0; j < m; ++j)
+ pc[j] = pn[j];
+ xlshift (2, pn, m);
+ for (n = (unsigned int) c, pa = pn + XDIM, pb = pc + XDIM;
+ pa >= pn; pa--, pb--)
+ {
+ n += *pa + *pb;
+ *pa = n;
+ n >>= 16;
+ }
+ }
+ }
+ for (j = 0; j < m && pn[j] == 0; ++j);
+ if (j == m)
+ ibex = 0;
+ else
+ {
+ ibex = xBias + xMax_p - 1;
+ if (j)
+ {
+ j <<= 4;
+ ibex -= j;
+ xlshift (j, pn, m);
+ }
+ while (pn[0])
+ {
+ xrshift (1, pn, m);
+ ++ibex;
+ }
+ pn[0] = ibex | sfg;
+ }
+ noip = ptr == q;
+ /* End Integer part */
+ if (*q == '.')
+ {
+ /* Fractionary part */
+ for (j = 0; j <= XDIM; ++j)
+ pc[j] = 0;
+ for (ptr = ++q; (c = *q - '0') >= 0 && c <= 9 && pf[0] == 0;
+ --fdex, ++q)
+ {
+ xlshift (1, pf, m);
+ for (j = 0; j < m; ++j)
+ pc[j] = pf[j];
+ xlshift (2, pf, m);
+ for (n = (unsigned int) c, pa = pf + XDIM, pb = pc + XDIM;
+ pa >= pf; pa--, pb--)
+ {
+ n += *pa + *pb;
+ *pa = n;
+ n >>= 16;
+ }
+ }
+ for (j = 0; j < m && pf[j] == 0; ++j);
+ if (j == m)
+ fbex = 0;
+ else
+ {
+ fbex = xBias + xMax_p - 1;
+ if (j)
+ {
+ j <<= 4;
+ fbex -= j;
+ xlshift (j, pf, m);
+ }
+ while (pf[0])
+ {
+ xrshift (1, pf, m);
+ ++fbex;
+ }
+ pf[0] = fbex | sfg;
+ }
+ nofp = ptr == q;
+ } /* end if (*q == '.') */
+ else
+ nofp = 1;
+ if ((noip) && (nofp))
+ /* Error ! */
+ return xNaN;
+ else
+ {
+ /*
+ Added on August 4th 2007:
+ If the decimal digits after the radix character ('.')
+ are too much with respect to the given precision,
+ all the meaningless ones must be neglected.
+ The absence of this loop produced a VERY hazardous bug
+ (thanks to Shina Tan
+ for the bug notification)
+ */
+ for(; *q >= '0' && *q <= '9'; q++);
+ /*
+ End addition
+ */
+ if ((endptr))
+ *endptr = (char *) q;
+ }
+ /* Exponent */
+ if (*q == 'e' || *q == 'E')
+ {
+ ++q;
+ sfg = 0;
+ if (*q == '+')
+ ++q;
+ else if (*q == '-')
+ {
+ sfg = 1;
+ ++q;
+ }
+ for (ptr = q, j = 0; (c = *q - '0') >= 0 && c <= 9
+ && j <= UPPER_BOUND; ++q)
+ {
+ j <<= 1;
+ m = j;
+ j <<= 2;
+ j += c + m;
+ }
+ if (ptr != q && (endptr))
+ *endptr = (char *) q;
+ if (sfg)
+ j = -j;
+ idex += j;
+ fdex += j;
+ }
+ /*
+ Remark: s and f have the same sign (see above).
+ */
+ if (idex > XMAX_10EX || fdex > XMAX_10EX)
+ return ((s.nmm[0] & xM_sgn) ? xMinf : xPinf);
+ else
+ {
+ if (idex)
+ s = xmul (s, xpwr (xTen, idex));
+ if (fdex)
+ f = xmul (f, xpwr (xTen, fdex));
+ return xadd (s, f, 0);
+ }
+}
+
+xpr
+atox (const char *q)
+{
+ return strtox (q, NULL);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/constant.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/constant.c
new file mode 100644
index 00000000..eeef4daa
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/constant.c
@@ -0,0 +1,72 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"xpre.h"
+
+const unsigned short xM_sgn = 0x8000;
+const unsigned short xM_exp = 0x7fff;
+const short xBias = 16383;
+
+const short xD_bias = 15360;
+const short xD_max = 2047;
+const short xD_lex = 12;
+
+const short xF_bias = 16256;
+const short xF_max = 255;
+const short xF_lex = 9;
+
+const short xMax_p = 16 * XDIM;
+const short xK_lin = -8 * XDIM;
+
+const xpr xZero = { {0x0, 0x0} };
+const xpr xOne = { {0x3fff, 0x8000} };
+const xpr xTwo = { {0x4000, 0x8000} };
+const xpr xTen = { {0x4002, 0xa000} };
+const xpr xPinf = { {0x7fff, 0x0} };
+const xpr xMinf = { {0xffff, 0x0} };
+const xpr xVSV = { {0x3ff2, 0x8000} };
+const xpr xVGV = { {0x4013, 0x8000} };
+const xpr xEmax = { {0x400c, 0xb16c} };
+const xpr xEmin = { {0xc00c, 0xb16c} };
+const xpr xE2min = { {0xc00c, 0xfffb} }; /* -16382.75 */
+const xpr xE2max = { {0x400c, 0xfffb} }; /* +16382.75 */
+/* const xpr HPA_MIN = pow(xTwo, RealNumber(-16381));*/ // Similar to DBL_MIN
+/* const xpr HPA_MAX = pow(xTwo, RealNumber(16381));*/ // Similar to DBL_MAX
+/* static xpr xpzero = { {0x0, 0x0} }; */
+/* static xpr xnzero = { {0x0, 0x0} }; */
+
+#if XDIM == 11
+#include"mp/const11.h"
+#elif XDIM == 15
+#include"mp/const15.h"
+#elif XDIM == 19
+#include"mp/const19.h"
+#elif XDIM == 23
+#include"mp/const23.h"
+#elif XDIM == 27
+#include"mp/const27.h"
+#elif XDIM == 31
+#include"mp/const31.h"
+#else
+/* We assume XDIM == 7 (default) */
+#include"mp/const07.h"
+#endif
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxaop.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxaop.c
new file mode 100644
index 00000000..f13c0fc5
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxaop.c
@@ -0,0 +1,170 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxpr
+cxadd (cxpr z1, cxpr z2, int k)
+{
+ cxpr w;
+
+ w.re = xadd (z1.re, z2.re, k);
+ w.im = xadd (z1.im, z2.im, k);
+ return w;
+}
+
+cxpr
+cxsum (cxpr z1, cxpr z2)
+{
+ cxpr w;
+
+ w.re = xadd (z1.re, z2.re, 0);
+ w.im = xadd (z1.im, z2.im, 0);
+ return w;
+}
+
+cxpr
+cxsub (cxpr z1, cxpr z2)
+{
+ cxpr w;
+
+ w.re = xadd (z1.re, z2.re, 1);
+ w.im = xadd (z1.im, z2.im, 1);
+ return w;
+}
+
+cxpr
+cxmul (cxpr z1, cxpr z2)
+{
+ cxpr w;
+
+ w.re = xadd (xmul (z1.re, z2.re), xmul (z1.im, z2.im), 1);
+ w.im = xadd (xmul (z1.im, z2.re), xmul (z1.re, z2.im), 0);
+ return w;
+}
+
+/* Multiplication by a real number */
+cxpr
+cxrmul (xpr c, cxpr z)
+{
+ cxpr w;
+
+ w.re = xmul (c, z.re);
+ w.im = xmul (c, z.im);
+ return w;
+}
+
+/* Multiplication by +i */
+cxpr
+cxdrot (cxpr z)
+{
+ cxpr y;
+
+ y.re = z.im;
+ y.im = z.re;
+ y.re.nmm[0] ^= xM_sgn;
+ return y;
+/* MS-VC requires a more explicit coding,
+ signaled on 2010-04-09 by A.Haumer
+
+ z.im.nmm[0] ^= xM_sgn;
+ return (cxpr)
+ {
+ z.im, z.re};
+*/
+}
+
+/* Multiplication by -i */
+cxpr
+cxrrot (cxpr z)
+{
+ cxpr y;
+
+ y.re = z.im;
+ y.im = z.re;
+ y.im.nmm[0] ^= xM_sgn;
+ return y;
+/* MS-VC requires a more explicit coding,
+ signaled on 2010-04-09 by A.Haumer
+
+ z.re.nmm[0] ^= xM_sgn;
+ return (cxpr)
+ {
+ z.im, z.re};
+*/
+}
+
+cxpr
+cxdiv (cxpr z1, cxpr z2)
+{
+ int tv = cxrec (z2, &z2);
+
+ if (!xsigerr (!tv, XEDIV, "cxdiv()"))
+ {
+ cxpr w;
+
+ w.re = xadd (xmul (z1.re, z2.re), xmul (z1.im, z2.im), 1);
+ w.im = xadd (xmul (z1.im, z2.re), xmul (z1.re, z2.im), 0);
+ return w;
+ }
+ else
+ return cxZero;
+}
+
+cxpr
+cxinv (cxpr z)
+{
+ int tv = cxrec (z, &z);
+
+ if (!xsigerr (!tv, XEDOM, "cxinv()"))
+ return z;
+ else
+ return cxZero;
+}
+
+cxpr
+cxsqr (cxpr z)
+{
+ cxpr w;
+
+ w.re = xadd (xmul (z.re, z.re), xmul (z.im, z.im), 1);
+ w.im = xmul (xTwo, xmul (z.im, z.re));
+ return w;
+}
+
+cxpr
+cxsqrt (cxpr z)
+{
+ xpr mod, arg;
+ cxpr w;
+
+ if (xsgn (&z.re) == 0 && xsgn (&z.im) == 0)
+ return cxZero;
+ else
+ {
+ mod = xsqrt (cxabs (z));
+ arg = xpr2 (cxarg (z), -1);
+ w.re = xmul (mod, xcos (arg));
+ w.im = xmul (mod, xsin (arg));
+ return w;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxbasic.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxbasic.c
new file mode 100644
index 00000000..4e8d7f8b
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxbasic.c
@@ -0,0 +1,251 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxpr
+cxreset (xpr re, xpr im)
+{
+ cxpr y;
+
+ y.re = re;
+ y.im = im;
+ return y;
+/* MS-VC requires a more explicit coding,
+ signaled on 2010-04-09 by A.Haumer
+
+ return (cxpr)
+ {
+ re, im};
+*/
+}
+
+cxpr
+cxconv (xpr x)
+{
+ cxpr y;
+
+ y.re = x;
+ y.im = xZero;
+ return y;
+/* MS-VC requires a more explicit coding,
+ signaled on 2010-04-09 by A.Haumer
+
+ return (cxpr)
+ {
+ x, xZero};
+*/
+}
+
+xpr
+cxre (cxpr z)
+{
+ return z.re;
+}
+
+xpr
+cxim (cxpr z)
+{
+ return z.im;
+}
+
+cxpr
+cxswap (cxpr z)
+{
+ cxpr y;
+
+ y.re = z.im;
+ y.im = z.re;
+ return y;
+/* MS-VC requires a more explicit coding,
+ signaled on 2010-04-09 by A.Haumer
+
+ return (cxpr)
+ {
+ z.im, z.re};
+*/
+}
+
+cxpr
+cxneg (cxpr z)
+{
+ z.re.nmm[0] ^= xM_sgn;
+ z.im.nmm[0] ^= xM_sgn;
+ return z;
+}
+
+cxpr
+cxconj (cxpr z)
+{
+ return (z.im.nmm[0] ^= xM_sgn, z);
+}
+
+#define XBOUND XDIM * 16 + 8
+
+xpr
+cxabs (cxpr z)
+{
+ xpr x;
+ int ea, eb;
+
+ if (xprcmp (&z.re, &xZero) == 0 && xprcmp (&z.im, &xZero) == 0)
+ return xZero;
+ else
+ {
+ ea = (z.re.nmm[0] &= xM_exp) - xBias;
+ eb = (z.im.nmm[0] &= xM_exp) - xBias;
+ if (ea > eb + XBOUND)
+ return z.re;
+ else if (eb > ea + XBOUND)
+ return z.im;
+ else
+ {
+ z.re.nmm[0] -= eb;
+ z.im.nmm[0] = xBias;
+ x = xsqrt (xadd (xmul (z.re, z.re), xmul (z.im, z.im), 0));
+ x.nmm[0] += eb;
+ return x;
+ }
+ }
+}
+
+xpr
+cxarg (cxpr z)
+{
+ int rs, is;
+
+ rs = xsgn (&z.re);
+ is = xsgn (&z.im);
+ if (rs > 0)
+ return xatan (xdiv (z.im, z.re));
+ else if (rs < 0)
+ {
+ z.re.nmm[0] ^= xM_sgn;
+ z.im.nmm[0] ^= xM_sgn;
+ if (is >= 0)
+ return xadd (xPi, xatan (xdiv (z.im, z.re)), 0);
+ else
+ return xadd (xatan (xdiv (z.im, z.re)), xPi, 1);
+ }
+ else /* z.re is zero ! */
+ {
+ if (!xsigerr (is == 0, XEDOM, "cxarg()"))
+ return (is > 0 ? xPi2 : xneg (xPi2));
+ else
+ return xneg (xPi2); /* Dummy value :) */
+ }
+}
+
+int
+cxrec (cxpr z, cxpr *w)
+{
+ xpr x;
+ int sa, sb, ea, eb;
+
+ if (xprcmp (&z.re, &xZero) == 0 && xprcmp (&z.im, &xZero) == 0)
+ return 0;
+ else
+ {
+ sa = z.re.nmm[0] & xM_sgn;
+ sb = z.im.nmm[0] & xM_sgn;
+ ea = (z.re.nmm[0] &= xM_exp) - xBias;
+ eb = (z.im.nmm[0] &= xM_exp) - xBias;
+ if (ea > eb + XBOUND)
+ x = z.re;
+ else if (eb > ea + XBOUND)
+ x = z.im;
+ else
+ {
+ z.re.nmm[0] -= eb;
+ z.im.nmm[0] = xBias;
+ x = xsqrt (xadd (xmul (z.re, z.re), xmul (z.im, z.im), 0));
+ x.nmm[0] += eb;
+ z.re.nmm[0] += eb;
+ z.im.nmm[0] += eb;
+ }
+ w->re = xdiv (xdiv (z.re, x), x);
+ w->im = xdiv (xdiv (z.im, x), x);
+ w->re.nmm[0] |= sa;
+ w->im.nmm[0] |= xM_sgn ^ sb;
+ return 1;
+ }
+}
+
+cxpr
+cxfloor (cxpr z)
+{
+ cxpr w;
+
+ w.re = xfloor (z.re);
+ w.im = xfloor (z.im);
+ return w;
+}
+
+cxpr
+cxceil (cxpr z)
+{
+ cxpr w;
+
+ w.re = xceil (z.re);
+ w.im = xceil (z.im);
+ return w;
+}
+
+cxpr
+cxround (cxpr z)
+{
+ cxpr w;
+
+ w.re = xround (z.re);
+ w.im = xround (z.im);
+ return w;
+}
+
+cxpr
+cxtrunc (cxpr z)
+{
+ cxpr w;
+
+ w.re = xtrunc (z.re);
+ w.im = xtrunc (z.im);
+ return w;
+}
+
+cxpr
+cxfrac (cxpr z)
+{
+ cxpr w;
+
+ w.re = xfrac (z.re);
+ w.im = xfrac (z.im);
+ return w;
+}
+
+cxpr
+cxfix (cxpr z)
+{
+ cxpr w;
+
+ w.re = xfix (z.re);
+ w.im = xfix (z.im);
+ return w;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxconstant.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxconstant.c
new file mode 100644
index 00000000..f53a3c83
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxconstant.c
@@ -0,0 +1,27 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h"
+
+const cxpr cxZero = { {{0x0, 0x0}}, {{0x0, 0x0}} };
+const cxpr cxOne = { {{0x3fff, 0x8000}}, {{0x0, 0x0}} };
+const cxpr cxIU = { {{0x0, 0x0}}, {{0x3fff, 0x8000}} };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxconvf.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxconvf.c
new file mode 100644
index 00000000..bc7336c8
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxconvf.c
@@ -0,0 +1,177 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include
+#include
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxpr
+strtocx (const char *q, char **endptr)
+{
+ cxpr z = cxZero;
+ char *ptr, *ptr2;
+
+ z.re = strtox (q, &ptr);
+ if ((endptr))
+ *endptr = ptr;
+ if (ptr != q)
+ {
+ if (*ptr == CX1I_CHAR)
+ {
+ z.im = z.re;
+ z.re = xZero;
+ if ((endptr))
+ *endptr = ptr + 1;
+ }
+ else
+ {
+ while (isspace (*ptr))
+ ptr++;
+ if (*ptr == '+' || *ptr == '-')
+ {
+ z.im = strtox (ptr, &ptr2);
+ if (*ptr2 != CX1I_CHAR)
+ z.im = xZero;
+ else
+ {
+ if ((endptr))
+ *endptr = ptr2 + 1;
+ }
+ }
+ /*
+ else
+ : we have successfully read a real number
+ but there is no another number after it.
+ : So, we leave z.im set to zero and return z.
+ */
+ }
+ }
+ else
+ /*
+ : q does not contain any valid number
+ ==> z.re is xNaN. Then we set z.im to
+ xNaN and return z.
+ We remark that, if endptr is
+ not NULL, then *endptr == q.
+ */
+ z.im = xNaN;
+ return z;
+}
+
+cxpr
+atocx (const char *s)
+{
+ return strtocx (s, NULL);
+}
+
+char *
+cxpr_asprint (cxpr z, int sc_not, int sign, int lim)
+{
+ char *str1, *str2, *t;
+
+ str1 = xpr_asprint (z.re, sc_not, sign, lim);
+ str2 = xpr_asprint (z.im, sc_not, 1, lim);
+ if (!str1 || !str2)
+ {
+ if ((str1))
+ free ((void*)str1);
+ if ((str2))
+ free ((void*)str2);
+ return NULL;
+ }
+ else
+ {
+ size_t n = strlen (str1) + strlen (str2) + 2;
+
+ if (!(t = (char*)malloc (n * sizeof (char))))
+ return NULL;
+ else
+ {
+ strcpy (t, str1);
+ strcat (t, str2);
+ for (n = 0; t[n] != '\0'; n++);
+ t[n] = CX1I_CHAR;
+ t[n + 1] = '\0';
+ return t;
+ }
+ }
+}
+
+char *
+cxtoa (cxpr z, int lim)
+{
+ return cxpr_asprint (z, 1, 0, lim);
+}
+
+cxpr
+dctocx (double re, double im)
+{
+ cxpr z;
+
+ z.re = dbltox (re);
+ z.im = dbltox (im);
+ return z;
+}
+
+cxpr
+fctocx (float re, float im)
+{
+ cxpr z;
+
+ z.re = flttox (re);
+ z.im = flttox (im);
+ return z;
+}
+
+cxpr
+ictocx (long re, long im)
+{
+ cxpr z;
+
+ z.re = inttox (re);
+ z.im = inttox (im);
+ return z;
+}
+
+cxpr uctocx (unsigned long re, unsigned long im)
+{
+ cxpr z;
+
+ z.re = uinttox (re);
+ z.im = uinttox (im);
+ return z;
+}
+
+void
+cxtodc (const cxpr *z, double *re, double *im)
+{
+ *re = xtodbl (z->re);
+ *im = xtodbl (z->im);
+}
+
+void
+cxtofc (const cxpr *z, float *re, float *im)
+{
+ *re = xtoflt (z->re);
+ *im = xtoflt (z->im);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxexp.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxexp.c
new file mode 100644
index 00000000..13fbb190
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxexp.c
@@ -0,0 +1,123 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxpr
+cxexp (cxpr z)
+{
+ cxpr w;
+
+ w.re = xmul (xexp (z.re), xcos (z.im));
+ w.im = xmul (xexp (z.re), xsin (z.im));
+ return w;
+}
+
+cxpr
+cxexp10 (cxpr z)
+{
+ cxpr w;
+
+ z.im = xmul (xLn10, z.im);
+ w.re = xmul (xexp10 (z.re), xcos (z.im));
+ w.im = xmul (xexp10 (z.re), xsin (z.im));
+ return w;
+}
+
+cxpr
+cxexp2 (cxpr z)
+{
+ cxpr w;
+
+ z.im = xmul (xLn2, z.im);
+ w.re = xmul (xexp2 (z.re), xcos (z.im));
+ w.im = xmul (xexp2 (z.re), xsin (z.im));
+ return w;
+}
+
+cxpr
+cxlog (cxpr z)
+{
+ xpr mod;
+ cxpr w;
+
+ mod = cxabs (z);
+ if (xsigerr (xsgn (&mod) <= 0, XEDOM, "cxlog()"))
+ return cxZero;
+ else
+ {
+ w.re = xlog (mod);
+ w.im = cxarg (z);
+ return w;
+ }
+}
+
+cxpr
+cxlog10 (cxpr z)
+{
+ xpr mod;
+ cxpr w;
+
+ mod = cxabs (z);
+ if (xsigerr (xsgn (&mod) <= 0, XEDOM, "cxlog10()"))
+ return cxZero;
+ else
+ {
+ w.re = xlog10 (mod);
+ w.im = xmul (cxarg (z), xLog10_e);
+ return w;
+ }
+}
+
+cxpr
+cxlog2 (cxpr z)
+{
+ xpr mod;
+ cxpr w;
+
+ mod = cxabs (z);
+ if (xsigerr (xsgn (&mod) <= 0, XEDOM, "cxlog2()"))
+ return cxZero;
+ else
+ {
+ w.re = xlog2 (mod);
+ w.im = xmul (cxarg (z), xLog2_e);
+ return w;
+ }
+}
+
+cxpr
+cxlog_sqrt (cxpr z)
+{
+ xpr mod;
+ cxpr w;
+
+ mod = cxabs (z);
+ if (xsigerr (xsgn (&mod) <= 0, XEDOM, "cxlog_sqrt()"))
+ return cxZero;
+ else
+ {
+ w.re = xpr2 (xlog (mod), -1);
+ w.im = xpr2 (cxarg (z), -1);
+ return w;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxhypb.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxhypb.c
new file mode 100644
index 00000000..55ac009e
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxhypb.c
@@ -0,0 +1,114 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxpr
+cxsinh (cxpr z)
+{
+ cxpr w;
+
+ w = cxsub (cxexp (z), cxexp (cxneg (z)));
+ w.re = xpr2 (w.re, -1);
+ w.im = xpr2 (w.im, -1);
+ return w;
+}
+
+cxpr
+cxcosh (cxpr z)
+{
+ cxpr w;
+
+ w = cxsum (cxexp (z), cxexp (cxneg (z)));
+ w.re = xpr2 (w.re, -1);
+ w.im = xpr2 (w.im, -1);
+ return w;
+}
+
+cxpr
+cxtanh (cxpr z)
+{
+ if (xsigerr (xprcmp (&z.re, &xEmax) > 0, XFPOFLOW, NULL))
+ return cxOne;
+ else if (xsigerr (xprcmp (&z.re, &xEmin) < 0, XFPOFLOW, NULL))
+ return cxneg (cxOne);
+ else
+ {
+ cxpr w;
+
+ if (xsigerr (!cxrec (cxcosh (z), &w), XEDOM, "cxtanh()"))
+ return cxZero;
+ else
+ return cxmul (cxsinh (z), w);
+ }
+}
+
+cxpr
+cxasinh (cxpr z)
+{
+ cxpr w;
+ xpr ls, rs;
+
+ /* In this way, cxasinh() works fine also with real numbers */
+ /* very near to -oo. */
+ w = cxsqrt (cxsum (cxOne, cxsqr (z)));
+ ls = cxabs (cxsum (z, w));
+ rs = xmul (xVSV, cxabs (z));
+ if (xprcmp (&ls, &rs) < 0)
+ return cxneg (cxlog (cxsub (w, z)));
+ else
+ return cxlog (cxsum (z, w));
+}
+
+cxpr
+cxacosh (cxpr z)
+{
+ cxpr w;
+ xpr ls, rs;
+
+ w = cxsqrt (cxsub (cxsqr (z), cxOne));
+ ls = cxabs (cxsum (z, w));
+ rs = xmul (xVSV, cxabs (z));
+ if (xprcmp (&ls, &rs) < 0)
+ return cxneg (cxlog (cxsub (z, w)));
+ else
+ return cxlog (cxsum (z, w));
+}
+
+cxpr
+cxatanh (cxpr z)
+{
+ cxpr w;
+ xpr t;
+ int errcond;
+
+ t = xadd (xabs (z.re), xOne, 1);
+ errcond = xsgn (&z.im) == 0 && xsgn (&t) == 0;
+ if (xsigerr (errcond, XEDOM, "cxatanh()"))
+ return cxZero;
+ else
+ {
+ w = cxdiv (cxsum (cxOne, z), cxsub (cxOne, z));
+ w = cxlog_sqrt (w);
+ return w;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxidiv.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxidiv.c
new file mode 100644
index 00000000..3203241d
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxidiv.c
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxpr
+cxgdiv (cxpr z1, cxpr z2)
+{
+ xpr mod2;
+
+ z1.re = xround (z1.re);
+ z1.im = xround (z1.im);
+ z2.re = xround (z2.re);
+ z2.im = xround (z2.im);
+ mod2 = xadd (xmul (z2.re, z2.re), xmul (z2.im, z2.im), 0);
+ if (xsigerr (xprcmp (&mod2, &xPinf) >= 0, XFPOFLOW, NULL) ||
+ xsigerr (xsgn (&mod2) <= 0, XEDIV, "cxgdiv()"))
+ return cxZero;
+ else
+ {
+ cxpr w;
+
+ w.re = xadd (xmul (z1.re, z2.re), xmul (z1.im, z2.im), 0);
+ w.im = xadd (xmul (z2.re, z1.im), xmul (z2.im, z1.re), 1);
+ w.re = xround (xdiv (w.re, mod2));
+ w.im = xround (xdiv (w.im, mod2));
+ return w;
+ }
+}
+
+cxpr
+cxidiv (cxpr z1, cxpr z2)
+{
+ xpr mod2;
+
+ z1.re = xround (z1.re);
+ z1.im = xround (z1.im);
+ z2.re = xround (z2.re);
+ z2.im = xround (z2.im);
+ mod2 = xadd (xmul (z2.re, z2.re), xmul (z2.im, z2.im), 0);
+ if (xsigerr (xprcmp (&mod2, &xPinf) >= 0, XFPOFLOW, NULL) ||
+ xsigerr (xsgn (&mod2) <= 0, XEDIV, "cxidiv()"))
+ return cxZero;
+ else
+ {
+ cxpr w;
+
+ w.re = xadd (xmul (z1.re, z2.re), xmul (z1.im, z2.im), 0);
+ w.im = xadd (xmul (z2.re, z1.im), xmul (z2.im, z1.re), 1);
+ w.re = xfix (xdiv (w.re, mod2));
+ w.im = xfix (xdiv (w.im, mod2));
+ return w;
+ }
+}
+
+cxpr
+cxgmod (cxpr z1, cxpr z2)
+{
+ xpr mod2;
+
+ z1.re = xround (z1.re);
+ z1.im = xround (z1.im);
+ z2.re = xround (z2.re);
+ z2.im = xround (z2.im);
+ mod2 = xadd (xmul (z2.re, z2.re), xmul (z2.im, z2.im), 0);
+ if (xsigerr (xprcmp (&mod2, &xPinf) >= 0, XFPOFLOW, NULL) ||
+ xsigerr (xsgn (&mod2) <= 0, XEDIV, "cxgmod()"))
+ return cxZero;
+ else
+ {
+ cxpr w, z;
+
+ w.re = xadd (xmul (z1.re, z2.re), xmul (z1.im, z2.im), 0);
+ w.im = xadd (xmul (z2.re, z1.im), xmul (z2.im, z1.re), 1);
+ w.re = xround (xdiv (w.re, mod2));
+ w.im = xround (xdiv (w.im, mod2));
+ z.re = xadd (xmul (w.re, z2.re), xmul (w.im, z2.im), 1);
+ z.im = xadd (xmul (w.im, z2.re), xmul (w.re, z2.im), 0);
+ w.re = xround (xadd (z1.re, z.re, 1));
+ w.im = xround (xadd (z1.im, z.im, 1));
+ return w;
+ }
+}
+
+cxpr
+cxmod (cxpr z1, cxpr z2)
+{
+ xpr mod2;
+
+ z1.re = xround (z1.re);
+ z1.im = xround (z1.im);
+ z2.re = xround (z2.re);
+ z2.im = xround (z2.im);
+ mod2 = xadd (xmul (z2.re, z2.re), xmul (z2.im, z2.im), 0);
+ if (xsigerr (xprcmp (&mod2, &xPinf) >= 0, XFPOFLOW, NULL) ||
+ xsigerr (xsgn (&mod2) <= 0, XEDIV, "cxmod()"))
+ return cxZero;
+ else
+ {
+ cxpr w, z;
+
+ w.re = xadd (xmul (z1.re, z2.re), xmul (z1.im, z2.im), 0);
+ w.im = xadd (xmul (z2.re, z1.im), xmul (z2.im, z1.re), 1);
+ w.re = xfix (xdiv (w.re, mod2));
+ w.im = xfix (xdiv (w.im, mod2));
+ z.re = xadd (xmul (w.re, z2.re), xmul (w.im, z2.im), 1);
+ z.im = xadd (xmul (w.im, z2.re), xmul (w.re, z2.im), 0);
+ w.re = xround (xadd (z1.re, z.re, 1));
+ w.im = xround (xadd (z1.im, z.im, 1));
+ return w;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxpow.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxpow.c
new file mode 100644
index 00000000..450acc45
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxpow.c
@@ -0,0 +1,123 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+static void
+unit_root (int i, int n, xpr *a, xpr *b)
+{
+ /*
+ We assume n != 0
+ */
+ i %= n;
+ *a = xdiv (xmul (xpr2 (inttox (i), 1), xPi), inttox (n));
+ *b = xsin (*a);
+ *a = xcos (*a);
+ if (x_exp (b) < -80)
+ *b = xZero;
+ if (x_exp (a) < -80)
+ *a = xZero;
+}
+
+cxpr
+cxpwr (cxpr z, int n)
+{
+ xpr mod, arg;
+ cxpr w;
+
+ mod = cxabs (z);
+ if (xsgn (&mod) <= 0)
+ {
+ int dummy;
+
+ dummy = xsigerr (n <= 0, XEBADEXP, "cxpwr()");
+ return cxZero;
+ }
+ else
+ {
+ arg = xmul (inttox (n), cxarg (z));
+ mod = xpwr (mod, n);
+ w.re = xmul (mod, xcos (arg));
+ w.im = xmul (mod, xsin (arg));
+ return w;
+ }
+ return w;
+}
+
+cxpr
+cxroot (cxpr z, int i, int n)
+{
+ xpr mod, arg, e, a, b;
+ cxpr w, zz;
+
+ if (xsigerr (n == 0, XEBADEXP, "cxroot()"))
+ return cxZero;
+ else
+ {
+ mod = cxabs (z);
+ if (xsgn (&mod) <= 0)
+ {
+ int dummy;
+
+ dummy = xsigerr (n < 0, XEBADEXP, "cxroot()");
+ return cxZero;
+ }
+ else /* mod > 0 */
+ {
+ arg = xdiv (cxarg (z), inttox (n));
+ e = xdiv (xOne, inttox (n)); /* 1/n */
+ /* x^e = exp(e*log(x)) for any x > 0 */
+ mod = xexp (xmul (e, xlog (mod)));
+ w.re = xmul (mod, xcos (arg));
+ w.im = xmul (mod, xsin (arg));
+ unit_root (i, n, &a, &b);
+ zz.re = xadd (xmul (w.re, a), xmul (w.im, b), 1);
+ zz.im = xadd (xmul (w.im, a), xmul (w.re, b), 0);
+ return zz;
+ }
+ }
+}
+
+cxpr
+cxpow (cxpr z1, cxpr z2)
+{
+ xpr mod, arg, a, b;
+ cxpr w;
+
+ mod = cxabs (z1);
+ if (xsgn (&mod) <= 0)
+ {
+ int dummy;
+
+ dummy = xsigerr (xsgn (&z2.re) <= 0, XEBADEXP, "cxpow()");
+ return cxZero;
+ }
+ else
+ {
+ arg = cxarg (z1);
+ a = xadd (xmul (z2.re, xlog (mod)), xmul (z2.im, arg), 1);
+ b = xadd (xmul (z2.re, arg), xmul (z2.im, xlog (mod)), 0);
+ w.re = xmul (xexp (a), xcos (b));
+ w.im = xmul (xexp (a), xsin (b));
+ return w;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxprcmp.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxprcmp.c
new file mode 100644
index 00000000..5bea235e
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxprcmp.c
@@ -0,0 +1,97 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxprcmp_res
+cxprcmp (const cxpr* z1, const cxpr* z2)
+{
+ cxprcmp_res r;
+
+ r.re = xprcmp (&z1->re, &z2->re);
+ r.im = xprcmp (&z1->im, &z2->im);
+ return r;
+}
+
+int
+cxis0 (const cxpr* z)
+{
+ return (xis0 (&z->re) && xis0 (&z->im));
+}
+
+int
+cxnot0 (const cxpr* z)
+{
+ return (xnot0 (&z->re) || xnot0 (&z->im));
+}
+
+int
+cxeq (cxpr z1, cxpr z2)
+{
+ return (xprcmp (&z1.re, &z2.re) == 0 && xprcmp (&z1.im, &z2.im) == 0);
+}
+
+int
+cxneq (cxpr z1, cxpr z2)
+{
+ return (xprcmp (&z1.re, &z2.re) != 0 || xprcmp (&z1.im, &z2.im) != 0);
+}
+
+int
+cxgt (cxpr z1, cxpr z2)
+{
+ int rs = xprcmp (&z1.re, &z2.re);
+ int is = xprcmp (&z1.im, &z2.im);
+
+ if (rs > 0)
+ return (is >= 0);
+ else if (is > 0)
+ return (rs >= 0);
+ else
+ return 0;
+}
+
+int
+cxge (cxpr z1, cxpr z2)
+{
+ return (xprcmp (&z1.re, &z2.re) >= 0 && xprcmp (&z1.im, &z2.im) >= 0);
+}
+
+int
+cxlt (cxpr z1, cxpr z2)
+{
+ int rs = xprcmp (&z1.re, &z2.re);
+ int is = xprcmp (&z1.im, &z2.im);
+
+ if (rs < 0)
+ return (is <= 0);
+ else if (is < 0)
+ return (rs <= 0);
+ else
+ return 0;
+}
+
+int
+cxle (cxpr z1, cxpr z2)
+{
+ return (xprcmp (&z1.re, &z2.re) <= 0 && xprcmp (&z1.im, &z2.im) <= 0);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxpre.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxpre.h
new file mode 100644
index 00000000..d17770d1
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxpre.h
@@ -0,0 +1,176 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#ifndef _CXPRE_H_
+#define _CXPRE_H_
+
+#include
+#include"xpre.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ typedef struct
+ {
+ xpr re, im;
+ } cxpr;
+
+ typedef struct
+ {
+ int re, im;
+ } cxprcmp_res;
+
+ extern const cxpr cxZero;
+ extern const cxpr cxOne;
+ extern const cxpr cxIU;
+
+ cxpr cxreset (xpr re, xpr im);
+ cxpr cxconv (xpr x);
+ xpr cxre (cxpr z);
+ xpr cxim (cxpr z);
+ cxpr cxswap (cxpr z);
+
+ xpr cxabs (cxpr z);
+ xpr cxarg (cxpr z);
+ int cxrec (cxpr z, cxpr *w);
+
+ cxpr cxadd (cxpr z1, cxpr z2, int k);
+ cxpr cxsum (cxpr z1, cxpr z2);
+ cxpr cxsub (cxpr z1, cxpr z2);
+ cxpr cxmul (cxpr z1, cxpr z2);
+ /* Multiplication by a real number */
+ cxpr cxrmul (xpr c, cxpr z);
+
+ /* Multiplication by +i */
+ cxpr cxdrot (cxpr z);
+
+ /* Multiplication by -i */
+ cxpr cxrrot (cxpr z);
+ cxpr cxdiv (cxpr z1, cxpr z2);
+
+ cxpr cxgdiv (cxpr z1, cxpr z2);
+ cxpr cxidiv (cxpr z1, cxpr z2);
+ cxpr cxgmod (cxpr z1, cxpr z2);
+ cxpr cxmod (cxpr z1, cxpr z2);
+ cxpr cxpwr (cxpr z, int n);
+ cxpr cxsqr (cxpr z);
+ cxpr cxpow (cxpr z1, cxpr z2);
+ cxpr cxroot (cxpr z, int i, int n);
+ cxpr cxsqrt (cxpr z);
+
+ cxprcmp_res cxprcmp (const cxpr* z1, const cxpr* z2);
+ int cxis0 (const cxpr* z);
+ int cxnot0 (const cxpr* z);
+ int cxeq (cxpr z1, cxpr z2);
+ int cxneq (cxpr z1, cxpr z2);
+ int cxgt (cxpr z1, cxpr z2);
+ int cxge (cxpr z1, cxpr z2);
+ int cxlt (cxpr z1, cxpr z2);
+ int cxle (cxpr z1, cxpr z2);
+
+ cxpr cxconj (cxpr z);
+ cxpr cxneg (cxpr z);
+ cxpr cxinv (cxpr z);
+
+ cxpr cxexp (cxpr z);
+ cxpr cxexp10 (cxpr z);
+ cxpr cxexp2 (cxpr z);
+ cxpr cxlog (cxpr z);
+ cxpr cxlog10 (cxpr z);
+ cxpr cxlog2 (cxpr z);
+ cxpr cxlog_sqrt (cxpr z);
+ cxpr cxsin (cxpr z);
+ cxpr cxcos (cxpr z);
+ cxpr cxtan (cxpr z);
+ cxpr cxsinh (cxpr z);
+ cxpr cxcosh (cxpr z);
+ cxpr cxtanh (cxpr z);
+ cxpr cxasin (cxpr z);
+ cxpr cxacos (cxpr z);
+ cxpr cxatan (cxpr z);
+ cxpr cxasinh (cxpr z);
+ cxpr cxacosh (cxpr z);
+ cxpr cxatanh (cxpr z);
+
+ cxpr cxfloor (cxpr z);
+ cxpr cxceil (cxpr z);
+ cxpr cxround (cxpr z);
+ cxpr cxtrunc (cxpr z);
+ cxpr cxfrac (cxpr z);
+ cxpr cxfix (cxpr z);
+
+/* Conversion's functions */
+ cxpr strtocx (const char *q, char **endptr);
+ cxpr atocx (const char *s);
+ char *cxpr_asprint (cxpr z, int sc_not, int sign, int lim);
+ char *cxtoa (cxpr z, int lim);
+ cxpr dctocx (double re, double im);
+ cxpr fctocx (float re, float im);
+ cxpr ictocx (long re, long im);
+ cxpr uctocx (unsigned long re, unsigned long im);
+ void cxtodc (const cxpr *z, double *re, double *im);
+ void cxtofc (const cxpr *z, float *re, float *im);
+
+/* Output functions */
+
+#define CX1I_CHAR 'i'
+#define CX1I_STR "i"
+
+ void cxpr_print (FILE * stream, cxpr z, int sc_not, int sign,
+ int lim);
+ void cxprcxpr (cxpr z, int m);
+ void cxprint (FILE * stream, cxpr z);
+
+/* Special output functions and related macros */
+
+#define XFMT_STD 0
+#define XFMT_RAW 1
+#define XFMT_ALT 2
+
+#define CXDEF_LDEL '('
+#define CXDEF_RDEL ')'
+#define CX_SEPARATOR ", " /* TO BE USED WITH THE ALT FORMAT */
+#define CX_EMPTY_SEP " " /* TO BE USED WITH THE RAW FORMAT */
+#define CX_SEP_L 2 /* LENGTH OF THE SEPARATOR */
+
+ int cxfout (FILE * pf, xoutflags ofs, cxpr z);
+ int cxout (xoutflags ofs, cxpr z);
+ unsigned long
+ cxsout (char *s, unsigned long n, xoutflags ofs, cxpr z);
+
+#define CXRESET(re, im) (cxpr){re, im}
+#define CXCONV(x) (cxpr){x, xZero}
+#define CXRE(z) (z).re
+#define CXIM(z) (z).im
+#define CXSWAP(z) (cxpr){(z).im, (z).re}
+
+#define cxconvert cxconv
+#define cxdiff cxsub
+#define cxprod cxmul
+#define cxipow cxpwr
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _CXPRE_H_ */
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxtrig.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxtrig.c
new file mode 100644
index 00000000..39e5eeab
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxtrig.c
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+cxpr
+cxsin (cxpr z)
+{
+ cxpr w1, w2;
+
+ w1 = cxdrot (z); /* Now w1= i*z, where i={0,1} */
+ w2 = cxrrot (z); /* Now w2= -i*z, where i={0,1} */
+ w1 = cxsub (cxexp (w1), cxexp (w2));
+ w2.re = xpr2 (w1.im, -1);
+ w1.re.nmm[0] ^= xM_sgn;
+ w2.im = xpr2 (w1.re, -1); /* Now w2= (exp(i*z)-exp(-i*z))/2i */
+ return w2;
+}
+
+cxpr
+cxcos (cxpr z)
+{
+ cxpr w1, w2;
+
+ w1 = cxdrot (z); /* Now w1= i*z, where i={0,1} */
+ w2 = cxrrot (z); /* Now w2= -i*z, where i={0,1} */
+ w1 = cxsum (cxexp (w1), cxexp (w2));
+ w2.re = xpr2 (w1.re, -1);
+ w2.im = xpr2 (w1.im, -1);
+ return w2;
+}
+
+cxpr
+cxtan (cxpr z)
+{
+ if (xsigerr (xprcmp (&z.im, &xEmax) > 0, XFPOFLOW, NULL))
+ return cxIU;
+ else if (xsigerr (xprcmp (&z.im, &xEmin) < 0, XFPOFLOW, NULL))
+ return cxneg (cxIU);
+ else
+ {
+ cxpr w;
+
+ if (xsigerr (!cxrec (cxcos (z), &w), XEDOM, "cxtan()"))
+ return cxZero;
+ else
+ return cxmul (cxsin (z), w);
+ }
+}
+
+cxpr
+cxasin (cxpr z)
+{
+ cxpr w;
+ xpr ls, rs;
+
+ w = cxsqrt (cxsub (cxOne, cxsqr (z)));
+ ls = cxabs (cxsum (cxdrot (z), w));
+ rs = xmul (xVSV, cxabs (z));
+ if (xprcmp (&ls, &rs) < 0)
+ w = cxdrot (cxlog (cxsub (w, cxdrot (z))));
+ else
+ w = cxrrot (cxlog (cxsum (cxdrot (z), w)));
+ return w;
+}
+
+cxpr
+cxacos (cxpr z)
+{
+ cxpr w;
+ xpr ls, rs;
+
+ w = cxsqrt (cxsub (cxOne, cxsqr (z)));
+ ls = cxabs (cxsum (z, cxdrot (w)));
+ rs = xmul (xVSV, cxabs (z));
+ if (xprcmp (&ls, &rs) < 0)
+ w = cxdrot (cxlog (cxsub (z, cxdrot (w))));
+ else
+ w = cxrrot (cxlog (cxsum (z, cxdrot (w))));
+ return w;
+}
+
+cxpr
+cxatan (cxpr z)
+{
+ cxpr w;
+ xpr mod;
+ int errcond;
+
+ mod = xadd (xabs (z.im), xOne, 1);
+ errcond = xsgn (&z.re) == 0 && xsgn (&mod) == 0;
+ if (xsigerr (errcond, XEDOM, "cxatan()"))
+ return cxZero;
+ else
+ {
+ /* In this way, cxatan() works fine also with complex numbers */
+ /* very far from the origin. */
+ mod = cxabs (z);
+ if (xprcmp (&mod, &xVGV) > 0)
+ {
+ w = cxsqrt (cxsum (cxOne, cxsqr (z)));
+ w = cxdiv (cxsum (cxOne, cxdrot (z)), w);
+ w = cxrrot (cxlog (w));
+ }
+ else
+ {
+ w = cxdiv (cxsum (cxOne, cxdrot (z)), cxsub (cxOne, cxdrot (z)));
+ w = cxrrot (cxlog_sqrt (w));
+ }
+ return w;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/read_item.cc b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/read_item.cc
new file mode 100644
index 00000000..55cb6c1e
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/read_item.cc
@@ -0,0 +1,61 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include
+using namespace std;
+
+int
+hpa_read_item (istream& is, char* buff, unsigned size)
+{
+ if (size == 0 || !buff)
+ return 0;
+ else /* size > 0 */
+ {
+ unsigned i, n;
+ char ch;
+
+ i = 0;
+ while ((is.get (ch)))
+ {
+ if (!isspace (ch))
+ {
+ i = 1;
+ break;
+ }
+ }
+ if (i == 0)
+ return 0;
+ else
+ {
+ i = n = 0;
+ do
+ {
+ if(n
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include "xcomplex.h"
+
+using namespace std;
+
+#define BUFF_SIZE 10240 /* 10 Kb */
+
+ const xcomplex cxZERO = cxZero;
+ const xcomplex cxONE = cxOne;
+ const xcomplex cxI = cxIU;
+
+xoutflags xcomplex::ioflags = { XFMT_STD, XOUT_FIXED, 0, 0, 6, ' ', CXDEF_LDEL, CXDEF_RDEL };
+
+ostream&
+operator<< (ostream& os, const xcomplex& x)
+{
+ char buffer[BUFF_SIZE];
+
+ cxsout (buffer, BUFF_SIZE, x.ioflags, x.br);
+ return os << buffer;
+}
+
+istream&
+operator>> (istream& is, xcomplex& x)
+{
+ double_complex z;
+ istream& res = is >> z.re >> z.im;
+
+ x.br = dctocx (z.re, z.im);
+ return res;
+}
+
+xcomplex
+operator+ (const xcomplex& x1, const xcomplex& x2)
+{
+ return xcomplex(cxadd (x1.br, x2.br, 0));
+}
+
+xcomplex
+operator- (const xcomplex& x1, const xcomplex& x2)
+{
+ return xcomplex(cxadd (x1.br, x2.br, 1));
+}
+
+xcomplex
+operator* (const xcomplex& x1, const xcomplex& x2)
+{
+ return xcomplex(cxmul (x1.br, x2.br));
+}
+
+xcomplex
+operator/ (const xcomplex& x1, const xcomplex& x2)
+{
+ return xcomplex(cxdiv (x1.br, x2.br));
+}
+
+xcomplex
+operator% (const xcomplex& x1, int n)
+{
+ cxpr z;
+
+ z.re = xpr2 (x1.br.re, n);
+ z.im = xpr2 (x1.br.im, n);
+ return xcomplex (z);
+}
+
+int
+operator== (const xcomplex& x1, const xcomplex& x2)
+{
+ cxprcmp_res t;
+
+ t.re = xprcmp (&x1.br.re, &x2.br.re);
+ t.im = xprcmp (&x1.br.im, &x2.br.im);
+ return (t.re == 0 && t.im == 0);
+}
+
+int
+operator!= (const xcomplex& x1, const xcomplex& x2)
+{
+ cxprcmp_res t;
+
+ t.re = xprcmp (&x1.br.re, &x2.br.re);
+ t.im = xprcmp (&x1.br.im, &x2.br.im);
+ return (t.re != 0 || t.im != 0);
+}
+
+int
+operator<= (const xcomplex& x1, const xcomplex& x2)
+{
+ cxprcmp_res t;
+
+ t.re = xprcmp (&x1.br.re, &x2.br.re);
+ t.im = xprcmp (&x1.br.im, &x2.br.im);
+ return (t.re <= 0 && t.im <= 0);
+}
+
+int
+operator>= (const xcomplex& x1, const xcomplex& x2)
+{
+ cxprcmp_res t;
+
+ t.re = xprcmp (&x1.br.re, &x2.br.re);
+ t.im = xprcmp (&x1.br.im, &x2.br.im);
+ return (t.re >= 0 && t.im >= 0);
+}
+
+int
+operator< (const xcomplex& x1, const xcomplex& x2)
+{
+ cxprcmp_res t;
+
+ t.re = xprcmp (&x1.br.re, &x2.br.re);
+ t.im = xprcmp (&x1.br.im, &x2.br.im);
+ if (t.re < 0)
+ return (t.im <= 0);
+ else if (t.im < 0)
+ return (t.re <= 0);
+ else
+ return 0;
+}
+
+int
+operator> (const xcomplex& x1, const xcomplex& x2)
+{
+ cxprcmp_res t;
+
+ t.re = xprcmp (&x1.br.re, &x2.br.re);
+ t.im = xprcmp (&x1.br.im, &x2.br.im);
+ if (t.re > 0)
+ return (t.im >= 0);
+ else if (t.im > 0)
+ return (t.re >= 0);
+ else
+ return 0;
+}
+
+unsigned long
+sget (string s, unsigned long startp, xcomplex& x)
+{
+ const char *startptr;
+ char *tail;
+
+ if (startp >= s.length())
+ {
+ x.br = cxZero;
+ return 0;
+ }
+ else
+ {
+ startptr = s.c_str() + startp;
+ x.br = strtocx (startptr, &tail);
+ return tail - startptr;
+ }
+}
+
+const char*
+bget (const char* buff, xcomplex& x)
+{
+ char* tail;
+
+ if (!buff)
+ {
+ cerr << "*** HPA::xcomplex::bget(): the first argument is the null pointer" << endl;
+ return 0;
+ }
+ else
+ {
+ x.br = strtocx (buff, &tail);
+ return (const char*) tail;
+ }
+}
+
+xcomplex
+rmul (const xreal& x, const xcomplex& z)
+{
+ return xcomplex (cxrmul (x._2xpr(), z.br));
+}
+
+xcomplex
+gdiv (const xcomplex& x1, const xcomplex& x2)
+{
+ return cxgdiv (x1.br, x2.br);
+}
+
+xcomplex
+gmod (const xcomplex& x1, const xcomplex& x2)
+{
+ return cxgmod (x1.br, x2.br);
+}
+
+xcomplex
+idiv (const xcomplex& x1, const xcomplex& x2)
+{
+ return cxidiv (x1.br, x2.br);
+}
+
+xcomplex
+mod (const xcomplex& x1, const xcomplex& x2)
+{
+ return cxmod (x1.br, x2.br);
+}
+
+xcomplex
+conj (const xcomplex& z)
+{
+ return cxconj (z.br);
+}
+
+xcomplex
+inv (const xcomplex& z)
+{
+ return cxinv (z.br);
+}
+
+xcomplex
+swap (const xcomplex& z)
+{
+ return cxswap (z.br);
+}
+
+xcomplex
+drot (const xcomplex& z)
+{
+ return cxdrot (z.br);
+}
+
+xcomplex
+rrot (const xcomplex& z)
+{
+ return cxrrot (z.br);
+}
+
+xreal
+abs (const xcomplex& s)
+{
+ return xreal (cxabs (s.br));
+}
+
+xreal
+arg (const xcomplex& s)
+{
+ return xreal (cxarg (s.br));
+}
+
+/*
+ Some stuff must be added here
+*/
+
+xcomplex
+frac (const xcomplex& x)
+{
+ return cxfrac (x.br);
+}
+
+xcomplex
+trunc (const xcomplex& x)
+{
+ return cxtrunc (x.br);
+}
+
+xcomplex
+round (const xcomplex& x)
+{
+ return cxround (x.br);
+}
+
+xcomplex
+ceil (const xcomplex& x)
+{
+ return cxceil (x.br);
+}
+
+xcomplex
+floor (const xcomplex& x)
+{
+ return cxfloor (x.br);
+}
+
+xcomplex
+fix (const xcomplex& x)
+{
+ return cxfix (x.br);
+}
+
+xcomplex
+tan (const xcomplex& x)
+{
+ return cxtan (x.br);
+}
+
+xcomplex
+sin (const xcomplex& x)
+{
+ return cxsin (x.br);
+}
+
+xcomplex
+cos (const xcomplex& x)
+{
+ return cxcos (x.br);
+}
+
+xcomplex
+atan (const xcomplex& a)
+{
+ return cxatan (a.br);
+}
+
+xcomplex
+asin (const xcomplex& a)
+{
+ return cxasin (a.br);
+}
+
+xcomplex
+acos (const xcomplex& a)
+{
+ return cxacos (a.br);
+}
+
+xcomplex
+sqr (const xcomplex& u)
+{
+ return cxsqr (u.br);
+}
+
+xcomplex
+sqrt (const xcomplex& u)
+{
+ return cxsqrt (u.br);
+}
+
+xcomplex
+root (const xcomplex& u, int i, int n)
+{
+ return cxroot (u.br, i, n);
+}
+
+xcomplex
+exp (const xcomplex& u)
+{
+ return cxexp (u.br);
+}
+
+xcomplex
+exp2 (const xcomplex& u)
+{
+ return cxexp2 (u.br);
+}
+
+xcomplex
+exp10 (const xcomplex& u)
+{
+ return cxexp10 (u.br);
+}
+
+xcomplex
+log (const xcomplex& u)
+{
+ return cxlog (u.br);
+}
+
+xcomplex
+log2 (const xcomplex& u)
+{
+ return cxlog2 (u.br);
+}
+
+xcomplex
+log10 (const xcomplex& u)
+{
+ return cxlog10 (u.br);
+}
+
+xcomplex
+log_sqrt (const xcomplex& u)
+{
+ return cxlog_sqrt (u.br);
+}
+
+xcomplex
+tanh (const xcomplex& v)
+{
+ return cxtanh (v.br);
+}
+
+xcomplex
+sinh (const xcomplex& v)
+{
+ return cxsinh (v.br);
+}
+
+xcomplex
+cosh (const xcomplex& v)
+{
+ return cxcosh (v.br);
+}
+
+xcomplex
+atanh (const xcomplex& v)
+{
+ return cxatanh (v.br);
+}
+
+xcomplex
+asinh (const xcomplex& v)
+{
+ return cxasinh (v.br);
+}
+
+xcomplex
+acosh (const xcomplex& v)
+{
+ return cxacosh (v.br);
+}
+
+xcomplex
+pow (const xcomplex& x, const xcomplex& y)
+{
+ return cxpow (x.br, y.br);
+}
+
+extern int
+hpa_read_item (istream& is, char* buff, unsigned size);
+
+int
+xcomplex::getfrom (istream& is)
+{
+ char buffer[BUFF_SIZE];
+ int n = hpa_read_item (is, buffer, BUFF_SIZE);
+
+ br = atocx (buffer);
+ return n;
+}
+
+int
+xcomplex::print (ostream& os, int sc_not, int sign, int lim) const
+{
+ char* s = cxpr_asprint (br, sc_not, sign, lim);
+
+ if (!s)
+ return -1;
+ else
+ {
+ os << s;
+ free ((void*) s);
+ return 0;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xcomplex.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xcomplex.h
new file mode 100644
index 00000000..5eac2151
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xcomplex.h
@@ -0,0 +1,391 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#ifndef _XCOMPLEX_H_
+#define _XCOMPLEX_H_
+
+#include "../cxpre.h"
+#include
+#include
+#include "xreal.h"
+
+using std::istream;
+using std::ostream;
+using std::string;
+
+ struct double_complex {
+ double re, im;
+ };
+
+ struct float_complex {
+ float re, im;
+ };
+
+typedef struct xcomplex
+{
+ friend ostream& operator<< (ostream& os, const xcomplex& x);
+ friend istream& operator>> (istream& is, xcomplex& x);
+ friend xcomplex operator+ (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex operator- (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex operator* (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex operator/ (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex operator% (const xcomplex& x1, int n);
+ friend int operator== (const xcomplex& x1, const xcomplex& x2);
+ friend int operator!= (const xcomplex& x1, const xcomplex& x2);
+ friend int operator<= (const xcomplex& x1, const xcomplex& x2);
+ friend int operator>= (const xcomplex& x1, const xcomplex& x2);
+ friend int operator< (const xcomplex& x1, const xcomplex& x2);
+ friend int operator> (const xcomplex& x1, const xcomplex& x2);
+ /* Friend functions */
+ friend unsigned long sget (string s, unsigned long startptr, xcomplex& x);
+ friend const char* bget (const char* buff, xcomplex& x);
+ friend xcomplex rmul (const xreal& x, const xcomplex& z);
+ friend xcomplex gdiv (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex gmod (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex idiv (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex mod (const xcomplex& x1, const xcomplex& x2);
+ friend xcomplex conj (const xcomplex& z);
+ friend xcomplex inv (const xcomplex& z);
+ friend xcomplex swap (const xcomplex& z);
+ friend xcomplex drot (const xcomplex& z);
+ friend xcomplex rrot (const xcomplex& z);
+ friend xreal abs (const xcomplex& s);
+ friend xreal arg (const xcomplex& s);
+ friend xcomplex frac (const xcomplex& x);
+ friend xcomplex trunc (const xcomplex& x);
+ friend xcomplex round (const xcomplex& x);
+ friend xcomplex ceil (const xcomplex& x);
+ friend xcomplex floor (const xcomplex& x);
+ friend xcomplex fix (const xcomplex& x);
+ friend xcomplex tan (const xcomplex& x);
+ friend xcomplex sin (const xcomplex& x);
+ friend xcomplex cos (const xcomplex& x);
+ friend xcomplex atan (const xcomplex& a);
+ friend xcomplex asin (const xcomplex& a);
+ friend xcomplex acos (const xcomplex& a);
+ friend xcomplex sqr (const xcomplex& u);
+ friend xcomplex sqrt (const xcomplex& u);
+ friend xcomplex root (const xcomplex& u, int i, int n);
+ friend xcomplex exp (const xcomplex& u);
+ friend xcomplex exp2 (const xcomplex& u);
+ friend xcomplex exp10 (const xcomplex& u);
+ friend xcomplex log (const xcomplex& u);
+ friend xcomplex log2 (const xcomplex& u);
+ friend xcomplex log10 (const xcomplex& u);
+ friend xcomplex log_sqrt (const xcomplex& u);
+ friend xcomplex tanh (const xcomplex& v);
+ friend xcomplex sinh (const xcomplex& v);
+ friend xcomplex cosh (const xcomplex& v);
+ friend xcomplex atanh (const xcomplex& v);
+ friend xcomplex asinh (const xcomplex& v);
+ friend xcomplex acosh (const xcomplex& v);
+ friend xcomplex pow (const xcomplex& x, const xcomplex& y);
+
+ xcomplex (const cxpr* px = &cxZero) : br(*px) { }
+ xcomplex (cxpr x) : br(x) { }
+ xcomplex (xpr x, xpr y = xZero) {
+ br.re = x, br.im = y;
+ }
+ xcomplex (xreal x, xreal y = xZERO) {
+ br.re = x._2xpr(), br.im = y._2xpr();
+ }
+ xcomplex (double x, double y = 0.0) {
+ br = dctocx (x, y);
+ }
+ xcomplex (float x, float y = 0.0) {
+ br = fctocx (x, y);
+ }
+ xcomplex (int m, int n = 0) {
+ br = ictocx (m, n);
+ }
+ xcomplex (long m, long n = 0) {
+ br = ictocx (m, n);
+ }
+ xcomplex (unsigned int u, unsigned int v = 0U) {
+ br = uctocx (u, v);
+ }
+ xcomplex (unsigned long u, unsigned long v = 0U) {
+ br = uctocx (u, v);
+ }
+ xcomplex (const char* str, char** endptr = 0) {
+ br = strtocx (str, endptr);
+ }
+ xcomplex (string str) {
+ br = atocx (str.c_str ());
+ }
+ xcomplex (const xcomplex& x) {
+ br = x.br;
+ }
+ /* Assignment operators */
+ xcomplex& operator= (const xcomplex& x) {
+ br = x.br;
+ return *this;
+ }
+ xcomplex& operator+= (const xcomplex& x) {
+ br = cxadd (br, x.br, 0);
+ return *this;
+ }
+ xcomplex& operator-= (const xcomplex& x) {
+ br = cxadd (br, x.br, 1);
+ return *this;
+ }
+ xcomplex& operator*= (const xcomplex& x) {
+ br = cxmul (br, x.br);
+ return *this;
+ }
+ xcomplex& operator*= (const xreal& x) {
+ br = cxrmul (x._2xpr(), br);
+ return *this;
+ }
+ xcomplex& operator/= (const xcomplex& x) {
+ br = cxdiv (br, x.br);
+ return *this;
+ }
+ xcomplex& operator%= (int n) {
+ br.re = xpr2 (br.re, n);
+ br.im = xpr2 (br.im, n);
+ return *this;
+ }
+ /* Increment operators */
+ xcomplex& operator++ () {
+ br = cxadd (br, cxOne, 0);
+ return *this;
+ }
+ xcomplex& operator-- () {
+ br = cxadd (br, cxOne, 1);
+ return *this;
+ }
+ xcomplex& operator++ (int dummy) {
+ br = cxadd (br, cxOne, 0);
+ return *this;
+ }
+ xcomplex& operator-- (int dummy) {
+ br = cxadd (br, cxOne, 1);
+ return *this;
+ }
+ /* Destructor */
+ ~xcomplex (void) {
+ br = cxZero;
+ }
+ /* Integer exponent power */
+ xcomplex operator() (int n) const {
+ return cxpwr (br, n);
+ }
+ /* Negation */
+ xcomplex operator-() const {
+ return cxneg (br);
+ }
+ int operator!() const {
+ return cxis0 (&br);
+ }
+ /* Functions for conversions */
+ double_complex _2dcomplex () const {
+ double_complex z;
+
+ cxtodc (&br, &z.re, &z.im);
+ return z;
+ }
+ float_complex _2fcomplex() const {
+ float_complex z;
+
+ cxtofc (&br, &z.re, &z.im);
+ return z;
+ }
+ cxpr _2cxpr() const {
+ return br;
+ }
+ string _2string() const {
+ char* s = cxpr_asprint (br, 1, 1, (XDIM * 48) / 10 - 2);
+ string str(s);
+
+ free ((void*) s);
+ return str;
+ }
+ /* Real and imaginary part */
+ xreal real () const {
+ return xreal (br.re);
+ }
+ xreal imag () const {
+ return xreal (br.im);
+ }
+ xpr _real () const {
+ return br.re;
+ }
+ xpr _imag () const {
+ return br.im;
+ }
+ double dreal () const {
+ return xtodbl (br.re);
+ }
+ double dimag () const {
+ return xtodbl (br.im);
+ }
+ double freal () const {
+ return xtoflt (br.re);
+ }
+ double fimag () const {
+ return xtoflt (br.im);
+ }
+ string sreal () const {
+ char* s = xpr_asprint (br.re, 1, 1, (XDIM * 48) / 10 - 2);
+ string str(s);
+
+ free ((void*) s);
+ return str;
+ }
+ string simag () const {
+ char* s = xpr_asprint (br.im, 1, 1, (XDIM * 48) / 10 - 2);
+ string str(s);
+
+ free ((void*) s);
+ return str;
+ }
+ void real (const xreal& x) {
+ br.re = x._2xpr();
+ }
+ void imag (const xreal& x) {
+ br.im = x._2xpr();
+ }
+ void real (xpr x) {
+ br.re = x;
+ }
+ void imag (xpr x) {
+ br.im = x;
+ }
+ void real (const xpr* px) {
+ br.re = *px;
+ }
+ void imag (const xpr* px) {
+ br.im = *px;
+ }
+ void real (double x) {
+ br.re = dbltox(x);
+ }
+ void imag (double x) {
+ br.im = dbltox(x);
+ }
+ void real (float x) {
+ br.re = flttox(x);
+ }
+ void imag (float x) {
+ br.im = flttox(x);
+ }
+ void real (int x) {
+ br.re = inttox(x);
+ }
+ void imag (int x) {
+ br.im = inttox(x);
+ }
+ void real (long x) {
+ br.re = inttox(x);
+ }
+ void imag (long x) {
+ br.im = inttox(x);
+ }
+ void real (unsigned int x) {
+ br.re = uinttox(x);
+ }
+ void imag (unsigned int x) {
+ br.im = uinttox(x);
+ }
+ void real (unsigned long x) {
+ br.re = uinttox(x);
+ }
+ void imag (unsigned long x) {
+ br.im = uinttox(x);
+ }
+ void real (const char* str, char** endptr = 0) {
+ br.re = strtox (str, endptr);
+ }
+ void imag (const char* str, char** endptr = 0) {
+ br.im = strtox (str, endptr);
+ }
+ void real (string str) {
+ br.re = atox (str.c_str ());
+ }
+ void imag (string str) {
+ br.im = atox (str.c_str ());
+ }
+ int getfrom (istream& is);
+ int print (ostream& os, int sc_not, int sign, int lim) const;
+ char* asprint (int sc_not, int sign, int lim) const {
+ return cxpr_asprint (br, sc_not, sign, lim);
+ }
+ static void set_fmt (short format) {
+ ioflags.fmt = format;
+ }
+ static void set_notation (short notat) {
+ ioflags.notat = notat;
+ }
+ static void set_signflag (short onoff) {
+ ioflags.sf = onoff;
+ }
+ static void set_mfwd (short wd) {
+ ioflags.mfwd = wd;
+ }
+ static void set_lim (short lim) {
+ ioflags.lim = lim;
+ }
+ static void set_padding (signed char ch) {
+ ioflags.padding = ch;
+ }
+ static void set_ldelim (signed char ch) {
+ ioflags.ldel = ch;
+ }
+ static void set_rdelim (signed char ch) {
+ ioflags.rdel = ch;
+ }
+ static short get_fmt (void) {
+ return ioflags.fmt;
+ }
+ static short get_notation (void) {
+ return ioflags.notat;
+ }
+ static short get_signflag (void) {
+ return ioflags.sf;
+ }
+ static short get_mfwd (void) {
+ return ioflags.mfwd;
+ }
+ static short get_lim (void) {
+ return ioflags.lim;
+ }
+ static signed char get_padding (void) {
+ return ioflags.padding;
+ }
+ static signed char get_ldelim (void) {
+ return ioflags.ldel;
+ }
+ static signed char get_rdelim (void) {
+ return ioflags.rdel;
+ }
+ cxpr br; /* binary representation */
+ static xoutflags ioflags; /* output flags */
+} ComplexNumber;
+
+ extern const xcomplex cxZERO, cxONE, cxI;
+#define xi cxI
+#define xj cxI
+#define _i cxI
+#define _j cxI
+
+#endif /* _XCOMPLEX_H_ */
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xreal.cc b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xreal.cc
new file mode 100644
index 00000000..04c9d734
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xreal.cc
@@ -0,0 +1,376 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include "xreal.h"
+
+using namespace std;
+
+#define BUFF_SIZE 5120 /* 5 Kb */
+
+const xreal xZERO = xZero;
+const xreal xONE = xOne;
+const xreal xTWO = xTwo;
+const xreal xTEN = xTen;
+const xreal xINF = xPinf;
+const xreal x_INF = xMinf;
+const xreal xNAN = xNaN;
+const xreal xPI = xPi;
+const xreal xPI2 = xPi2;
+const xreal xPI4 = xPi4;
+const xreal xEE = xEe;
+const xreal xSQRT2 = xSqrt2;
+const xreal xLN2 = xLn2;
+const xreal xLN10 = xLn10;
+const xreal xLOG2_E = xLog2_e;
+const xreal xLOG2_10 = xLog2_10;
+const xreal xLOG10_E = xLog10_e;
+const xreal x_floatMin = HPA_MIN;
+const xreal x_floatMax = HPA_MAX;
+xoutflags xreal::ioflags = { -1, XOUT_FIXED, 0, 0, 6, ' ', -1, -1 };
+
+ostream& operator<< (ostream& os, const xreal& x)
+{
+ char buffer[BUFF_SIZE];
+
+ xsout (buffer, BUFF_SIZE, x.ioflags, x.br);
+ return os << buffer;
+}
+
+istream& operator>> (istream& is, xreal& x)
+{
+ double f;
+ istream& res = is >> f;
+
+ x.br = dbltox (f);
+ return res;
+}
+
+xreal operator+ (const xreal& x1, const xreal& x2)
+{
+ return xreal(xadd (x1.br, x2.br, 0));
+}
+
+xreal operator- (const xreal& x1, const xreal& x2)
+{
+ return xreal(xadd (x1.br, x2.br, 1));
+}
+
+xreal operator* (const xreal& x1, const xreal& x2)
+{
+ return xreal(xmul (x1.br, x2.br));
+}
+
+xreal operator/ (const xreal& x1, const xreal& x2)
+{
+ return xreal(xdiv (x1.br, x2.br));
+}
+
+xreal operator% (const xreal& x, int n)
+{
+ return xpr2 (x.br, n);
+}
+
+int operator== (const xreal& x1, const xreal& x2)
+{
+ return (xprcmp (&x1.br, &x2.br) == 0);
+}
+
+int operator!= (const xreal& x1, const xreal& x2)
+{
+ return (xprcmp (&x1.br, &x2.br) != 0);
+}
+
+int operator<= (const xreal& x1, const xreal& x2)
+{
+ return (xprcmp (&x1.br, &x2.br) <= 0);
+}
+
+int operator>= (const xreal& x1, const xreal& x2)
+{
+ return (xprcmp (&x1.br, &x2.br) >= 0);
+}
+
+int operator< (const xreal& x1, const xreal& x2)
+{
+ return (xprcmp (&x1.br, &x2.br) < 0);
+}
+
+int operator> (const xreal& x1, const xreal& x2)
+{
+ return (xprcmp (&x1.br, &x2.br) > 0);
+}
+
+unsigned long sget (string s, unsigned long startp, xreal& x)
+{
+ const char *startptr;
+ char *tail;
+
+ if (startp >= s.length())
+ {
+ x.br = xZero;
+ return 0;
+ }
+ else
+ {
+ startptr = s.c_str() + startp;
+ x.br = strtox (startptr, &tail);
+ return tail - startptr;
+ }
+}
+
+const char* bget (const char* buff, xreal& x)
+{
+ char* tail;
+
+ if (!buff)
+ {
+ cerr << "*** HPA::xreal::bget(): the first argument is the null pointer" << endl;
+ return 0;
+ }
+ else
+ {
+ x.br = strtox (buff, &tail);
+ return (const char*) tail;
+ }
+}
+
+int compare (const xreal& x1, const xreal& x2)
+{
+ return xprcmp (&x1.br, &x2.br);
+}
+
+int isNaN (const xreal& x)
+{
+ return xisNaN (&x.br);
+}
+
+xreal abs (const xreal& s)
+{
+ return xabs (s.br);
+}
+
+xreal frexp (const xreal& s, int *p)
+{
+ return xfrexp (s.br, p);
+}
+
+xreal qfmod (const xreal& s, const xreal& t, xreal& q)
+{
+ return xfmod (s.br, t.br, &q.br);
+}
+
+xreal fmod (const xreal& s, const xreal& t)
+{
+ xpr q;
+
+ return xfmod (s.br, t.br, &q);
+}
+
+xreal sfmod (const xreal& s, int *p)
+{
+ return xsfmod (s.br, p);
+}
+
+xreal frac (const xreal& x)
+{
+ return xfrac (x.br);
+}
+
+xreal trunc (const xreal& x)
+{
+ return xtrunc (x.br);
+}
+
+xreal round (const xreal& x)
+{
+ return xround (x.br);
+}
+
+xreal ceil (const xreal& x)
+{
+ return xceil (x.br);
+}
+
+xreal floor (const xreal& x)
+{
+ return xfloor (x.br);
+}
+
+xreal fix (const xreal& x)
+{
+ return xfix (x.br);
+}
+
+xreal tan (const xreal& x)
+{
+ return xtan (x.br);
+}
+
+xreal sin (const xreal& x)
+{
+ return xsin (x.br);
+}
+
+xreal cos (const xreal& x)
+{
+ return xcos (x.br);
+}
+
+xreal atan (const xreal& a)
+{
+ return xatan (a.br);
+}
+
+xreal asin (const xreal& a)
+{
+ return xasin (a.br);
+}
+
+xreal acos (const xreal& a)
+{
+ return xacos (a.br);
+}
+
+xreal atan2 (const xreal& y, const xreal& x)
+{
+ return xatan2 (y.br, x.br);
+}
+
+xreal sqrt (const xreal& u)
+{
+ return xsqrt (u.br);
+}
+
+xreal exp (const xreal& u)
+{
+ return xexp (u.br);
+}
+
+xreal exp2 (const xreal& u)
+{
+ return xexp2 (u.br);
+}
+
+xreal exp10 (const xreal& u)
+{
+ return xexp10 (u.br);
+}
+
+xreal log (const xreal& u)
+{
+ return xlog (u.br);
+}
+
+xreal log2 (const xreal& u)
+{
+ return xlog2 (u.br);
+}
+
+xreal log10 (const xreal& u)
+{
+ return xlog10 (u.br);
+}
+
+xreal tanh (const xreal& v)
+{
+ return xtanh (v.br);
+}
+
+xreal sinh (const xreal& v)
+{
+ return xsinh (v.br);
+}
+
+xreal cosh (const xreal& v)
+{
+ return xcosh (v.br);
+}
+
+xreal atanh (const xreal& v)
+{
+ return xatanh (v.br);
+}
+
+xreal asinh (const xreal& v)
+{
+ return xasinh (v.br);
+}
+
+xreal acosh (const xreal& v)
+{
+ return xacosh (v.br);
+}
+
+xreal pow (const xreal& x, const xreal& y)
+{
+ return xpow (x.br, y.br);
+}
+
+extern int hpa_read_item (istream& is, char* buff, unsigned size);
+
+int xreal::getfrom (istream& is)
+{
+ char buffer[BUFF_SIZE];
+ int n = hpa_read_item (is, buffer, BUFF_SIZE);
+
+ br = atox (buffer);
+ return n;
+}
+
+int xreal::print (ostream& os, int sc_not, int sign, int lim) const
+{
+ char* s = xpr_asprint (br, sc_not, sign, lim);
+
+ if (!s)
+ return -1;
+ else
+ {
+ os << s;
+ free ((void*) s);
+ return 0;
+ }
+}
+
+extern "C" {
+
+extern int xErrNo;
+
+}
+
+int xmatherrcode ()
+{
+#ifdef XERR_DFL
+ return xErrNo;
+#else
+ return -1;
+#endif
+}
+
+void clear_xmatherr ()
+{
+#ifdef XERR_DFL
+ xErrNo = 0;
+#else
+ cerr << "*** HPA: Feature not available, sorry" << endl;
+#endif
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xreal.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xreal.h
new file mode 100644
index 00000000..4970a046
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/cxxsrc/xreal.h
@@ -0,0 +1,244 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#ifndef _XREAL_H_
+#define _XREAL_H_
+
+#include "../xpre.h"
+#include
+#include
+#include
+
+using std::ostream;
+using std::istream;
+using std::string;
+
+typedef struct xreal
+{
+ friend ostream& operator<< (ostream& os, const xreal& x);
+ friend istream& operator>> (istream& is, xreal& x);
+ friend xreal operator+ (const xreal& x1, const xreal& x2);
+ friend xreal operator- (const xreal& x1, const xreal& x2);
+ friend xreal operator* (const xreal& x1, const xreal& x2);
+ friend xreal operator/ (const xreal& x1, const xreal& x2);
+ friend xreal operator% (const xreal& x1, int n);
+ friend int operator== (const xreal& x1, const xreal& x2);
+ friend int operator!= (const xreal& x1, const xreal& x2);
+ friend int operator<= (const xreal& x1, const xreal& x2);
+ friend int operator>= (const xreal& x1, const xreal& x2);
+ friend int operator< (const xreal& x1, const xreal& x2);
+ friend int operator> (const xreal& x1, const xreal& x2);
+ /* Friend functions */
+ friend unsigned long sget (string s, unsigned long startptr, xreal& x);
+ friend const char* bget (const char* buff, xreal& x);
+ friend int compare (const xreal& x1, const xreal& x2);
+ friend int isNaN (const xreal& x);
+ friend xreal abs (const xreal& s);
+ friend xreal frexp (const xreal& s, int *p);
+ friend xreal qfmod (const xreal& s, const xreal& t, xreal& q);
+ friend xreal fmod (const xreal& s, const xreal& t);
+ friend xreal sfmod (const xreal& s, int *p);
+ friend xreal frac (const xreal& x);
+ friend xreal trunc (const xreal& x);
+ friend xreal round (const xreal& x);
+ friend xreal ceil (const xreal& x);
+ friend xreal floor (const xreal& x);
+ friend xreal fix (const xreal& x);
+ friend xreal tan (const xreal& x);
+ friend xreal sin (const xreal& x);
+ friend xreal cos (const xreal& x);
+ friend xreal atan (const xreal& a);
+ friend xreal atan2 (const xreal& y, const xreal& x);
+ friend xreal asin (const xreal& a);
+ friend xreal acos (const xreal& a);
+ friend xreal sqrt (const xreal& u);
+ friend xreal exp (const xreal& u);
+ friend xreal exp2 (const xreal& u);
+ friend xreal exp10 (const xreal& u);
+ friend xreal log (const xreal& u);
+ friend xreal log2 (const xreal& u);
+ friend xreal log10 (const xreal& u);
+ friend xreal tanh (const xreal& v);
+ friend xreal sinh (const xreal& v);
+ friend xreal cosh (const xreal& v);
+ friend xreal atanh (const xreal& v);
+ friend xreal asinh (const xreal& v);
+ friend xreal acosh (const xreal& v);
+ friend xreal pow (const xreal& x, const xreal& y);
+
+ xreal (const xpr* px = &xZero) : br(*px) { }
+ xreal (xpr x) : br(x) { }
+ xreal (double x) {
+ br = dbltox (x);
+ }
+ xreal (float x) {
+ br = flttox (x);
+ }
+ xreal (int n) {
+ br = inttox (n);
+ }
+ xreal (long n) {
+ br = inttox (n);
+ }
+ xreal (unsigned int u) {
+ br = uinttox (u);
+ }
+ xreal (unsigned long u) {
+ br = uinttox (u);
+ }
+ xreal (const char* str, char** endptr = 0) {
+ br = strtox (str, endptr);
+ }
+ xreal (string str) {
+ br = atox (str.c_str ());
+ }
+ xreal (const xreal& x) {
+ br = x.br;
+ }
+ /* Assignment operators */
+ xreal& operator= (const xreal& x) {
+ br = x.br;
+ return *this;
+ }
+ xreal& operator+= (const xreal& x) {
+ br = xadd (br, x.br, 0);
+ return *this;
+ }
+ xreal& operator-= (const xreal& x) {
+ br = xadd (br, x.br, 1);
+ return *this;
+ }
+ xreal& operator*= (const xreal& x) {
+ br = xmul (br, x.br);
+ return *this;
+ }
+ xreal& operator/= (const xreal& x) {
+ br = xdiv (br, x.br);
+ return *this;
+ }
+ xreal& operator%= (int n) {
+ br = xpr2 (br, n);
+ return *this;
+ }
+ /* Increment operators */
+ xreal& operator++ () {
+ br = xadd (br, xOne, 0);
+ return *this;
+ }
+ xreal& operator-- () {
+ br = xadd (br, xOne, 1);
+ return *this;
+ }
+ xreal& operator++ (int dummy) {
+ br = xadd (br, xOne, 0);
+ return *this;
+ }
+ xreal& operator-- (int dummy) {
+ br = xadd (br, xOne, 1);
+ return *this;
+ }
+ /* Destructor */
+ ~xreal (void) {
+ br = xZero;
+ }
+ /* Integer exponent power */
+ xreal operator() (int n) const {
+ return xpwr (br, n);
+ }
+ /* Negation */
+ xreal operator-() const {
+ return xneg (br);
+ }
+ int operator!() const {
+ return xis0 (&br);
+ }
+ int isneg() const {
+ return x_neg ((xpr*)&br);
+ }
+ int exp() const {
+ return x_exp ((xpr*)&br);
+ }
+ /* Functions for conversions */
+ double _2double () const {
+ return xtodbl(br);
+ }
+ float _2float() const {
+ return xtoflt(br);
+ }
+ xpr _2xpr() const {
+ return br;
+ }
+ string _2string() const {
+ char* s = xpr_asprint (br, 1, 1, (XDIM * 48) / 10 - 2);
+ string str(s);
+
+ free ((void*) s);
+ return str;
+ }
+ int getfrom (istream& is);
+ int print (ostream& os, int sc_not, int sign, int lim) const;
+ char* asprint (int sc_not, int sign, int lim) const {
+ return xpr_asprint (br, sc_not, sign, lim);
+ }
+ static void set_notation (short notat) {
+ ioflags.notat = notat;
+ }
+ static void set_signflag (short onoff) {
+ ioflags.sf = onoff;
+ }
+ static void set_mfwd (short wd) {
+ ioflags.mfwd = wd;
+ }
+ static void set_lim (short lim) {
+ ioflags.lim = lim;
+ }
+ static void set_padding (signed char ch) {
+ ioflags.padding = ch;
+ }
+ static short get_notation (void) {
+ return ioflags.notat;
+ }
+ static short get_signflag (void) {
+ return ioflags.sf;
+ }
+ static short get_mfwd (void) {
+ return ioflags.mfwd;
+ }
+ static short get_lim (void) {
+ return ioflags.lim;
+ }
+ static signed char get_padding (void) {
+ return ioflags.padding;
+ }
+ xpr br; /* binary representation */
+ static xoutflags ioflags; /* output flags */
+} RealNumber;
+
+ int xmatherrcode ();
+ void clear_xmatherr ();
+
+ extern const xreal xZERO, xONE, xTWO, xTEN;
+ extern const xreal xINF, x_INF, xNAN;
+ extern const xreal xPI, xPI2, xPI4, xEE, xSQRT2;
+ extern const xreal xLN2, xLN10, xLOG2_E, xLOG2_10, xLOG10_E, x_floatMin, x_floatMax;
+
+#endif /* _XREAL_H_ */
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/hpa.txt b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/hpa.txt
new file mode 100644
index 00000000..e3a00b40
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/hpa.txt
@@ -0,0 +1,4604 @@
+HIGH PRECISION ARITHMETIC LIBRARY PROGRAMMER'S MANUAL
+Copyright (C) 2005 - 2010 Ivano Primi
+Last Update: 2010-07-21
+
+
+------------------------------------------------------------------------
+
+ 1. Summary
+ 2. License
+ 3. General Technical Comments
+ 4. General overview
+ 5. Dealing with runtime errors
+ 6. Compiling and linking
+ 7. Real arithmetic
+ 7.1. Real constants
+ 7.2. Extended Precision Floating Point Arithmetic
+ 7.3. Extended Precision Math Library
+ 7.4. Applications of Extended Precision Arithmetic
+ 8. Complex Arithmetic
+ 8.1. Complex constants
+ 8.2. Extended Precision Complex Arithmetic
+ 8.3. Extended Precision Complex Math Library
+ 9. The C++ interface
+ 10. Compiling and linking with the C++ wrapper
+ 11. The xreal class
+ 12. The xcomplex class
+ 13. Acknowledgments
+ 14. GNU Free Documentation License
+
+
+------------------------------------------------------------------------
+
+Permission is granted to copy, distribute and/or modify this document under
+the terms of the GNU Free Documentation License, Version 1.3 or any later
+version published by the Free Software Foundation; with no
+Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
+A copy of the license is included in the
+section "GNU Free Documentation License" (#GNUFDL).
+
+
+ 1. Summary
+ ==========
+
+The High Precision Arithmetic (HPA) library implements a high
+precision floating point arithmetic together with a
+comprehensive set of support functions. The general
+areas covered by these functions include:
+
+- Extended Precision Arithmetic,
+- Extended Precision Math Library,
+- Applications of High Precision Computation.
+
+The math library support includes evaluation of
+trigonometric, inverse trigonometric, hyperbolic,
+logarithm, and exponential functions at the same
+precision as the floating point math itself.
+The HPA library also supports high precision complex
+arithmetic and includes an Extended Precision
+Complex Math Library.
+
+
+ 2. License
+ ==========
+
+The HPA library has been derived
+from a branch of the source code of the CCMath library,
+which is a work by Daniel A. Atkinson.
+Since Daniel A. Atkinson released the code of the CCMath Library
+under GNU Lesser General Public License, it has been possible
+for Ivano Primi to modify, complete and redistribute this source code
+under the same terms.
+
+The HPA (abbreviation of High Precision Arithmetic) Library is then
+copyrighted by Ivano Primi and
+Daniel A. Atkinson. As for the CCMath Library, its source code
+is released under the terms of the GNU Lesser General
+Public License, as published by the Free Software Foundation;
+either version 2.1 of the License, or (at your option) any later version.
+
+The HPA library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this library; if not, see http://www.gnu.org/licenses/.
+Write to the email address
+
+ .
+
+if you want to ask for additional information, report bugs or submit patches.
+
+
+ 3. General Technical Comments
+ =============================
+
+The functions forming the HPA library are all implemented in a portable
+fashion in the C language.
+The IEEE 754 standard for floating point hardware and software is assumed
+in the PC/Unix version of this library. The normal configuration of the library
+employs a floating point mantissa of 112 bits, which corresponds approximately to a
+32 decimal digit precision. Higher precision is available as an option.
+An extended floating point number is represented as a combination of the
+following elements:
+
+- sign bit(s): 0 -> positive, 1 -> negative ;
+- exponent(e): 15-bit biased integer (bias=16383) ;
+- mantissa(m): 7 words of 16 bit length with the leading 1 explicitly represented .
+
+The range of representable numbers is then given by
+
+
+ 2^16384 > x > 2^[-16383]
+
+or
+
+
+ 1.19*10^4932 > x > 1.68*10^-[4932].
+
+Special values of the exponent are:
+
+- all ones -> infinity (floating point overflow)
+- all zeros -> number = zero.
+
+Underflow in operations is handled by a flush to zero. Thus, a number with
+the exponent zero and nonzero mantissa is invalid (not-a-number).
+From the point of view of the HPA library, a complex number is simply
+a structure formed by two extended floating point numbers, representing
+respectively the real and the imaginary part of the complex number.
+
+
+ 4. General overview
+ ===================
+
+The HPA library is composed by two modules. The first one is formed
+by the functions for real arithmetic, i.e. by the functions
+operating on real arguments. The second one is formed by all functions
+which manipulate complex arguments.
+The lists of the functions which compose the HPA library
+are in the header files xpre.h and cxpre.h.
+xpre.h is the header file for real arithmetic, it contains the definition
+of an extended precision real number (struct xpr),
+and the declarations of the functions provided by the library
+to manipulate real arguments.
+The numeric type struct xpr can be used to declare and define
+real variables, just as in
+
+
+ struct xpr q;
+
+The size of a variable of type struct xpr is given by
+(2 x XDIM + 2) bytes, where XDIM is a constant defined in the file
+xpre.h (namely, in the file hpaconf.h which is included by
+xpre.h).
+
+cxpre.h is the header file for complex arithmetic, it contains
+the definition of an extended precision complex number
+(struct cxpr), and the declarations of the functions supplied
+by the library to manipulate complex arguments.
+The numeric type struct cxpr can be used to declare and define
+complex variables, just as in
+
+
+ struct cxpr q;
+
+The size of a variable of type struct cxpr is given by
+(4 x XDIM + 4) bytes, where XDIM is the same constant as above.
+
+Before declaring or defining variables of type struct xpr
+and before using anyone of the functions declared in the header file
+xpre.h, you have to insert the line
+
+
+ #include
+
+in your source code file.
+Similarly, before declaring or defining variables of type struct cxpr
+and before using anyone of the functions declared in the header file
+cxpre.h, you have to add the line
+
+
+ #include
+
+to your source code file.
+
+After including in your source code the header file xpre.h or,
+if you also need functions handling complex arguments, the header file
+cxpre.h, you can start to use the HPA library
+by defining all variables and calling
+all functions which are necessary for your computations.
+In fact, the HPA library DOES NOT REQUIRE that a special initialization
+routine must be called before any other function of the library.
+Moreover, variables of type struct xpr or struct cxpr
+DO NOT NEED to be initialized before they can be used.
+
+When the HPA library was written, a sort of namespace was created
+for all the identifiers used by the library.
+This has been achieved by sticking to the following rules:
+
+1. Identifiers of functions and types are lowercase; the unique
+exception to this rule is the function xisNaN(). Their names start
+by x, if they are defined in xpre.h, or by cx, if they are defined
+in cxpre.h, with the only exception of a few functions,
+which have a name ending by tox or tocx:
+
+ strtox(), strtocx(), atox(), atocx(),
+
+
+ dbltox(), dctocx(), flttox(), fctocx(),
+
+
+ inttox(), ictocx(), uinttox(), uctocx();
+
+2. The names of the macros defined by the HPA library are all uppercase
+and start by X or CX;
+3. The names of the global constants defined by the HPA library start
+by x (real constants) or by cx (complex constants) and the letter
+which immediately follows this prefix is always uppercase, just as in
+xZero, xPi, cxOne, cxIU (IU stays for imaginary
+unit);
+4. The unique global variable defined by the HPA library is an
+error indicator of int type, whose name is xErrNo.
+
+This is a trivial program showing the use of the HPA library:
+
+
+
+ #include
+ #include
+
+ int main (void)
+ {
+ struct xpr s;
+ int i, n;
+
+ do
+ {
+ printf ("Give me a number, n = ? \t");
+ scanf ("%d", &n);
+ s = xZero;
+ for (i = 0; i <= n; i++)
+ s = xadd (s, xpr2(xOne, i), 0);
+ printf ("The sum 2^0 + 2^1 + ... + 2^n is equal to\n");
+ xprxpr (s, 30);
+ putchar ('\n');
+ } while (n > 0);
+ return 0;
+ }
+
+
+This program takes in input from the user an integer value n
+and prints on the screen the sum of the first n powers of 2.
+In the program we use the functions xpr2() and xprxpr().
+xpr2(x, n), where n is an integer, returns x* 2^n, while
+xprxpr(x, m), where m is an integer, prints on the screen
+the number x with m decimal digits after the decimal point (.) .
+
+The HPA library is NOT thread safe. Some of the HPA internal
+data could get corrupted if multiple HPA functions are active at the
+same time. This is due to the fact that some functions of the HPA library
+use static variables to store information.
+The user should then guarantee that only one thread is performing
+HPA functions. This can usually be achieved by a call to the operating
+system to obtain a semaphore, mutex, or critical code section;
+the operating system will then guarantee that only one HPA thread will be
+active at a time.
+
+
+ 5. Dealing with runtime errors
+ ==============================
+
+During the use of the HPA library it could happen to pass
+to a function an illegal argument, namely, an argument whose
+value is not compatible with the mathematical definition of the function.
+For example, this occurs when a negative value is passed to
+the function xsqrt(). This function computes and returns
+the (real) square root of its argument, but the square root of a number
+is defined only for non-negative numbers.
+So, if x is less than zero, xsqrt(x) can not
+be computed and a mathematical error occurs, a so called domain error.
+Another type of mathematical error occurs when the second argument
+of the division function (xdiv()) is zero: since it is impossible
+to divide a number by zero, a division by zero error occurs.
+What exactly happens when a mathematical error is detected during the
+execution of a function depends on the way the HPA library was compiled
+when it was installed on the system where you are working.
+If, during the installation process, the default setting was left
+unchanged, then, whenever a runtime error occurs within a function of the HPA
+library, this function will set an external error indicator to
+a suitable value. This value can be looked up later
+to know what exactly went wrong.
+The name of the variable of type int used as error indicator
+is xErrNo. Before any function of the HPA library is
+executed, the value of xErrNo is 0.
+If a mathematical error occurs when the first HPA function is called,
+then xErrNo is set to a suitable positive value,
+which indicates the exact type of the error.
+After, xErrNo is modified if and only if, during the execution of
+an HPA function, another mathematical error occurs. xErrNo is never
+reset to 0 by the HPA library; therefore, in order to detect
+possible errors, one has to
+set xErrNo to zero before calling any function of the HPA library.
+An example of error handling is given by:
+
+
+
+ #include
+ #include
+
+ extern int xErrNo;
+
+ int main (void)
+ {
+ int n;
+ struct xpr sr;
+
+ do
+ {
+ printf ("Give me a number, n = ? \t");
+ scanf ("%d", &n);
+ xErrNo = 0;
+ sr = xsqrt (inttox (n));
+ if (xErrNo == 0)
+ {
+ printf ("The square root of %d is\n", n);
+ xprxpr (sr, 30);
+ putchar ('\n');
+ }
+ else
+ fprintf (stderr, "*** Error: Out of domain\n");
+ } while (n != 0);
+ return 0;
+ }
+
+
+In this program xErrNo is reset to zero, at each execution of the
+do {...} while(); loop, before the call of the xsqrt() function.
+
+However, the HPA library could be compiled to deal differently with
+runtime errors.
+For example, in case of error a suitable message could be
+printed on stderr and the library could also cause the
+termination of the calling program via exit(1).
+Finally, the library could also be compiled to ignore
+any mathematical error (sigh !). To know how the routines of
+the HPA library deal with errors is sufficient to examine the file
+hpaconf.h (which is automatically included by xpre.h and
+cxpre.h). This file defines the macro:
+
+- XERR_DFL to mean that, in case of error,
+xErrNo is suitably set;
+- XERR_WARN to mean that, in case of error,
+a suitable message is printed on stderr;
+- XERR_EXIT to mean that, in case of error,
+the calling program is terminated
+through a call to exit(1) after
+printing a message on stderr;
+- XERR_IGN to mean that, in case of error,
+nothing is done or signaled.
+
+When the macro XERR_DFL is defined, the header file xpre.h
+also defines the macros XENONE, XEDIV, XEDOM,
+XEBADEXP, XFPOFLOW and XNERR:
+
+
+ #define XENONE 0 /* No error */
+ #define XEDIV 1 /* Division by zero */
+ #define XEDOM 2 /* Out of domain */
+ #define XEBADEXP 3 /* Bad exponent */
+ #define XFPOFLOW 4 /* Floating point overflow */
+
+ #define XNERR 4 /* Number of the non-null error codes */
+
+These macros can be used, together with xErrNo, to recover the exact
+type of the error occurred during the execution of a routine
+of the HPA library.
+
+
+ 6. Compiling and linking
+ ========================
+
+Together with the HPA library is installed a little and simple
+program called hpaconf.
+You can use it to quickly compile and build your programs.
+If PREFIX is the root directory chosen to install the HPA library
+(the default value for PREFIX is /usr/local), then hpaconf
+should be installed inside PREFIX/bin. You can know where hpaconf
+is installed by launching the command
+
+
+ which hpaconf
+
+in your console or terminal.
+In the following it is assumed that the directory PREFIX/bin
+is included in your PATH environment variable (This is surely
+true if the command which was able to find hpaconf).
+
+hpaconf recognizes four options:
+
+-v
+ to return the version of HPA installed on your system,
+-c
+ to return the flags needed to compile with HPA,
+-l
+ to return the flags needed to link against HPA,
+-n
+ to print a newline at the end of the output.
+
+The option -v cannot be used together with the options -c and -l,
+but it may be used together with -n:
+
+
+ hpaconf -v
+
+prints on the standard output (console)
+the version of HPA installed on your system,
+
+
+ hpaconf -v -n
+
+or
+
+
+ hpaconf -n -v
+
+(order does not matter) behaves exactly the same but
+also prints a newline to force the following output to be written on the next line.
+
+The options -c and -l cannot be used together with -v, but they
+can be used both at the same time and can also be accompanied by the option
+-n. Of course, order does not matter.
+
+
+ hpaconf -c
+
+prints on the standard output the flags needed to compile with HPA,
+
+
+ hpaconf -l
+
+prints on the standard output the flags needed to link against HPA,
+
+
+ hpaconf -c -l
+
+or
+
+
+ hpaconf -l -c
+
+prints both the flags to compile with HPA and the flags to link against HPA.
+
+If the option -n is added, then the information printed is followed
+by a newline.
+An example will show the usefulness of hpaconf.
+To compile the source file example.c you should tell the compiler
+where looking for the header files of HPA and for the library itself;
+to do this it is sufficient to specify the related paths through the options
+-I and -L, at least if you are using GCC/G++ as C/C++ compiler.
+But in this way you are constrained to remember the path
+where HPA was installed, and this is quite uncomfortable.
+With hpaconf you can simply use the command
+
+
+ cc -c $(hpaconf -c) example.c
+
+or
+
+
+ cc -c `hpaconf -c` example.c
+
+to compile the file example.c and obtain the object file example.o.
+The previous one is the right form of the command
+for a shell sh compatible, like ash, bash or ksh.
+If you are using another shell, probably the
+right form to obtain the expansion of the command hpaconf -c
+will be another one (see the manual of your preferred shell for this).
+On GNU/Linux, bash is the default shell for all users. If this is
+not true for your machine, ask your system administrator.
+Once you have obtained the object file example.o, you may do the linkage
+by using the command (for a shell sh-compatible):
+
+
+ cc example.o $(hpaconf -l) -o example
+
+or
+
+
+ cc example.o `hpaconf -l` -o example
+
+If you want, you may also compile and build at the same time by using
+
+
+ cc example.c $(hpaconf -c -l) -o example
+
+or
+
+
+ cc example.c `hpaconf -c -l` -o example
+
+which will compile example.c and build the program example.
+Naturally, compiling and building at the same time is only
+possible when the source code of your program is entirely contained in one
+file.
+
+The hpaconf program may also tell you which options were used
+to compile the HPA library for the system where you are working.
+This information is displayed, together with hints about usage, when
+hpaconf is called with no options. This is the output obtained
+on my personal machine:
+
+
+ ivano@darkstar[~]$ hpaconf
+ *** Usage: hpaconf [-v] [-n] or
+ *** hpaconf [-c] [-l] [-n]
+
+ *** Meaning of the options:
+ -v returns the current version of the HPA library,
+ -c returns the flags to compile with HPA library,
+ -l returns the flags to link against HPA library,
+ -n adds a newline at the end of the output.
+
+ ----- Features of the HPA library (including build options) -----
+
+ Size of an extended precision floating point value (in bytes): 16
+ Number of bits available for the sign: 1
+ Number of bits available for the exponent: 15
+ Number of bits available for the mantissa: 112
+ Decimal digits of accuracy: ~33
+ Dynamic range supported: 2^16384 > x > 2^(-16383) i.e.
+ 1.19*10^4932 > x > 1.68*10^-(4932)
+ In case of floating point error
+ the global (extern) variable 'xErrNo' is suitably set
+
+The first value shown after the header Features of the HPA library
+is the size of a variable of struct xpr type. When I installed the
+HPA library on my machine, I chose to compile it by setting XDIM
+to 7. Then a variable of type struct xpr turns out to have a size of
+16 = 2 * 7 + 2 bytes.
+Since XDIM could have been set to another value on the system
+where you are working (XDIM could also have the values
+11, 15, 19, 23, 27 and 31), the first value shown by hpaconf
+could differ on your machine.
+The next 2 values (bits available for sign and exponent) are
+the same for all installations.
+The decimal digits of accuracy depend on the value of XDIM,
+namely, they increase together with XDIM till to a maximum of
+149 when XDIM is 31. As you can see, the value of XDIM
+determines the accuracy provided by the mathematical functions of
+the HPA library. Even if a larger value for XDIM implies
+a greater accuracy, together with XDIM increase the memory
+and the time requested by the routines of the HPA library
+to perform their computations.
+
+The dynamic range supported by the HPA library is always the same, or almost.
+The HPA library can be compiled to deal differently with
+the error conditions (see previous section (#runtime_errors)).
+In the last line of the output of hpaconf, you can find
+information about the way runtime errors are handled.
+This information can also be retrieved from the file
+hpaconf.h, as explained in the previous section.
+
+The file hpaconf.h also defines the macro HPA_VERSION, a string
+containing the version number of the release of the
+HPA library currently in use.
+
+
+ 7. Real arithmetic
+ ==================
+
+The first module of the HPA library is made of functions for
+Extended Precision Floating Point Arithmetic, functions of the
+Extended Precision Math Library, and of applications of the Extended
+Precision Arithmetic. They are all declared in the file xpre.h
+together with some macros and numerical constants.
+The header file xpre.h also defines the structure xoutflags:
+
+
+ struct xoutflags
+ {
+ short fmt, notat, sf, mfwd, lim;
+ signed char padding, ldel, rdel;
+ };
+
+A structure of such kind is used by the output functions
+xfout(), xout() and xsout() to know how they have to print
+numbers.
+
+The field notat refers to the notation: it can
+be equal to XOUT_SCIENTIFIC (scientific notation) or to XOUT_FIXED
+(floating point notation).
+
+Both XOUT_SCIENTIFIC and XOUT_FIXED are
+macros defined inside xpre.h.
+
+The field sf refers to the sign: if sf is not zero, then every non-negative
+number is printed with a plus sign (+) ahead.
+
+The field mfwd indicates the minimum field width to use in
+printing numbers. When mfwd is zero no minimum field width is used.
+When mfwd is negative, then the actual minimum field width is given
+by -mfwd and the printed number is left adjusted on the
+field boundary (default is right justification).
+
+lim has a different meaning depending on the notation in use.
+Together with the scientific notation, lim gives the number of
+decimal digits to the right of the decimal point
+(lim+1 = total digits displayed). Otherwise, lim + 1 is the
+number of significant digits displayed. When lim is negative,
+the default value (6) is used.
+
+Finally, padding defines the padding character to use together
+with a non-zero minimum field width.
+If padding is negative, then the default padding char (i.e. the
+blank character) is used.
+
+The fields fmt, ldel and rdel are ignored by the functions
+xfout(), xout() and xsout(). They are only used by the
+functions cxfout(), cxout() and cxsout() to
+format and print complex numbers.
+
+fmt specifies the format to use in printing complex numbers.
+The possible values for fmt are XFMT_STD, XFMT_RAW and XFMT_ALT
+(these macros are declared inside cxpre.h).
+If fmt == XFMT_STD, then the complex number (a, b) is printed
+using the notation a+bi or a-bi (depending on the sign of b).
+Of course, a and b are printed according to the rules
+exposed above.
+If fmt == XFMT_RAW, then (a, b) is printed in the form
+
+
+ ab
+
+just like in
+
+
+ 1.0 2.5
+
+assuming that a = 1.0 and b = 2.5.
+Finally, if fmt == XFMT_ALT, then (a,b) is printed
+as
+
+
+ a, b
+
+where and are the characters
+given by the fields ldel and rdel respectively.
+If ldel < 0 or rdel < 0, then ( or ) is used as
+default / .
+
+Care that none of the functions xfout(), xout(), xsout(),
+cxfout(), cxout() or cxsout() adds a newline at the end
+of the printed number.
+
+
+ 7.1. Real constants
+ ===================
+
+The header file xpre.h defines several constants. Between the
+constants defined in xpre.h there are those ones
+corresponding to particular mathematical values:
+
+
+ extern const struct xpr xZero, xOne, xTwo, xTen;
+ extern const struct xpr xPinf, xMinf, xNaN;
+ extern const struct xpr xPi, xPi2, xPi4, xEe, xSqrt2;
+ extern const struct xpr xLn2, xLn10, xLog2_e, xLog2_10,
+ xLog10_e;
+
+xZero (= 0), xOne (= 1), xTwo (= 2)and xTen (= 10)
+do not need a comment.
+xPi, xPi2, xPi4, xEe, xSqrt2, xLn2, xLn10, xLog2_e, xLog2_10, xLog10_e
+represent, respectively, the values PI (= 3.14159...), PI/2, PI/4,
+e (= 2.7182818...), square root of 2 (= 1.4142135...), natural
+logarithm of 2 and 10, base-2 logarithm of e and 10, 10-base
+logarithm of e.
+
+xPinf, xMinf and xNan are special values: xPinf represents the value
++oo (plus infinity), xMinf the value -oo (minus infinity) and xNaN
+is used to mean an invalid number (NaN stays for Not a Number).
+xPinf and xMinf are usually returned by a function to signal a
+floating point overflow, positive and negative respectively, while
+xNaN is returned by the functions converting ASCII strings to floating
+point numbers to indicate that the string given to them as argument
+does not contain any valid number.
+xPinf, xMinf and xNaN should never be used as arguments for functions,
+since this has unpredictable results.
+
+
+ 7.2. Extended Precision Floating Point Arithmetic
+ =================================================
+
+The arithmetic functions support the basic computations and input/output
+operations for extended precision floating point mathematics. Some
+of the operations supply capabilities designed to enhance the computational
+efficiency of this arithmetic (e.g., xpwr).
+What follows is their complete list including the synopsis for each of them.
+
+
+
+
+
+xadd - Add or subtract two extended precision numbers.
+
+
+ struct xpr xadd(struct xpr s,struct xpr t,int f)
+
+
+- s = structure containing first number;
+- t = structure containing second number;
+- f = control flag: if 0, then s and t are added,
+else they are subtracted (s-t).
+
+The value returned by xadd() is the result
+of the addition/subtraction. xadd() can return xPinf or xMinf to
+signal a floating point overflow.
+
+-------------------------------------------------------------------------
+xmul - Multiply two extended precision numbers.
+
+
+ struct xpr xmul(struct xpr s,struct xpr t)
+
+
+- s = structure containing first number;
+- t = structure containing second number.
+
+The value returned by xmul() is the product s*t.
+It can be xPinf or xMinf in case of overflow.
+
+-------------------------------------------------------------------------
+xdiv - Divide one extended precision number by a second.
+
+
+ struct xpr xdiv(struct xpr s,struct xpr t)
+
+
+- s = structure containing numerator;
+- t = structure containing denominator.
+
+The value returned by xdiv() is the quotient s/t.
+
+-------------------------------------------------------------------------
+xneg - Change sign (unary minus).
+
+
+ struct xpr xneg(struct xpr s)
+
+
+- s = structure containing input number.
+
+The value returned by xneg() is a structure containing
+its argument with the changed sign.
+
+-------------------------------------------------------------------------
+xabs - Compute absolute value.
+
+
+ struct xpr xabs(struct xpr s)
+
+
+- s = structure containing input number.
+
+The value returned by xabs() is a structure containing
+the absolute value of its argument.
+
+-------------------------------------------------------------------------
+x_exp - Extract the binary exponent.
+
+
+ int x_exp(const struct xpr *p)
+
+
+- p = pointer to an extended precision number.
+
+The value returned by x_exp() is the binary exponent
+(power of 2) of the number pointed to by p.
+
+-------------------------------------------------------------------------
+x_neg - Test the sign of an extended precision number.
+
+
+ int x_neg(const struct xpr *p)
+
+
+- p = pointer to an extended precision number.
+
+The value returned by x_neg() is a sign flag, with
+0 meaning positive input, 1 negative input. The input
+is, of course, the number pointed to by p. Note that
+neither x_exp() nor x_neg() alter the input number.
+
+-------------------------------------------------------------------------
+xpwr - Raise to integer powers.
+
+
+ struct xpr xpwr(struct xpr s,int n)
+
+
+- s = structure containing input number;
+- n = power desired.
+
+The return value is the nth power of the first argument.
+
+-------------------------------------------------------------------------
+xpr2 - Multiplication by a power of 2.
+
+
+ struct xpr xpr2(struct xpr s,int m)
+
+
+- s = structure containing input number;
+- m = power of two desired.
+
+The return value is the product of
+the first argument by the mth power of two.
+xpr2() returns xZero in case of underflow, xPinf or
+xMinf in case of overflow.
+
+-------------------------------------------------------------------------
+xpow - Power function.
+
+
+ struct xpr xpow (struct xpr x, struct xpr y)
+
+
+- x = base;
+- y = exponent.
+
+The return value is the
+power of the first argument raised to the second one.
+Note that the first argument must be greater than zero.
+
+-------------------------------------------------------------------------
+xprcmp - Compare two extended precision numbers.
+
+
+ int xprcmp (const struct xpr *p, const struct xpr *q)
+
+
+- p = pointer to first number;
+- q = pointer to second number.
+
+The value returned by xprcmp() is a comparison flag, with
+ 1 meaning *p greater than *q, 0 meaning *p equal
+to *q, and -1 meaning *p less than *q. Note that
+the input numbers are not altered by xprcmp().
+
+-------------------------------------------------------------------------
+xeq - Check if two numbers are or are not equal.
+
+
+ int xeq (struct xpr x1, struct xpr x2)
+
+
+- x1 = first number;
+- x2 = second number.
+
+The return value is 0 if x1 and x2 are different, else a
+non-null value.
+
+-------------------------------------------------------------------------
+xneq - Check if two numbers are or are not equal.
+
+
+ int xneq (struct xpr x1, struct xpr x2)
+
+
+- x1 = first number;
+- x2 = second number.
+
+The return value is 0 if x1 and x2 are equal, else
+a non-null value.
+
+-------------------------------------------------------------------------
+xgt - Check if a number is greater than another one.
+
+
+ int xgt (struct xpr x1, struct xpr x2)
+
+
+- x1 = first number;
+- x2 = second number.
+
+The return value is 0 if x1 is less or equal to x2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+xge - Check if a number is greater or equal to another one.
+
+
+ int xge (struct xpr x1, struct xpr x2)
+
+
+- x1 = first number;
+- x2 = second number.
+
+The return value is 0 if x1 is less than x2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+xlt - Check if a number is less than another one.
+
+
+ int xlt (struct xpr x1, struct xpr x2)
+
+
+- x1 = first number;
+- x2 = second number.
+
+The return value is 0 if x1 is greater or equal to x2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+xle - Check if a number is less or equal to another one.
+
+
+ int xle (struct xpr x1, struct xpr x2)
+
+
+- x1 = first number;
+- x2 = second number.
+
+The return value is 0 if x1 is greater than x2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+xisNaN - Check if a number is valid or not.
+
+
+ int xisNaN (const struct xpr *u)
+
+
+- u = pointer to a structure containing a number.
+
+The return value is 0 if *u is a valid number,
+else a non-null value.
+
+Remark:
+A number is considered invalid (not-a-number) when its
+exponent is zero but not its mantissa.
+
+-------------------------------------------------------------------------
+xisPinf - Check if a number is equal to +oo.
+
+
+ int xisPinf (const struct xpr *u)
+
+
+- u = pointer to a structure containing a number.
+
+The return value is 1 if *u is equal to
+xPinf (+oo), 0 otherwise.
+
+-------------------------------------------------------------------------
+xisMinf - Check if a number is equal to -oo.
+
+
+ int xisMinf (const struct xpr *u)
+
+
+- u = pointer to a structure containing a number.
+
+The return value is 1 if *u is equal to
+xMinf (-oo), 0 otherwise.
+
+-------------------------------------------------------------------------
+xisordnumb - Check if a given number is an ordinary number.
+
+
+ int xisordnumb (const struct xpr *u)
+
+
+- u = pointer to a structure containing a number.
+
+The return value is 1 if *u is a valid number
+and is neither xPinf (+oo) nor xMinf (-oo),
+else 0.
+
+-------------------------------------------------------------------------
+xis0 - Compare a number with zero.
+
+
+ int xis0 (const struct xpr *u)
+
+
+- u = pointer to a structure containing a number.
+
+The return value is 0 if *u is not zero, else a non-zero value.
+
+-------------------------------------------------------------------------
+xnot0 - Compare a number with zero.
+
+
+ int xnot0 (const struct xpr *u)
+
+
+- u = pointer to a structure containing a number.
+
+The return value is 0 if *u is zero, else a non-zero value.
+
+-------------------------------------------------------------------------
+xsgn - Obtain the sign of a number.
+
+
+ int xsgn (const struct xpr *u)
+
+
+- u = pointer to a structure containing a number.
+
+The return value is 0 when *u is zero or
+is an invalid number (not-a-number), 1 if *u is positive,
+-1 if *u is negative.
+
+Remark:
+xPinf is considered a positive value, xMinf a negative value.
+
+-------------------------------------------------------------------------
+xtodbl - Cast extended precision numbers to double precision ones.
+
+
+ double xtodbl(struct xpr s)
+
+
+- s = structure containing extended precision input.
+
+The return value is the double precision float corresponding
+to s.
+
+-------------------------------------------------------------------------
+dbltox - Convert double precision numbers to extended precision ones.
+
+
+ struct xpr dbltox(double y)
+
+
+- y = double precision floating point input.
+
+The return value is a structure containing extended equivalent
+of y.
+
+-------------------------------------------------------------------------
+xtoflt - Cast extended precision numbers to single precision ones.
+
+
+ float xtoflt(struct xpr s)
+
+
+- s = structure containing extended precision input.
+
+The return value is the single precision float corresponding
+to s.
+
+-------------------------------------------------------------------------
+flttox - Convert single precision numbers to extended precision ones.
+
+
+ struct xpr flttox(float y)
+
+
+- y = single precision floating point input.
+
+The return value is a structure containing extended equivalent
+of y.
+
+-------------------------------------------------------------------------
+inttox - Convert signed integers to extended precision numbers.
+
+
+ struct xpr inttox(long n)
+
+
+- n = integer input.
+
+The return value is a structure containing extended equivalent
+of n.
+
+-------------------------------------------------------------------------
+uinttox - Convert unsigned integers to extended precision numbers.
+
+
+ struct xpr uinttox(unsigned long n)
+
+
+- n = integer input.
+
+The return value is a structure containing extended equivalent
+of n.
+
+-------------------------------------------------------------------------
+strtox - Convert a floating point number,
+expressed as a decimal ASCII string
+in a form consistent with C, into the extended precision format.
+
+
+ struct xpr strtox (const char* s, char** endptr)
+
+
+- s = pointer to a null terminated ASCII string expressing a
+decimal number;
+- endptr = NULL, or address of a pointer defined
+outside strtox().
+
+The value returned by strtox() is a structure containing
+the input number in the extended precision format.
+
+Remarks:
+The strtox() function converts the initial portion of the string pointed to
+by s to its extended precision representation.
+
+The expected form of the (initial portion of the) string is: optional
+leading white space as recognized by the standard library function
+isspace(), an optional plus (+) or minus sign (-), and
+then a decimal number.
+A decimal number consists of a nonempty sequence of decimal digits possibly
+containing a radix character (decimal point, i.e. '.'), optionally
+followed by a decimal exponent. A decimal exponent consists of an
+E or e, followed by an optional plus or minus sign, followed by
+a non-empty sequence of decimal digits, and indicates multiplication by
+a power of 10.
+
+This function returns the converted value, if any.
+If the correct value would cause overflow, then xPinf
+or xMinf is returned, according to the sign of the value.
+If the correct value would cause underflow, xZero is returned.
+If no conversion is performed, xNaN is returned.
+
+If endptr is not NULL, a pointer to the character after the last character
+used in the conversion is stored in the location referenced by
+endptr.
+If no conversion is performed, the value of s is
+stored in the location referenced by endptr.
+
+-------------------------------------------------------------------------
+atox - Convert a floating point number,
+expressed as a decimal ASCII string
+in a form consistent with C, into the extended precision format.
+
+
+ struct xpr atox(const char *s)
+
+
+- s = pointer to a null terminated ASCII string expressing a
+decimal number.
+
+
+Remark:
+The call atox(s) is equivalent to strtox(s, NULL).
+
+-------------------------------------------------------------------------
+xfmod - This function is the extended precision analog of the
+fmod function from the C standard library.
+
+
+ struct xpr xfmod(struct xpr s,struct xpr t,struct xpr* q)
+
+
+- s = structure containing argument of fmod;
+- t = structure containing base number (t must be different from zero);
+- q = pointer to store for output integer m.
+
+The return value is the extended number with same sign as s
+and absolute value less than that of t, satisfying
+s = m*t + x if s*t>0, or
+s = -m*t + x if s*t<0.
+
+-------------------------------------------------------------------------
+xfrexp - This function is the extended precision analog of the
+frexp function from the C standard library.
+
+
+ struct xpr xfrexp(struct xpr s,int *p)
+
+
+- s = structure containing argument;
+- p = pointer to store for output exponent e.
+
+The return value is the extended number satisfying
+x = s*2^(-e) with (-1 < x < +1).
+
+-------------------------------------------------------------------------
+xfrac - This function returns the fractional part of the
+input number.
+
+
+ struct xpr xfrac (struct xpr s)
+
+
+- s = structure containing argument.
+
+The return value is the fractional part of the number s, with
+the same sign as s.
+
+Remark:
+The fractional part of the number s is 0 if s is an
+integer number, otherwise is given by (-)0.xyz..., where
+xyz... are the digits of s following the radix character
+(.) in the decimal representation. xfrac(s) has always
+the same sign as s.
+
+-------------------------------------------------------------------------
+xtrunc - This function returns the integer part of the input number.
+
+
+ struct xpr xtrunc (struct xpr s)
+
+
+- s = structure containing argument.
+
+The return value is the integer part of the number s, with
+the same sign as s.
+
+Remark:
+
+The integer part of the number s is given by (-)xyz..., where
+xyz... are the digits of s before the radix character (.) in
+its decimal representation.
+
+-------------------------------------------------------------------------
+xfix - Obtain the integer part of a number (2nd method).
+
+
+ struct xpr xfix (struct xpr s)
+
+
+- s = structure containing argument.
+
+Remark:
+
+xfix() is provided as an alternative to xtrunc(). xfix() tries
+to take into account possible rounding errors and cancel their
+effects. The use of xfix() is strongly suggested whenever the argument
+is presumed to be an integer number, but it is reasonable to expect
+that some rounding errors make its actual value a bit different from
+that one it should be.
+For instance, when sizeof(struct xpr) == 64, on my machine I
+obtain
+
+
+ xtrunc (xdiv (inttox(100), inttox(100))) == xZero
+
+
+while the expect result is xOne. This happens since
+xdiv (inttox(100), inttox(100)) returns a number a bit lower
+than 1. On the other hand
+
+
+ xfix (xdiv (inttox(100), inttox(100))) == xOne .
+
+
+Since xfix() introduces another type of rounding error
+to give the correct answer in the cases similar to the previous
+one, it is not always the right choice.
+
+-------------------------------------------------------------------------
+xround - Round an extended precision number to its nearest integer
+value (halfway cases are rounded away from zero).
+
+
+ struct xpr xround (struct xpr s)
+
+
+- s = structure containing argument.
+
+The return value is the integer value nearest to s.
+
+-------------------------------------------------------------------------
+xceil - Round an extended precision number to the smallest integral
+value not less than it.
+
+
+ struct xpr xceil (struct xpr s)
+
+
+- s = structure containing argument.
+
+The return value is the smallest integral value not less than
+the argument.
+
+-------------------------------------------------------------------------
+xfloor - Round an extended precision number to the largest integral
+value not greater than it.
+
+
+ struct xpr xfloor (struct xpr s)
+
+
+- s = structure containing argument.
+
+The return value is the largest integral value not greater than
+the argument.
+
+-------------------------------------------------------------------------
+xpr_print - Print an extended precision number in scientific or
+floating point format to a given file.
+
+
+ void xpr_print (FILE* stream, struct xpr u, int sc_not,
+ int sign, int lim)
+
+
+- stream = file where the number must be printed;
+- u = structure containing number to print;
+- sc_not = zero to mean floating point format,
+not zero to mean scientific format;
+- sign = not zero to put a plus sign (+) before the number if
+it is non-negative (in case of negative number a minus sign (-)
+is printed even if the parameter sign is zero);
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed) in
+case of scientific format, otherwise number of significant digits - 1
+(lim+1 = total of significant digits).
+
+-------------------------------------------------------------------------
+xpr_asprint - Convert an extended precision number to a string.
+
+
+ char* xpr_asprint (struct xpr u, int sc_not, int sign, int lim)
+
+
+- u = structure containing number to print;
+- sc_not = zero to mean floating point format, not zero to mean scientific format;
+- sign = not zero to put a plus sign (+) before the number if
+it is non-negative (in case of negative number a minus sign (-)
+is printed even if the parameter sign is zero);
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed) in
+case of scientific format, otherwise number of significant digits - 1
+(lim+1 = total of significant digits).
+
+xpr_asprint() returns the string with the converted number.
+The memory for this string is calloc'ed inside the function.
+
+-------------------------------------------------------------------------
+xprxpr - Print an extended precision number in scientific format.
+
+
+ void xprxpr(struct xpr u,int lim)
+
+
+- u = structure containing number to print;
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed).
+
+Remark:
+
+
+ xprxpr(u, lim)
+
+
+is equivalent to
+
+
+ xpr_print(stdout, u, 1, 0, lim)
+
+-------------------------------------------------------------------------
+xtoa - This function converts an extended precision number to a
+string. Scientific format is always used.
+
+
+ char* xtoa (struct xpr u,int lim)
+
+
+- u = structure containing number to print;
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed).
+
+Remark:
+
+
+ xtoa(u, lim)
+
+
+is equivalent to
+
+
+ xpr_asprint(u, 1, 0, lim)
+
+-------------------------------------------------------------------------
+xbprint - Print an extended precision number in binary format.
+
+
+ void xbprint (FILE* stream, struct xpr u)
+
+
+- stream = file where the number must be printed;
+- u = structure containing number to print.
+
+The xbprint() function supports a bit oriented analysis of
+rounding error effects. It always prints a newline (\n)
+at the end of the binary string.
+
+-------------------------------------------------------------------------
+xprint - Print an extended precision number as a string of
+hexadecimal numbers.
+
+
+ void xprint(FILE* stream, struct xpr u)
+
+
+- stream = file where the number must be printed;
+- u = structure containing number to print.
+
+The xprint() function supports a bit oriented analysis of
+rounding error effects. It always prints a newline (\n)
+at the end.
+
+-------------------------------------------------------------------------
+xfout - Print an extended precision number on file according to
+a given set of I/O flags.
+
+
+ int xfout (FILE * stream, struct xoutflags ofs, struct xpr x)
+
+
+- stream = file where the number must be printed;
+- ofs = structure containing all I/O flags;
+- x = structure containing number to print.
+
+The return value is 0 in case of success,
+-1 to mean a failure.
+
+Remark:
+For the definition of struct xoutflags and the meaning
+of its fields see section "Real Arithmetic" (#real_arith).
+xfout() does not add any newline
+at the end of the printed number.
+
+-------------------------------------------------------------------------
+xout - Print an extended precision number on stdout according to
+a given set of I/O flags.
+
+
+ int xout (struct xoutflags ofs, struct xpr x)
+
+
+- ofs = structure containing all I/O flags;
+- x = structure containing number to print.
+
+The return value is 0 in case of success, -1 to mean a failure.
+
+Remark:
+For the definition of struct xoutflags and the meaning
+of its fields see section "Real Arithmetic" (#real_arith).
+xout() does not add any newline
+at the end of the printed number.
+
+-------------------------------------------------------------------------
+xsout - Write an extended precision number on a string according to
+a given set of I/O flags.
+
+
+ int xsout (char* s, unsigned long n, struct xoutflags ofs,
+ struct xpr x)
+
+
+- s = pointer to a buffer of characters (char);
+- n = size of the buffer;
+- ofs = structure containing all I/O flags;
+- x = structure containing number to print.
+
+The return value is the number of non-null characters written
+to the buffer or, if it is greater or equal than n, which would have been
+written to the buffer if enough space had been available.
+
+Remarks:
+For the definition of struct xoutflags and the meaning of its fields
+see section "Real Arithmetic" (#real_arith).
+xsout() always adds a null character ('\0') at the end of
+the written number.
+xsout() does not write more than n bytes (including
+the trailing '\0'). Thus, a return value of n or more
+means that the output was truncated. In this case, the contents of the
+buffer pointed to by the first argument of xsout() are
+completely unreliable.
+
+
+ 7.3. Extended Precision Math Library
+ ====================================
+
+The Extended Precision Math Library
+provides the elementary functions normally
+supported in a C math library.
+They are designed to provide full precision accuracy.
+
+
+
+
+
+xsqrt - Compute the square root of an extended precision number.
+
+
+ struct xpr xsqrt(struct xpr x)
+
+
+- x = structure containing the input number.
+
+The return value is the square root of the
+input number. A negative argument results in a domain error.
+
+-------------------------------------------------------------------------
+xexp - Compute the exponential function.
+
+
+ struct xpr xexp(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is e (the base of natural logarithms)
+raised to x.
+
+-------------------------------------------------------------------------
+xexp2 - Compute the base-2 exponential function.
+
+
+ struct xpr xexp2(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is 2 raised to x.
+
+-------------------------------------------------------------------------
+xexp10 - Compute the base-10 exponential function.
+
+
+ struct xpr xexp10(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is 10 raised to x.
+
+-------------------------------------------------------------------------
+xlog - Compute natural (base e) logarithms.
+
+
+ struct xpr xlog(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the natural logarithm of
+its argument. A null or negative argument results in a
+domain error.
+
+-------------------------------------------------------------------------
+xlog2 - Compute base-2 logarithms.
+
+
+ struct xpr xlog2(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the base-2 logarithm of
+its argument. A null or negative argument results in a
+domain error.
+
+-------------------------------------------------------------------------
+xlog10 - Compute base-10 logarithms.
+
+
+ struct xpr xlog10(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the base-10 logarithm of
+its argument. A null or negative argument results in a
+domain error.
+
+-------------------------------------------------------------------------
+xtan - Tangent function.
+
+
+ struct xpr xtan(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is the tangent of x, where x is
+given in radians.
+xtan(x) returns xPinf if x is equal to xPi2
+(up to an integer multiple of xPi),
+xMinf if x is equal to -xPi2 (up to an
+integer multiple of xPi). In both cases a
+domain error is produced.
+
+-------------------------------------------------------------------------
+xcos - Cosine function.
+
+
+ struct xpr xcos(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is the cosine of x, where x is
+given in radians.
+
+-------------------------------------------------------------------------
+xsin - Sine function.
+
+
+ struct xpr xsin(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is the sine of x, where x is
+given in radians.
+
+-------------------------------------------------------------------------
+xatan - Arc tangent function.
+
+
+ struct xpr xatan(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the arc tangent of x in radians and
+the value is mathematically defined to be between -Pi/2
+and Pi/2 (inclusive).
+
+-------------------------------------------------------------------------
+xasin - Arc sine function.
+
+
+ struct xpr xasin(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the arc sine of x in radians and
+the value is mathematically defined to be between -Pi/2
+and Pi/2 (inclusive). If x falls outside the range
+-1 to 1, a domain error is produced.
+
+-------------------------------------------------------------------------
+xacos - Arc cosine function.
+
+
+ struct xpr xacos(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the arc cosine of x in radians and
+the value is mathematically defined to be between zero
+and Pi (inclusive). If x falls outside the range
+-1 to 1, a domain error is produced.
+
+-------------------------------------------------------------------------
+xatan2 - arc tangent function of two variables.
+
+
+ struct xpr xatan2 (struct xpr y, struct xpr x)
+
+
+- y = structure containing first argument;
+- x = structure containing second argument.
+
+This function returns the principal value of the arc tangent of y/x,
+using the signs of the two arguments to determine the
+quadrant of the result, a real number in the range [-xPi,xPi)
+(-xPi is included, xPi is excluded). If x and y
+are both zero, a domain error is produced and the dummy value
+zero is returned. If x is zero and y is positive, then
+xPi2 (i.e. PI/2) is returned.
+If x is zero and y is negative, the function
+returns -xPi2 (i.e. -PI/2).
+
+-------------------------------------------------------------------------
+xtanh - Hyperbolic tangent function.
+
+
+ struct xpr xtanh(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is the hyperbolic tangent of x.
+
+-------------------------------------------------------------------------
+xcosh - Hyperbolic cosine function.
+
+
+ struct xpr xcosh(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is the hyperbolic cosine of x.
+
+-------------------------------------------------------------------------
+xsinh - Hyperbolic sine function.
+
+
+ struct xpr xsinh(struct xpr x)
+
+
+- x = structure containing function argument.
+
+The return value is the hyperbolic sine of x.
+
+-------------------------------------------------------------------------
+xatanh - Hyperbolic arc tangent function.
+
+
+ struct xpr xatanh(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the hyperbolic arc tangent of x.
+If the absolute value of x is greater than 1,
+then a domain error is produced.
+
+-------------------------------------------------------------------------
+xasinh - Hyperbolic arc sine function.
+
+
+ struct xpr xasinh(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the hyperbolic arc sine of x.
+
+-------------------------------------------------------------------------
+xacosh - Hyperbolic arc cosine function.
+
+
+ struct xpr xacosh(struct xpr x)
+
+
+- x = structure containing function argument.
+
+This function returns the hyperbolic arc cosine of x.
+If x is less than 1, a domain error is produced.
+
+
+ 7.4. Applications of Extended Precision Arithmetic
+ ==================================================
+
+The Tchebycheff expansion supplied with the library can be used to
+compute the Tchebycheff expansion coefficients of a function to an accuracy
+of 32 digits at least. This ability is useful in developing high accuracy function
+approximations, since the effect of rounding error on coefficients used in
+double precision can effectively be eliminated with these inputs.
+The functions provided to this purpose are xchcof() and
+xevtch().
+
+
+
+
+
+xchcof - Compute the Tchebycheff expansion coefficients of a
+specified function f(x).
+
+
+ struct xpr* xchcof(int m,struct xpr (*xfunc)(struct xpr))
+
+
+- m = index of the last coefficient (the computed coefficients will
+be m+1, indexed from 0 to m);
+- xfunc = pointer to user defined function returning extended
+precision values of the function f();
+
+The return value is the array of the computed coefficients.
+The equality
+
+
+ f(x) = c[0]/2 + Sum(k=1 to m) c[k]*Tk(x)
+
+holds, where Tk is the kth Tchebycheff polynomial.
+
+Remarks:
+The memory needed by the returned array is malloc'ed
+inside the function xchcof().
+To avoid memory leaks it should be explicitly freed through a call to free().
+In case of insufficient memory xchcof() will return NULL.
+
+If m <= XMAX_DEGREE (= 50), then the array returned by xchcof()
+will have exactly m+1 elements, indexed from 0 to m.
+If m > XMAX_DEGREE, then xchcof() will behave as if
+m were equal to XMAX_DEGREE, namely,
+the array returned by xchcof() will have only
+XMAX_DEGREE + 1 elements, indexed from 0 to XMAX_DEGREE.
+In other words, a value of m greater than XMAX_DEGREE is
+ignored and replaced by XMAX_DEGREE.
+XMAX_DEGREE is a macro declared inside the header file
+xpre.h .
+
+-------------------------------------------------------------------------
+xevtch - Evaluate an extended precision Tchebycheff expansion.
+
+
+ struct xpr xevtch(struct xpr x,struct xpr *a,int m)
+
+
+- x = structure containing function argument;
+- a = structure array containing expansion coefficients;
+- m = maximum index of coefficient array (dimension=m+1).
+
+The return value is the number given by the formula
+
+
+ f(x) = Sum(k=0 to m) a[k]*Tk(x),
+
+where Tk is the kth Tchebycheff polynomial.
+
+
+ 8. Complex Arithmetic
+ =====================
+
+The second module of the HPA library is formed by
+functions for Extended Precision Complex Arithmetic and functions
+of the Extended Precision Complex Math Library.
+They are all declared in the file cxpre.h together with some
+macros and numerical constants.
+
+
+ 8.1. Complex constants
+ ======================
+
+The header file cxpre.h defines the constants
+cxZero (= 0), cxOne (= 1) and cxIU (= imaginary unit):
+
+
+ extern const struct cxpr cxZero;
+ extern const struct cxpr cxOne;
+ extern const struct cxpr cxIU;
+
+which require no explanation.
+
+
+ 8.2. Extended Precision Complex Arithmetic
+ ==========================================
+
+The functions for complex arithmetic support the basic computations
+and input/output operations with extended precision complex values.
+Some of the functions supply capabilities designed to enhance the
+computational efficiency of the complex arithmetic (e.g., cxpwr and cxpow).
+What follows is the complete list of the functions
+with related synopses.
+
+
+
+
+
+cxreset - Make a new complex number from its real
+and imaginary parts.
+
+
+ struct cxpr cxreset (struct xpr re, struct xpr im)
+
+
+- re = structure containing real part;
+- im = structure containing imaginary part.
+
+The value returned by cxreset() is the complex
+number having re as its real part, im
+as its imaginary part.
+
+Remark:
+cxreset() is also available in the form of a macro:
+
+
+ #define CXRESET(re, im) (struct cxpr){re, im}
+
+-------------------------------------------------------------------------
+cxconv - Convert a real number into a complex one.
+
+
+ struct cxpr cxconv (struct xpr x)
+
+
+- re = structure containing real part.
+
+The value returned by cxconv() is the complex
+number having x as its real part, zero
+as its imaginary part.
+
+Remark:
+cxconv() is also available in the form of a macro:
+
+
+ #define CXCONV(x) (struct cxpr){x, xZero}
+
+-------------------------------------------------------------------------
+cxre - Obtain the real part of a complex number.
+
+
+ struct xpr cxre (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The value returned by cxre(z) is the real part of z.
+
+Remark:
+cxre() is also available in the form of a macro:
+
+
+ #define CXRE(z) (z).re
+
+-------------------------------------------------------------------------
+cxim - Obtain the imaginary part of a complex number.
+
+
+ struct xpr cxim (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The value returned by cxim(z) is the imaginary part of z.
+
+Remark:
+cxim() is also available in the form of a macro:
+
+
+ #define CXIM(z) (z).im
+
+-------------------------------------------------------------------------
+cxswap - Swap the real and the imaginary part
+of a complex number.
+
+
+ struct cxpr cxswap (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The value returned by cxswap(z) is the complex
+number {cxim(z), cxre(z)}.
+
+Remark:
+cxswap() is also available in the form of a macro:
+
+
+ #define CXSWAP(z) (struct cxpr){(z).im, (z).re}
+
+-------------------------------------------------------------------------
+cxconj - Calculate the complex conjugate of a complex number.
+
+
+ struct cxpr cxconj (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The cxconj() function returns the complex conjugate value of
+its argument, i.e. the value obtained by changing the sign of the
+imaginary part.
+
+-------------------------------------------------------------------------
+cxneg - Change sign (unary minus)
+
+
+ struct cxpr cxneg (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxneg(z) returns the complex number -z: if
+z = a+ib, then cxneg(z) returns -a-ib.
+
+-------------------------------------------------------------------------
+cxinv - Obtain the reciprocal of a complex number.
+
+
+ struct cxpr cxinv (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The value returned by cxinv() is the
+reciprocal of its argument. If z is zero,
+then a division-by-zero error is produced.
+
+-------------------------------------------------------------------------
+cxabs - Calculate the absolute value of a complex number.
+
+
+ struct xpr cxabs (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxabs(z) returns the absolute value of the complex number z.
+The result is a real number.
+
+-------------------------------------------------------------------------
+cxarg - Calculate the argument of a complex number.
+
+
+ struct xpr cxarg (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxarg(z) returns the argument or phase angle
+of the complex number z. The result is a real number
+in the range [-xPi,xPi) (-xPi is included, xPi is excluded).
+cxarg(z) is equivalent to xatan2(z.im, z.re).
+
+-------------------------------------------------------------------------
+cxadd - Add/subtract two extended precision complex numbers.
+
+
+ struct cxpr cxadd (struct cxpr z1, struct cxpr z2, int k)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number;
+- k = control flag: if 0, then z1 and z2 are added,
+else they are subtracted (z1-z2).
+
+The value returned by cxadd() is the result
+of the addition/subtraction.
+
+-------------------------------------------------------------------------
+cxsum - Add two extended precision complex numbers.
+
+
+ struct cxpr cxsum (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+The value returned by cxsum() is the result
+of the addition z1 + z2.
+
+-------------------------------------------------------------------------
+cxsub - Subtract two extended precision complex numbers.
+
+
+ struct cxpr cxsub (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+The value returned by cxsub() is the result
+of the subtraction z1 - z2.
+
+-------------------------------------------------------------------------
+cxmul - Multiply two extended precision complex numbers.
+
+
+ struct cxpr cxmul (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+The value returned by cxmul() is the
+product z1 * z2.
+
+-------------------------------------------------------------------------
+cxrmul - Multiply a complex number by a real one.
+
+
+ struct cxpr cxrmul (struct xpr c, struct cxpr z)
+
+
+- c = structure containing a real number;
+- z = structure containing a complex number.
+
+The value returned by cxrmul() is the
+product c * z.
+
+-------------------------------------------------------------------------
+cxdrot - Multiply a complex number by the imaginary unit.
+
+
+ struct cxpr cxdrot (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The value returned by cxdrot(z) is the product of
+z times the imaginary unit.
+
+-------------------------------------------------------------------------
+cxrrot - Multiply a complex number by -1i, where
+1i is the imaginary unit.
+
+
+ struct cxpr cxrrot (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The value returned by cxrrot(z) is the product of
+z times the negative imaginary unit.
+
+-------------------------------------------------------------------------
+cxdiv - Divide two extended precision complex numbers.
+
+
+ struct cxpr cxdiv (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+The value returned by cxdiv(z1, z2) is
+the quotient z1 / z2. If z2 is zero, then a
+division-by-zero error is produced.
+
+-------------------------------------------------------------------------
+cxgdiv - Gaussian division between complex numbers having
+both real and imaginary part integer.
+
+
+ struct cxpr cxgdiv (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+After eventually rounding z1 and z2 by means of
+cxround() (see below), cxgdiv(z1, z2) returns
+the quotient of the gaussian division of z1 by z2.
+If z2 is zero, then a division-by-zero error is produced.
+
+If you do not know what gaussian division means, probably
+you will never need this function :)
+
+-------------------------------------------------------------------------
+cxgmod - Remainder of the Gaussian division.
+
+
+ struct cxpr cxgmod (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+After eventually rounding z1 and z2 by means of
+cxround() (see below), cxgmod(z1, z2) returns
+the remainder of the gaussian division of z1 by z2.
+If z2 is zero, then a division-by-zero error is produced.
+
+If you do not know what gaussian division means, probably
+you will never need this function :)
+
+-------------------------------------------------------------------------
+cxidiv - Integer division.
+
+
+ struct cxpr cxidiv (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+After eventually rounding z1 and z2 by means of
+cxround() (see below), cxidiv(z1, z2) returns
+the quotient of the integer division of z1 by z2.
+If z2 is zero, then a division-by-zero error is produced.
+cxidiv() is a smooth extension of the integer division
+between real numbers.
+
+-------------------------------------------------------------------------
+cxmod - Remainder of the integer division.
+
+
+ struct cxpr cxmod (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = structure containing first number;
+- z2 = structure containing second number.
+
+After eventually rounding z1 and z2 by means of
+cxround() (see below), cxmod(z1, z2) returns
+the remainder of the integer division of z1 by z2.
+If z2 is zero, then a division-by-zero error is produced.
+
+-------------------------------------------------------------------------
+cxpwr - Raise to integer powers.
+
+
+ struct cxpr cxpwr (struct cxpr z, int n)
+
+
+- z = structure containing input number;
+- n = exponent.
+
+The return value is the nth power
+of the first argument.
+
+-------------------------------------------------------------------------
+cxpow - Power function.
+
+
+ struct cxpr cxpow (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = base;
+- z2 = exponent.
+
+The return value is the power of the first argument
+raised to the second one.
+Note that the modulus of the first argument must be greater than zero,
+if the real part of z2 is less or equal than zero,
+otherwise a bad-exponent error is produced.
+
+-------------------------------------------------------------------------
+cxsqr - Square of a number.
+
+
+ struct cxpr cxsqr (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the square of its argument.
+
+-------------------------------------------------------------------------
+cxroot - nth root of a complex number.
+
+
+ struct cxpr cxroot (struct cxpr z, int i, int n)
+
+
+cxroot(z,i,n) returns the ith branch of
+the nth root of z.
+If n is zero or negative and the modulus of z is zero,
+then a bad-exponent error is produced.
+
+-------------------------------------------------------------------------
+cxsqrt - Principal branch of the square root of a complex number.
+
+
+ struct cxpr cxsqrt (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the principal branch of
+the square root of its argument.
+
+-------------------------------------------------------------------------
+cxprcmp - Compare two extended precision complex numbers.
+
+
+ struct cxprcmp_res cxprcmp (const struct cxpr* z1,
+ const struct cxpr* z2)
+
+
+- z1 = pointer to first number;
+- z2 = pointer to second number.
+
+The value returned by cxprcmp() is a structure formed by two
+comparison flags:
+
+
+ struct cxprcmp_res
+ {
+ int re, im;
+ };
+
+If the .re field of the returned structure is:
+
+- +1, then z1->re is greater than z2->re,
+- 0, then z1->re is equal to z2->re,
+- -1, then z1->re is less than z2->re.
+
+The meaning of the .im field is the same but refers
+to z1->im and z2->im.
+Note that the input numbers are not altered by cxprcmp().
+
+-------------------------------------------------------------------------
+cxis0 - Compare a complex number with zero.
+
+
+ int cxis0 (const struct cxpr* z)
+
+
+- z = pointer to an extended precision complex number.
+
+The return value is 0 if *z is not zero, else a non-zero value.
+
+-------------------------------------------------------------------------
+cxnot0 - Compare a complex number with zero.
+
+
+ int cxnot0 (const struct cxpr* z)
+
+
+- z = pointer to an extended precision complex number.
+
+The return value is 0 if *z is zero, else a non-zero value.
+
+-------------------------------------------------------------------------
+cxeq - Check if two complex numbers are or are not equal.
+
+
+ int cxeq (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = first number;
+- z2 = second number.
+
+The return value is 0 if z1 and z2 are different, else a
+non-null value.
+
+-------------------------------------------------------------------------
+cxneq - Check if two complex numbers are or are not equal.
+
+
+ int cxneq (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = first number;
+- z2 = second number.
+
+The return value is 0 if z1 and z2 are equal, else
+a non-null value.
+
+-------------------------------------------------------------------------
+cxgt - Check if a complex number is greater than another one.
+
+
+ int cxgt (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = first number;
+- z2 = second number.
+
+The return value is 0 if z1 is not greater than z2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+cxge - Check if a complex number is greater or equal to another one.
+
+
+ int cxge (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = first number;
+- z2 = second number.
+
+The return value is 0 if z1 is not greater or equal to z2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+cxlt - Check if a complex number is less than another one.
+
+
+ int cxlt (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = first number;
+- z2 = second number.
+
+The return value is 0 if z1 is not less than z2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+cxle - Check if a complex number is less or equal to another one.
+
+
+ int cxle (struct cxpr z1, struct cxpr z2)
+
+
+- z1 = first number;
+- z2 = second number.
+
+The return value is 0 if z1 is not less or equal to z2,
+else a non-null value.
+
+-------------------------------------------------------------------------
+dctocx - Convert a double precision complex number to
+an extended precision number.
+
+
+ struct cxpr dctocx (double re, double im)
+
+
+- re = real part of the double precision complex number;
+- im = imaginary part of the double precision complex number.
+
+The value returned by dctocx(re,im) is the
+extended precision equivalent of the complex number
+(re, im).
+
+-------------------------------------------------------------------------
+cxtodc - Convert an extended precision complex number to
+a double precision complex number.
+
+
+ void cxtodc (const struct cxpr *z, double *re, double *im)
+
+
+- z = pointer to an extended precision complex number;
+- re = pointer to a double precision number;
+- im = pointer to a double precision number.
+
+cxtodc() stores in its second and last argument respectively
+the real and the imaginary part of the number
+pointed to by its first argument.
+
+-------------------------------------------------------------------------
+fctocx - Convert a single precision complex number to
+an extended precision number.
+
+
+ struct cxpr fctocx (float re, float im)
+
+
+- re = real part of the single precision complex number;
+- im = imaginary part of the single precision complex number.
+
+The value returned by fctocx(re,im) is the
+extended precision equivalent of the complex number
+(re, im).
+
+-------------------------------------------------------------------------
+cxtofc - Convert an extended precision complex number to
+a single precision complex number.
+
+
+ void cxtofc (const struct cxpr *z, float *re, float *im)
+
+
+z = pointer to an extended precision complex number;
+
+- re = pointer to a single precision number;
+- im = pointer to a single precision number.
+
+cxtofc() stores in its second and last argument respectively
+the real and the imaginary part of the number
+pointed to by its first argument.
+
+-------------------------------------------------------------------------
+ictocx - Convert an integer complex number to
+an extended precision number.
+
+
+ struct cxpr ictocx (long re, long im)
+
+
+- re = real part of the integer complex number;
+- im = imaginary part of the integer complex number.
+
+The value returned by ictocx(re,im) is the
+extended precision equivalent of the complex number
+(re, im).
+
+-------------------------------------------------------------------------
+uctocx - Convert an integer complex number to
+an extended precision number.
+
+
+ struct cxpr uctocx (unsigned long re, unsigned long im)
+
+
+- re = real part of the integer complex number;
+- im = imaginary part of the integer complex number.
+
+The value returned by uctocx(re,im) is the
+extended precision equivalent of the complex number
+(re, im).
+
+-------------------------------------------------------------------------
+strtocx - Convert a floating point complex number,
+expressed as a decimal ASCII string
+in a form consistent with C, into the extended precision format.
+
+
+ struct cxpr strtocx (const char *s, char **endptr)
+
+
+- s = pointer to a null terminated ASCII string expressing a
+complex number;
+- endptr = NULL or address of a pointer defined
+outside strtocx().
+
+The value returned by strtocx() is
+the input number in extended precision format.
+
+Remarks:
+The strtocx() function converts the initial portion of
+the string pointed to
+by s to its extended precision representation.
+
+The expected form of the (initial portion of the) string is optional
+leading white space as recognized by the standard library function
+isspace(), an optional plus (+) or minus sign (-) and
+then a decimal number.
+A decimal number consists of a nonempty sequence of decimal digits possibly
+containing a radix character (decimal point, i.e. '.'), optionally
+followed by a decimal exponent. A decimal exponent consists of an
+E or e, followed by an optional plus or minus sign, followed by
+a non-empty sequence of decimal digits, and indicates multiplication by
+a power of 10.
+
+After this decimal number there can be an i character or,
+alternatively, some optional white spaces,
+an optional plus (+) or minus sign (-) and
+then another decimal number followed by an i character.
+Examples of valid representations of complex numbers are:
+
+"12","34.56",".7895i","-34.56-7.23i",
+"-45.7 +23.4i".
+
+This function returns the converted value, if any.
+If the correct value for the real or/and
+the imaginary part would cause overflow, then xPinf
+or xMinf is returned in the corresponding field,
+according to the sign of the value.
+If the correct value would cause underflow, xZero is returned.
+If no conversion is performed, xNaN is returned.
+
+If endptr is not NULL, a pointer to the character after the last character
+used in the conversion is stored in the location referenced by
+endptr.
+If no conversion is performed, the value of s is
+stored in the location referenced by endptr.
+
+-------------------------------------------------------------------------
+atocx - Convert a floating point complex number,
+expressed as a decimal ASCII string
+in a form consistent with C, into the extended precision format.
+
+
+ struct cxpr atocx (const char *s)
+
+
+- s = pointer to a null terminated ASCII string expressing a
+complex number.
+
+The return value is the input number converted to the
+extended precision format.
+
+Remark:
+The call atocx(s) is equivalent to strtocx(s, NULL).
+
+-------------------------------------------------------------------------
+cxpr_asprint - Convert an extended precision complex
+number to a string.
+
+
+ char *cxpr_asprint (struct cxpr z, int sc_not, int sign,
+ int lim)
+
+
+- z = structure containing number to print;
+- sc_not = zero to mean floating point notation, not zero to mean scientific notation;
+- sign = not zero to put a plus sign (+) before the real part
+of the number if it is non-negative (in case of negative real part
+a minus sign (-) is printed even if the parameter sign is zero);
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed) in
+case of scientific notation, else number of significant digits - 1
+(lim+1 = total of significant digits).
+
+cxpr_asprint() returns the string with the converted number.
+The memory for this string is calloc'ed inside the function.
+cxpr_asprint() uses always the format "a+bi" in
+the conversion.
+
+-------------------------------------------------------------------------
+cxtoa - This function converts an extended precision complex
+number to a string.
+Scientific notation is always used for both real and imaginary part.
+
+
+ char *cxtoa (struct cxpr z, int lim)
+
+
+- z = structure containing number to print;
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed).
+
+Remark:
+
+
+ cxtoa(z, lim)
+
+is equivalent to
+
+
+ cxpr_asprint(z, 1, 0, lim)
+
+-------------------------------------------------------------------------
+cxfrac - Fractional part of both real and imaginary part.
+
+
+ struct cxpr cxfrac (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxfrac(z) returns {xfrac(z.re), xfrac(z.im)}.
+
+-------------------------------------------------------------------------
+cxtrunc - Integer part of both real and imaginary part.
+
+
+ struct cxpr cxtrunc (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxtrunc(z) returns {xtrunc(z.re), xtrunc(z.im)}.
+
+-------------------------------------------------------------------------
+cxfix - Integer part of both real and imaginary part (2nd method).
+
+
+ struct cxpr cxfix (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxfix(z) returns {xfix(z.re), xfix(z.im)}.
+
+-------------------------------------------------------------------------
+cxround - Rounding real and imaginary part
+to the nearest integer values
+(halfway cases are rounded away from zero).
+
+
+ struct cxpr cxround (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxround(z) returns {xround(z.re), xround(z.im)}.
+
+-------------------------------------------------------------------------
+cxfloor - Rounding real and imaginary part
+to the largest integral values not greater than them.
+
+
+ struct cxpr cxfloor (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxfloor(z) returns {xfloor(z.re), xfloor(z.im)}.
+
+-------------------------------------------------------------------------
+cxceil - Rounding real and imaginary part
+to the smallest integral values not less than them.
+
+
+ struct cxpr cxceil (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+cxceil(z) returns {xceil(z.re), xceil(z.im)}.
+
+-------------------------------------------------------------------------
+cxpr_print - Print an extended precision complex number
+in scientific or floating point notation to a given file.
+
+
+ void cxpr_print (FILE * stream, struct cxpr z, int sc_not,
+ int sign, int lim)
+
+
+- stream = file where the number must be printed;
+- z = structure containing number to print;
+- sc_not = zero to mean floating point notation, not zero to mean scientific notation;
+- sign = not zero to put a plus sign (+) before the real part
+of the number if it is non-negative (in case of negative real part
+a minus sign (-) is printed even if the parameter sign is zero);
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed) in
+case of scientific notation, else number of significant digits - 1
+(lim+1 = total of significant digits).
+
+-------------------------------------------------------------------------
+cxprcxpr - Print an extended precision complex number
+in scientific notation.
+
+
+ void cxprcxpr (struct cxpr z, int m)
+
+
+- z = structure containing number to print;
+- lim = number of decimal digits to the right of the
+decimal point (lim+1 = total digits displayed).
+
+Remark:
+
+
+ cxprcxpr(z, lim)
+
+is equivalent to
+
+
+ cxpr_print(stdout, z, 1, 0, lim)
+
+-------------------------------------------------------------------------
+cxprint - Print an extended precision complex number as a couple
+of strings of hexadecimal numbers.
+
+
+ void cxprint (FILE * stream, struct cxpr z)
+
+
+- stream = file where the number must be printed;
+- z = structure containing number to print.
+
+The cxprint() function supports a bit oriented analysis of
+rounding error effects. It always prints a newline (\n)
+at the end.
+
+-------------------------------------------------------------------------
+cxfout - Print an extended precision complex number to a file
+according to a given set of I/O flags.
+
+
+ int cxfout (FILE * stream, struct xoutflags ofs, struct cxpr z)
+
+
+- stream = file where the number must be printed;
+- ofs = structure containing all I/O flags;
+- z = structure containing number to print.
+
+The return value is 0 in case of success,
+-1 to mean a failure.
+
+Remark:
+For the definition of struct xoutflags and the meaning
+of its fields see section "Real Arithmetic" (#real_arith).
+cxfout() does not add any newline
+at the end of the printed number.
+
+-------------------------------------------------------------------------
+cxout - Print an extended precision complex number on stdout
+according to a given set of I/O flags.
+
+
+ int cxout (struct xoutflags ofs, struct cxpr z)
+
+
+- ofs = structure containing all I/O flags;
+- z = structure containing number to print.
+
+The return value is 0 in case of success, -1 to mean a failure.
+
+Remark:
+For the definition of struct xoutflags and the meaning
+of its fields see section "Real Arithmetic" (#real_arith).
+cxout() does not add any newline
+at the end of the printed number.
+
+-------------------------------------------------------------------------
+cxsout - Write an extended precision complex number on a string
+according to a given set of I/O flags.
+
+
+ unsigned long cxsout (char *s, unsigned long n,
+ struct xoutflags ofs, struct cxpr z)
+
+
+- s = pointer to a buffer of characters (char);
+- n = size of the buffer;
+- ofs = structure containing all I/O flags;
+- z = structure containing number to print.
+
+The return value is the number of the non-null characters written
+to the buffer or, if it is greater or equal than n, which would have been
+written to the buffer if enough space had been available.
+
+Remark:
+For the definition of struct xoutflags and the meaning of its fields
+see section "Real Arithmetic" (#real_arith).
+cxsout() always adds a null character ('\0') at the end of
+the written number.
+cxsout() does not write more than n bytes (including
+the trailing '\0'). Thus, a return value of n or more
+means that the output was truncated. In this case, the contents of the
+buffer pointed to by the first argument of cxsout() are
+completely unreliable.
+
+
+ 8.3. Extended Precision Complex Math Library
+ ============================================
+
+The Extended Precision Complex Math Library
+provides the elementary functions normally
+supported in a complex math library.
+They are designed to provide full precision accuracy.
+
+
+
+
+
+cxexp - Compute the complex exponential function.
+
+
+ struct cxpr cxexp (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is e (the base of natural logarithms)
+raised to z.
+
+-------------------------------------------------------------------------
+cxexp2 - Compute the base-2 complex exponential function.
+
+
+ struct cxpr cxexp2 (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is 2 raised to z.
+
+-------------------------------------------------------------------------
+cxexp10 - Compute the base-10 complex exponential function.
+
+
+ struct cxpr cxexp10 (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is 10 raised to z.
+
+-------------------------------------------------------------------------
+cxlog - Compute natural (base e) logarithm of a complex number.
+
+
+ struct cxpr cxlog (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the natural logarithm of
+its argument. A null argument results in a
+domain error.
+The imaginary part of the result lies in the interval
+[-xPi,xPi) (-xPi is included, xPi is excluded).
+
+-------------------------------------------------------------------------
+cxlog2 - Compute base-2 logarithm of a complex number.
+
+
+ struct cxpr cxlog2 (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the base-2 logarithm of
+its argument. A null argument results in a
+domain error.
+
+-------------------------------------------------------------------------
+cxlog10 - Compute base-10 logarithm of a complex number.
+
+
+ struct cxpr cxlog10 (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the base-10 logarithm of
+its argument. A null argument results in a
+domain error.
+
+-------------------------------------------------------------------------
+cxlog_sqrt - Compute natural (base e) logarithm of the
+principal branch of the square root of a complex number.
+
+
+ struct cxpr cxlog_sqrt (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the natural logarithm of
+the principal branch of the square root of its argument.
+A null argument results in a domain error.
+The imaginary part of the result lies in the range
+[-xPi2,xPi2) (-xPi2 is included, xPi2 is excluded).
+
+-------------------------------------------------------------------------
+cxtan - Complex tangent function.
+
+
+ struct cxpr cxtan (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is the tangent of the complex number z.
+cxtan(z) yields a domain error if the imaginary
+part of z is null and the real part is equal,
+up to an integer multiple of xPi, to xPi2.
+
+-------------------------------------------------------------------------
+cxcos - Complex cosine function.
+
+
+ struct cxpr cxcos (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is the cosine of the complex number z.
+
+-------------------------------------------------------------------------
+cxsin - Complex sine function.
+
+
+ struct cxpr cxsin (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is the sine of the complex number z.
+
+-------------------------------------------------------------------------
+cxatan - Complex arc tangent function.
+
+
+ struct cxpr cxatan (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the arc tangent of the complex
+number z, i.e. a number w such that
+z = tan(w).
+If the real part of z is null and the
+imaginary part is equal to +1 or -1,
+then a domain error is produced.
+
+-------------------------------------------------------------------------
+cxasin - Complex arc sine function.
+
+
+ struct cxpr cxasin (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the arc sine of the complex
+number z, i.e. a number w such that
+z = sin(w).
+
+-------------------------------------------------------------------------
+cxacos - Complex arc cosine function.
+
+
+ struct cxpr cxacos (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the arc cosine of the complex
+number z, i.e. a number w such that
+z = cos(w).
+
+-------------------------------------------------------------------------
+cxtanh - Complex hyperbolic tangent function.
+
+
+ struct cxpr cxtanh (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is the hyperbolic tangent
+of the complex number z.
+cxtanh(z) yields a domain error if the real
+part of z is null and the imaginary part is equal,
+up to an integer multiple of xPi, to xPi2.
+
+-------------------------------------------------------------------------
+cxcosh - Complex hyperbolic cosine function.
+
+
+ struct cxpr cxcosh (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is the hyperbolic cosine of
+the complex number z.
+
+-------------------------------------------------------------------------
+cxsinh - Complex hyperbolic sine function.
+
+
+ struct cxpr cxsinh (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+The return value is the hyperbolic sine of
+the complex number z.
+
+-------------------------------------------------------------------------
+cxatanh - Complex hyperbolic arc tangent function.
+
+
+ struct cxpr cxatanh (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the hyperbolic arc tangent of
+the complex number z, i.e. a number w such that
+z = tanh(w).
+If the imaginary part of z is null and the
+real part is equal to +1 or -1,
+then a domain error is produced.
+
+-------------------------------------------------------------------------
+cxasinh - Complex hyperbolic arc sine function.
+
+
+ struct cxpr cxasinh (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the hyperbolic arc sine of
+the complex number z, i.e. a number w such that
+z = sinh(w).
+
+-------------------------------------------------------------------------
+cxacosh - Complex hyperbolic arc cosine function.
+
+
+ struct cxpr cxacosh (struct cxpr z)
+
+
+- z = structure containing function argument.
+
+This function returns the hyperbolic arc cosine of
+the complex number z, i.e. a number w such that
+z = cosh(w).
+
+-------------------------------------------------------------------------
+
+
+
+FINAL REMARK:
+The header file cxpre.h also defines the macros
+cxconvert, cxdiff, cxprod and cxipow:
+
+
+ #define cxconvert cxconv
+ #define cxdiff cxsub
+ #define cxprod cxmul
+ #define cxipow cxpwr
+
+This allows to use cxconvert as synonym of cxconv,
+cxdiff as synonym of cxsub, cxprod in place
+of cxmul, and cxipow for cxpwr.
+
+
+ 9. The C++ interface
+ ====================
+
+The HPA library supplies a C++ wrapper allowing to
+perform high precision computations with the
+same syntax of the normal code.
+Using the C++ wrapper permits you to write things like:
+
+
+ // Compute the factorial of the integer n
+
+ xreal factorial(xreal n)
+ {
+ xreal i;
+ xreal product = 1;
+ for (i=2; i <= n; i++)
+ product *= i;
+ return product;
+ }
+
+Technically, the C++ wrapper is contained in a separate
+library. However, this module is distributed together
+with the HPA library as an extension to it.
+This section of the manual describes
+the C++ interface of this extension.
+This one is formed by two classes, called xreal
+and xcomplex respectively.
+The type xreal can be used to declare or define
+real variables. In addition, it defines the mathematical
+operations and functions which can be used with them.
+The same is for the type xcomplex with respect to
+complex variables and their manipulation.
+Once you have variables of xreal and xcomplex type,
+you can use the usual C++ syntax, but all computations
+will be performed with the high precision math library.
+Of course, this possibility
+greatly simplifies the writing of code.
+Note the difference between
+
+
+ struct xpr x, y;
+ char buffer[256];
+
+ while ( (fgets (buffer, 256, stdin)) )
+ {
+ x = atox (buffer);
+ printf ("The square root of 2 * %s + 1 is ", buffer);
+ y = xadd (xpr2(x, 1), xOne, 0);
+ xprxpr (xsqrt (y), 30);
+ putchar ('\n');
+ }
+
+and its C++ version:
+
+
+ xreal x;
+
+ while ( x.getfrom(cin) > 0 )
+ cout << "The square root of 2 * " << x << " + 1 is "
+ << sqrt(2 * x + 1) << endl;
+
+which is much more compact and easier to understand.
+
+The use of the C++ wrapper requires however a recent
+and ANSI-compliant C++ compiler (for instance g++ 3.x).
+Moreover, before declaring or defining variables of xreal
+type and before using anyone of the functions or operators
+declared in the header file xreal.h, you have to insert the line
+
+
+ #include
+
+in your source code file.
+
+Similarly, before declaring or defining variables of xcomplex
+type and before using anyone of the functions or operators
+declared in the header file xcomplex.h, you have to add the line
+
+
+ #include
+
+to your source code file.
+
+After that, it is recommendable to add the directive
+
+
+ using namespace HPA;
+
+since all objects of the C++ wrapper are declared
+or defined within the namespace HPA.
+Alternatively, you should always use the prefix
+HPA:: in front of any identifiers coming
+from the files xreal.h or xcomplex.h.
+One has to tell the compiler indeed, where it has to look for
+the classes xreal, xcomplex and the related stuff.
+
+This code comes from a real program:
+
+
+ #include
+ #include
+ using namespace HPA;
+
+ int main (void)
+ {
+ xreal x;
+
+ while ( x.getfrom(cin) > 0 )
+ cout << "The square root of 2 * " << x << " + 1 is "
+ << sqrt(2 * x + 1) << endl;
+ return 0;
+ }
+
+The header files xreal.h and
+xcomplex.h make also directly available the standard classes
+ostream, istream and string
+(see sections "The xreal class" (#xreal_class)
+ and "The xcomplex class" (#xcomplex_class)).
+
+
+ 10. Compiling and linking with the C++ wrapper
+ ==============================================
+
+Whenever you have to compile and build a program making use
+of the C++ wrapper for the HPA library, you can do it by following
+the same instructions given in the section "Compiling and linking" (#comp_link),
+just take care to use hpaxxconf in place of
+hpaconf, as in
+
+
+ c++ -c $(hpaxxconf -c) example.cc
+
+
+
+ c++ -c `hpaxxconf -c` example.cc
+
+to compile the file example.cc and obtain the object file example.o,
+or in
+
+
+ c++ example.o $(hpaxxconf -l) -o example
+
+
+
+ c++ example.o `hpaxxconf -l` -o example
+
+to do the linkage.
+If you want, you may also compile and build at the same time by using
+
+
+ c++ example.cc $(hpaxxconf -c -l) -o example
+
+
+
+ c++ example.cc `hpaxxconf -c -l` -o example
+
+All these examples assume that you are working
+with bash or with another shell sh-compatible.
+In any case, the synopsis of hpaxxconf is the same of hpaconf.
+
+Warning:
+The command hpaxxconf is available only if
+the C++ wrapper was also built when the HPA library was installed on
+the system where you are working.
+It is possible to install the HPA library without
+its C++ wrapper. In this case, if you try to launch
+the command hpaxxconf, the shell will print
+the error message "Command not found" or
+something similar.
+
+
+ 11. The xreal class
+ ===================
+
+The interface of the xreal class is
+contained in the header file xreal.h,
+whose contents you can find here together
+with the necessary explanations.
+
+
+ #ifndef _XREAL_H_
+ #define _XREAL_H_
+
+ #include
+ #include
+ #include
+ #include
+
+ using std::ostream;
+ using std::istream;
+ using std::string;
+
+ namespace HPA {
+
+ class xreal {
+ // << and >> are used respectively for the output and the
+ // input of extended precision numbers.
+ // The input operator >> reads a double precision
+ // number and then converts it to an extended precision
+ // number. This can have undesirable rounding effects.
+ // To avoid them, use the input function
+ // xreal::getfrom() (see below).
+ friend ostream& operator<< (ostream& os, const xreal& x);
+ friend istream& operator>> (istream& is, xreal& x);
+
+ // +, -, *, / are the usual arithmetic operators
+ friend xreal operator+ (const xreal& x1, const xreal& x2);
+ friend xreal operator- (const xreal& x1, const xreal& x2);
+ friend xreal operator* (const xreal& x1, const xreal& x2);
+ friend xreal operator/ (const xreal& x1, const xreal& x2);
+
+ // x % n is equal to x * pow (2,n)
+ friend xreal operator% (const xreal& x1, int n);
+
+ // ==, !=, <=, >=, <, > are the usual comparison operators
+ friend int operator== (const xreal& x1, const xreal& x2);
+ friend int operator!= (const xreal& x1, const xreal& x2);
+ friend int operator<= (const xreal& x1, const xreal& x2);
+ friend int operator>= (const xreal& x1, const xreal& x2);
+ friend int operator< (const xreal& x1, const xreal& x2);
+ friend int operator> (const xreal& x1, const xreal& x2);
+
+ // sget (s, n, x) tries to read an extended precision
+ // number from the string 's' starting from the position
+ // 'n'. The retrieved number is converted and stored in
+ // 'x'. The return value is the number of characters
+ // composing the decimal representation of this number
+ // as read from 's'. For example, if s == "12.34dog" and
+ // n == 0, then 'x' is set to 12.34 and the return value
+ // is 5.
+ // If the portion of 's' starting from the position 'n'
+ // can not be converted to a number, then 'x' is set to
+ // xNAN and 0 is returned.
+ // If the exactly converted value would cause overflow,
+ // then xINF or x_INF is returned, according to the sign
+ // of the value.
+ // If 'n' is greater or equal to the length of 's', then 0
+ // is returned and 'x' is set to xZERO.
+ friend unsigned long sget (string s, unsigned long startptr,
+ xreal& x);
+
+ // bget (buff, x) tries to read an extended precision
+ // number from the buffer pointed to by 'buff'.
+ // The retrieved number is converted and stored in 'x'.
+ // The return value is a pointer to the character after
+ // the last character used in the conversion.
+ // For example, if 'buff' is a pointer to the buffer
+ // "12.34dog", then 'x' is set to 12.34 and the return
+ // value is a pointer to "dog" (i.e., a pointer
+ // to the character 'd').
+ // If the initial portion of the string pointed to by 'buff'
+ // can not be converted to a number, then 'x' is set to xNAN
+ // and 'buff' is returned.
+ // If the exactly converted value would cause overflow,
+ // then xINF or x_INF is returned, according to the sign
+ // of the value.
+ // If 'buff' is NULL (0), then an error message is printed
+ // on 'cerr' (standard error device).
+ friend const char* bget (const char* buff, xreal& x);
+
+ // compare (x1, x2) returns
+ //+1 to mean x1 > x2
+ // 0 to mean x1 == x2
+ //-1 to mean x1 < x2
+ friend int compare (const xreal& x1, const xreal& x2);
+
+ //isNaN (x) returns 1 when x == xNAN, else 0
+ friend int isNaN (const xreal& x);
+
+ // The following functions do not need a particular comment:
+ // each of them is defined as the corresponding function
+ // of the standard math library, that is to say the function
+ // from having the same name.
+ // However qfmod(), sfmod(), frac() and fix() do not have
+ // counterparts in the standard math library.
+ // With respect to fmod(), qfmod() requires one more
+ // argument, where the quotient of the division of
+ // the first argument by the second one is stored.
+ // sfmod (x,&n) stores in the integer variable
+ // 'n' the integer part of 'x' and, at the same time,
+ // returns the fractional part of 'x'.
+ // The usage of sfmod() is strongly discouraged.
+ // frac() returns the fractional part of its argument.
+ // Finally, fix() is a frontend to the xfix()
+ // function (see section "Extended Precision Floating
+ // Point Arithmetic").
+ friend xreal abs (const xreal& s);
+ friend xreal frexp (const xreal& s, int *p);
+ friend xreal qfmod (const xreal& s, const xreal& t, xreal& q);
+ friend xreal fmod (const xreal& s, const xreal& t);
+ friend xreal sfmod (const xreal& s, int *p);
+ friend xreal frac (const xreal& x);
+ friend xreal trunc (const xreal& x);
+ friend xreal round (const xreal& x);
+ friend xreal ceil (const xreal& x);
+ friend xreal floor (const xreal& x);
+ friend xreal fix (const xreal& x);
+ friend xreal tan (const xreal& x);
+ friend xreal sin (const xreal& x);
+ friend xreal cos (const xreal& x);
+ friend xreal atan (const xreal& a);
+ friend xreal atan2 (const xreal& y, const xreal& x);
+ friend xreal asin (const xreal& a);
+ friend xreal acos (const xreal& a);
+ friend xreal sqrt (const xreal& u);
+ friend xreal exp (const xreal& u);
+ friend xreal exp2 (const xreal& u);
+ friend xreal exp10 (const xreal& u);
+ friend xreal log (const xreal& u);
+ friend xreal log2 (const xreal& u);
+ friend xreal log10 (const xreal& u);
+ friend xreal tanh (const xreal& v);
+ friend xreal sinh (const xreal& v);
+ friend xreal cosh (const xreal& v);
+ friend xreal atanh (const xreal& v);
+ friend xreal asinh (const xreal& v);
+ friend xreal acosh (const xreal& v);
+ friend xreal pow (const xreal& x, const xreal& y);
+
+ public:
+ // Various constructors. They allow to define
+ // an extended precision number in several ways.
+ // In addition, they allow for conversions from other
+ // numeric types.
+ xreal (const struct xpr* px = &xZero);
+ xreal (struct xpr x);
+ xreal (double x);
+ xreal (float x);
+ xreal (int n);
+ xreal (long n);
+ xreal (unsigned int u);
+ xreal (unsigned long u);
+
+ // This constructor requires a special comment. If
+ // only the first argument is present, the initial portion
+ // of the string pointed to by this argument is converted
+ // into an extended precision number, if a conversion is
+ // possible. If no conversion is possible, then the
+ // returned number is xNAN. If the second argument is
+ // present and is not null, it must be the address of a
+ // valid pointer to 'char'.
+ // Before returning, the constructor will set this pointer
+ // so that it points to the character of the string 'str' after the last
+ // character used in the conversion.
+ xreal (const char* str, char** endptr = 0);
+ xreal (string str);
+ xreal (const xreal& x);
+
+ // Assignment operators. They do not require
+ // any explanation with the only exception of '%=',
+ // which combines a '%' operation with an assignment.
+ // So, x %= n is equivalent to x *= pow(2,n) .
+ xreal& operator= (const xreal& x);
+ xreal& operator+= (const xreal& x);
+ xreal& operator-= (const xreal& x);
+ xreal& operator*= (const xreal& x);
+ xreal& operator/= (const xreal& x);
+ xreal& operator%= (int n);
+
+ // Increment and decrement operators. Both prefixed
+ // and postfixed versions are defined.
+ xreal& operator++ ();
+ xreal& operator-- ();
+ xreal& operator++ (int dummy);
+ xreal& operator-- (int dummy);
+
+ // Destructor. You will never have to recall it
+ // explicitly in your code.
+ ~xreal (void);
+
+ // Integer exponent power. For any extended precision
+ // number 'x', x(n) is equal to 'x' raised to 'n'.
+ xreal operator() (int n) const;
+
+ // This is the usual unary minus.
+ xreal operator-() const;
+
+ // For any extended precision number 'x', !x evaluates to 1
+ // when 'x' is null, else it evaluates to 0.
+ int operator!() const;
+
+ // x.isneg() returns 1 if 'x' is negative, else it
+ // returns 0.
+ int isneg() const;
+
+ // x.exp() returns the exponent part
+ // of the binary representation of 'x'.
+ int exp() const;
+
+ // Functions for conversions. x._2double(), x._2float(),
+ // x._2xpr() and x._2string() convert the extended precision
+ // number 'x' in a double precision number, in a single
+ // precision number, in a structure of
+ // type 'xpr', and in a string, respectively.
+ double _2double () const;
+ float _2float() const;
+ struct xpr _2xpr() const;
+ string _2string() const;
+
+ // The member function xreal::getfrom() can be used to
+ // recover an extended precision number from an input
+ // stream. The input stream is passed as argument to the
+ // function.
+ // The return value is 0 in case of input error (in case
+ // of End-Of-File, for example).
+ // When it starts to process its input, this function drops
+ // all the eventual leading white spaces.
+ // After reading the first non space character, it
+ // continues to read from the input stream until it finds
+ // a white space or reaches the End-Of-File.
+ // Then it tries to convert into an extended
+ // precision number the (initial portion of the) string just
+ // read.
+ // If no conversion can be performed, then x.getfrom(is)
+ // sets 'x' to the value xNAN.
+ // If the exactly converted value would cause overflow,
+ // then 'x' is set to xINF or x_INF, according to the sign
+ // of the correct value.
+ int getfrom (istream& is);
+
+ // The member function xreal::print() can be used to write
+ // an extended precision number to an output stream.
+ // The output stream is passed to the function as first
+ // argument. The next three arguments have the same meanings
+ // of the fields 'notat', 'sf' and 'lim' of the
+ // structure 'xoutflags', respectively (see section "Real Arithmetic").
+ int print (ostream& os, int sc_not, int sign, int lim) const;
+
+ // The function call x.asprint(sc_not, sign, lim) returns
+ // a buffer of characters with the representation, in form
+ // of a decimal ASCII string, of the extended precision
+ // number 'x'. The arguments 'sc_not', 'sign' and 'lim' are
+ // used to format the string.
+ // They have the same meanings of the fields 'notat', 'sf'
+ // and 'lim' of the structure 'xoutflags', respectively (see section
+ // "Real Arithmetic").
+ // The buffer returned by this function is malloc'ed inside
+ // the function. In case of insufficient memory, the null
+ // pointer is returned.
+ char* asprint (int sc_not, int sign, int lim) const;
+
+ // The following static functions are used to set
+ // or get the values of the fields of the structure
+ // 'xreal::ioflags'. This structure is a static member
+ // variable of the class 'xreal' and it is used by the
+ // output operator << to know how to format its second
+ // argument. The meaning of the fields of the structure
+ // 'xreal::ioflags' is explained in the section
+ // "Real arithmetic".
+
+ // xreal::set_notation (which) sets to 'which' the value
+ // of 'xreal::ioflags.notat' .
+ static void set_notation (short notat);
+
+ // xreal::set_signflag (which) sets to 'which' the value
+ // of 'xreal::ioflags.sf' .
+ static void set_signflag (short onoff);
+
+ // xreal::set_mfwd (which) sets to 'which' the value
+ // of 'xreal::ioflags.mfwd' .
+ static void set_mfwd (short wd);
+
+ // xreal::set_lim (which) sets to 'which' the value
+ // of 'xreal::ioflags.lim' .
+ static void set_lim (short lim);
+
+ // xreal::set_padding (which) sets to 'which' the value
+ // of 'xreal::ioflags.padding' .
+ static void set_padding (signed char ch);
+
+ // xreal::get_notation () returns the current value
+ // of 'xreal::ioflags.notat' .
+ static short get_notation (void);
+
+ // xreal::get_signflag () returns the current value
+ // of 'xreal::ioflags.sf' .
+ static short get_signflag (void);
+
+ // xreal::get_mfwd () returns the current value
+ // of 'xreal::ioflags.mfwd' .
+ static short get_mfwd (void);
+
+ // xreal::get_lim () returns the current value
+ // of 'xreal::ioflags.lim' .
+ static short get_lim (void);
+
+ // xreal::get_padding () returns the current value
+ // of 'xreal::ioflags.padding' .
+ static signed char get_padding (void);
+ private:
+ struct xpr br; /* binary representation */
+ static struct xoutflags ioflags; /* output flags */
+ };
+
+ // xmatherrcode() returns the current value of the global
+ // variable 'xErrNo' (see section
+ // "Dealing with runtime errors"), if
+ // this variable is defined.
+ // Otherwise xmatherrcode() returns -1.
+ int xmatherrcode ();
+
+ // clear_xmatherr() resets to 0 the value of the global
+ // variable 'xErrNo' (see section "Dealing with runtime
+ // errors"), if this variable is defined.
+ // Otherwise, clear_xmatherr() prints a suitable warning
+ // on 'cerr' (standard error device).
+ void clear_xmatherr ();
+
+ // Some useful constants:
+ // xZERO == 0
+ // xONE == 1
+ // xTWO == 2
+ // xTEN == 10
+ // xINF == +INF
+ // x_INF == -INF
+ // xNAN == Not-A-Number
+ // xPI == Pi Greek
+ // xPI2 == Pi / 2
+ // xPI4 == Pi / 4
+ // xEE == e (base of natural logarithms)
+ // xSQRT2 == square root of 2
+ // xLN2 == natural logarithm of 2
+ // xLN10 == natural logarithm of 10
+ // xLOG2_E == base-2 logarithm of e
+ // xLOG2_10 == base-2 logarithm of 10
+ // xLOG10_E == base-10 logarithm of e
+ extern const xreal xZERO, xONE, xTWO, xTEN;
+ extern const xreal xINF, x_INF, xNAN;
+ extern const xreal xPI, xPI2, xPI4, xEE, xSQRT2;
+ extern const xreal xLN2, xLN10, xLOG2_E, xLOG2_10, xLOG10_E;
+
+ } /* End namespace HPA */
+
+ #endif /* _XREAL_H_ */
+
+
+ 12. The xcomplex class
+ ======================
+
+The interface of the xcomplex class is
+contained in the header file xcomplex.h,
+whose contents you can find here together
+with the necessary explanations.
+
+
+ #ifndef _XCOMPLEX_H_
+ #define _XCOMPLEX_H_
+
+ #include
+ #include
+ #include
+ #include "xreal.h"
+
+ using std::istream;
+ using std::ostream;
+ using std::string;
+
+ namespace HPA {
+
+ struct double_complex {
+ double re, im;
+ };
+
+ struct float_complex {
+ float re, im;
+ };
+
+ class xcomplex {
+ // << and >> are used respectively for the output and the
+ // input of extended precision complex numbers.
+ // The input operator >> reads a couple of double
+ // precision numbers and then converts it into
+ // an extended precision complex number. This can have
+ // undesirable rounding effects. To avoid them, use the
+ // input function xcomplex::getfrom() (see below).
+ friend ostream& operator<< (ostream& os, const xcomplex& z);
+ friend istream& operator>> (istream& is, xcomplex& z);
+
+ // +, -, *, / are the usual arithmetic operators
+ friend xcomplex
+ operator+ (const xcomplex& z1, const xcomplex& z2);
+ friend xcomplex
+ operator- (const xcomplex& z1, const xcomplex& z2);
+ friend xcomplex
+ operator* (const xcomplex& z1, const xcomplex& z2);
+ friend xcomplex
+ operator/ (const xcomplex& z1, const xcomplex& z2);
+
+ // z % n is equal to z * pow (2,n)
+ friend xcomplex
+ operator% (const xcomplex& z, int n);
+
+ // ==, !=, <=, >=, <, > are the usual comparison operators
+ friend int
+ operator== (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator!= (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator<= (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator>= (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator< (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator> (const xcomplex& z1, const xcomplex& z2);
+
+ // sget (s, n, z) tries to read an extended precision
+ // complex number from the string 's' starting from the
+ // position 'n'. The retrieved number is converted and
+ // stored in 'z'. The return value is the number of
+ // characters composing the decimal representation of this
+ // number as read from 's'.
+ // For example, if s == "12.34+6.7idog" and n == 0,
+ // then 'z' is set to 12.34+6.7i and the return value
+ // is 10.
+ // If the portion of 's' starting from the position 'n' can
+ // not be converted to a number, then 'z' is set to
+ // xNAN + xNANi and 0 is returned.
+ // If the exactly converted value would cause overflow in
+ // the real or/and imaginary part, then the real or/and the
+ // imaginary part of 'z' are set to xINF or x_INF, according
+ // to the signs of the correct value.
+ // If 'n' is greater or equal to the length of 's', then 0
+ // is returned and 'z' is set to cxZERO.
+ friend unsigned long sget (string s, unsigned long startptr,
+ xcomplex& z);
+
+ // bget (buff, z) tries to read an extended precision
+ // complex number from the buffer pointed to by 'buff'.
+ // The retrieved number is converted and stored in 'z'.
+ // The return value is a pointer to the character after
+ // the last character used in the conversion.
+ // For example, if 'buff' is a pointer to the buffer
+ // "12.34+6.7idog", then 'z' is set to 12.34+6.7i and
+ // the return value is a pointer to "dog" (i.e.,
+ // a pointer to the character 'd').
+ // If the initial portion of the string pointed to by 'buff'
+ // can not be converted to a number, then 'z' is set to
+ // xNAN + xNANi and 'buff' is returned.
+ // If the exactly converted value would cause overflow
+ // in the real or/and imaginary part, then the real or/and
+ // the imaginary part of 'z' are set to xINF or x_INF,
+ // according to the signs of the correct value.
+ // If 'buff' is NULL (0), then an error message is printed
+ // on 'cerr' (standard error device).
+ friend const char* bget (const char* buff, xcomplex& z);
+
+ // rmul (x,z) (here 'x' is a real number) returns the
+ // product x * z.
+ // It is faster than the * operator.
+ friend xcomplex rmul (const xreal& x, const xcomplex& z);
+
+ // After eventually rounding 'z1' and 'z2' by recalling
+ // round() (see below) on them, gdiv(z1, z2) returns
+ // the quotient of the gaussian division of 'z1' by 'z2'.
+ // If you do not know what gaussian division means, probably
+ // you will never need this function :)
+ friend xcomplex
+ gdiv (const xcomplex& z1, const xcomplex& z2);
+
+ // After eventually rounding 'z1' and 'z2' by recalling
+ // round() (see below) on them, gmod(z1, z2) returns
+ // the remainder of the gaussian division of 'z1' by 'z2'.
+ // If you do not know what gaussian division means, probably
+ // you will never need this function :)
+ friend xcomplex
+ gmod (const xcomplex& z1, const xcomplex& z2);
+
+ // idiv() is a wrapper to cxidiv() (see section
+ // "Extended Precision Complex Arithmetic").
+ friend xcomplex
+ idiv (const xcomplex& z1, const xcomplex& z2);
+
+ // mod() is a wrapper to cxmod() (see section
+ // "Extended Precision Complex Arithmetic").
+ friend xcomplex
+ mod (const xcomplex& z1, const xcomplex& z2);
+
+ // conj() returns the complex conjugate of its argument.
+ friend xcomplex conj (const xcomplex& z);
+
+ // inv() returns the complex reciprocal of its argument:
+ // inv(z) == 1/z .
+ friend xcomplex inv (const xcomplex& z);
+
+ // swap(z) returns the complex number {z.im, z.re}.
+ friend xcomplex swap (const xcomplex& z);
+
+ // Multiplication by 1i (imaginary unit).
+ friend xcomplex drot (const xcomplex& z);
+
+ // Multiplication by -1i
+ friend xcomplex rrot (const xcomplex& z);
+
+ // abs() returns the absolute value (or modulus) of its
+ // argument.
+ // The return value of abs() is then an 'xreal' number.
+ friend xreal abs (const xcomplex& z);
+
+ // arg(z) returns the phase angle (or argument)
+ // of the complex number 'z'.
+ // The return value of arg() is an 'xreal' number
+ // in the range [-xPI, xPI) (-xPI is included, xPI is excluded).
+ // If 'z' is null, then a domain-error is produced.
+ friend xreal arg (const xcomplex& z);
+
+ // The next six functions have the same
+ // meanings of the corresponding real functions,
+ // but they affect both the real
+ // and the imaginary part of their argument.
+ friend xcomplex frac (const xcomplex& z);
+ friend xcomplex trunc (const xcomplex& z);
+ friend xcomplex round (const xcomplex& z);
+ friend xcomplex ceil (const xcomplex& z);
+ friend xcomplex floor (const xcomplex& z);
+ friend xcomplex fix (const xcomplex& z);
+
+ // sqr() returns the square of its argument.
+ friend xcomplex sqr (const xcomplex& z);
+
+ // sqrt() returns the principal branch of the square root
+ // of its argument.
+ friend xcomplex sqrt (const xcomplex& z);
+
+ // root (z,i,n) returns the 'i'th branch of the 'n'th root
+ // of 'z'. If 'n' is zero or negative and 'z' is
+ // zero, then a bad-exponent error is produced.
+ friend xcomplex root (const xcomplex& z, int i, int n);
+
+ // These functions do not require any comment, except that
+ // tan() and tanh() yield a domain-error in the same cases
+ // as cxtan() and cxtanh(), respectively.
+ friend xcomplex exp (const xcomplex& z);
+ friend xcomplex exp2 (const xcomplex& z);
+ friend xcomplex exp10 (const xcomplex& z);
+ friend xcomplex tan (const xcomplex& z);
+ friend xcomplex sin (const xcomplex& z);
+ friend xcomplex cos (const xcomplex& z);
+ friend xcomplex tanh (const xcomplex& z);
+ friend xcomplex sinh (const xcomplex& z);
+ friend xcomplex cosh (const xcomplex& z);
+
+ // Natural, base-2 and base-10 logarithm of a complex
+ // number.
+ // A null argument results in a domain-error.
+ // The imaginary part of the return value of log() is always
+ // in the interval [-xPI,xPI) (-xPI is included, xPI is excluded).
+ friend xcomplex log (const xcomplex& z);
+ friend xcomplex log2 (const xcomplex& z);
+ friend xcomplex log10 (const xcomplex& z);
+
+ // log_sqrt(z) returns the natural logarithm of the
+ // principal branch of the square root of 'z'.
+ // A null argument results in a domain-error.
+ // The imaginary part of the return value of log_sqrt()
+ // is always in the interval [-xPI2,xPI2) (-xPI2 is included, xPI2 is excluded).
+ friend xcomplex log_sqrt (const xcomplex& z);
+
+ // These functions are self-explanatory. atan(z)
+ // yields a domain-error if the real part of 'z' is null and
+ // the imaginary part is equal to '+1' or '-1'.
+ // Similarly, atanh(z) yields a domain-error if the
+ // imaginary part of 'z' is null and the
+ // real part is equal to '+1' or '-1'.
+ friend xcomplex atan (const xcomplex& z);
+ friend xcomplex asin (const xcomplex& z);
+ friend xcomplex acos (const xcomplex& z);
+ friend xcomplex atanh (const xcomplex& z);
+ friend xcomplex asinh (const xcomplex& z);
+ friend xcomplex acosh (const xcomplex& z);
+
+ // The return value of pow() is the power of the first
+ // argument raised to the second one.
+ // Note that the modulus of the first argument must be
+ // greater than zero, if the real part of
+ // the second argument is less or equal than zero, otherwise
+ // a bad-exponent error is produced.
+ friend xcomplex pow (const xcomplex& z1, const xcomplex& z2);
+
+ public:
+ // Various constructors. They allow to define
+ // an extended precision complex number in several ways.
+ // In addition, they allow for conversions from other
+ // numeric types.
+ xcomplex (const struct cxpr* pz = &cxZero);
+ xcomplex (struct cxpr z);
+ xcomplex (struct xpr x, struct xpr y = xZero);
+ xcomplex (xreal x, xreal y = xZERO);
+ xcomplex (double x, double y = 0.0);
+ xcomplex (float x, float y = 0.0);
+ xcomplex (int m, int n = 0);
+ xcomplex (long m, long n = 0);
+ xcomplex (unsigned int u, unsigned int v = 0U);
+ xcomplex (unsigned long u, unsigned long v = 0U);
+
+ // This constructor requires a special comment. If
+ // only the first argument is present, the initial portion
+ // of the string pointed to by this argument is converted
+ // into an extended precision complex number, if a
+ // conversion is possible. If no conversion is possible,
+ // then the returned number is xNAN + xNANi.
+ // If the second argument is present and is not null,
+ // it must be the address of a valid pointer to 'char'.
+ // Before returning, the constructor will set this pointer
+ // so that it points to the character after the last
+ // character used in the conversion.
+ xcomplex (const char* str, char** endptr = 0);
+
+ xcomplex (string str);
+ xcomplex (const xcomplex& z);
+
+ // Assignment operators. They do not require
+ // any explanation with the only exception of '%=',
+ // which combines a '%' operation with an assignment.
+ // So, x %= n is equivalent to x *= pow(2,n) .
+ xcomplex& operator= (const xcomplex& z);
+ xcomplex& operator+= (const xcomplex& z);
+ xcomplex& operator-= (const xcomplex& z);
+ xcomplex& operator*= (const xcomplex& z);
+ xcomplex& operator*= (const xreal& x);
+ xcomplex& operator/= (const xcomplex& z);
+ xcomplex& operator%= (int n);
+
+ // Increment and decrement operators. Both prefixed
+ // and postfixed versions are defined. These operators
+ // only act on the real part of their argument.
+ xcomplex& operator++ ();
+ xcomplex& operator-- ();
+ xcomplex& operator++ (int dummy);
+ xcomplex& operator-- (int dummy);
+
+ // Destructor. You will never have to recall it
+ // explicitly in your code.
+ ~xcomplex (void);
+
+ // Integer exponent power. For any extended precision
+ // complex number 'z', z(n) is equal to 'z' raised to 'n'.
+ xcomplex operator() (int n) const;
+
+ // This is the usual unary minus.
+ xcomplex operator-() const;
+
+ // For any extended precision complex number 'z',
+ // !z evaluates to 1 when
+ // 'z' is null, else it evaluates to 0.
+ int operator!() const;
+
+ // Functions for conversions. z._2dcomplex(), z._2fcomplex(),
+ // z._2cxpr() and z._2string() convert the extended
+ // precision complex number 'z' in a double precision
+ // complex number, in a single precision complex
+ // number, in a structure of type 'cxpr', and in a
+ // string, respectively.
+ double_complex _2dcomplex () const;
+ float_complex _2fcomplex() const;
+ struct cxpr _2cxpr() const;
+ string _2string() const;
+
+ // For any extended precision complex number 'z',
+ // z.real() and z.imag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of an extended precision number.
+ xreal real () const;
+ xreal imag () const;
+
+ // For any extended precision complex number 'z',
+ // z._real() and z._imag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a structure of 'xpr' type.
+ struct xpr _real () const;
+ struct xpr _imag () const;
+
+ // For any extended precision complex number 'z',
+ // z.dreal() and z.dimag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a double precision number.
+ double dreal () const;
+ double dimag () const;
+
+ // For any extended precision complex number 'z',
+ // z.freal() and z.fimag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a single precision number.
+ double freal () const;
+ double fimag () const;
+
+ // For any extended precision complex number 'z',
+ // z.sreal() and z.simag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a string.
+ string sreal () const;
+ string simag () const;
+
+ // The next functions allow to set (or reset)
+ // the real and the imaginary part of a complex number.
+ void real (const xreal& x);
+ void imag (const xreal& x);
+ void real (struct xpr x);
+ void imag (struct xpr x);
+ void real (const struct xpr* px);
+ void imag (const struct xpr* px);
+ void real (double x);
+ void imag (double x);
+ void real (float x);
+ void imag (float x);
+ void real (int n);
+ void imag (int n);
+ void real (long n);
+ void imag (long n);
+ void real (unsigned int u);
+ void imag (unsigned int u);
+ void real (unsigned long u);
+ void imag (unsigned long u);
+ void real (const char* str, char** endptr = 0);
+ void imag (const char* str, char** endptr = 0);
+ void real (string str);
+ void imag (string str);
+
+ // The member function xcomplex::getfrom() can be used
+ // to recover an extended precision complex number from an
+ // input stream. The input stream is passed as argument to
+ // the function.
+ // The return value is 0 in case of input error (in case of
+ // End-Of-File, for example).
+ // When it starts to process its input, this function drops
+ // all eventual leading white spaces.
+ // After reading the first non space character, it continues
+ // to read from the input stream until it finds a white
+ // space or reaches the End-Of-File.
+ // Then it tries to convert into an extended
+ // precision complex number the (initial portion of the)
+ // string which has just been read from the input stream.
+ // If no conversion can be performed, then z.getfrom(is)
+ // sets 'z' to the value xNAN + xNANi.
+ // If the exactly converted value would cause overflow in
+ // the real or/and in the imaginary part, then the real part
+ // or/and the imaginary part of 'z' are set to xINF or x_INF,
+ // according to the signs of the correct value.
+ int getfrom (istream& is);
+
+ // The member function xcomplex::print() can be used to
+ // write an extended precision complex number to an output
+ // stream. The output stream is passed to the function as
+ // first argument. The next three arguments have the same
+ // meanings of the fields 'notat', 'sf'
+ // and 'lim' of the structure 'xoutflags', respectively (see section
+ // "Real Arithmetic").
+ int print (ostream& os, int sc_not, int sign, int lim) const;
+
+ // The function call z.asprint(sc_not, sign, lim) returns
+ // a buffer of characters with the representation,
+ // in form of a decimal ASCII string,
+ // of the extended precision complex number 'z'.
+ // The arguments 'sc_not', 'sign' and 'lim' are used
+ // to format the string.
+ // They have the same meanings of the fields 'notat', 'sf'
+ // and 'lim' of the structure 'xoutflags', respectively (see section
+ // "Real Arithmetic").
+ // The buffer returned by this function is malloc'ed inside
+ // the function. In case of insufficient memory, the null
+ // pointer is returned.
+ char* asprint (int sc_not, int sign, int lim) const;
+
+ // The following static functions are used to set
+ // or get the values of the fields of the structure
+ // 'xcomplex::ioflags'. This structure is a static member
+ // variable of the class 'xcomplex' and it is used by
+ // the output operator << to know how to format its second
+ // argument. The meaning of the
+ // fields of the structure 'xcomplex::ioflags' is explained
+ // in the section "Real arithmetic".
+
+ // xcomplex::set_fmt (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.fmt' .
+ static void set_fmt (short format);
+
+ // xcomplex::set_notation (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.notat' .
+ static void set_notation (short notat);
+
+ // xcomplex::set_signflag (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.sf' .
+ static void set_signflag (short onoff);
+
+ // xcomplex::set_mfwd (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.mfwd' .
+ static void set_mfwd (short wd);
+
+ // xcomplex::set_lim (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.lim' .
+ static void set_lim (short lim);
+
+ // xcomplex::set_padding (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.padding' .
+ static void set_padding (signed char ch);
+
+ // xcomplex::set_ldelim (ch) sets to 'ch' the value
+ // of 'xcomplex::ioflags.ldel' .
+ static void set_ldelim (signed char ch);
+
+ // xcomplex::set_rdelim (ch) sets to 'ch' the value
+ // of 'xcomplex::ioflags.rdel' .
+ static void set_rdelim (signed char ch);
+
+ // xcomplex::get_fmt () returns the current value
+ // of 'xcomplex::ioflags.fmt' .
+ static short get_fmt (void);
+
+ // xcomplex::get_notation () returns the current value
+ // of 'xcomplex::ioflags.notat' .
+ static short get_notation (void);
+
+ // xcomplex::get_signflag () returns the current value
+ // of 'xcomplex::ioflags.sf' .
+ static short get_signflag (void);
+
+ // xcomplex::get_mfwd () returns the current value
+ // of 'xcomplex::ioflags.mfwd' .
+ static short get_mfwd (void);
+
+ // xcomplex::get_lim () returns the current value
+ // of 'xcomplex::ioflags.lim' .
+ static short get_lim (void);
+
+ // xcomplex::get_padding () returns the current value
+ // of 'xcomplex::ioflags.padding' .
+ static signed char get_padding (void);
+
+ // xcomplex::get_ldelim () returns the current value
+ // of 'xcomplex::ioflags.ldel' .
+ static signed char get_ldelim (void);
+
+ // xcomplex::get_rdelim () returns the current value
+ // of 'xcomplex::ioflags.rdel' .
+ static signed char get_rdelim (void);
+ private:
+ struct cxpr br; /* binary representation */
+ static struct xoutflags ioflags; /* output flags */
+ };
+
+ // Some useful constants:
+ // cxZERO == 0
+ // cxONE == 1
+ // cxI == 1i
+ extern const xcomplex cxZERO, cxONE, cxI;
+
+ } /* End namespace HPA */
+
+ #define xi cxI
+ #define xj cxI
+ #define _i cxI
+ #define _j cxI
+
+ #endif /* _XCOMPLEX_H_ */
+
+
+ 13. Acknowledgments
+ ===================
+
+A big thanks to Daniel A. Atkinson,
+since without his work the HPA library would not exist.
+I have also to thank Aurelio Marinho Jargas
+, author of txt2tags
+(http://txt2tags.sf.net), a free (GPL'ed) and wonderful
+text formatting and conversion tool,
+which I used extensively in writing this manual
+and the web page of the HPA library.
+
+Last but not least, I want to thank all the
+people till now involved in the Free Software
+community, starting from those ones directly involved
+in the GNU project (http://www.gnu.org).
+
+
+ 14. GNU Free Documentation License
+ ==================================
+
+
+
+ GNU Free Documentation License
+ Version 1.3, 3 November 2008
+
+
+ Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
+
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ 0. PREAMBLE
+
+ The purpose of this License is to make a manual, textbook, or other
+ functional and useful document "free" in the sense of freedom: to
+ assure everyone the effective freedom to copy and redistribute it,
+ with or without modifying it, either commercially or noncommercially.
+ Secondarily, this License preserves for the author and publisher a way
+ to get credit for their work, while not being considered responsible
+ for modifications made by others.
+
+ This License is a kind of "copyleft", which means that derivative
+ works of the document must themselves be free in the same sense. It
+ complements the GNU General Public License, which is a copyleft
+ license designed for free software.
+
+ We have designed this License in order to use it for manuals for free
+ software, because free software needs free documentation: a free
+ program should come with manuals providing the same freedoms that the
+ software does. But this License is not limited to software manuals;
+ it can be used for any textual work, regardless of subject matter or
+ whether it is published as a printed book. We recommend this License
+ principally for works whose purpose is instruction or reference.
+
+
+ 1. APPLICABILITY AND DEFINITIONS
+
+ This License applies to any manual or other work, in any medium, that
+ contains a notice placed by the copyright holder saying it can be
+ distributed under the terms of this License. Such a notice grants a
+ world-wide, royalty-free license, unlimited in duration, to use that
+ work under the conditions stated herein. The "Document", below,
+ refers to any such manual or work. Any member of the public is a
+ licensee, and is addressed as "you". You accept the license if you
+ copy, modify or distribute the work in a way requiring permission
+ under copyright law.
+
+ A "Modified Version" of the Document means any work containing the
+ Document or a portion of it, either copied verbatim, or with
+ modifications and/or translated into another language.
+
+ A "Secondary Section" is a named appendix or a front-matter section of
+ the Document that deals exclusively with the relationship of the
+ publishers or authors of the Document to the Document's overall
+ subject (or to related matters) and contains nothing that could fall
+ directly within that overall subject. (Thus, if the Document is in
+ part a textbook of mathematics, a Secondary Section may not explain
+ any mathematics.) The relationship could be a matter of historical
+ connection with the subject or with related matters, or of legal,
+ commercial, philosophical, ethical or political position regarding
+ them.
+
+ The "Invariant Sections" are certain Secondary Sections whose titles
+ are designated, as being those of Invariant Sections, in the notice
+ that says that the Document is released under this License. If a
+ section does not fit the above definition of Secondary then it is not
+ allowed to be designated as Invariant. The Document may contain zero
+ Invariant Sections. If the Document does not identify any Invariant
+ Sections then there are none.
+
+ The "Cover Texts" are certain short passages of text that are listed,
+ as Front-Cover Texts or Back-Cover Texts, in the notice that says that
+ the Document is released under this License. A Front-Cover Text may
+ be at most 5 words, and a Back-Cover Text may be at most 25 words.
+
+ A "Transparent" copy of the Document means a machine-readable copy,
+ represented in a format whose specification is available to the
+ general public, that is suitable for revising the document
+ straightforwardly with generic text editors or (for images composed of
+ pixels) generic paint programs or (for drawings) some widely available
+ drawing editor, and that is suitable for input to text formatters or
+ for automatic translation to a variety of formats suitable for input
+ to text formatters. A copy made in an otherwise Transparent file
+ format whose markup, or absence of markup, has been arranged to thwart
+ or discourage subsequent modification by readers is not Transparent.
+ An image format is not Transparent if used for any substantial amount
+ of text. A copy that is not "Transparent" is called "Opaque".
+
+ Examples of suitable formats for Transparent copies include plain
+ ASCII without markup, Texinfo input format, LaTeX input format, SGML
+ or XML using a publicly available DTD, and standard-conforming simple
+ HTML, PostScript or PDF designed for human modification. Examples of
+ transparent image formats include PNG, XCF and JPG. Opaque formats
+ include proprietary formats that can be read and edited only by
+ proprietary word processors, SGML or XML for which the DTD and/or
+ processing tools are not generally available, and the
+ machine-generated HTML, PostScript or PDF produced by some word
+ processors for output purposes only.
+
+ The "Title Page" means, for a printed book, the title page itself,
+ plus such following pages as are needed to hold, legibly, the material
+ this License requires to appear in the title page. For works in
+ formats which do not have any title page as such, "Title Page" means
+ the text near the most prominent appearance of the work's title,
+ preceding the beginning of the body of the text.
+
+ The "publisher" means any person or entity that distributes copies of
+ the Document to the public.
+
+ A section "Entitled XYZ" means a named subunit of the Document whose
+ title either is precisely XYZ or contains XYZ in parentheses following
+ text that translates XYZ in another language. (Here XYZ stands for a
+ specific section name mentioned below, such as "Acknowledgements",
+ "Dedications", "Endorsements", or "History".) To "Preserve the Title"
+ of such a section when you modify the Document means that it remains a
+ section "Entitled XYZ" according to this definition.
+
+ The Document may include Warranty Disclaimers next to the notice which
+ states that this License applies to the Document. These Warranty
+ Disclaimers are considered to be included by reference in this
+ License, but only as regards disclaiming warranties: any other
+ implication that these Warranty Disclaimers may have is void and has
+ no effect on the meaning of this License.
+
+ 2. VERBATIM COPYING
+
+ You may copy and distribute the Document in any medium, either
+ commercially or noncommercially, provided that this License, the
+ copyright notices, and the license notice saying this License applies
+ to the Document are reproduced in all copies, and that you add no
+ other conditions whatsoever to those of this License. You may not use
+ technical measures to obstruct or control the reading or further
+ copying of the copies you make or distribute. However, you may accept
+ compensation in exchange for copies. If you distribute a large enough
+ number of copies you must also follow the conditions in section 3.
+
+ You may also lend copies, under the same conditions stated above, and
+ you may publicly display copies.
+
+
+ 3. COPYING IN QUANTITY
+
+ If you publish printed copies (or copies in media that commonly have
+ printed covers) of the Document, numbering more than 100, and the
+ Document's license notice requires Cover Texts, you must enclose the
+ copies in covers that carry, clearly and legibly, all these Cover
+ Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
+ the back cover. Both covers must also clearly and legibly identify
+ you as the publisher of these copies. The front cover must present
+ the full title with all words of the title equally prominent and
+ visible. You may add other material on the covers in addition.
+ Copying with changes limited to the covers, as long as they preserve
+ the title of the Document and satisfy these conditions, can be treated
+ as verbatim copying in other respects.
+
+ If the required texts for either cover are too voluminous to fit
+ legibly, you should put the first ones listed (as many as fit
+ reasonably) on the actual cover, and continue the rest onto adjacent
+ pages.
+
+ If you publish or distribute Opaque copies of the Document numbering
+ more than 100, you must either include a machine-readable Transparent
+ copy along with each Opaque copy, or state in or with each Opaque copy
+ a computer-network location from which the general network-using
+ public has access to download using public-standard network protocols
+ a complete Transparent copy of the Document, free of added material.
+ If you use the latter option, you must take reasonably prudent steps,
+ when you begin distribution of Opaque copies in quantity, to ensure
+ that this Transparent copy will remain thus accessible at the stated
+ location until at least one year after the last time you distribute an
+ Opaque copy (directly or through your agents or retailers) of that
+ edition to the public.
+
+ It is requested, but not required, that you contact the authors of the
+ Document well before redistributing any large number of copies, to
+ give them a chance to provide you with an updated version of the
+ Document.
+
+
+ 4. MODIFICATIONS
+
+ You may copy and distribute a Modified Version of the Document under
+ the conditions of sections 2 and 3 above, provided that you release
+ the Modified Version under precisely this License, with the Modified
+ Version filling the role of the Document, thus licensing distribution
+ and modification of the Modified Version to whoever possesses a copy
+ of it. In addition, you must do these things in the Modified Version:
+
+ A. Use in the Title Page (and on the covers, if any) a title distinct
+ from that of the Document, and from those of previous versions
+ (which should, if there were any, be listed in the History section
+ of the Document). You may use the same title as a previous version
+ if the original publisher of that version gives permission.
+ B. List on the Title Page, as authors, one or more persons or entities
+ responsible for authorship of the modifications in the Modified
+ Version, together with at least five of the principal authors of the
+ Document (all of its principal authors, if it has fewer than five),
+ unless they release you from this requirement.
+ C. State on the Title page the name of the publisher of the
+ Modified Version, as the publisher.
+ D. Preserve all the copyright notices of the Document.
+ E. Add an appropriate copyright notice for your modifications
+ adjacent to the other copyright notices.
+ F. Include, immediately after the copyright notices, a license notice
+ giving the public permission to use the Modified Version under the
+ terms of this License, in the form shown in the Addendum below.
+ G. Preserve in that license notice the full lists of Invariant Sections
+ and required Cover Texts given in the Document's license notice.
+ H. Include an unaltered copy of this License.
+ I. Preserve the section Entitled "History", Preserve its Title, and add
+ to it an item stating at least the title, year, new authors, and
+ publisher of the Modified Version as given on the Title Page. If
+ there is no section Entitled "History" in the Document, create one
+ stating the title, year, authors, and publisher of the Document as
+ given on its Title Page, then add an item describing the Modified
+ Version as stated in the previous sentence.
+ J. Preserve the network location, if any, given in the Document for
+ public access to a Transparent copy of the Document, and likewise
+ the network locations given in the Document for previous versions
+ it was based on. These may be placed in the "History" section.
+ You may omit a network location for a work that was published at
+ least four years before the Document itself, or if the original
+ publisher of the version it refers to gives permission.
+ K. For any section Entitled "Acknowledgements" or "Dedications",
+ Preserve the Title of the section, and preserve in the section all
+ the substance and tone of each of the contributor acknowledgements
+ and/or dedications given therein.
+ L. Preserve all the Invariant Sections of the Document,
+ unaltered in their text and in their titles. Section numbers
+ or the equivalent are not considered part of the section titles.
+ M. Delete any section Entitled "Endorsements". Such a section
+ may not be included in the Modified Version.
+ N. Do not retitle any existing section to be Entitled "Endorsements"
+ or to conflict in title with any Invariant Section.
+ O. Preserve any Warranty Disclaimers.
+
+ If the Modified Version includes new front-matter sections or
+ appendices that qualify as Secondary Sections and contain no material
+ copied from the Document, you may at your option designate some or all
+ of these sections as invariant. To do this, add their titles to the
+ list of Invariant Sections in the Modified Version's license notice.
+ These titles must be distinct from any other section titles.
+
+ You may add a section Entitled "Endorsements", provided it contains
+ nothing but endorsements of your Modified Version by various
+ parties--for example, statements of peer review or that the text has
+ been approved by an organization as the authoritative definition of a
+ standard.
+
+ You may add a passage of up to five words as a Front-Cover Text, and a
+ passage of up to 25 words as a Back-Cover Text, to the end of the list
+ of Cover Texts in the Modified Version. Only one passage of
+ Front-Cover Text and one of Back-Cover Text may be added by (or
+ through arrangements made by) any one entity. If the Document already
+ includes a cover text for the same cover, previously added by you or
+ by arrangement made by the same entity you are acting on behalf of,
+ you may not add another; but you may replace the old one, on explicit
+ permission from the previous publisher that added the old one.
+
+ The author(s) and publisher(s) of the Document do not by this License
+ give permission to use their names for publicity for or to assert or
+ imply endorsement of any Modified Version.
+
+
+ 5. COMBINING DOCUMENTS
+
+ You may combine the Document with other documents released under this
+ License, under the terms defined in section 4 above for modified
+ versions, provided that you include in the combination all of the
+ Invariant Sections of all of the original documents, unmodified, and
+ list them all as Invariant Sections of your combined work in its
+ license notice, and that you preserve all their Warranty Disclaimers.
+
+ The combined work need only contain one copy of this License, and
+ multiple identical Invariant Sections may be replaced with a single
+ copy. If there are multiple Invariant Sections with the same name but
+ different contents, make the title of each such section unique by
+ adding at the end of it, in parentheses, the name of the original
+ author or publisher of that section if known, or else a unique number.
+ Make the same adjustment to the section titles in the list of
+ Invariant Sections in the license notice of the combined work.
+
+ In the combination, you must combine any sections Entitled "History"
+ in the various original documents, forming one section Entitled
+ "History"; likewise combine any sections Entitled "Acknowledgements",
+ and any sections Entitled "Dedications". You must delete all sections
+ Entitled "Endorsements".
+
+
+ 6. COLLECTIONS OF DOCUMENTS
+
+ You may make a collection consisting of the Document and other
+ documents released under this License, and replace the individual
+ copies of this License in the various documents with a single copy
+ that is included in the collection, provided that you follow the rules
+ of this License for verbatim copying of each of the documents in all
+ other respects.
+
+ You may extract a single document from such a collection, and
+ distribute it individually under this License, provided you insert a
+ copy of this License into the extracted document, and follow this
+ License in all other respects regarding verbatim copying of that
+ document.
+
+
+ 7. AGGREGATION WITH INDEPENDENT WORKS
+
+ A compilation of the Document or its derivatives with other separate
+ and independent documents or works, in or on a volume of a storage or
+ distribution medium, is called an "aggregate" if the copyright
+ resulting from the compilation is not used to limit the legal rights
+ of the compilation's users beyond what the individual works permit.
+ When the Document is included in an aggregate, this License does not
+ apply to the other works in the aggregate which are not themselves
+ derivative works of the Document.
+
+ If the Cover Text requirement of section 3 is applicable to these
+ copies of the Document, then if the Document is less than one half of
+ the entire aggregate, the Document's Cover Texts may be placed on
+ covers that bracket the Document within the aggregate, or the
+ electronic equivalent of covers if the Document is in electronic form.
+ Otherwise they must appear on printed covers that bracket the whole
+ aggregate.
+
+
+ 8. TRANSLATION
+
+ Translation is considered a kind of modification, so you may
+ distribute translations of the Document under the terms of section 4.
+ Replacing Invariant Sections with translations requires special
+ permission from their copyright holders, but you may include
+ translations of some or all Invariant Sections in addition to the
+ original versions of these Invariant Sections. You may include a
+ translation of this License, and all the license notices in the
+ Document, and any Warranty Disclaimers, provided that you also include
+ the original English version of this License and the original versions
+ of those notices and disclaimers. In case of a disagreement between
+ the translation and the original version of this License or a notice
+ or disclaimer, the original version will prevail.
+
+ If a section in the Document is Entitled "Acknowledgements",
+ "Dedications", or "History", the requirement (section 4) to Preserve
+ its Title (section 1) will typically require changing the actual
+ title.
+
+
+ 9. TERMINATION
+
+ You may not copy, modify, sublicense, or distribute the Document
+ except as expressly provided under this License. Any attempt
+ otherwise to copy, modify, sublicense, or distribute it is void, and
+ will automatically terminate your rights under this License.
+
+ However, if you cease all violation of this License, then your license
+ from a particular copyright holder is reinstated (a) provisionally,
+ unless and until the copyright holder explicitly and finally
+ terminates your license, and (b) permanently, if the copyright holder
+ fails to notify you of the violation by some reasonable means prior to
+ 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+ reinstated permanently if the copyright holder notifies you of the
+ violation by some reasonable means, this is the first time you have
+ received notice of violation of this License (for any work) from that
+ copyright holder, and you cure the violation prior to 30 days after
+ your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+ licenses of parties who have received copies or rights from you under
+ this License. If your rights have been terminated and not permanently
+ reinstated, receipt of a copy of some or all of the same material does
+ not give you any rights to use it.
+
+
+ 10. FUTURE REVISIONS OF THIS LICENSE
+
+ The Free Software Foundation may publish new, revised versions of the
+ GNU Free Documentation License from time to time. Such new versions
+ will be similar in spirit to the present version, but may differ in
+ detail to address new problems or concerns. See
+ http://www.gnu.org/copyleft/.
+
+ Each version of the License is given a distinguishing version number.
+ If the Document specifies that a particular numbered version of this
+ License "or any later version" applies to it, you have the option of
+ following the terms and conditions either of that specified version or
+ of any later version that has been published (not as a draft) by the
+ Free Software Foundation. If the Document does not specify a version
+ number of this License, you may choose any version ever published (not
+ as a draft) by the Free Software Foundation. If the Document
+ specifies that a proxy can decide which future versions of this
+ License can be used, that proxy's public statement of acceptance of a
+ version permanently authorizes you to choose that version for the
+ Document.
+
+ 11. RELICENSING
+
+ "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
+ World Wide Web server that publishes copyrightable works and also
+ provides prominent facilities for anybody to edit those works. A
+ public wiki that anybody can edit is an example of such a server. A
+ "Massive Multiauthor Collaboration" (or "MMC") contained in the site
+ means any set of copyrightable works thus published on the MMC site.
+
+ "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
+ license published by Creative Commons Corporation, a not-for-profit
+ corporation with a principal place of business in San Francisco,
+ California, as well as future copyleft versions of that license
+ published by that same organization.
+
+ "Incorporate" means to publish or republish a Document, in whole or in
+ part, as part of another Document.
+
+ An MMC is "eligible for relicensing" if it is licensed under this
+ License, and if all works that were first published under this License
+ somewhere other than this MMC, and subsequently incorporated in whole or
+ in part into the MMC, (1) had no cover texts or invariant sections, and
+ (2) were thus incorporated prior to November 1, 2008.
+
+ The operator of an MMC Site may republish an MMC contained in the site
+ under CC-BY-SA on the same site at any time before August 1, 2009,
+ provided the MMC is eligible for relicensing.
+
+
+ ADDENDUM: How to use this License for your documents
+
+ To use this License in a document you have written, include a copy of
+ the License in the document and put the following copyright and
+ license notices just after the title page:
+
+ Copyright (c) YEAR YOUR NAME.
+ Permission is granted to copy, distribute and/or modify this document
+ under the terms of the GNU Free Documentation License, Version 1.3
+ or any later version published by the Free Software Foundation;
+ with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
+ A copy of the license is included in the section entitled "GNU
+ Free Documentation License".
+
+ If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
+ replace the "with...Texts." line with this:
+
+ with the Invariant Sections being LIST THEIR TITLES, with the
+ Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
+
+ If you have Invariant Sections without Cover Texts, or some other
+ combination of the three, merge those two alternatives to suit the
+ situation.
+
+ If your document contains nontrivial examples of program code, we
+ recommend releasing these examples in parallel under your choice of
+ free software license, such as the GNU General Public License,
+ to permit their use in free software.
+
+
+
+
+
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/xcomplex.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/xcomplex.h
new file mode 100644
index 00000000..b5b5f424
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/xcomplex.h
@@ -0,0 +1,509 @@
+#ifndef _XCOMPLEX_H_
+#define _XCOMPLEX_H_
+
+#include
+#include
+#include
+#include "xreal.h"
+
+using std::istream;
+using std::ostream;
+using std::string;
+
+namespace HPA {
+
+ struct double_complex {
+ double re, im;
+ };
+
+ struct float_complex {
+ float re, im;
+ };
+
+class xcomplex {
+ // << and >> are used respectively for the output and the
+ // input of extended precision complex numbers.
+ // The input operator >> reads a couple of double
+ // precision numbers and then converts it into
+ // an extended precision complex number. This can have
+ // undesirable rounding effects. To avoid them, use the
+ // input function xcomplex::getfrom() (see below).
+ friend ostream& operator<< (ostream& os, const xcomplex& z);
+ friend istream& operator>> (istream& is, xcomplex& z);
+
+ // +, -, *, / are the usual arithmetic operators
+ friend xcomplex
+ operator+ (const xcomplex& z1, const xcomplex& z2);
+ friend xcomplex
+ operator- (const xcomplex& z1, const xcomplex& z2);
+ friend xcomplex
+ operator* (const xcomplex& z1, const xcomplex& z2);
+ friend xcomplex
+ operator/ (const xcomplex& z1, const xcomplex& z2);
+
+ // z % n is equal to z * pow (2,n)
+ friend xcomplex
+ operator% (const xcomplex& z, int n);
+
+ // ==, !=, <=, >=, <, > are the usual comparison operators
+ friend int
+ operator== (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator!= (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator<= (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator>= (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator< (const xcomplex& z1, const xcomplex& z2);
+ friend int
+ operator> (const xcomplex& z1, const xcomplex& z2);
+
+ // sget (s, n, z) tries to read an extended precision
+ // complex number from the string 's' starting from the
+ // position 'n'. The retrieved number is converted and
+ // stored in 'z'. The return value is the number of
+ // characters composing the decimal representation of this
+ // number as read from 's'.
+ // For example, if s == "12.34+6.7idog" and n == 0,
+ // then 'z' is set to 12.34+6.7i and the return value
+ // is 10.
+ // If the portion of 's' starting from the position 'n' can
+ // not be converted to a number, then 'z' is set to
+ // xNAN + xNANi and 0 is returned.
+ // If the exactly converted value would cause overflow in
+ // the real or/and imaginary part, then the real or/and the
+ // imaginary part of 'z' are set to xINF or x_INF, according
+ // to the signs of the correct value.
+ // If 'n' is greater or equal to the length of 's', then 0
+ // is returned and 'z' is set to cxZERO.
+ friend unsigned long sget (string s, unsigned long startptr,
+ xcomplex& z);
+
+ // bget (buff, z) tries to read an extended precision
+ // complex number from the buffer pointed to by 'buff'.
+ // The retrieved number is converted and stored in 'z'.
+ // The return value is a pointer to the character after
+ // the last character used in the conversion.
+ // For example, if 'buff' is a pointer to the buffer
+ // "12.34+6.7idog", then 'z' is set to 12.34+6.7i and
+ // the return value is a pointer to "dog" (i.e.,
+ // a pointer to the character 'd').
+ // If the initial portion of the string pointed to by 'buff'
+ // can not be converted to a number, then 'z' is set to
+ // xNAN + xNANi and 'buff' is returned.
+ // If the exactly converted value would cause overflow
+ // in the real or/and imaginary part, then the real or/and
+ // the imaginary part of 'z' are set to xINF or x_INF,
+ // according to the signs of the correct value.
+ // If 'buff' is NULL (0), then an error message is printed
+ // on 'cerr' (standard error device).
+ friend const char* bget (const char* buff, xcomplex& z);
+
+ // rmul (x,z) (here 'x' is a real number) returns the
+ // product x * z.
+ // It is faster than the * operator.
+ friend xcomplex rmul (const xreal& x, const xcomplex& z);
+
+ // After eventually rounding 'z1' and 'z2' by recalling
+ // round() (see below) on them, gdiv(z1, z2) returns
+ // the quotient of the gaussian division of 'z1' by 'z2'.
+ // If you do not know what gaussian division means, probably
+ // you will never need this function :)
+ friend xcomplex
+ gdiv (const xcomplex& z1, const xcomplex& z2);
+
+ // After eventually rounding 'z1' and 'z2' by recalling
+ // round() (see below) on them, gmod(z1, z2) returns
+ // the remainder of the gaussian division of 'z1' by 'z2'.
+ // If you do not know what gaussian division means, probably
+ // you will never need this function :)
+ friend xcomplex
+ gmod (const xcomplex& z1, const xcomplex& z2);
+
+ // idiv() is a wrapper to cxidiv() (see section
+ // "Extended Precision Complex Arithmetic").
+ friend xcomplex
+ idiv (const xcomplex& z1, const xcomplex& z2);
+
+ // mod() is a wrapper to cxmod() (see section
+ // "Extended Precision Complex Arithmetic").
+ friend xcomplex
+ mod (const xcomplex& z1, const xcomplex& z2);
+
+ // conj() returns the complex conjugate of its argument.
+ friend xcomplex conj (const xcomplex& z);
+
+ // inv() returns the complex reciprocal of its argument:
+ // inv(z) == 1/z .
+ friend xcomplex inv (const xcomplex& z);
+
+ // swap(z) returns the complex number {z.im, z.re}.
+ friend xcomplex swap (const xcomplex& z);
+
+ // Multiplication by 1i (imaginary unit).
+ friend xcomplex drot (const xcomplex& z);
+
+ // Multiplication by -1i
+ friend xcomplex rrot (const xcomplex& z);
+
+ // abs() returns the absolute value (or modulus) of its
+ // argument.
+ // The return value of abs() is then an 'xreal' number.
+ friend xreal abs (const xcomplex& z);
+
+ // arg(z) returns the phase angle (or argument)
+ // of the complex number 'z'.
+ // The return value of arg() is an 'xreal' number
+ // in the range [-xPI, xPI) (-xPI is included, xPI is excluded).
+ // If 'z' is null, then a domain-error is produced.
+ friend xreal arg (const xcomplex& z);
+
+ // The next six functions have the same
+ // meanings of the corresponding real functions,
+ // but they affect both the real
+ // and the imaginary part of their argument.
+ friend xcomplex frac (const xcomplex& z);
+ friend xcomplex trunc (const xcomplex& z);
+ friend xcomplex round (const xcomplex& z);
+ friend xcomplex ceil (const xcomplex& z);
+ friend xcomplex floor (const xcomplex& z);
+ friend xcomplex fix (const xcomplex& z);
+
+ // sqr() returns the square of its argument.
+ friend xcomplex sqr (const xcomplex& z);
+
+ // sqrt() returns the principal branch of the square root
+ // of its argument.
+ friend xcomplex sqrt (const xcomplex& z);
+
+ // root (z,i,n) returns the 'i'th branch of the 'n'th root
+ // of 'z'. If 'n' is zero or negative and 'z' is
+ // zero, then a bad-exponent error is produced.
+ friend xcomplex root (const xcomplex& z, int i, int n);
+
+ // These functions do not require any comment, except that
+ // tan() and tanh() yield a domain-error in the same cases
+ // as cxtan() and cxtanh(), respectively.
+ friend xcomplex exp (const xcomplex& z);
+ friend xcomplex exp2 (const xcomplex& z);
+ friend xcomplex exp10 (const xcomplex& z);
+ friend xcomplex tan (const xcomplex& z);
+ friend xcomplex sin (const xcomplex& z);
+ friend xcomplex cos (const xcomplex& z);
+ friend xcomplex tanh (const xcomplex& z);
+ friend xcomplex sinh (const xcomplex& z);
+ friend xcomplex cosh (const xcomplex& z);
+
+ // Natural, base-2 and base-10 logarithm of a complex
+ // number.
+ // A null argument results in a domain-error.
+ // The imaginary part of the return value of log() is always
+ // in the interval [-xPI,xPI) (-xPI is included, xPI is excluded).
+ friend xcomplex log (const xcomplex& z);
+ friend xcomplex log2 (const xcomplex& z);
+ friend xcomplex log10 (const xcomplex& z);
+
+ // log_sqrt(z) returns the natural logarithm of the
+ // principal branch of the square root of 'z'.
+ // A null argument results in a domain-error.
+ // The imaginary part of the return value of log_sqrt()
+ // is always in the interval [-xPI2,xPI2) (-xPI2 is included, xPI2 is excluded).
+ friend xcomplex log_sqrt (const xcomplex& z);
+
+ // These functions are self-explanatory. atan(z)
+ // yields a domain-error if the real part of 'z' is null and
+ // the imaginary part is equal to '+1' or '-1'.
+ // Similarly, atanh(z) yields a domain-error if the
+ // imaginary part of 'z' is null and the
+ // real part is equal to '+1' or '-1'.
+ friend xcomplex atan (const xcomplex& z);
+ friend xcomplex asin (const xcomplex& z);
+ friend xcomplex acos (const xcomplex& z);
+ friend xcomplex atanh (const xcomplex& z);
+ friend xcomplex asinh (const xcomplex& z);
+ friend xcomplex acosh (const xcomplex& z);
+
+ // The return value of pow() is the power of the first
+ // argument raised to the second one.
+ // Note that the modulus of the first argument must be
+ // greater than zero, if the real part of
+ // the second argument is less or equal than zero, otherwise
+ // a bad-exponent error is produced.
+ friend xcomplex pow (const xcomplex& z1, const xcomplex& z2);
+
+ public:
+ // Various constructors. They allow to define
+ // an extended precision complex number in several ways.
+ // In addition, they allow for conversions from other
+ // numeric types.
+ xcomplex (const struct cxpr* pz = &cxZero);
+ xcomplex (struct cxpr z);
+ xcomplex (struct xpr x, struct xpr y = xZero);
+ xcomplex (xreal x, xreal y = xZERO);
+ xcomplex (double x, double y = 0.0);
+ xcomplex (float x, float y = 0.0);
+ xcomplex (int m, int n = 0);
+ xcomplex (long m, long n = 0);
+ xcomplex (unsigned int u, unsigned int v = 0U);
+ xcomplex (unsigned long u, unsigned long v = 0U);
+
+ // This constructor requires a special comment. If
+ // only the first argument is present, the initial portion
+ // of the string pointed to by this argument is converted
+ // into an extended precision complex number, if a
+ // conversion is possible. If no conversion is possible,
+ // then the returned number is xNAN + xNANi.
+ // If the second argument is present and is not null,
+ // it must be the address of a valid pointer to 'char'.
+ // Before returning, the constructor will set this pointer
+ // so that it points to the character after the last
+ // character used in the conversion.
+ xcomplex (const char* str, char** endptr = 0);
+
+ xcomplex (string str);
+ xcomplex (const xcomplex& z);
+
+ // Assignment operators. They do not require
+ // any explanation with the only exception of '%=',
+ // which combines a '%' operation with an assignment.
+ // So, x %= n is equivalent to x *= pow(2,n) .
+ xcomplex& operator= (const xcomplex& z);
+ xcomplex& operator+= (const xcomplex& z);
+ xcomplex& operator-= (const xcomplex& z);
+ xcomplex& operator*= (const xcomplex& z);
+ xcomplex& operator*= (const xreal& x);
+ xcomplex& operator/= (const xcomplex& z);
+ xcomplex& operator%= (int n);
+
+ // Increment and decrement operators. Both prefixed
+ // and postfixed versions are defined. These operators
+ // only act on the real part of their argument.
+ xcomplex& operator++ ();
+ xcomplex& operator-- ();
+ xcomplex& operator++ (int dummy);
+ xcomplex& operator-- (int dummy);
+
+ // Destructor. You will never have to recall it
+ // explicitly in your code.
+ ~xcomplex (void);
+
+ // Integer exponent power. For any extended precision
+ // complex number 'z', z(n) is equal to 'z' raised to 'n'.
+ xcomplex operator() (int n) const;
+
+ // This is the usual unary minus.
+ xcomplex operator-() const;
+
+ // For any extended precision complex number 'z',
+ // !z evaluates to 1 when
+ // 'z' is null, else it evaluates to 0.
+ int operator!() const;
+
+ // Functions for conversions. z._2dcomplex(), z._2fcomplex(),
+ // z._2cxpr() and z._2string() convert the extended
+ // precision complex number 'z' in a double precision
+ // complex number, in a single precision complex
+ // number, in a structure of type 'cxpr', and in a
+ // string, respectively.
+ double_complex _2dcomplex () const;
+ float_complex _2fcomplex() const;
+ struct cxpr _2cxpr() const;
+ string _2string() const;
+
+ // For any extended precision complex number 'z',
+ // z.real() and z.imag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of an extended precision number.
+ xreal real () const;
+ xreal imag () const;
+
+ // For any extended precision complex number 'z',
+ // z._real() and z._imag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a structure of 'xpr' type.
+ struct xpr _real () const;
+ struct xpr _imag () const;
+
+ // For any extended precision complex number 'z',
+ // z.dreal() and z.dimag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a double precision number.
+ double dreal () const;
+ double dimag () const;
+
+ // For any extended precision complex number 'z',
+ // z.freal() and z.fimag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a single precision number.
+ double freal () const;
+ double fimag () const;
+
+ // For any extended precision complex number 'z',
+ // z.sreal() and z.simag() return, respectively, the
+ // real and the imaginary part of 'z' in the form
+ // of a string.
+ string sreal () const;
+ string simag () const;
+
+ // The next functions allow to set (or reset)
+ // the real and the imaginary part of a complex number.
+ void real (const xreal& x);
+ void imag (const xreal& x);
+ void real (struct xpr x);
+ void imag (struct xpr x);
+ void real (const struct xpr* px);
+ void imag (const struct xpr* px);
+ void real (double x);
+ void imag (double x);
+ void real (float x);
+ void imag (float x);
+ void real (int n);
+ void imag (int n);
+ void real (long n);
+ void imag (long n);
+ void real (unsigned int u);
+ void imag (unsigned int u);
+ void real (unsigned long u);
+ void imag (unsigned long u);
+ void real (const char* str, char** endptr = 0);
+ void imag (const char* str, char** endptr = 0);
+ void real (string str);
+ void imag (string str);
+
+ // The member function xcomplex::getfrom() can be used
+ // to recover an extended precision complex number from an
+ // input stream. The input stream is passed as argument to
+ // the function.
+ // The return value is 0 in case of input error (in case of
+ // End-Of-File, for example).
+ // When it starts to process its input, this function drops
+ // all eventual leading white spaces.
+ // After reading the first non space character, it continues
+ // to read from the input stream until it finds a white
+ // space or reaches the End-Of-File.
+ // Then it tries to convert into an extended
+ // precision complex number the (initial portion of the)
+ // string which has just been read from the input stream.
+ // If no conversion can be performed, then z.getfrom(is)
+ // sets 'z' to the value xNAN + xNANi.
+ // If the exactly converted value would cause overflow in
+ // the real or/and in the imaginary part, then the real part
+ // or/and the imaginary part of 'z' are set to xINF or x_INF,
+ // according to the signs of the correct value.
+ int getfrom (istream& is);
+
+ // The member function xcomplex::print() can be used to
+ // write an extended precision complex number to an output
+ // stream. The output stream is passed to the function as
+ // first argument. The next three arguments have the same
+ // meanings of the fields 'notat', 'sf'
+ // and 'lim' of the structure 'xoutflags', respectively (see section
+ // "Real Arithmetic").
+ int print (ostream& os, int sc_not, int sign, int lim) const;
+
+ // The function call z.asprint(sc_not, sign, lim) returns
+ // a buffer of characters with the representation,
+ // in form of a decimal ASCII string,
+ // of the extended precision complex number 'z'.
+ // The arguments 'sc_not', 'sign' and 'lim' are used
+ // to format the string.
+ // They have the same meanings of the fields 'notat', 'sf'
+ // and 'lim' of the structure 'xoutflags', respectively (see section
+ // "Real Arithmetic").
+ // The buffer returned by this function is malloc'ed inside
+ // the function. In case of insufficient memory, the null
+ // pointer is returned.
+ char* asprint (int sc_not, int sign, int lim) const;
+
+ // The following static functions are used to set
+ // or get the values of the fields of the structure
+ // 'xcomplex::ioflags'. This structure is a static member
+ // variable of the class 'xcomplex' and it is used by
+ // the output operator << to know how to format its second
+ // argument. The meaning of the
+ // fields of the structure 'xcomplex::ioflags' is explained
+ // in the section "Real arithmetic".
+
+ // xcomplex::set_fmt (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.fmt' .
+ static void set_fmt (short format);
+
+ // xcomplex::set_notation (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.notat' .
+ static void set_notation (short notat);
+
+ // xcomplex::set_signflag (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.sf' .
+ static void set_signflag (short onoff);
+
+ // xcomplex::set_mfwd (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.mfwd' .
+ static void set_mfwd (short wd);
+
+ // xcomplex::set_lim (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.lim' .
+ static void set_lim (short lim);
+
+ // xcomplex::set_padding (which) sets to 'which' the value
+ // of 'xcomplex::ioflags.padding' .
+ static void set_padding (signed char ch);
+
+ // xcomplex::set_ldelim (ch) sets to 'ch' the value
+ // of 'xcomplex::ioflags.ldel' .
+ static void set_ldelim (signed char ch);
+
+ // xcomplex::set_rdelim (ch) sets to 'ch' the value
+ // of 'xcomplex::ioflags.rdel' .
+ static void set_rdelim (signed char ch);
+
+ // xcomplex::get_fmt () returns the current value
+ // of 'xcomplex::ioflags.fmt' .
+ static short get_fmt (void);
+
+ // xcomplex::get_notation () returns the current value
+ // of 'xcomplex::ioflags.notat' .
+ static short get_notation (void);
+
+ // xcomplex::get_signflag () returns the current value
+ // of 'xcomplex::ioflags.sf' .
+ static short get_signflag (void);
+
+ // xcomplex::get_mfwd () returns the current value
+ // of 'xcomplex::ioflags.mfwd' .
+ static short get_mfwd (void);
+
+ // xcomplex::get_lim () returns the current value
+ // of 'xcomplex::ioflags.lim' .
+ static short get_lim (void);
+
+ // xcomplex::get_padding () returns the current value
+ // of 'xcomplex::ioflags.padding' .
+ static signed char get_padding (void);
+
+ // xcomplex::get_ldelim () returns the current value
+ // of 'xcomplex::ioflags.ldel' .
+ static signed char get_ldelim (void);
+
+ // xcomplex::get_rdelim () returns the current value
+ // of 'xcomplex::ioflags.rdel' .
+ static signed char get_rdelim (void);
+ private:
+ struct cxpr br; /* binary representation */
+ static struct xoutflags ioflags; /* output flags */
+};
+
+ // Some useful constants:
+ // cxZERO == 0
+ // cxONE == 1
+ // cxI == 1i
+extern const xcomplex cxZERO, cxONE, cxI;
+
+} /* End namespace HPA */
+
+#define xi cxI
+#define xj cxI
+#define _i cxI
+#define _j cxI
+
+#endif /* _XCOMPLEX_H_ */
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/xreal.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/xreal.h
new file mode 100644
index 00000000..5aad7f21
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/doc/xreal.h
@@ -0,0 +1,354 @@
+#ifndef _XREAL_H_
+#define _XREAL_H_
+
+#include
+#include
+#include
+#include
+
+using std::ostream;
+using std::istream;
+using std::string;
+
+namespace HPA {
+
+class xreal {
+ // << and >> are used respectively for the output and the
+ // input of extended precision numbers.
+ // The input operator >> reads a double precision
+ // number and then converts it to an extended precision
+ // number. This can have undesirable rounding effects.
+ // To avoid them, use the input function
+ // xreal::getfrom() (see below).
+ friend ostream& operator<< (ostream& os, const xreal& x);
+ friend istream& operator>> (istream& is, xreal& x);
+
+ // +, -, *, / are the usual arithmetic operators
+ friend xreal operator+ (const xreal& x1, const xreal& x2);
+ friend xreal operator- (const xreal& x1, const xreal& x2);
+ friend xreal operator* (const xreal& x1, const xreal& x2);
+ friend xreal operator/ (const xreal& x1, const xreal& x2);
+
+ // x % n is equal to x * pow (2,n)
+ friend xreal operator% (const xreal& x1, int n);
+
+ // ==, !=, <=, >=, <, > are the usual comparison operators
+ friend int operator== (const xreal& x1, const xreal& x2);
+ friend int operator!= (const xreal& x1, const xreal& x2);
+ friend int operator<= (const xreal& x1, const xreal& x2);
+ friend int operator>= (const xreal& x1, const xreal& x2);
+ friend int operator< (const xreal& x1, const xreal& x2);
+ friend int operator> (const xreal& x1, const xreal& x2);
+
+ // sget (s, n, x) tries to read an extended precision
+ // number from the string 's' starting from the position
+ // 'n'. The retrieved number is converted and stored in
+ // 'x'. The return value is the number of characters
+ // composing the decimal representation of this number
+ // as read from 's'. For example, if s == "12.34dog" and
+ // n == 0, then 'x' is set to 12.34 and the return value
+ // is 5.
+ // If the portion of 's' starting from the position 'n'
+ // can not be converted to a number, then 'x' is set to
+ // xNAN and 0 is returned.
+ // If the exactly converted value would cause overflow,
+ // then xINF or x_INF is returned, according to the sign
+ // of the value.
+ // If 'n' is greater or equal to the length of 's', then 0
+ // is returned and 'x' is set to xZERO.
+ friend unsigned long sget (string s, unsigned long startptr,
+ xreal& x);
+
+ // bget (buff, x) tries to read an extended precision
+ // number from the buffer pointed to by 'buff'.
+ // The retrieved number is converted and stored in 'x'.
+ // The return value is a pointer to the character after
+ // the last character used in the conversion.
+ // For example, if 'buff' is a pointer to the buffer
+ // "12.34dog", then 'x' is set to 12.34 and the return
+ // value is a pointer to "dog" (i.e., a pointer
+ // to the character 'd').
+ // If the initial portion of the string pointed to by 'buff'
+ // can not be converted to a number, then 'x' is set to xNAN
+ // and 'buff' is returned.
+ // If the exactly converted value would cause overflow,
+ // then xINF or x_INF is returned, according to the sign
+ // of the value.
+ // If 'buff' is NULL (0), then an error message is printed
+ // on 'cerr' (standard error device).
+ friend const char* bget (const char* buff, xreal& x);
+
+ // compare (x1, x2) returns
+ //+1 to mean x1 > x2
+ // 0 to mean x1 == x2
+ //-1 to mean x1 < x2
+ friend int compare (const xreal& x1, const xreal& x2);
+
+ //isNaN (x) returns 1 when x == xNAN, else 0
+ friend int isNaN (const xreal& x);
+
+ // The following functions do not need a particular comment:
+ // each of them is defined as the corresponding function
+ // of the standard math library, that is to say the function
+ // from having the same name.
+ // However qfmod(), sfmod(), frac() and fix() do not have
+ // counterparts in the standard math library.
+ // With respect to fmod(), qfmod() requires one more
+ // argument, where the quotient of the division of
+ // the first argument by the second one is stored.
+ // sfmod (x,&n) stores in the integer variable
+ // 'n' the integer part of 'x' and, at the same time,
+ // returns the fractional part of 'x'.
+ // The usage of sfmod() is strongly discouraged.
+ // frac() returns the fractional part of its argument.
+ // Finally, fix() is a frontend to the xfix()
+ // function (see section "Extended Precision Floating
+ // Point Arithmetic").
+ friend xreal abs (const xreal& s);
+ friend xreal frexp (const xreal& s, int *p);
+ friend xreal qfmod (const xreal& s, const xreal& t, xreal& q);
+ friend xreal fmod (const xreal& s, const xreal& t);
+ friend xreal sfmod (const xreal& s, int *p);
+ friend xreal frac (const xreal& x);
+ friend xreal trunc (const xreal& x);
+ friend xreal round (const xreal& x);
+ friend xreal ceil (const xreal& x);
+ friend xreal floor (const xreal& x);
+ friend xreal fix (const xreal& x);
+ friend xreal tan (const xreal& x);
+ friend xreal sin (const xreal& x);
+ friend xreal cos (const xreal& x);
+ friend xreal atan (const xreal& a);
+ friend xreal atan2 (const xreal& y, const xreal& x);
+ friend xreal asin (const xreal& a);
+ friend xreal acos (const xreal& a);
+ friend xreal sqrt (const xreal& u);
+ friend xreal exp (const xreal& u);
+ friend xreal exp2 (const xreal& u);
+ friend xreal exp10 (const xreal& u);
+ friend xreal log (const xreal& u);
+ friend xreal log2 (const xreal& u);
+ friend xreal log10 (const xreal& u);
+ friend xreal tanh (const xreal& v);
+ friend xreal sinh (const xreal& v);
+ friend xreal cosh (const xreal& v);
+ friend xreal atanh (const xreal& v);
+ friend xreal asinh (const xreal& v);
+ friend xreal acosh (const xreal& v);
+ friend xreal pow (const xreal& x, const xreal& y);
+
+ public:
+ // Various constructors. They allow to define
+ // an extended precision number in several ways.
+ // In addition, they allow for conversions from other
+ // numeric types.
+ xreal (const struct xpr* px = &xZero);
+ xreal (struct xpr x);
+ xreal (double x);
+ xreal (float x);
+ xreal (int n);
+ xreal (long n);
+ xreal (unsigned int u);
+ xreal (unsigned long u);
+
+ // This constructor requires a special comment. If
+ // only the first argument is present, the initial portion
+ // of the string pointed to by this argument is converted
+ // into an extended precision number, if a conversion is
+ // possible. If no conversion is possible, then the
+ // returned number is xNAN. If the second argument is
+ // present and is not null, it must be the address of a
+ // valid pointer to 'char'.
+ // Before returning, the constructor will set this pointer
+ // so that it points to the character of the string 'str' after the last
+ // character used in the conversion.
+ xreal (const char* str, char** endptr = 0);
+ xreal (string str);
+ xreal (const xreal& x);
+
+ // Assignment operators. They do not require
+ // any explanation with the only exception of '%=',
+ // which combines a '%' operation with an assignment.
+ // So, x %= n is equivalent to x *= pow(2,n) .
+ xreal& operator= (const xreal& x);
+ xreal& operator+= (const xreal& x);
+ xreal& operator-= (const xreal& x);
+ xreal& operator*= (const xreal& x);
+ xreal& operator/= (const xreal& x);
+ xreal& operator%= (int n);
+
+ // Increment and decrement operators. Both prefixed
+ // and postfixed versions are defined.
+ xreal& operator++ ();
+ xreal& operator-- ();
+ xreal& operator++ (int dummy);
+ xreal& operator-- (int dummy);
+
+ // Destructor. You will never have to recall it
+ // explicitly in your code.
+ ~xreal (void);
+
+ // Integer exponent power. For any extended precision
+ // number 'x', x(n) is equal to 'x' raised to 'n'.
+ xreal operator() (int n) const;
+
+ // This is the usual unary minus.
+ xreal operator-() const;
+
+ // For any extended precision number 'x', !x evaluates to 1
+ // when 'x' is null, else it evaluates to 0.
+ int operator!() const;
+
+ // x.isneg() returns 1 if 'x' is negative, else it
+ // returns 0.
+ int isneg() const;
+
+ // x.exp() returns the exponent part
+ // of the binary representation of 'x'.
+ int exp() const;
+
+ // Functions for conversions. x._2double(), x._2float(),
+ // x._2xpr() and x._2string() convert the extended precision
+ // number 'x' in a double precision number, in a single
+ // precision number, in a structure of
+ // type 'xpr', and in a string, respectively.
+ double _2double () const;
+ float _2float() const;
+ struct xpr _2xpr() const;
+ string _2string() const;
+
+ // The member function xreal::getfrom() can be used to
+ // recover an extended precision number from an input
+ // stream. The input stream is passed as argument to the
+ // function.
+ // The return value is 0 in case of input error (in case
+ // of End-Of-File, for example).
+ // When it starts to process its input, this function drops
+ // all the eventual leading white spaces.
+ // After reading the first non space character, it
+ // continues to read from the input stream until it finds
+ // a white space or reaches the End-Of-File.
+ // Then it tries to convert into an extended
+ // precision number the (initial portion of the) string just
+ // read.
+ // If no conversion can be performed, then x.getfrom(is)
+ // sets 'x' to the value xNAN.
+ // If the exactly converted value would cause overflow,
+ // then 'x' is set to xINF or x_INF, according to the sign
+ // of the correct value.
+ int getfrom (istream& is);
+
+ // The member function xreal::print() can be used to write
+ // an extended precision number to an output stream.
+ // The output stream is passed to the function as first
+ // argument. The next three arguments have the same meanings
+ // of the fields 'notat', 'sf' and 'lim' of the
+ // structure 'xoutflags', respectively (see section "Real Arithmetic").
+ int print (ostream& os, int sc_not, int sign, int lim) const;
+
+ // The function call x.asprint(sc_not, sign, lim) returns
+ // a buffer of characters with the representation, in form
+ // of a decimal ASCII string, of the extended precision
+ // number 'x'. The arguments 'sc_not', 'sign' and 'lim' are
+ // used to format the string.
+ // They have the same meanings of the fields 'notat', 'sf'
+ // and 'lim' of the structure 'xoutflags', respectively (see section
+ // "Real Arithmetic").
+ // The buffer returned by this function is malloc'ed inside
+ // the function. In case of insufficient memory, the null
+ // pointer is returned.
+ char* asprint (int sc_not, int sign, int lim) const;
+
+ // The following static functions are used to set
+ // or get the values of the fields of the structure
+ // 'xreal::ioflags'. This structure is a static member
+ // variable of the class 'xreal' and it is used by the
+ // output operator << to know how to format its second
+ // argument. The meaning of the fields of the structure
+ // 'xreal::ioflags' is explained in the section
+ // "Real arithmetic".
+
+ // xreal::set_notation (which) sets to 'which' the value
+ // of 'xreal::ioflags.notat' .
+ static void set_notation (short notat);
+
+ // xreal::set_signflag (which) sets to 'which' the value
+ // of 'xreal::ioflags.sf' .
+ static void set_signflag (short onoff);
+
+ // xreal::set_mfwd (which) sets to 'which' the value
+ // of 'xreal::ioflags.mfwd' .
+ static void set_mfwd (short wd);
+
+ // xreal::set_lim (which) sets to 'which' the value
+ // of 'xreal::ioflags.lim' .
+ static void set_lim (short lim);
+
+ // xreal::set_padding (which) sets to 'which' the value
+ // of 'xreal::ioflags.padding' .
+ static void set_padding (signed char ch);
+
+ // xreal::get_notation () returns the current value
+ // of 'xreal::ioflags.notat' .
+ static short get_notation (void);
+
+ // xreal::get_signflag () returns the current value
+ // of 'xreal::ioflags.sf' .
+ static short get_signflag (void);
+
+ // xreal::get_mfwd () returns the current value
+ // of 'xreal::ioflags.mfwd' .
+ static short get_mfwd (void);
+
+ // xreal::get_lim () returns the current value
+ // of 'xreal::ioflags.lim' .
+ static short get_lim (void);
+
+ // xreal::get_padding () returns the current value
+ // of 'xreal::ioflags.padding' .
+ static signed char get_padding (void);
+ private:
+ struct xpr br; /* binary representation */
+ static struct xoutflags ioflags; /* output flags */
+};
+
+ // xmatherrcode() returns the current value of the global
+ // variable 'xErrNo' (see section
+ // "Dealing with runtime errors"), if
+ // this variable is defined.
+ // Otherwise xmatherrcode() returns -1.
+ int xmatherrcode ();
+
+ // clear_xmatherr() resets to 0 the value of the global
+ // variable 'xErrNo' (see section "Dealing with runtime
+ // errors"), if this variable is defined.
+ // Otherwise, clear_xmatherr() prints a suitable warning
+ // on 'cerr' (standard error device).
+ void clear_xmatherr ();
+
+ // Some useful constants:
+ // xZERO == 0
+ // xONE == 1
+ // xTWO == 2
+ // xTEN == 10
+ // xINF == +INF
+ // x_INF == -INF
+ // xNAN == Not-A-Number
+ // xPI == Pi Greek
+ // xPI2 == Pi / 2
+ // xPI4 == Pi / 4
+ // xEE == e (base of natural logarithms)
+ // xSQRT2 == square root of 2
+ // xLN2 == natural logarithm of 2
+ // xLN10 == natural logarithm of 10
+ // xLOG2_E == base-2 logarithm of e
+ // xLOG2_10 == base-2 logarithm of 10
+ // xLOG10_E == base-10 logarithm of e
+ extern const xreal xZERO, xONE, xTWO, xTEN;
+ extern const xreal xINF, x_INF, xNAN;
+ extern const xreal xPI, xPI2, xPI4, xEE, xSQRT2;
+ extern const xreal xLN2, xLN10, xLOG2_E, xLOG2_10, xLOG10_E;
+
+} /* End namespace HPA */
+
+#endif /* _XREAL_H_ */
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/hpaconf.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/hpaconf.c
new file mode 100644
index 00000000..b34f32d2
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/hpaconf.c
@@ -0,0 +1,91 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include
+
+/* The macros VERSION, IPATH and LPATH are directly defined on the */
+/* command line to the compiler. */
+
+#ifndef VERSION
+#define VERSION "unknown"
+#endif
+
+#ifndef IPATH
+#define IPATH ""
+#endif
+
+#ifndef LPATH
+#define LPATH ""
+#endif
+
+/* The same is for the macros XMANTISSA_SIZE and XERR_... */
+
+#ifndef XMANTISSA_SIZE
+#define XMANTISSA_SIZE 7
+#endif
+
+#if !defined(XERR_IGN) && !defined(XERR_WARN) && !defined (XERR_EXIT)
+#define XERR_DFL 1
+#endif
+
+#define XSIZE 2 * (XMANTISSA_SIZE + 1)
+#define SGN_NBITS 1
+#define EXP_NBITS 15
+#define MNT_NBITS XMANTISSA_SIZE * 16
+#define PREC_DIGS (XMANTISSA_SIZE * 4816) / 1000
+
+#define DYN_RANGE " 2^16384 > x > 2^(-16383)"
+#define DYN_RANGE_10 "1.19*10^4932 > x > 1.68*10^-(4932)"
+
+void library_desc (void)
+{
+ fprintf (stdout,
+ "----- Features of the HPA library (including build options) -----\n\n");
+ fprintf (stdout,
+ "Size of an extended precision floating point value (in bytes): %u\n",
+ XSIZE);
+ fprintf (stdout, "Number of bits available for the sign: %u\n",
+ SGN_NBITS);
+ fprintf (stdout, "Number of bits available for the exponent: %u\n",
+ EXP_NBITS);
+ fprintf (stdout, "Number of bits available for the mantissa: %u\n",
+ MNT_NBITS);
+ fprintf (stdout, "Decimal digits of accuracy: ~%u\n",
+ PREC_DIGS);
+ fprintf (stdout,
+ "Dynamic range supported: %s i.e.\n \t\t\t %s\n",
+ DYN_RANGE, DYN_RANGE_10);
+ fprintf (stdout, "In case of floating point error\n");
+#ifdef XERR_IGN
+ fprintf (stdout, "nothing is signaled\n\n");
+#elif defined(XERR_WARN)
+ fprintf (stdout, "a warning message is printed on stderr\n\n");
+#elif defined(XERR_EXIT)
+ fprintf (stdout,
+ "the calling process is terminated through a call to exit(1)\n");
+ fprintf (stdout, "after printing a suitable message on stderr\n\n");
+#else
+ fprintf (stdout,
+ "the global (extern) variable \'xErrNo\' is suitably set\n\n");
+#endif
+}
\ No newline at end of file
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/hpaconf.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/hpaconf.h
new file mode 100644
index 00000000..d5f86617
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/hpaconf.h
@@ -0,0 +1,14 @@
+#ifndef _HPACONF_H_
+#define _HPACONF_H_
+
+#define HPA_VERSION "1.7"
+extern int XLITTLE_ENDIAN;
+#define XULONG_BITSIZE (sizeof(unsigned long)*8)
+#define XERR_DFL 1
+// Here is the precision
+// Available precision = 7, 11, 15, 19, 23, 27, 31
+// 7 = 34 decimal places
+// Algorithm become slower when XDIM > 19
+// 31 = 150 decimal places
+#define XDIM 15
+#endif
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const07.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const07.h
new file mode 100644
index 00000000..28f32070
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const07.h
@@ -0,0 +1,76 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+/* Constants file for XDIM=7
+*/
+
+const int xItt_div = 2;
+const int xK_tanh = 5;
+const int xMS_exp = 21;
+const int xMS_hyp = 25;
+const int xMS_trg = 31;
+
+const xpr xPi4 = { {0x3ffe, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc}
+};
+const xpr xPi2 = { {0x3fff, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc}
+};
+const xpr xPi = { {0x4000, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc}
+};
+const xpr xEe = { {0x4000, 0xadf8, 0x5458, 0xa2bb,
+ 0x4a9a, 0xafdc, 0x5620, 0x273d}
+};
+const xpr xLn2 = { {0x3ffe, 0xb172, 0x17f7, 0xd1cf,
+ 0x79ab, 0xc9e3, 0xb398, 0x03f3}
+};
+const xpr xLn10 = { {0x4000, 0x935d, 0x8ddd, 0xaaa8,
+ 0xac16, 0xea56, 0xd62b, 0x82d3}
+};
+const xpr xSqrt2 = { {0x3fff, 0xb504, 0xf333, 0xf9de,
+ 0x6484, 0x597d, 0x89b3, 0x754b}
+};
+
+const xpr xLog2_e = { {0x3fff, 0xb8aa, 0x3b29, 0x5c17,
+ 0xf0bb, 0xbe87, 0xfed0, 0x691d}
+};
+const xpr xLog2_10 = { {0x4000, 0xd49a, 0x784b, 0xcd1b,
+ 0x8afe, 0x492b, 0xf6ff, 0x4db0}
+};
+const xpr xLog10_e = { {0x3ffd, 0xde5b, 0xd8a9, 0x3728,
+ 0x7195, 0x355b, 0xaaaf, 0xad34}
+};
+
+const xpr xRndcorr = { {0x3ffe, 0x8000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0068}
+};
+
+const xpr xFixcorr = { {0x3f97, 0xc000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000}
+};
+
+const xpr xNaN = { {0x0000, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff}
+};
+const xpr HPA_MIN = { {0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFE, 0xC979 } };
+const xpr HPA_MAX = { {0x7FFC, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x9B43 } };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const11.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const11.h
new file mode 100644
index 00000000..0ebbcd88
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const11.h
@@ -0,0 +1,89 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+/* Constants file for XDIM=11
+*/
+
+const int xItt_div = 2;
+const int xK_tanh = 6;
+const int xMS_exp = 31;
+const int xMS_hyp = 35;
+const int xMS_trg = 43;
+
+const xpr xPi4 = { {0x3ffe, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a68}
+};
+const xpr xPi2 = { {0x3fff, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a68}
+};
+const xpr xPi = { {0x4000, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a68}
+};
+const xpr xEe = { {0x4000, 0xadf8, 0x5458, 0xa2bb,
+ 0x4a9a, 0xafdc, 0x5620, 0x273d,
+ 0x3cf1, 0xd8b9, 0xc583, 0xce2d}
+};
+const xpr xLn2 = { {0x3ffe, 0xb172, 0x17f7, 0xd1cf,
+ 0x79ab, 0xc9e3, 0xb398, 0x03f2,
+ 0xf6af, 0x40f3, 0x4326, 0x7299}
+};
+const xpr xLn10 = { {0x4000, 0x935d, 0x8ddd, 0xaaa8,
+ 0xac16, 0xea56, 0xd62b, 0x82d3,
+ 0x0a28, 0xe28f, 0xecf9, 0xda5e}
+};
+const xpr xSqrt2 = { {0x3fff, 0xb504, 0xf333, 0xf9de,
+ 0x6484, 0x597d, 0x89b3, 0x754a,
+ 0xbe9f, 0x1d6f, 0x60ba, 0x893c}
+};
+
+const xpr xLog2_e = { {0x3fff, 0xb8aa, 0x3b29, 0x5c17,
+ 0xf0bb, 0xbe87, 0xfed0, 0x691d,
+ 0x3e88, 0xeb57, 0x7aa8, 0xdd69}
+};
+const xpr xLog2_10 = { {0x4000, 0xd49a, 0x784b, 0xcd1b,
+ 0x8afe, 0x492b, 0xf6ff, 0x4daf,
+ 0xdb4c, 0xd96c, 0x55fe, 0x37b4}
+};
+const xpr xLog10_e = { {0x3ffd, 0xde5b, 0xd8a9, 0x3728,
+ 0x7195, 0x355b, 0xaaaf, 0xad33,
+ 0xdc32, 0x3ee3, 0x4602, 0x45ca}
+};
+
+const xpr xRndcorr = { {0x3ffe, 0x8000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x00f8}
+};
+
+const xpr xFixcorr = { {0x3f57, 0xc000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000}
+};
+
+const xpr xNaN = { {0x0000, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff}
+};
+const xpr HPA_MIN = { {0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFD, 0x6691 } };
+const xpr HPA_MAX = { {0x7FFC, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x4CB7 } };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const15.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const15.h
new file mode 100644
index 00000000..0fda15a9
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const15.h
@@ -0,0 +1,102 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+/* Constants file for XDIM=15
+*/
+
+const int xItt_div = 3;
+const int xK_tanh = 6;
+const int xMS_exp = 39;
+const int xMS_hyp = 45;
+const int xMS_trg = 55;
+
+const xpr xPi4 = { {0x3ffe, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b14}
+};
+const xpr xPi2 = { {0x3fff, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b14}
+};
+const xpr xPi = { {0x4000, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b14}
+};
+const xpr xEe = { {0x4000, 0xadf8, 0x5458, 0xa2bb,
+ 0x4a9a, 0xafdc, 0x5620, 0x273d,
+ 0x3cf1, 0xd8b9, 0xc583, 0xce2d,
+ 0x3695, 0xa9e1, 0x3641, 0x1464}
+};
+const xpr xLn2 = { {0x3ffe, 0xb172, 0x17f7, 0xd1cf,
+ 0x79ab, 0xc9e3, 0xb398, 0x03f2,
+ 0xf6af, 0x40f3, 0x4326, 0x7298,
+ 0xb62d, 0x8a0d, 0x175b, 0x8bab}
+};
+const xpr xLn10 = { {0x4000, 0x935d, 0x8ddd, 0xaaa8,
+ 0xac16, 0xea56, 0xd62b, 0x82d3,
+ 0x0a28, 0xe28f, 0xecf9, 0xda5d,
+ 0xf90e, 0x83c6, 0x1e82, 0x01f0}
+};
+const xpr xSqrt2 = { {0x3fff, 0xb504, 0xf333, 0xf9de,
+ 0x6484, 0x597d, 0x89b3, 0x754a,
+ 0xbe9f, 0x1d6f, 0x60ba, 0x893b,
+ 0xa84c, 0xed17, 0xac85, 0x8334}
+};
+
+const xpr xLog2_e = { {0x3fff, 0xb8aa, 0x3b29, 0x5c17,
+ 0xf0bb, 0xbe87, 0xfed0, 0x691d,
+ 0x3e88, 0xeb57, 0x7aa8, 0xdd69,
+ 0x5a58, 0x8b25, 0x166c, 0xd1a1}
+};
+const xpr xLog2_10 = { {0x4000, 0xd49a, 0x784b, 0xcd1b,
+ 0x8afe, 0x492b, 0xf6ff, 0x4daf,
+ 0xdb4c, 0xd96c, 0x55fe, 0x37b3,
+ 0xad4e, 0x91b6, 0xac80, 0x82e8}
+};
+const xpr xLog10_e = { {0x3ffd, 0xde5b, 0xd8a9, 0x3728,
+ 0x7195, 0x355b, 0xaaaf, 0xad33,
+ 0xdc32, 0x3ee3, 0x4602, 0x45c9,
+ 0xa202, 0x3a3f, 0x2d44, 0xf78f}
+};
+
+const xpr xRndcorr = { {0x3ffe, 0x8000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x01ae}
+};
+
+const xpr xFixcorr = { {0x3f17, 0xc000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000}
+};
+
+const xpr xNaN = { {0x0000, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff}
+};
+const xpr HPA_MIN = { {0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC, 0xB519 } };
+const xpr HPA_MAX = { {0x7FFC, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0xA573 } };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const19.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const19.h
new file mode 100644
index 00000000..dfda1279
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const19.h
@@ -0,0 +1,115 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+/* Constants file for XDIM=19
+*/
+
+const int xItt_div = 3;
+const int xK_tanh = 6;
+const int xMS_exp = 39;
+const int xMS_hyp = 45;
+const int xMS_trg = 55;
+
+const xpr xPi4 = { {0x3ffe, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34}
+};
+const xpr xPi2 = { {0x3fff, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34}
+};
+const xpr xPi = { {0x4000, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34}
+};
+const xpr xEe = { {0x4000, 0xadf8, 0x5458, 0xa2bb,
+ 0x4a9a, 0xafdc, 0x5620, 0x273d,
+ 0x3cf1, 0xd8b9, 0xc583, 0xce2d,
+ 0x3695, 0xa9e1, 0x3641, 0x1464,
+ 0x33fb, 0xcc93, 0x9dce, 0x249b}
+};
+const xpr xLn2 = { {0x3ffe, 0xb172, 0x17f7, 0xd1cf,
+ 0x79ab, 0xc9e3, 0xb398, 0x03f2,
+ 0xf6af, 0x40f3, 0x4326, 0x7298,
+ 0xb62d, 0x8a0d, 0x175b, 0x8baa,
+ 0xfa2b, 0xe7b8, 0x7620, 0x6dec}
+};
+const xpr xLn10 = { {0x4000, 0x935d, 0x8ddd, 0xaaa8,
+ 0xac16, 0xea56, 0xd62b, 0x82d3,
+ 0x0a28, 0xe28f, 0xecf9, 0xda5d,
+ 0xf90e, 0x83c6, 0x1e82, 0x01f0,
+ 0x2d72, 0x962f, 0x02d7, 0xb1a8}
+};
+const xpr xSqrt2 = { {0x3fff, 0xb504, 0xf333, 0xf9de,
+ 0x6484, 0x597d, 0x89b3, 0x754a,
+ 0xbe9f, 0x1d6f, 0x60ba, 0x893b,
+ 0xa84c, 0xed17, 0xac85, 0x8333,
+ 0x9915, 0x4afc, 0x8304, 0x3ab9}
+};
+
+const xpr xLog2_e = { {0x3fff, 0xb8aa, 0x3b29, 0x5c17,
+ 0xf0bb, 0xbe87, 0xfed0, 0x691d,
+ 0x3e88, 0xeb57, 0x7aa8, 0xdd69,
+ 0x5a58, 0x8b25, 0x166c, 0xd1a1,
+ 0x3247, 0xde1c, 0x43f7, 0x5517}
+};
+const xpr xLog2_10 = { {0x4000, 0xd49a, 0x784b, 0xcd1b,
+ 0x8afe, 0x492b, 0xf6ff, 0x4daf,
+ 0xdb4c, 0xd96c, 0x55fe, 0x37b3,
+ 0xad4e, 0x91b6, 0xac80, 0x82e7,
+ 0x859d, 0x0665, 0x0fde, 0x9dd5}
+};
+const xpr xLog10_e = { {0x3ffd, 0xde5b, 0xd8a9, 0x3728,
+ 0x7195, 0x355b, 0xaaaf, 0xad33,
+ 0xdc32, 0x3ee3, 0x4602, 0x45c9,
+ 0xa202, 0x3a3f, 0x2d44, 0xf78e,
+ 0xa53c, 0x7542, 0x4efa, 0x1403}
+};
+
+const xpr xRndcorr = { {0x3ffe, 0x8000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0284}
+};
+
+const xpr xFixcorr = { {0x3ed7, 0xc000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000}
+};
+
+const xpr xNaN = { {0x0000, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff}
+};
+const xpr HPA_MIN = { {0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFA, 0xF97A } };
+const xpr HPA_MAX = { {0x7FFC, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x8342 } };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const23.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const23.h
new file mode 100644
index 00000000..91f03348
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const23.h
@@ -0,0 +1,128 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+/* Constants file for XDIM=23
+*/
+
+const int xItt_div = 3;
+const int xK_tanh = 7;
+const int xMS_exp = 57;
+const int xMS_hyp = 65;
+const int xMS_trg = 75;
+
+const xpr xPi4 = { {0x3ffe, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a}
+};
+const xpr xPi2 = { {0x3fff, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a}
+};
+const xpr xPi = { {0x4000, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a}
+};
+const xpr xEe = { {0x4000, 0xadf8, 0x5458, 0xa2bb,
+ 0x4a9a, 0xafdc, 0x5620, 0x273d,
+ 0x3cf1, 0xd8b9, 0xc583, 0xce2d,
+ 0x3695, 0xa9e1, 0x3641, 0x1464,
+ 0x33fb, 0xcc93, 0x9dce, 0x249b,
+ 0x3ef9, 0x7d2f, 0xe363, 0x630c}
+};
+const xpr xLn2 = { {0x3ffe, 0xb172, 0x17f7, 0xd1cf,
+ 0x79ab, 0xc9e3, 0xb398, 0x03f2,
+ 0xf6af, 0x40f3, 0x4326, 0x7298,
+ 0xb62d, 0x8a0d, 0x175b, 0x8baa,
+ 0xfa2b, 0xe7b8, 0x7620, 0x6deb,
+ 0xac98, 0x5595, 0x52fb, 0x4afa}
+};
+const xpr xLn10 = { {0x4000, 0x935d, 0x8ddd, 0xaaa8,
+ 0xac16, 0xea56, 0xd62b, 0x82d3,
+ 0x0a28, 0xe28f, 0xecf9, 0xda5d,
+ 0xf90e, 0x83c6, 0x1e82, 0x01f0,
+ 0x2d72, 0x962f, 0x02d7, 0xb1a8,
+ 0x105c, 0xcc70, 0xcbc0, 0x2c5f}
+};
+const xpr xSqrt2 = { {0x3fff, 0xb504, 0xf333, 0xf9de,
+ 0x6484, 0x597d, 0x89b3, 0x754a,
+ 0xbe9f, 0x1d6f, 0x60ba, 0x893b,
+ 0xa84c, 0xed17, 0xac85, 0x8333,
+ 0x9915, 0x4afc, 0x8304, 0x3ab8,
+ 0xa2c3, 0xa8b1, 0xfe6f, 0xdc84}
+};
+
+const xpr xLog2_e = { {0x3fff, 0xb8aa, 0x3b29, 0x5c17,
+ 0xf0bb, 0xbe87, 0xfed0, 0x691d,
+ 0x3e88, 0xeb57, 0x7aa8, 0xdd69,
+ 0x5a58, 0x8b25, 0x166c, 0xd1a1,
+ 0x3247, 0xde1c, 0x43f7, 0x5517,
+ 0x6cd6, 0x24d9, 0x2f75, 0xc16c}
+};
+const xpr xLog2_10 = { {0x4000, 0xd49a, 0x784b, 0xcd1b,
+ 0x8afe, 0x492b, 0xf6ff, 0x4daf,
+ 0xdb4c, 0xd96c, 0x55fe, 0x37b3,
+ 0xad4e, 0x91b6, 0xac80, 0x82e7,
+ 0x859d, 0x0665, 0x0fde, 0x9dd5,
+ 0x1f3a, 0x3e24, 0xbeab, 0x63ad}
+};
+const xpr xLog10_e = { {0x3ffd, 0xde5b, 0xd8a9, 0x3728,
+ 0x7195, 0x355b, 0xaaaf, 0xad33,
+ 0xdc32, 0x3ee3, 0x4602, 0x45c9,
+ 0xa202, 0x3a3f, 0x2d44, 0xf78e,
+ 0xa53c, 0x7542, 0x4efa, 0x1402,
+ 0xf3f2, 0x9223, 0x5592, 0xc646}
+};
+
+const xpr xRndcorr = { {0x3ffe, 0x8000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x03ee}
+};
+
+const xpr xFixcorr = { {0x3e97, 0xc000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000}
+};
+
+const xpr xNaN = { {0x0000, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff}
+};
+const xpr HPA_MIN = { {0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFF9, 0x3DD5 } };
+const xpr HPA_MAX = { {0x7FFC, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x6112 } };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const27.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const27.h
new file mode 100644
index 00000000..3aee5451
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const27.h
@@ -0,0 +1,141 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+/* Constants file for XDIM=27
+*/
+
+const int xItt_div = 4;
+const int xK_tanh = 7;
+const int xMS_exp = 65;
+const int xMS_hyp = 73;
+const int xMS_trg = 85;
+
+const xpr xPi4 = { {0x3ffe, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a,
+ 0x431b, 0x302b, 0x0a6d, 0xf25f}
+};
+const xpr xPi2 = { {0x3fff, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a,
+ 0x431b, 0x302b, 0x0a6d, 0xf25f}
+};
+const xpr xPi = { {0x4000, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a,
+ 0x431b, 0x302b, 0x0a6d, 0xf25f}
+};
+const xpr xEe = { {0x4000, 0xadf8, 0x5458, 0xa2bb,
+ 0x4a9a, 0xafdc, 0x5620, 0x273d,
+ 0x3cf1, 0xd8b9, 0xc583, 0xce2d,
+ 0x3695, 0xa9e1, 0x3641, 0x1464,
+ 0x33fb, 0xcc93, 0x9dce, 0x249b,
+ 0x3ef9, 0x7d2f, 0xe363, 0x630c,
+ 0x75d8, 0xf681, 0xb202, 0xaec4}
+};
+const xpr xLn2 = { {0x3ffe, 0xb172, 0x17f7, 0xd1cf,
+ 0x79ab, 0xc9e3, 0xb398, 0x03f2,
+ 0xf6af, 0x40f3, 0x4326, 0x7298,
+ 0xb62d, 0x8a0d, 0x175b, 0x8baa,
+ 0xfa2b, 0xe7b8, 0x7620, 0x6deb,
+ 0xac98, 0x5595, 0x52fb, 0x4afa,
+ 0x1b10, 0xed2e, 0xae35, 0xc138}
+};
+const xpr xLn10 = { {0x4000, 0x935d, 0x8ddd, 0xaaa8,
+ 0xac16, 0xea56, 0xd62b, 0x82d3,
+ 0x0a28, 0xe28f, 0xecf9, 0xda5d,
+ 0xf90e, 0x83c6, 0x1e82, 0x01f0,
+ 0x2d72, 0x962f, 0x02d7, 0xb1a8,
+ 0x105c, 0xcc70, 0xcbc0, 0x2c5f,
+ 0x0d68, 0x2c62, 0x2418, 0x410c}
+};
+const xpr xSqrt2 = { {0x3fff, 0xb504, 0xf333, 0xf9de,
+ 0x6484, 0x597d, 0x89b3, 0x754a,
+ 0xbe9f, 0x1d6f, 0x60ba, 0x893b,
+ 0xa84c, 0xed17, 0xac85, 0x8333,
+ 0x9915, 0x4afc, 0x8304, 0x3ab8,
+ 0xa2c3, 0xa8b1, 0xfe6f, 0xdc83,
+ 0xdb39, 0x0f74, 0xa85e, 0x439c}
+};
+
+const xpr xLog2_e = { {0x3fff, 0xb8aa, 0x3b29, 0x5c17,
+ 0xf0bb, 0xbe87, 0xfed0, 0x691d,
+ 0x3e88, 0xeb57, 0x7aa8, 0xdd69,
+ 0x5a58, 0x8b25, 0x166c, 0xd1a1,
+ 0x3247, 0xde1c, 0x43f7, 0x5517,
+ 0x6cd6, 0x24d9, 0x2f75, 0xc16b,
+ 0xe0b3, 0xea90, 0xb9e6, 0x0c4b}
+};
+const xpr xLog2_10 = { {0x4000, 0xd49a, 0x784b, 0xcd1b,
+ 0x8afe, 0x492b, 0xf6ff, 0x4daf,
+ 0xdb4c, 0xd96c, 0x55fe, 0x37b3,
+ 0xad4e, 0x91b6, 0xac80, 0x82e7,
+ 0x859d, 0x0665, 0x0fde, 0x9dd5,
+ 0x1f3a, 0x3e24, 0xbeab, 0x63ad,
+ 0x0bd6, 0x1435, 0xee48, 0x0566}
+};
+const xpr xLog10_e = { {0x3ffd, 0xde5b, 0xd8a9, 0x3728,
+ 0x7195, 0x355b, 0xaaaf, 0xad33,
+ 0xdc32, 0x3ee3, 0x4602, 0x45c9,
+ 0xa202, 0x3a3f, 0x2d44, 0xf78e,
+ 0xa53c, 0x7542, 0x4efa, 0x1402,
+ 0xf3f2, 0x9223, 0x5592, 0xc646,
+ 0x4a15, 0x18ce, 0x3bd9, 0xfd39}
+};
+
+const xpr xRndcorr = { {0x3ffe, 0x8000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0446}
+};
+
+const xpr xFixcorr = { {0x3e57, 0xc000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000}
+};
+
+const xpr xNaN = { {0x0000, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff}
+};
+const xpr HPA_MIN = { {0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFF8, 0xE51A } };
+const xpr HPA_MAX = { {0x7FFC, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x8D69 } };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const31.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const31.h
new file mode 100644
index 00000000..6841c513
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/mp/const31.h
@@ -0,0 +1,154 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+/* Constants file for XDIM=31
+*/
+
+const int xItt_div = 4;
+const int xK_tanh = 7;
+const int xMS_exp = 73;
+const int xMS_hyp = 83;
+const int xMS_trg = 95;
+
+const xpr xPi4 = { {0x3ffe, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a,
+ 0x431b, 0x302b, 0x0a6d, 0xf25f,
+ 0x1437, 0x4fe1, 0x356d, 0x6d52}
+};
+const xpr xPi2 = { {0x3fff, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a,
+ 0x431b, 0x302b, 0x0a6d, 0xf25f,
+ 0x1437, 0x4fe1, 0x356d, 0x6d52}
+};
+const xpr xPi = { {0x4000, 0xc90f, 0xdaa2, 0x2168,
+ 0xc234, 0xc4c6, 0x628b, 0x80dc,
+ 0x1cd1, 0x2902, 0x4e08, 0x8a67,
+ 0xcc74, 0x020b, 0xbea6, 0x3b13,
+ 0x9b22, 0x514a, 0x0879, 0x8e34,
+ 0x04dd, 0xef95, 0x19b3, 0xcd3a,
+ 0x431b, 0x302b, 0x0a6d, 0xf25f,
+ 0x1437, 0x4fe1, 0x356d, 0x6d52}
+};
+const xpr xEe = { {0x4000, 0xadf8, 0x5458, 0xa2bb,
+ 0x4a9a, 0xafdc, 0x5620, 0x273d,
+ 0x3cf1, 0xd8b9, 0xc583, 0xce2d,
+ 0x3695, 0xa9e1, 0x3641, 0x1464,
+ 0x33fb, 0xcc93, 0x9dce, 0x249b,
+ 0x3ef9, 0x7d2f, 0xe363, 0x630c,
+ 0x75d8, 0xf681, 0xb202, 0xaec4,
+ 0x617a, 0xd3df, 0x1ed5, 0xd5fd}
+};
+const xpr xLn2 = { {0x3ffe, 0xb172, 0x17f7, 0xd1cf,
+ 0x79ab, 0xc9e3, 0xb398, 0x03f2,
+ 0xf6af, 0x40f3, 0x4326, 0x7298,
+ 0xb62d, 0x8a0d, 0x175b, 0x8baa,
+ 0xfa2b, 0xe7b8, 0x7620, 0x6deb,
+ 0xac98, 0x5595, 0x52fb, 0x4afa,
+ 0x1b10, 0xed2e, 0xae35, 0xc138,
+ 0x2144, 0x2757, 0x3b29, 0x116a}
+};
+const xpr xLn10 = { {0x4000, 0x935d, 0x8ddd, 0xaaa8,
+ 0xac16, 0xea56, 0xd62b, 0x82d3,
+ 0x0a28, 0xe28f, 0xecf9, 0xda5d,
+ 0xf90e, 0x83c6, 0x1e82, 0x01f0,
+ 0x2d72, 0x962f, 0x02d7, 0xb1a8,
+ 0x105c, 0xcc70, 0xcbc0, 0x2c5f,
+ 0x0d68, 0x2c62, 0x2418, 0x410b,
+ 0xe2da, 0xfb8f, 0x7884, 0x02e5}
+};
+const xpr xSqrt2 = { {0x3fff, 0xb504, 0xf333, 0xf9de,
+ 0x6484, 0x597d, 0x89b3, 0x754a,
+ 0xbe9f, 0x1d6f, 0x60ba, 0x893b,
+ 0xa84c, 0xed17, 0xac85, 0x8333,
+ 0x9915, 0x4afc, 0x8304, 0x3ab8,
+ 0xa2c3, 0xa8b1, 0xfe6f, 0xdc83,
+ 0xdb39, 0x0f74, 0xa85e, 0x439c,
+ 0x7b4a, 0x7804, 0x8736, 0x3dfa}
+};
+
+const xpr xLog2_e = { {0x3fff, 0xb8aa, 0x3b29, 0x5c17,
+ 0xf0bb, 0xbe87, 0xfed0, 0x691d,
+ 0x3e88, 0xeb57, 0x7aa8, 0xdd69,
+ 0x5a58, 0x8b25, 0x166c, 0xd1a1,
+ 0x3247, 0xde1c, 0x43f7, 0x5517,
+ 0x6cd6, 0x24d9, 0x2f75, 0xc16b,
+ 0xe0b3, 0xea90, 0xb9e6, 0x0c4a,
+ 0x909f, 0xc4bf, 0xaf03, 0x53df}
+};
+const xpr xLog2_10 = { {0x4000, 0xd49a, 0x784b, 0xcd1b,
+ 0x8afe, 0x492b, 0xf6ff, 0x4daf,
+ 0xdb4c, 0xd96c, 0x55fe, 0x37b3,
+ 0xad4e, 0x91b6, 0xac80, 0x82e7,
+ 0x859d, 0x0665, 0x0fde, 0x9dd5,
+ 0x1f3a, 0x3e24, 0xbeab, 0x63ad,
+ 0x0bd6, 0x1435, 0xee48, 0x0565,
+ 0xca54, 0xcff1, 0x62cd, 0x4f60}
+};
+const xpr xLog10_e = { {0x3ffd, 0xde5b, 0xd8a9, 0x3728,
+ 0x7195, 0x355b, 0xaaaf, 0xad33,
+ 0xdc32, 0x3ee3, 0x4602, 0x45c9,
+ 0xa202, 0x3a3f, 0x2d44, 0xf78e,
+ 0xa53c, 0x7542, 0x4efa, 0x1402,
+ 0xf3f2, 0x9223, 0x5592, 0xc646,
+ 0x4a15, 0x18ce, 0x3bd9, 0xfd38,
+ 0xdcbc, 0x6fa2, 0xb8d2, 0xc8ce}
+};
+
+const xpr xRndcorr = { {0x3ffe, 0x8000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x06f8}
+};
+
+const xpr xFixcorr = { {0x3e17, 0xc000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000}
+};
+
+const xpr xNaN = { {0x0000, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff}
+};
+const xpr HPA_MIN = { {0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFF8, 0x8C5E } };
+const xpr HPA_MAX = { {0x7FFC, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0xB9D0 } };
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/prcxpr.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/prcxpr.c
new file mode 100644
index 00000000..47b6c9c4
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/prcxpr.c
@@ -0,0 +1,170 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include /* for free() */
+#include /* for strcat() */
+#include"cxpre.h" /* Automatically includes "xpre.h" */
+
+/* See print.c for the next 2 functions */
+extern void xfileputc (int c, FILE * stream);
+extern void xprintfmt (FILE * stream, const char *fmt, ...);
+
+void
+cxpr_print (FILE * stream, cxpr z, int sc_not, int sign, int lim)
+{
+ xpr_print (stream, z.re, sc_not, sign, lim);
+ xpr_print (stream, z.im, sc_not, 1, lim);
+ xfileputc (CX1I_CHAR, stream);
+}
+
+void
+cxprcxpr (cxpr z, int lim)
+{
+ cxpr_print (stdout, z, 1, 0, lim);
+}
+
+void
+cxprint (FILE * stream, cxpr z)
+{
+ int i;
+
+ xprintfmt (stream, "(%04x.", z.re.nmm[0]);
+ for (i = 0; i < XDIM; ++i)
+ xprintfmt (stream, "%04x", z.re.nmm[i + 1]);
+ xprintfmt (stream, " , %04x.", z.im.nmm[0]);
+ for (i = 0; i < XDIM; ++i)
+ xprintfmt (stream, "%04x", z.im.nmm[i + 1]);
+ xprintfmt (stream, ")\n");
+}
+
+int
+cxfout (FILE * fp, xoutflags ofs, cxpr z)
+{
+ if (ofs.fmt < 0)
+ ofs.fmt = XFMT_STD;
+ else if (ofs.fmt > 2)
+ ofs.fmt = XFMT_ALT;
+ if (ofs.fmt == XFMT_ALT)
+ {
+ if (ofs.ldel < 0)
+ ofs.ldel = CXDEF_LDEL;
+ if (ofs.rdel < 0)
+ ofs.rdel = CXDEF_RDEL;
+ if (fputc (ofs.ldel, fp) == EOF)
+ return -1;
+ }
+ if ((xfout (fp, ofs, z.re)))
+ return -1;
+ else if (ofs.fmt == XFMT_RAW && fprintf (fp, CX_EMPTY_SEP) < 0)
+ return -1;
+ else if (ofs.fmt == XFMT_ALT && fprintf (fp, CX_SEPARATOR) < 0)
+ return -1;
+ else if ((ofs.sf = ofs.fmt == XFMT_STD ? 1 : ofs.sf, xfout (fp, ofs, z.im)))
+ return -1;
+ else
+ {
+ if (ofs.fmt == XFMT_STD)
+ {
+ if (fputc (CX1I_CHAR, fp) == EOF)
+ return -1;
+ }
+ else if (ofs.fmt == XFMT_ALT)
+ {
+ if (fputc (ofs.rdel, fp) == EOF)
+ return -1;
+ }
+ return 0;
+ }
+}
+
+/* Exactly the same as xfout(), but it prints on stdout */
+
+int
+cxout (xoutflags ofs, cxpr z)
+{
+ return cxfout (stdout, ofs, z);
+}
+
+unsigned long
+cxsout (char *s, unsigned long n, xoutflags ofs, cxpr z)
+{
+ char *ptr;
+ unsigned long u, retval;
+
+ if (!s || n == 0)
+ return 0; /* Just as xsout() under the same condition */
+ else
+ ptr = s, retval = 0;
+ /* Remark: we are sure that n >= 1 */
+ if (ofs.fmt < 0)
+ ofs.fmt = XFMT_STD;
+ else if (ofs.fmt > 2)
+ ofs.fmt = XFMT_ALT;
+ /* Optional left delimiter */
+ if (ofs.fmt == XFMT_ALT)
+ {
+ if (ofs.ldel < 0)
+ ofs.ldel = CXDEF_LDEL;
+ if (ofs.rdel < 0)
+ ofs.rdel = CXDEF_RDEL;
+ if (n > 1)
+ *ptr++ = (char) ofs.ldel, n--;
+ retval++;
+ }
+ /* Real part */
+ if ((u = xsout (ptr, n, ofs, z.re)) < n)
+ ptr += u, n -= u;
+ retval += u;
+ /* Separator */
+ if (ofs.fmt != XFMT_STD)
+ {
+ if (n > CX_SEP_L)
+ {
+ if (ofs.fmt == XFMT_ALT)
+ strcat (ptr, CX_SEPARATOR);
+ else
+ strcat (ptr, CX_EMPTY_SEP); /* RAW format enabled */
+ ptr += CX_SEP_L, n -= CX_SEP_L;
+ }
+ retval += CX_SEP_L;
+ }
+ /* Imaginary part */
+ if ((ofs.sf = ofs.fmt == XFMT_STD ? 1 : ofs.sf,
+ u = xsout (ptr, n, ofs, z.im)) < n)
+ ptr += u, n -= u;
+ retval += u;
+ /* Optional right delimiter */
+ if (ofs.fmt == XFMT_STD)
+ {
+ if (n > 1)
+ *ptr++ = (char) CX1I_CHAR, n--;
+ retval += 1;
+ }
+ else if (ofs.fmt == XFMT_ALT)
+ {
+ if (n > 1)
+ *ptr++ = (char) ofs.rdel, n--;
+ retval += 1;
+ }
+ *ptr = '\0'; /* We have to close the string ! */
+ return retval;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/print.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/print.c
new file mode 100644
index 00000000..26955141
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/print.c
@@ -0,0 +1,165 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include
+#include
+#include /* for size_t */
+#include "xpre.h"
+
+void
+xfileputc (int c, FILE * stream)
+{
+ if (fputc (c, stream) == EOF)
+ {
+ fprintf (stderr, "*** In file \"%s\" of the HPA library\n", __FILE__);
+ fprintf (stderr, " xfileputc(): I/O Error on stream %p\n", stream);
+ }
+}
+
+void
+xstrputc (char c, char* buffer)
+{
+ register char *ptr;
+
+ for (ptr = buffer; *ptr != '\0'; ptr++);
+ *ptr = c;
+}
+
+void
+xprintfmt (FILE * stream, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ if (vfprintf (stream, fmt, ap) < 0)
+ {
+ fprintf (stderr, "*** In file \"%s\" of the HPA library\n", __FILE__);
+ fprintf (stderr, " xprintfmt(): I/O Error on stream %p\n", stream);
+ }
+ va_end (ap);
+}
+
+/* Be really careful to the way you employ this function ! */
+
+void
+xsprintfmt (char *buffer, const char *fmt, ...)
+{
+ char ibuff[1024];
+ va_list ap;
+
+ va_start (ap, fmt);
+ vsprintf (ibuff, fmt, ap);
+ va_end (ap);
+ strcat (buffer, ibuff);
+}
+
+int
+xwprint (const char *buff, short mfwd, char padding, FILE * fp)
+{
+ unsigned short length = strlen (buff);
+ register long i;
+
+ if (!buff || !fp)
+ return -1;
+ else if (mfwd < 0)
+ {
+ if (fprintf (fp, "%s", buff) < 0)
+ return -1;
+ else
+ {
+ for (i = length; i < -mfwd; i++)
+ if (fputc (padding, fp) == EOF)
+ return -1;
+ return 0;
+ }
+ }
+ else
+ {
+ for (i = length; i < mfwd; i++)
+ if (fputc (padding, fp) == EOF)
+ return -1;
+ if (fprintf (fp, "%s", buff) < 0)
+ return -1;
+ else
+ return 0;
+ }
+}
+
+void
+xwsprint (char *dest, const char *src, short mfwd, char padding)
+{
+ unsigned short length = strlen (src);
+ register long i;
+
+ if (!dest || !src)
+ return;
+ else if (mfwd < 0)
+ {
+ strcpy (dest, src);
+ for (i = length; i < -mfwd; i++)
+ dest[i] = padding;
+ dest[i] = '\0';
+ }
+ else
+ {
+ for (i = length; i < mfwd; i++)
+ dest[i - length] = padding;
+ dest[i - length] = '\0';
+ strcat (dest, src);
+ }
+}
+
+unsigned short
+xwsnprint (char *dest, size_t dsize, const char *src,
+ short mfwd, char padding)
+{
+ unsigned short n = strlen (src);
+ register long i;
+
+ if (dsize == 0 || !dest || !src)
+ return 0;
+ else if (mfwd < 0)
+ {
+ unsigned short l = n;
+
+ strncpy (dest, src, dsize - 1);
+ if (n >= dsize)
+ n = dsize - 1;
+ /* n is the number of chars copied */
+ /* from 'src' to 'dest'. */
+ for (i = n; i < dsize - 1 && i < -mfwd; i++)
+ dest[i] = padding;
+ dest[i] = '\0';
+ return (-mfwd > l ? -mfwd : l);
+ }
+ else
+ {
+ for (i = n; i - n < dsize - 1 && i < mfwd; i++)
+ dest[i - n] = padding;
+ dest[i - n] = '\0';
+ if (i - n < dsize - 1)
+ strncat (dest, src, dsize - 1 + n - i);
+ dest[dsize - 1] = '\0';
+ return (mfwd > n ? mfwd : n);
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/prxpr.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/prxpr.c
new file mode 100644
index 00000000..ab0c41b2
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/prxpr.c
@@ -0,0 +1,472 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include /* for calloc() */
+#include /* for strcpy() */
+#include "xpre.h" /* Automatically includes */
+
+const double __Log10_2__ = .3010299956639812;
+
+/* Source code added by Ivano Primi - 11/28/2004 */
+
+/* See print.c for all these functions */
+extern void xfileputc (int c, FILE * stream);
+extern void xstrputc (char c, char* buffer);
+extern void xprintfmt (FILE * stream, const char *fmt, ...);
+extern void xsprintfmt (char *buffer, const char *fmt, ...);
+
+static int
+printed_special_value (FILE* stream, xpr u, int sign)
+{
+ if ((xisPinf(&u)))
+ {
+ if ((sign))
+ xfileputc ('+', stream);
+ xprintfmt (stream, "Inf");
+ return 1;
+ }
+ else if ((xisMinf(&u)))
+ {
+ xprintfmt (stream, "-Inf");
+ return 1;
+ }
+ else if ((xisNaN(&u)))
+ {
+ if ((sign))
+ xfileputc ('\?', stream);
+ xprintfmt (stream, "NaN");
+ return 1;
+ }
+ else
+ return 0;
+}
+
+
+/*
+ Remark: 's' must have a size >= 5 !
+*/
+
+static int
+copied_special_value (char* s, xpr u, int sign)
+{
+ if ((xisPinf(&u)))
+ {
+ if ((sign))
+ *s = '+', s++;
+ strcpy (s, "Inf");
+ return 1;
+ }
+ else if ((xisMinf(&u)))
+ {
+ strcpy (s, "-Inf");
+ return 1;
+ }
+ else if ((xisNaN(&u)))
+ {
+ if ((sign))
+ *s = '\?', s++;
+ strcpy (s, "NaN");
+ return 1;
+ }
+ else
+ return 0;
+}
+
+/* sc_not != 0 tells using scientific notation */
+/* sign != 0 tells putting a '+' sign before non negative values */
+
+void
+xpr_print (FILE * stream, xpr u, int sc_not, int sign, int lim)
+{
+ char q[5 * XDIM + 4];
+ register char *p = q;
+ register int k, m;
+ int dig;
+ unsigned short *pa = (unsigned short *) &u;
+
+ if (lim < 0)
+ lim = 0;
+ if (lim >= 5 * XDIM + 2)
+ lim = 5 * XDIM + 2;
+ if ((printed_special_value (stream, u, sign)))
+ return;
+ if ((*pa & xM_sgn))
+ {
+ *pa ^= xM_sgn;
+ xfileputc ('-', stream);
+ }
+ else
+ {
+ if ((sign))
+ xfileputc ('+', stream);
+ }
+ if ((xis0(&u)))
+ {
+ xprintfmt (stream, "0.");
+ for (k = 0; k < lim; ++k)
+ xfileputc ('0', stream);
+ if ((sc_not))
+ xprintfmt (stream, "e+0");
+ }
+ else
+ {
+ m = ((*pa & xM_exp) - xBias);
+ m = (int) ((double) (m + 1) * __Log10_2__);
+ if ((m))
+ u = xmul (u, xpwr (xTen, -m));
+ while ((*pa & xM_exp) < xBias)
+ {
+ --m;
+ u = xmul (u, xTen);
+ }
+ for (*p = 0, k = 0; k <= lim; ++k)
+ {
+ u = xsfmod (u, &dig);
+ ++p, *p = (char) dig;
+ if (*pa == 0)
+ break;
+ u = xmul (xTen, u);
+ }
+ for (; k <= lim; ++k)
+ *++p = 0;
+ if ((*pa))
+ {
+ u = xsfmod (u, &dig);
+ if (dig >= 5)
+ ++(*p);
+ while (*p == 10)
+ {
+ *p = 0;
+ ++(*--p);
+ }
+ }
+ p = q;
+ if (*p == 0)
+ ++p;
+ else
+ ++m;
+ /* Now has come the moment to print */
+ if (m > XMAX_10EX)
+ xprintfmt (stream, "Inf");
+ else if ((sc_not))
+ {
+ xprintfmt (stream, "%c.", '0' + *p++);
+ for (k = 0; k < lim; ++k)
+ xfileputc ('0'+ *p++, stream);
+ if (m >= 0)
+ xprintfmt (stream, "e+%d", m);
+ else
+ xprintfmt (stream, "e%d", m);
+ }
+ else
+ {
+ if (m >= 0)
+ {
+ for (k = 0; k <= m; k++)
+ {
+ if (k <= lim)
+ xfileputc ('0' + p[k], stream);
+ else
+ xfileputc ('0', stream);
+ }
+ if (k <= lim)
+ {
+ xfileputc ('.', stream);
+ for (; k <= lim; k++)
+ xfileputc ('0' + p[k], stream);
+ }
+ }
+ else
+ {
+ xprintfmt (stream, "0.");
+ for (k = 1; k < -m; k++)
+ xfileputc ('0', stream);
+ for (k = 0; k <= lim; ++k)
+ xfileputc ('0' + *p++, stream);
+ }
+ }
+ } /* End of *pa != 0 */
+}
+
+#define BUFF_SIZE 5120 /* 5 Kb !!! */
+
+char *
+xpr_asprint (xpr u, int sc_not, int sign, int lim)
+{
+ char q[5 * XDIM + 4], *buffer, *ptr;
+ register char *p = q;
+ register int k, m;
+ int dig;
+ unsigned short *pa = (unsigned short *) &u;
+
+ if (lim < 0)
+ lim = 0;
+ if (lim > 5 * XDIM + 2)
+ lim = 5 * XDIM + 2;
+ if (!(buffer = (char *) calloc (BUFF_SIZE, sizeof (char))))
+ return NULL;
+ else if((copied_special_value (buffer, u, sign)))
+ {
+ for (k = 0; buffer[k] != '\0'; k++);
+ /* Now k is the length of the buffer. */
+ /* We shrink the buffer so that it has the exact */
+ /* size to contain all its non null chars. */
+ ptr = (char *) realloc (buffer, k + 1);
+ return (ptr != NULL) ? ptr : buffer;
+ }
+ else
+ {
+ if ((*pa & xM_sgn))
+ {
+ *pa ^= xM_sgn;
+ xstrputc ('-', buffer);
+ }
+ else
+ {
+ if ((sign))
+ xstrputc ('+', buffer);
+ }
+ if ((xis0(&u)))
+ {
+ xsprintfmt (buffer, "0.");
+ for (k = 0; k < lim; ++k)
+ xstrputc ('0', buffer);
+ if ((sc_not))
+ xsprintfmt (buffer, "e+0");
+ }
+ else
+ {
+ m = ((*pa & xM_exp) - xBias);
+ m = (int) ((double) (m + 1) * __Log10_2__);
+ if ((m))
+ u = xmul (u, xpwr (xTen, -m));
+ while ((*pa & xM_exp) < xBias)
+ {
+ --m;
+ u = xmul (u, xTen);
+ }
+ for (*p = 0, k = 0; k <= lim; ++k)
+ {
+ u = xsfmod (u, &dig);
+ ++p, *p = (char) dig;
+ if (*pa == 0)
+ break;
+ u = xmul (xTen, u);
+ }
+ for (; k <= lim; ++k)
+ *++p = 0;
+ if ((*pa))
+ {
+ u = xsfmod (u, &dig);
+ if (dig >= 5)
+ ++(*p);
+ while (*p == 10)
+ {
+ *p = 0;
+ ++(*--p);
+ }
+ }
+ p = q;
+ if (*p == 0)
+ ++p;
+ else
+ ++m;
+ /* Now has come the moment to print */
+ if (m > XMAX_10EX)
+ xsprintfmt (buffer, "Inf");
+ else if ((sc_not))
+ {
+ xsprintfmt (buffer, "%c.", '0' + *p++);
+ for (k = 0; k < lim; ++k)
+ xstrputc ('0' + *p++, buffer);
+ if (m >= 0)
+ xsprintfmt (buffer, "e+%d", m);
+ else
+ xsprintfmt (buffer, "e%d", m);
+ }
+ else
+ {
+ if (m >= 0)
+ {
+ for (k = 0; k <= m; k++)
+ {
+ if (k <= lim)
+ xstrputc ('0' + p[k], buffer);
+ else
+ xstrputc ('0', buffer);
+ }
+ if (k <= lim)
+ {
+ xstrputc ('.', buffer);
+ for (; k <= lim; k++)
+ xstrputc ('0' + p[k], buffer);
+ }
+ }
+ else
+ {
+ xsprintfmt (buffer, "0.");
+ for (k = 1; k < -m; k++)
+ xstrputc ('0', buffer);
+ for (k = 0; k <= lim; ++k)
+ xstrputc ('0' + *p++, buffer);
+ }
+ }
+ } /* End of *pa != 0 */
+ for (k = 0; buffer[k] != '\0'; k++);
+ /* Now k is the length of the buffer. */
+ /* We shrink the buffer so that it has the exact */
+ /* size to contain all its non null chars. */
+ ptr = (char *) realloc (buffer, k + 1);
+ return (ptr != NULL) ? ptr : buffer;
+ } /* End of buffer != 0 */
+}
+
+char *
+xtoa (xpr u, int lim)
+{
+ return xpr_asprint (u, 1, 0, lim);
+}
+
+void
+xbprint (FILE * stream, xpr u)
+{
+ register int i;
+ register unsigned short n;
+
+ for (n = 0x8000; n != 0x0; n >>= 1)
+ {
+ if ((n & u.nmm[0]))
+ xfileputc ('1', stream);
+ else
+ xfileputc ('0', stream);
+ }
+ xfileputc ('.', stream);
+ for (i = 0; i < XDIM; ++i)
+ {
+ for (n = 0x8000; n != 0x0; n >>= 1)
+ {
+ if ((n & u.nmm[i + 1]))
+ xfileputc ('1', stream);
+ else
+ xfileputc ('0', stream);
+ }
+ xfileputc (' ', stream);
+ }
+ xfileputc ('\n', stream);
+}
+
+/* End Additions 11/28/2004 */
+
+void
+xprxpr (xpr u, int lim)
+{
+ /* Modified by Ivano Primi - 11/29/2004 */
+ xpr_print (stdout, u, 1, 0, lim);
+}
+
+void
+xprint (FILE * stream, xpr u)
+{
+ register int i;
+
+ /* Modified by Ivano Primi - 4/2/2005 */
+ xprintfmt (stream, "%04x.", u.nmm[0]);
+ for (i = 0; i < XDIM; ++i)
+ xprintfmt (stream, "%04x", u.nmm[i + 1]);
+ xprintfmt (stream, "\n");
+}
+
+/*
+ Special output functions.
+ Added by Ivano Primi, 01/06/2005
+*/
+
+/* See print.c for the next three functions */
+
+extern int xwprint (const char *buff, short mfwd, char padding, FILE * fp);
+extern void xwsprint (char *dest, const char *src, short mfwd, char padding);
+extern unsigned short xwsnprint (char *dest, size_t dsize, const char *src,
+ short mfwd, char padding);
+
+int
+xfout (FILE * fp, xoutflags ofs, xpr x)
+{
+ char *str;
+ int errcode;
+
+ ofs.notat = (ofs.notat <= 0) ? XOUT_FIXED : XOUT_SCIENTIFIC;
+ ofs.sf = (ofs.sf <= 0) ? 0 : 1;
+ if (ofs.lim < 0)
+ ofs.lim = XDEF_LIM;
+ if (ofs.padding < 0)
+ ofs.padding = ' '; /* blank */
+ str = xpr_asprint (x, ofs.notat, ofs.sf, ofs.lim);
+ errcode = xwprint (str, ofs.mfwd, ofs.padding, fp);
+ if ((str))
+ free ((void *) str);
+ return errcode;
+}
+
+/* Exactly the same as xfout(), but it prints on stdout */
+
+int
+xout (xoutflags ofs, xpr x)
+{
+ char *str;
+ int errcode;
+
+ ofs.notat = (ofs.notat <= 0) ? XOUT_FIXED : XOUT_SCIENTIFIC;
+ ofs.sf = (ofs.sf <= 0) ? 0 : 1;
+ if (ofs.lim < 0)
+ ofs.lim = XDEF_LIM;
+ if (ofs.padding < 0)
+ ofs.padding = ' '; /* blank */
+ str = xpr_asprint (x, ofs.notat, ofs.sf, ofs.lim);
+ errcode = xwprint (str, ofs.mfwd, ofs.padding, stdout);
+ if ((str))
+ free ((void *) str);
+ return errcode;
+}
+
+/*
+ Remark: xsout() returns an 'unsigned short' value
+ casted to 'unsigned long'.
+*/
+
+unsigned long
+xsout (char *s, unsigned long n, xoutflags ofs, xpr x)
+{
+ char *str;
+ unsigned long nw;
+
+ ofs.notat = (ofs.notat <= 0) ? XOUT_FIXED : XOUT_SCIENTIFIC;
+ ofs.sf = (ofs.sf <= 0) ? 0 : 1;
+ if (ofs.lim < 0)
+ ofs.lim = XDEF_LIM;
+ if (ofs.padding < 0)
+ ofs.padding = ' '; /* blank */
+ str = xpr_asprint (x, ofs.notat, ofs.sf, ofs.lim);
+ nw = xwsnprint (s, n, str, ofs.mfwd, ofs.padding);
+ if ((str))
+ free ((void *) str);
+ return nw;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/sfmod.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/sfmod.c
new file mode 100644
index 00000000..bd01a105
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/sfmod.c
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xsfmod (xpr s, int *p)
+{
+ unsigned short *pa, *pb;
+ short e, k;
+
+ pa = (unsigned short *) &s;
+ pb = pa + 1;
+ e = (*pa & xM_exp) - xBias;
+ if ((xsigerr (e >= 15, XFPOFLOW, NULL)))
+ {
+ *p = -1;
+ return s;
+ }
+ else if (e < 0)
+ {
+ *p = 0;
+ return s;
+ }
+ *p = *pb >> (15 - e);
+ xlshift (++e, pb, XDIM);
+ *pa -= e;
+ for (e = 0; *pb == 0 && e < xMax_p; ++pb, e += 16);
+ if (e == xMax_p)
+ return xZero;
+ for (k = 0; !((*pb << k) & xM_sgn); ++k);
+ if ((k += e))
+ {
+ xlshift (k, pa + 1, XDIM);
+ *pa -= k;
+ }
+ return s;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/shift.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/shift.c
new file mode 100644
index 00000000..d8d6db7a
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/shift.c
@@ -0,0 +1,66 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+#include "xpre.h"
+
+void
+xlshift (int n, unsigned short *pm, int m)
+{
+ unsigned short *pa, *pc;
+
+ pc = pm + m - 1;
+ if (n < 16 * m)
+ {
+ pa = pm + n / 16;
+ m = n % 16;
+ n = 16 - m;
+ while (pa < pc)
+ {
+ *pm = (*pa++) << m;
+ *pm++ |= *pa >> n;
+ }
+ *pm++ = *pa << m;
+ }
+ while (pm <= pc)
+ *pm++ = 0;
+}
+
+void
+xrshift (int n, unsigned short *pm, int m)
+{
+ unsigned short *pa, *pc;
+
+ pc = pm + m - 1;
+ if (n < 16 * m)
+ {
+ pa = pc - n / 16;
+ m = n % 16;
+ n = 16 - m;
+ while (pa > pm)
+ {
+ *pc = (*pa--) >> m;
+ *pc-- |= *pa << n;
+ }
+ *pc-- = *pa >> m;
+ }
+ while (pc >= pm)
+ *pc-- = 0;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xadd.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xadd.c
new file mode 100644
index 00000000..1b320742
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xadd.c
@@ -0,0 +1,114 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xadd (xpr s, xpr t, int f)
+{
+ unsigned short pe[XDIM + 1], h, u;
+ register unsigned short *pa, *pb, *pc, *pf = pe;
+ register unsigned int n = 0;
+ short e;
+ register short k;
+
+ pa = (unsigned short *) &s;
+ pb = (unsigned short *) &t;
+ e = *pa & xM_exp;
+ k = *pb & xM_exp;
+ if (f)
+ *pb ^= xM_sgn;
+ u = (*pb ^ *pa) & xM_sgn;
+ f = 0;
+ if (e > k)
+ {
+ if ((k = e - k) >= xMax_p)
+ return s;
+ xrshift (k, pb + 1, XDIM);
+ }
+ else if (e < k)
+ {
+ if ((e = k - e) >= xMax_p)
+ return t;
+ xrshift (e, pa + 1, XDIM);
+ e = k;
+ pc = pa;
+ pa = pb;
+ pb = pc;
+ }
+ else if (u)
+ {
+ for (pc = pa, pf = pb; *(++pc) == *(++pf) && f < XDIM; ++f);
+ if (f >= XDIM)
+ return xZero;
+ if (*pc < *pf)
+ {
+ pc = pa;
+ pa = pb;
+ pb = pc;
+ }
+ pf = pe + f;
+ }
+ h = *pa & xM_sgn;
+ if (u)
+ {
+ for (pc = pb + XDIM; pc > pb; --pc)
+ *pc = ~(*pc);
+ n = 1L;
+ }
+ for (pc = pe + XDIM, pa += XDIM, pb += XDIM; pc > pf;)
+ {
+ n += *pa;
+ pa--;
+ n += *pb;
+ pb--;
+ *pc = n;
+ pc--;
+ n >>= 16;
+ }
+ if (u)
+ {
+ for (; *(++pc) == 0; ++f);
+ for (k = 0; !((*pc << k) & xM_sgn); ++k);
+ if ((k += 16 * f))
+ {
+ if ((e -= k) <= 0)
+ return xZero;
+ xlshift (k, pe + 1, XDIM);
+ }
+ }
+ else
+ {
+ if (n)
+ {
+ ++e;
+ if ((xsigerr (e == (short) xM_exp, XFPOFLOW, NULL)))
+ return (!h ? xPinf : xMinf);
+ ++pf;
+ xrshift (1, pf, XDIM);
+ *pf |= xM_sgn;
+ }
+ }
+ *pe = e;
+ *pe |= h;
+ return *(xpr *) pe;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xchcof.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xchcof.c
new file mode 100644
index 00000000..cc67d443
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xchcof.c
@@ -0,0 +1,70 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include "xpre.h"
+
+xpr*
+xchcof (int m, xpr (*xfunc) (xpr))
+{
+ xpr a, b, *c, *cs;
+ int i, j, k, n;
+
+ if (m > XMAX_DEGREE)
+ m = XMAX_DEGREE;
+ ++m;
+ n = 2 * m;
+ if ( !(cs = (xpr*) malloc ((n+1)*sizeof(xpr))) )
+ return NULL;
+ else if ( !(c = (xpr*) malloc (m*sizeof(xpr))) )
+ {
+ free ((void*)cs);
+ return NULL;
+ }
+ else
+ {
+ a = xdiv (xPi2, inttox (m));
+ b = a;
+ cs[0] = xOne;
+ for (j = 0; j < m; ++j)
+ c[j] = xZero;
+ for (j = 1; j <= n; b = xadd (b, a, 0), ++j)
+ cs[j] = xcos (b);
+ for (j = 1; j < n; j += 2)
+ {
+ a = (*xfunc) (cs[j]);
+ c[0] = xadd (c[0], a, 0);
+ for (k = 1; k < m; ++k)
+ {
+ i = (k * j) % (2 * n);
+ if (i > n)
+ i = 2 * n - i;
+ c[k] = xadd (c[k], xmul (a, cs[i]), 0);
+ }
+ }
+ b = xpr2 (xdiv (xOne, inttox (m)), 1);
+ for (j = 0; j < m; ++j)
+ c[j] = xmul (c[j], b);
+ free ((void*)cs);
+ return c;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xdiv.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xdiv.c
new file mode 100644
index 00000000..984c558a
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xdiv.c
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xdiv (xpr s, xpr t)
+{
+ xpr a;
+ unsigned short *pc, e, i;
+
+ pc = (unsigned short *) &t;
+ e = *pc;
+ *pc = xBias;
+ if ((xsigerr (xprcmp (&t, &xZero) == 0, XEDIV, "xdiv()")))
+ return xZero;
+ else
+ {
+ a = dbltox (1 / xtodbl (t));
+ *pc = e;
+ pc = (unsigned short *) &a;
+ *pc += xBias - (e & xM_exp);
+ *pc |= e & xM_sgn;
+ for (i = 0; i < xItt_div; ++i)
+ a = xmul (a, xadd (xTwo, xmul (a, t), 1));
+ return xmul (s, a);
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xevtch.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xevtch.c
new file mode 100644
index 00000000..c7d5f7fa
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xevtch.c
@@ -0,0 +1,40 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xevtch (xpr z, xpr *a, int m)
+{
+ xpr *p, f, t, tp, w;
+
+ w = xpr2 (z, 1);
+ t = xZero;
+ tp = xZero;
+ for (p = a + m; p > a;)
+ {
+ f = xadd (*p--, xadd (xmul (w, t), tp, 1), 0);
+ tp = t;
+ t = f;
+ }
+ return xadd (*p, xadd (xmul (z, t), tp, 1), 0);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xexp.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xexp.c
new file mode 100644
index 00000000..c3030960
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xexp.c
@@ -0,0 +1,80 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xexp2 (xpr x)
+{
+ xpr s, d, f;
+ unsigned short *pf = (unsigned short *) &x;
+ int m, k;
+
+ if (xprcmp (&x, &xE2min) < 0)
+ return xZero;
+ else if ((xsigerr (xprcmp (&x, &xE2max) > 0, XFPOFLOW, NULL)))
+ return xPinf;
+ else
+ {
+ m = (*pf & xM_sgn) ? 1 : 0;
+ x = xsfmod (x, &k);
+ if ((m))
+ k *= -1;
+ /* -xBias <= k <= +xBias */
+ x = xmul (x, xLn2);
+ if (x_exp (&x) > -xBias)
+ {
+ x = xpr2 (x, -1);
+ s = xmul (x, x);
+ f = xZero;
+ for (d = inttox (m = xMS_exp); m > 1; m -= 2, d = inttox (m))
+ f = xdiv (s, xadd (d, f, 0));
+ f = xdiv (x, xadd (d, f, 0));
+ f = xdiv (xadd (d, f, 0), xadd (d, f, 1));
+ }
+ else
+ f = xOne;
+ pf = (unsigned short *) &f;
+ if (-k > *pf)
+ return xZero;
+ else
+ {
+ *pf += k;
+ if ((xsigerr (*pf >= xM_exp, XFPOFLOW, NULL)))
+ return xPinf;
+ else
+ return f;
+ }
+ }
+}
+
+xpr
+xexp (xpr z)
+{
+ return xexp2 (xmul (z, xLog2_e));
+}
+
+xpr
+xexp10 (xpr z)
+{
+ return xexp2 (xmul (z, xLog2_10));
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xfmod.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xfmod.c
new file mode 100644
index 00000000..9328aa86
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xfmod.c
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+/*
+ Heavily modified by Ivano Primi - 01/30/2005
+*/
+
+xpr
+xfmod (xpr s, xpr t, xpr *q)
+{
+ if ((xsigerr (xprcmp (&t, &xZero) == 0, XEDIV, "xfmod()")))
+ return xZero;
+ else
+ {
+ unsigned short *p, mask = 0xffff;
+ short e, i;
+ int u;
+
+ *q = xdiv (s, t);
+ p = (unsigned short *) q;
+ u = (*p & xM_sgn) ? 0 : 1;
+ e = (*p &= xM_exp); /* biased exponent of *q */
+ e = e < xBias ? 0 : e - xBias + 1;
+ for (i = 1; e / 16 > 0; i++, e -= 16);
+ if (i <= XDIM)
+ {
+ /* e = 0, ..., 15 */
+ mask <<= 16 - e;
+ p[i] &= mask;
+ for (i++; i <= XDIM; p[i] = 0, i++);
+ }
+ /* Now *q == abs(quotient of (s/t)) */
+ return xadd (s, xmul (t, *q), u);
+ }
+}
+
+xpr
+xfrexp (xpr s, int *p)
+{
+ unsigned short *ps = (unsigned short *) &s, u;
+
+ *p = (*ps & xM_exp) - xBias + 1;
+ u = *ps & xM_sgn;
+ *ps = xBias - 1;
+ *ps |= u;
+ return s;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xfrac.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xfrac.c
new file mode 100644
index 00000000..18dd5828
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xfrac.c
@@ -0,0 +1,224 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+/*
+ All the functions in this file have been created by
+ Ivano Primi - 12/11/2004
+*/
+
+/*
+ After skipping the first 'skip' bites of the vector 'p',
+ this function nullifies all the remaining ones. 'k' is
+ the number of words forming the vector p.
+ Warning: 'skip' must be positive !
+*/
+
+static void
+nullify (int skip, unsigned short *p, int k)
+{
+ int i;
+ unsigned short mask = 0xffff;
+
+ for (i = 0; skip / 16 > 0; i++, skip -= 16);
+ if (i < k)
+ {
+ /* skip = 0, ..., 15 */
+ mask <<= 16 - skip;
+ p[i] &= mask;
+ for (i++; i < k; p[i] = 0, i++);
+ }
+}
+
+static void
+canonic_form (xpr *px)
+{
+ unsigned short *p, u;
+ short e, i, j, skip;
+
+ p = (unsigned short *) px;
+ e = (*p & xM_exp); /* biased exponent of x */
+ u = (*p & xM_sgn); /* sign of x */
+ if (e < xBias - 1)
+ return;
+ else
+ {
+ unsigned short mask = 0xffff;
+
+ /* e >= xBias - 1 */
+ for (i = 1, skip = e + 1 - xBias; skip / 16 > 0; i++, skip -= 16);
+ if (i <= XDIM)
+ {
+ /* skip = 0, ..., 15 */
+ mask >>= skip;
+ if ((p[i] & mask) != mask)
+ return;
+ else
+ {
+ for (j = i + 1; j <= XDIM && p[j] == 0xffff; j++);
+ if (j > XDIM)
+ {
+ p[i] -= mask;
+ for (j = i + 1; j <= XDIM; p[j] = 0, j++);
+ if (!(p[1] & 0x8000))
+ {
+ p[1] = 0x8000;
+ *p = ++e;
+ *p |= u;
+ }
+ else if ((u))
+ *px = xadd (*px, xOne, 1);
+ else
+ *px = xadd (*px, xOne, 0);
+ }
+ }
+ } /* end if(i <= XDIM ) */
+ } /* end outer else */
+}
+
+/*
+ xfrac(x) returns the fractional part of the number x.
+ xfrac(x) has the same sign as x.
+*/
+
+xpr
+xfrac (xpr x)
+{
+ unsigned short u, *p;
+ short e;
+ int n;
+
+ canonic_form (&x);
+ p = (unsigned short *) &x;
+ e = (*p & xM_exp); /* biased exponent of x */
+ if (e < xBias)
+ return x; /* The integer part of x is zero */
+ else
+ {
+ u = *p & xM_sgn; /* sign of x */
+ n = e - xBias + 1;
+ xlshift (n, p + 1, XDIM);
+ e = xBias - 1;
+ /* Now I have to take in account the rule */
+ /* of the leading one. */
+ while (e > 0 && !(p[1] & xM_sgn))
+ {
+ xlshift (1, p + 1, XDIM);
+ e -= 1;
+ }
+ /* Now p+1 points to the fractionary part of x, */
+ /* u is its sign, e is its biased exponent. */
+ p[0] = e;
+ p[0] |= u;
+ return *(xpr *) p;
+ }
+}
+
+
+/*
+ xtrunc(x) returns the integer part of the number x.
+ xtrunc(x) has the same sign as x.
+*/
+
+xpr
+xtrunc (xpr x)
+{
+ unsigned short *p;
+ short e;
+
+ canonic_form (&x);
+ p = (unsigned short *) &x;
+ e = (*p & xM_exp); /* biased exponent of x */
+ if (e < xBias)
+ return xZero; /* The integer part of x is zero */
+ else
+ {
+ nullify (e - xBias + 1, p + 1, XDIM);
+ return *(xpr *) p;
+ }
+}
+
+xpr
+xround (xpr x)
+{
+ return xtrunc (xadd (x, xRndcorr, x.nmm[0] & xM_sgn));
+}
+
+xpr
+xceil (xpr x)
+{
+ unsigned short *ps = (unsigned short *) &x;
+
+ if ((*ps & xM_sgn))
+ return xtrunc (x);
+ else
+ {
+ xpr y = xfrac (x);
+ /* y has the same sign as x (see above). */
+
+ return (xprcmp (&y, &xZero) > 0 ? xadd (xtrunc (x), xOne, 0) : x);
+ }
+}
+
+xpr
+xfloor (xpr x)
+{
+ unsigned short *ps = (unsigned short *) &x;
+
+ if ((*ps & xM_sgn))
+ {
+ xpr y = xfrac (x);
+ /* y has the same sign as x (see above). */
+
+ return (xprcmp (&y, &xZero) < 0 ? xadd (xtrunc (x), xOne, 1) : x);
+ }
+ else
+ return xtrunc (x);
+}
+
+static void
+xadd_correction (xpr* px, int k)
+{
+ short e = (px->nmm[0] & xM_exp) - xBias;
+
+/* e = (e > 0 ? e : 0); */
+ *px = xadd (*px, xpr2 (xFixcorr, e), k);
+}
+
+xpr
+xfix (xpr x)
+{
+ unsigned short *p;
+ short e;
+
+ xadd_correction (&x, x.nmm[0] & xM_sgn);
+ p = (unsigned short *) &x;
+ e = (*p & xM_exp); /* biased exponent of x */
+ if (e < xBias)
+ return xZero; /* The integer part of x is zero */
+ else
+ {
+ nullify (e - xBias + 1, p + 1, XDIM);
+ return *(xpr *) p;
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xhypb.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xhypb.c
new file mode 100644
index 00000000..28dedbe8
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xhypb.c
@@ -0,0 +1,82 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xtanh (xpr z)
+{
+ xpr s, d, f;
+ int m, k;
+
+ if ((k = x_exp (&z)) > xK_tanh)
+ {
+ if (x_neg (&z))
+ return xneg (xOne);
+ else
+ return xOne;
+ }
+ if (k < xK_lin)
+ return z;
+ ++k;
+ if (k > 0)
+ z = xpr2 (z, -k);
+ s = xmul (z, z);
+ f = xZero;
+ for (d = inttox (m = xMS_hyp); m > 1;)
+ {
+ f = xdiv (s, xadd (d, f, 0));
+ d = inttox (m -= 2);
+ }
+ f = xdiv (z, xadd (d, f, 0));
+ for (; k > 0; --k)
+ f = xdiv (xpr2 (f, 1), xadd (d, xmul (f, f), 0));
+ return f;
+}
+
+xpr
+xsinh (xpr z)
+{
+ int k;
+
+ if ((k = x_exp (&z)) < xK_lin)
+ return z;
+ else if (k < 0)
+ {
+ z = xtanh (xpr2 (z, -1));
+ return xdiv (xpr2 (z, 1), xadd (xOne, xmul (z, z), 1));
+ }
+ else
+ {
+ z = xexp (z);
+ return xpr2 (xadd (z, xdiv (xOne, z), 1), -1);
+ }
+}
+
+xpr
+xcosh (xpr z)
+{
+ if (x_exp (&z) < xK_lin)
+ return xOne;
+ z = xexp (z);
+ return xpr2 (xadd (z, xdiv (xOne, z), 0), -1);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xivhypb.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xivhypb.c
new file mode 100644
index 00000000..0ae8b4e7
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xivhypb.c
@@ -0,0 +1,64 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xatanh (xpr x)
+{
+ xpr y = x;
+
+ y.nmm[0] &= xM_exp; /* Now y == abs(x) */
+ if ((xsigerr (xprcmp (&y, &xOne) >= 0, XEDOM, "xatanh")))
+ return ((x.nmm[0] & xM_sgn) ? xMinf : xPinf);
+ else
+ {
+ y = xdiv (xadd (xOne, x, 0), xadd (xOne, x, 1));
+ return xpr2 (xlog (y), -1);
+ }
+}
+
+xpr
+xasinh (xpr x)
+{
+ xpr y = xmul (x, x);
+
+ y = xsqrt (xadd (xOne, y, 0));
+ if ((x.nmm[0] & xM_sgn))
+ return xneg (xlog (xadd (y, x, 1)));
+ else
+ return xlog (xadd (x, y, 0));
+}
+
+xpr
+xacosh (xpr x)
+{
+ if ((xsigerr (xprcmp (&x, &xOne) < 0, XEDOM, "xacosh()")))
+ return xZero;
+ else
+ {
+ xpr y = xmul (x, x);
+
+ y = xsqrt (xadd (y, xOne, 1));
+ return xlog (xadd (x, y, 0));
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xivtrg.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xivtrg.c
new file mode 100644
index 00000000..57eb7a79
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xivtrg.c
@@ -0,0 +1,124 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+#include
+
+xpr
+xatan (xpr z)
+{
+ xpr s, f;
+ int k, m;
+
+ if ((k = x_exp (&z)) < xK_lin)
+ return z;
+ if (k >= 0)
+ {
+ /* k>=0 is equivalent to abs(z) >= 1.0 */
+ z = xdiv (xOne, z);
+ m = 1;
+ }
+ else
+ m = 0;
+ f = dbltox (atan (xtodbl (z)));
+ s = xadd (xOne, xmul (z, z), 0);
+ for (k = 0; k < xItt_div; ++k)
+ f = xadd (f, xdiv (xadd (z, xtan (f), 1), s), 0);
+ if (m)
+ {
+ if (x_neg (&f))
+ return xadd (xneg (xPi2), f, 1);
+ else
+ return xadd (xPi2, f, 1);
+ }
+ else
+ return f;
+}
+
+xpr
+xasin (xpr z)
+{
+ xpr u = z;
+
+ u.nmm[0] &= xM_exp;
+ if ((xsigerr (xprcmp (&u, &xOne) > 0, XEDOM, "xasin()")))
+ return ((x_neg (&z)) ? xneg (xPi2) : xPi2);
+ else
+ {
+ if (x_exp (&z) < xK_lin)
+ return z;
+ u = xsqrt (xadd (xOne, xmul (z, z), 1));
+ if (x_exp (&u) == -xBias)
+ return ((x_neg (&z)) ? xneg (xPi2) : xPi2);
+ return xatan (xdiv (z, u));
+ }
+}
+
+xpr
+xacos (xpr z)
+{
+ xpr u = z;
+
+ u.nmm[0] &= xM_exp;
+ if ((xsigerr (xprcmp (&u, &xOne) > 0, XEDOM, "xacos()")))
+ return ((x_neg (&z)) ? xPi : xZero);
+ else
+ {
+ if (x_exp (&z) == -xBias)
+ return xPi2;
+ u = xsqrt (xadd (xOne, xmul (z, z), 1));
+ u = xatan (xdiv (u, z));
+ if (x_neg (&z))
+ return xadd (xPi, u, 0);
+ else
+ return u;
+ }
+}
+
+/* Kindly added by A.Haumer 2010-04.09 */
+
+xpr
+xatan2 (xpr y, xpr x)
+{
+ int rs, is;
+
+ rs = xsgn (&x);
+ is = xsgn (&y);
+ if (rs > 0)
+ return xatan (xdiv (y, x));
+ else if (rs < 0)
+ {
+ x.nmm[0] ^= xM_sgn;
+ y.nmm[0] ^= xM_sgn;
+ if (is >= 0)
+ return xadd (xPi, xatan (xdiv (y, x)), 0);
+ else
+ return xadd (xatan (xdiv (y, x)), xPi, 1);
+ }
+ else /* x is zero ! */
+ {
+ if (!xsigerr (is == 0, XEDOM, "xatan2()"))
+ return (is > 0 ? xPi2 : xneg (xPi2));
+ else
+ return xZero; /* Dummy value :) */
+ }
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xlog.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xlog.c
new file mode 100644
index 00000000..222e3c2f
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xlog.c
@@ -0,0 +1,87 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include "xpre.h"
+
+xpr
+xlog (xpr z)
+{
+ xpr f, h;
+ int k, m;
+
+ if ((xsigerr ((x_neg (&z)) || x_exp (&z) == -xBias, XEDOM, "xlog()")))
+ return xMinf;
+ else if (xprcmp (&z, &xOne) == 0)
+ return xZero;
+ else
+ {
+ z = xfrexp (z, &m);
+ z = xmul (z, xSqrt2);
+ z = xdiv (xadd (z, xOne, 1), xadd (z, xOne, 0));
+ h = xpr2 (z, 1);
+ z = xmul (z, z);
+ for (f = h, k = 1; x_exp (&h) > -xMax_p;)
+ {
+ h = xmul (h, z);
+ f = xadd (f, xdiv (h, inttox (k += 2)), 0);
+ }
+ return xadd (f, xmul (xLn2, dbltox (m - .5)), 0);
+ }
+}
+
+xpr
+xlog2 (xpr z)
+{
+ xpr f, h;
+ int k, m;
+
+ if ((xsigerr ((x_neg (&z)) || x_exp (&z) == -xBias, XEDOM, "xlog2()")))
+ return xMinf;
+ else if (xprcmp (&z, &xOne) == 0)
+ return xZero;
+ else
+ {
+ z = xfrexp (z, &m);
+ z = xmul (z, xSqrt2);
+ z = xdiv (xadd (z, xOne, 1), xadd (z, xOne, 0));
+ h = xpr2 (z, 1);
+ z = xmul (z, z);
+ for (f = h, k = 1; x_exp (&h) > -xMax_p;)
+ {
+ h = xmul (h, z);
+ f = xadd (f, xdiv (h, inttox (k += 2)), 0);
+ }
+ return xadd (xmul (f, xLog2_e), dbltox (m - .5), 0);
+ }
+}
+
+xpr
+xlog10 (xpr z)
+{
+ xpr w = xlog(z);
+
+ if (xprcmp (&w, &xMinf) <= 0)
+ return xMinf;
+ else
+ return xmul (w, xLog10_e);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xmul.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xmul.c
new file mode 100644
index 00000000..db127192
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xmul.c
@@ -0,0 +1,69 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xmul (xpr s, xpr t)
+{
+ unsigned short pe[XDIM + 2], *q0, *q1, h;
+ register unsigned short *pa, *pb, *pc;
+ unsigned int m, n, p;
+ short e;
+ register short k;
+
+ q0 = (unsigned short *) &s;
+ q1 = (unsigned short *) &t;
+ e = (*q0 & xM_exp) - xBias;
+ k = (*q1 & xM_exp) + 1;
+ if ((xsigerr (e > (short) xM_exp - k, XFPOFLOW, NULL)))
+ return (((s.nmm[0] & xM_sgn) ^ (t.nmm[0] & xM_sgn)) ? xMinf : xPinf);
+ if ((e += k) <= 0)
+ return xZero;
+ h = (*q0 ^ *q1) & xM_sgn;
+ for (++q1, k = XDIM, p = n = 0L, pc = pe + XDIM + 1; k > 0; --k)
+ {
+ for (pa = q0 + k, pb = q1; pa > q0;)
+ {
+ m = *pa--;
+ m *= *pb++;
+ n += (m & 0xffffL);
+ p += (m >> 16);
+ }
+ *pc-- = n;
+ n = p + (n >> 16);
+ p = 0L;
+ }
+ *pc = n;
+ if (!(*pc & xM_sgn))
+ {
+ --e;
+ if (e <= 0)
+ return xZero;
+ xlshift (1, pc, XDIM + 1);
+ }
+ if ((xsigerr (e == (short) xM_exp, XFPOFLOW, NULL)))
+ return (!h ? xPinf : xMinf);
+ *pe = e;
+ *pe |= h;
+ return *(xpr *) pe;
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xneg.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xneg.c
new file mode 100644
index 00000000..e1632a19
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xneg.c
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xneg (xpr s)
+{
+ unsigned short *p = (unsigned short *) &s;
+
+ *p ^= xM_sgn;
+ return s;
+}
+
+xpr
+xabs (xpr s)
+{
+ unsigned short *p = (unsigned short *) &s;
+
+ *p &= xM_exp;
+ return s;
+}
+
+int
+x_exp (const xpr *ps)
+{
+ unsigned short *q = (unsigned short *) ps;
+
+ return (*q & xM_exp) - xBias;
+}
+
+int
+x_neg (const xpr *ps)
+{
+ unsigned short *q = (unsigned short *) ps;
+
+ return (*q & xM_sgn);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xprcmp.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xprcmp.c
new file mode 100644
index 00000000..25ce5ae8
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xprcmp.c
@@ -0,0 +1,195 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+/*
+
+ Modified by Ivano Primi - 11/21/2004 and 03/05/2005
+
+*/
+
+int
+xprcmp (const xpr *pa, const xpr *pb)
+{
+ register unsigned short e, k, *p, *q, p0, q0;
+ register int m;
+
+ p = (unsigned short *) pa;
+ q = (unsigned short *) pb;
+ for (m = 1; m <= XDIM && p[m] == 0; m++);
+ if (m > XDIM && (*p & xM_exp) < xM_exp)
+ /* *pa is actually zero */
+ p0 = 0;
+ else
+ p0 = *p;
+ for (m = 1; m <= XDIM && q[m] == 0; m++);
+ if (m > XDIM && (*q & xM_exp) < xM_exp)
+ /* *pb is actually zero */
+ q0 = 0;
+ else
+ q0 = *q;
+ e = p0 & xM_sgn;
+ k = q0 & xM_sgn;
+ if (e && !k)
+ return -1;
+ else if (!e && k)
+ return 1;
+ else /* *pa and *pb have the same sign */
+ {
+ m = (e) ? -1 : 1;
+ e = p0 & xM_exp;
+ k = q0 & xM_exp;
+ if (e > k)
+ return m;
+ else if (e < k)
+ return -m;
+ else
+ {
+ for (e = 0; *(++p) == *(++q) && e < XDIM; ++e);
+ if (e < XDIM)
+ return (*p > *q ? m : -m);
+ else
+ return 0;
+ }
+ }
+}
+
+int
+xeq (xpr x1, xpr x2)
+{
+ return (xprcmp (&x1, &x2) == 0);
+}
+
+int
+xneq (xpr x1, xpr x2)
+{
+ return (xprcmp (&x1, &x2) != 0);
+}
+
+int
+xgt (xpr x1, xpr x2)
+{
+ return (xprcmp (&x1, &x2) > 0);
+}
+
+int
+xge (xpr x1, xpr x2)
+{
+ return (xprcmp (&x1, &x2) >= 0);
+}
+
+int
+xlt (xpr x1, xpr x2)
+{
+ return (xprcmp (&x1, &x2) < 0);
+}
+
+int
+xle (xpr x1, xpr x2)
+{
+ return (xprcmp (&x1, &x2) <= 0);
+}
+
+/*
+ xisNaN (&x) returns 1 if and only if x is not a valid number
+*/
+
+int
+xisNaN (const xpr *u)
+{
+ register unsigned short* p = (unsigned short *) u;
+
+ if ((*p))
+ return 0;
+ else
+ {
+ register int i;
+
+ for (i=1; i <= XDIM && p[i] == 0x0; i++);
+ return (i <= XDIM ? 1 : 0);
+ }
+}
+
+int
+xis0 (const xpr *u)
+{
+ register unsigned short* p = (unsigned short *) u;
+ register int m;
+
+ for (m = 1; m <= XDIM && p[m] == 0; m++);
+ return (m > XDIM && (*p & xM_exp) < xM_exp ? 1 : 0);
+}
+
+int
+xnot0 (const xpr *u)
+{
+ register unsigned short* p = (unsigned short *) u;
+ register int m;
+
+ for (m = 1; m <= XDIM && p[m] == 0; m++);
+ return (m > XDIM && (*p & xM_exp) < xM_exp ? 0 : 1);
+}
+
+int
+xsgn (const xpr *u)
+{
+ register unsigned short* p = (unsigned short *) u;
+ register int m;
+
+ for (m = 1; m <= XDIM && p[m] == 0; m++);
+ if ((m > XDIM && (*p & xM_exp) < xM_exp) || !*p)
+ return 0;
+ else
+ return ((*p & xM_sgn) ? -1 : 1);
+}
+
+int
+xisPinf (const xpr *u)
+{
+ return (*u->nmm == xM_exp ? 1 : 0);
+}
+
+int
+xisMinf (const xpr *u)
+{
+ return (*u->nmm == (xM_exp | xM_sgn) ? 1 : 0);
+}
+
+int
+xisordnumb (const xpr *u)
+{
+ int isNaN, isfinite;
+ register unsigned short* p = (unsigned short *) u;
+
+ if ((*p))
+ isNaN = 0;
+ else
+ {
+ register int i;
+
+ for (i=1; i <= XDIM && p[i] == 0x0; i++);
+ isNaN = i <= XDIM;
+ }
+ isfinite = (*p & xM_exp) < xM_exp;
+ return (!isNaN && (isfinite) ? 1 : 0);
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xpre.h b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xpre.h
new file mode 100644
index 00000000..1c8fdb8e
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xpre.h
@@ -0,0 +1,194 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#ifndef _XPRE_H_
+#define _XPRE_H_
+
+#include "hpaconf.h"
+
+/* This macro has been added by Ivano Primi - 12/21/2004 */
+#define XMAX_10EX 4931
+
+/* This macro has been added by Ivano Primi - 05/10/2004 */
+/* It is used in the file xchcof.c */
+#define XMAX_DEGREE 50
+
+/* Dealing with errors. Added by Ivano Primi - 01/04/2005 */
+#ifndef XERR_IGN
+
+#define XENONE 0
+#define XEDIV 1
+#define XEDOM 2
+#define XEBADEXP 3
+#define XFPOFLOW 4 /* Floating point overflow */
+
+#define XNERR 4
+#define XEINV 5 /* == XNERR + 1 */
+
+#endif /* !XERR_IGN */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ typedef struct
+ {
+ unsigned short nmm[XDIM + 1];
+ } xpr;
+
+ extern const unsigned short xM_sgn, xM_exp;
+ extern const short xBias;
+ extern const int xItt_div, xK_tanh;
+ extern const int xMS_exp, xMS_trg, xMS_hyp;
+ extern const short xMax_p, xK_lin;
+ extern const short xD_bias, xD_max, xD_lex;
+ extern const short xF_bias, xF_max, xF_lex;
+ extern const xpr xZero, xOne, xTwo, xTen;
+ extern const xpr xPinf, xMinf, xNaN;
+ extern const xpr xPi, xPi2, xPi4, xEe, xSqrt2;
+ extern const xpr xLn2, xLn10, xLog2_e, xLog2_10, xLog10_e;
+ extern const xpr xRndcorr, xFixcorr;
+ extern const xpr xVSV, xVGV, xEmax, xEmin, xE2min, xE2max, HPA_MIN, HPA_MAX;
+
+ xpr xadd (xpr a, xpr b, int k);
+ xpr xmul (xpr s, xpr t);
+ xpr xdiv (xpr s, xpr t);
+/* strtox() has been added by Ivano Primi - 12/21/2004 */
+ xpr strtox (const char *q, char **endptr);
+ xpr atox (const char *s);
+ xpr dbltox (double y);
+/* flttox() has been added by Ivano Primi - 11/22/2004 */
+ xpr flttox (float y);
+ xpr inttox (long n);
+ xpr uinttox (unsigned long n);
+ int xprcmp (const xpr *p, const xpr *q);
+ int xeq (xpr x1, xpr x2);
+ int xneq (xpr x1, xpr x2);
+ int xgt (xpr x1, xpr x2);
+ int xge (xpr x1, xpr x2);
+ int xlt (xpr x1, xpr x2);
+ int xle (xpr x1, xpr x2);
+ int xisNaN (const xpr *u);
+ int xisPinf (const xpr *u);
+ int xisMinf (const xpr *u);
+ int xisordnumb (const xpr *u);
+ int xis0 (const xpr *u);
+ int xnot0 (const xpr *u);
+ int xsgn (const xpr *u);
+ int x_neg (const xpr *p);
+ int x_exp (const xpr *p);
+ xpr xsfmod (xpr t, int *p);
+ xpr xpwr (xpr s, int n);
+ xpr xpr2 (xpr s, int n);
+ xpr xneg (xpr s);
+ xpr xabs (xpr s);
+ xpr xfrexp (xpr s, int *p);
+/* xfmod() has been modified by Ivano Primi - 01/30/2005 */
+ xpr xfmod (xpr s, xpr t, xpr *q);
+/* xfrac() and xtrunc() have been added by Ivano Primi - 12/11/2004 */
+ xpr xfrac (xpr x);
+ xpr xtrunc (xpr x);
+/* xround(), xceil() and xfloor() have been added by Ivano Primi - 01/05/2004 */
+ xpr xround (xpr x);
+ xpr xceil (xpr x);
+ xpr xfloor (xpr x);
+/* xfix() has been added by Ivano Primi - 05/01/2004 */
+ xpr xfix (xpr x);
+
+ double xtodbl (xpr s);
+/* xtoflt() has been added by Ivano Primi - 11/22/2004 */
+ float xtoflt (xpr s);
+ xpr xtan (xpr x);
+ xpr xsin (xpr x);
+ xpr xcos (xpr x);
+ xpr xatan (xpr a);
+ xpr xasin (xpr a);
+ xpr xacos (xpr a);
+ xpr xatan2 (xpr y, xpr x);
+ xpr xsqrt (xpr u);
+ xpr xexp (xpr u);
+ xpr xexp2 (xpr u);
+ xpr xexp10 (xpr u);
+ xpr xlog (xpr u);
+ xpr xlog2 (xpr u);
+ xpr xlog10 (xpr u);
+ xpr xtanh (xpr v);
+ xpr xsinh (xpr v);
+ xpr xcosh (xpr v);
+ xpr xatanh (xpr v);
+ xpr xasinh (xpr v);
+ xpr xacosh (xpr v);
+ xpr xpow (xpr x, xpr y);
+
+ xpr* xchcof (int m, xpr (*xfunc) (xpr));
+ xpr xevtch (xpr z, xpr *a, int m);
+/* The following 4 functions have been added */
+/* by Ivano Primi 11/29/2004 */
+
+#include
+
+ void xpr_print (FILE * stream, xpr u, int sc_not, int sign, int lim);
+ char *xpr_asprint (xpr u, int sc_not, int sign, int lim);
+ char *xtoa (xpr u, int lim);
+ void xbprint (FILE * stream, xpr u);
+ void xprxpr (xpr u, int m);
+ void xprint (FILE * stream, xpr u);
+ void xlshift (int i, unsigned short *p, int k);
+ void xrshift (int i, unsigned short *p, int k);
+
+/* The next special output functions have been added by Ivano Primi, */
+/* 01/06/2005. */
+
+#define XOUT_FIXED 0
+#define XOUT_SCIENTIFIC 1
+
+#define XDEF_LIM 6
+
+ typedef struct
+ {
+ short fmt, notat, sf, mfwd, lim;
+ signed char padding, ldel, rdel;
+ } xoutflags;
+
+/* Special output functions */
+/* Remark: xfout(), xout() and xsout() actually ignore the fields ofs.fmt, */
+/* ofs.ldel and ofs.rdel . */
+/* These fields are only used by cxfout(),cxout() and cxsout()(see cxpre.h).*/
+ int xfout (FILE * pf, xoutflags ofs, xpr x);
+ int xout (xoutflags ofs, xpr x);
+ unsigned long
+ xsout (char *s, unsigned long n, xoutflags ofs, xpr x);
+
+#ifndef XERR_IGN
+ int xsigerr (int errcond, int errcode, const char *where);
+#else
+#define xsigerr(errcond, errcode, where) 0
+#endif
+
+#define xsum(a, b) xadd (a, b, 0)
+#define xsub(a, b) xadd (a, b, 1)
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _XPRE_H_ */
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xpwr.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xpwr.c
new file mode 100644
index 00000000..5b9c260d
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xpwr.c
@@ -0,0 +1,92 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include "xpre.h"
+
+xpr
+xpwr (xpr s, int n)
+{
+ xpr t;
+ unsigned k, m;
+
+ t = xOne;
+ if (n < 0)
+ {
+ m = -n;
+ if ((xsigerr (xprcmp (&s, &xZero) == 0, XEBADEXP, "xpwr()")))
+ return xZero;
+ s = xdiv (xOne, s);
+ }
+ else
+ m = n;
+ if ((m))
+ {
+ k = 1;
+ while (1)
+ {
+ if ((k & m))
+ t = xmul (s, t);
+ if ((k <<= 1) <= m)
+ s = xmul (s, s);
+ else
+ break;
+ }
+ }
+ else
+ xsigerr (xprcmp (&s, &xZero) == 0, XEBADEXP, "xpwr()");
+ return t;
+}
+
+xpr
+xpr2 (xpr s, int m)
+{
+ unsigned short *p = (unsigned short *) &s;
+ long e;
+
+ for (e = 1; e <= XDIM && p[e] == 0; e++);
+ if (e <= XDIM)
+ {
+ e = *p & xM_exp; /* biased exponent */
+ if (e + m < 0)
+ return xZero;
+ else if ((xsigerr (e + m >= xM_exp, XFPOFLOW, NULL)))
+ return ((s.nmm[0] & xM_sgn) ? xMinf : xPinf);
+ else
+ {
+ *p += m;
+ return s;
+ }
+ }
+ else /* s is zero or +-Inf */
+ return s;
+}
+
+xpr
+xpow (xpr x, xpr y)
+{
+ if (xsigerr ((xis0(&x)) || x_exp (&x) == -xBias, XEDOM, "xpow()"))
+ return xZero;
+ else if (x_neg(&x))
+ return xexp2(xmul(xlog2(xneg(x)), y));
+ else
+ return xexp2 (xmul (xlog2 (x), y));
+}
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xsigerr.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xsigerr.c
new file mode 100644
index 00000000..398c1a47
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xsigerr.c
@@ -0,0 +1,88 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson
+ Copyright (C) 2004 Ivano Primi
+
+ This file is part of the HPA Library.
+
+ The HPA Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The HPA Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the HPA Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include
+#include
+#include "xpre.h"
+
+#ifdef XERR_EXIT
+#define XERR_WARN
+#endif /* XERR_EXIT ==> XERR_WARN */
+
+/* The source code in this file is compiled only when */
+/* the macro XERR_IGN is not defined. */
+#ifndef XERR_IGN
+
+#ifdef XERR_WARN
+
+static const char *errmsg[] = {
+ "No error",
+ "Division by zero",
+ "Out of domain",
+ "Bad exponent",
+ "Floating point overflow",
+ "Invalid error code"
+};
+
+#else
+
+int xErrNo = 0;
+
+#endif /* XERR_WARN */
+
+/*
+ Remarks:
+
+ errcode must come from the evaluation of an error condition.
+ errcode, which should describe the type of the error,
+ should always be one between XEDIV, XEDOM, XEBADEXP and XFPOFLOW.
+*/
+
+int
+xsigerr (int errcond, int errcode, const char *where)
+{
+ if (!errcond)
+ errcode = 0;
+ if (errcode < 0 || errcode > XNERR)
+ errcode = XEINV;
+#ifdef XERR_WARN
+ if ((errcode))
+ {
+ if ((where))
+ fprintf (stderr, "*** %s: %s\n", where, errmsg[errcode]);
+ else
+ fprintf (stderr, "*** %s\n", errmsg[errcode]);
+#ifdef XERR_EXIT
+ exit (EXIT_FAILURE);
+#else
+ return errcode;
+#endif
+ }
+ return 0;
+#else /* DEFAULT */
+ if ((errcode))
+ xErrNo = errcode;
+ return errcode;
+#endif
+}
+
+#endif /* XERR_IGN */
diff --git a/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xsqrt.c b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xsqrt.c
new file mode 100644
index 00000000..a14f1e73
--- /dev/null
+++ b/libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/numericSys/HPFloat/xsqrt.c
@@ -0,0 +1,54 @@
+/*
+ Copyright (C) 2000 Daniel A. Atkinson |