diff --git a/external_libs/z-fft b/external_libs/z-fft index 92ac919442f0da215dd2162677563c9ec5b8da57..ee987e491849d61589ffa6de0648af6cb5e8832a 160000 --- a/external_libs/z-fft +++ b/external_libs/z-fft @@ -1 +1 @@ -Subproject commit 92ac919442f0da215dd2162677563c9ec5b8da57 +Subproject commit ee987e491849d61589ffa6de0648af6cb5e8832a diff --git a/lib/basic.cpp b/lib/basic.cpp index 791213fb772e46898778c2c798cf1e66f26fcc27..f0ea7ff38ec8717c2a9c796d2454c28426c54eac 100644 --- a/lib/basic.cpp +++ b/lib/basic.cpp @@ -152,6 +152,82 @@ EXPORT void sum(pFunCallArg_t pArgs, float* output) output[i] = res; } +EXPORT void __sqrt(pFunCallArg_t pArgs, float* output) +{ + int allCalNum = pArgs->allCalNum; + float* arg0 = static_cast(pArgs->args[0]); + + for (int i = 0;i < allCalNum;i++) + output[i] = sqrtf(arg0[i]); +} + +EXPORT void to_signed(pFunCallArg_t pArgs, float* output) +{ + int allCalNum = pArgs->allCalNum; + float* arg0 = static_cast(pArgs->args[0]); + int bits = (int) *static_cast(pArgs->args[1]); + + uint32_t mask = 1 << bits - 1; + uint32_t maxValue = 1 << bits; + + for (int i = 0;i < allCalNum;i++) + output[i] = arg0[i] < mask ? arg0[i] : arg0[i] - maxValue; +} + +EXPORT void to_unsigned(pFunCallArg_t pArgs, float* output) +{ + int allCalNum = pArgs->allCalNum; + float* arg0 = static_cast(pArgs->args[0]); + int bits = (int) *static_cast(pArgs->args[1]); + + uint32_t maxValue = 1 << bits; + + for (int i = 0;i < allCalNum;i++) + output[i] = arg0[i] > 0 ? arg0[i] : arg0[i] + maxValue; +} + +EXPORT void complex(pFunCallArg_t pArgs, float* output) +{ + int allCalNum = pArgs->allCalNum / 2; + float* arg0 = static_cast(pArgs->args[0]); + float* arg1 = static_cast(pArgs->args[1]); + + Complex_t* out = reinterpret_cast(output); + + for (int i = 0;i < allCalNum;i++) + { + out[i].real = arg0[i]; + out[i].image = arg1[i]; + } +} + +EXPORT void real(pFunCallArg_t pArgs, float* output) +{ + int allCalNum = pArgs->allCalNum; + Complex_t* arg0 = static_cast(pArgs->args[0]); + + memset(output, 0, sizeof(float) * allCalNum); + + allCalNum /= 2; + + for (int i = 0;i < allCalNum;i++) + output[i] = arg0[i].real; +} + +EXPORT void image(pFunCallArg_t pArgs, float* output) +{ + int allCalNum = pArgs->allCalNum; + Complex_t* arg0 = static_cast(pArgs->args[0]); + + memset(output, 0, sizeof(float) * allCalNum); + + allCalNum /= 2; + + for (int i = 0;i < allCalNum;i++) + output[i] = arg0[i].image; +} + + LibFunction_t funcs[] = { LIB_FUNCTION(__sin, 1, .name = "sin"), LIB_FUNCTION(__cos, 1, .name = "cos"), @@ -165,6 +241,12 @@ LibFunction_t funcs[] = { // LIB_FUNCTION(angle, 1), LIB_FUNCTION(conv, 4), LIB_FUNCTION(sum, 1), + LIB_FUNCTION(__sqrt, 1, .name = "sqrt"), + LIB_FUNCTION(to_signed, 2), + LIB_FUNCTION(to_unsigned, 2), + LIB_FUNCTION(complex, 2), + LIB_FUNCTION(real, 1), + LIB_FUNCTION(image, 1), END_OF_LIB }; diff --git a/lib/io.cpp b/lib/io.cpp index c2d95088dd9bb380d6e96bde1c2ba91e86ec6a19..d92b05f6a0b92a7410e1c647488090b0a0f5ba95 100644 --- a/lib/io.cpp +++ b/lib/io.cpp @@ -19,15 +19,28 @@ EXPORT void read_file(pFunCallArg_t pArgs, float* output) QFile file(arg0); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + const auto& lineList = file.readAll().split('\n'); + auto pt = lineList.begin(); + auto end = lineList.end(); + + file.close(); + for (size_t i = 0;i < arg1;i++) - file.readLine(); + pt++; - for (int i = 0;i < allCalNum;i++) + for (int i = 0;i < allCalNum && pt != end;i++, pt++) { - QString line = file.readLine(64); + const QString& line = pt->trimmed();//file.readLine(64).trimmed(); + if (line.isEmpty()) break; - output[i] = line.toFloat(); + + if (line.startsWith("0x")) + output[i] = line.toInt(nullptr, 16); + else if (line.startsWith("0b")) + output[i] = line.right(line.length() - 2).toInt(nullptr, 2); + else + output[i] = line.toFloat(); } } diff --git a/lib/transform.cpp b/lib/transform.cpp index d038117b245e6cc6c5fdbcef376f7c9c4ad052ec..8c7dff91e818e00de4d1cdbfd6d24fd494a9a81a 100644 --- a/lib/transform.cpp +++ b/lib/transform.cpp @@ -14,7 +14,7 @@ EXPORT void __dft(pFunCallArg_t pArgs, float* output) pComplex_t pOut = new Complex_t[allCalNum]; - dft(pOut, arg0, allCalNum); + rdft(pOut, arg0, allCalNum); memcpy(output, pOut, allCalNum * sizeof(float)); delete[] pOut; @@ -29,7 +29,7 @@ EXPORT void __idft(pFunCallArg_t pArgs, float* output) memset(pIn, 0, allCalNum * sizeof(Complex_t)); memcpy(pIn, arg0, allCalNum * sizeof(float)); - idft(output, pIn, allCalNum); + irdft(output, pIn, allCalNum); delete[] pIn; @@ -44,7 +44,7 @@ EXPORT void __fft(pFunCallArg_t pArgs, float* output) pComplex_t pOut = new Complex_t[allCalNum]; - fft(pOut, arg0, allCalNum); + rfft(pOut, arg0, allCalNum); memcpy(output, pOut, allCalNum * sizeof(float)); delete[] pOut; @@ -59,7 +59,7 @@ EXPORT void __ifft(pFunCallArg_t pArgs, float* output) memset(pIn, 0, allCalNum * sizeof(Complex_t)); memcpy(pIn, arg0, allCalNum * sizeof(float)); - ifft(output, pIn, allCalNum); + irfft(output, pIn, allCalNum); for (size_t i = 0;i < allCalNum;i++) { diff --git a/util/log.h b/util/log.h index 6bdadfa1a83078c07028cb18d40745f8277f058d..bb6830f40c1ed381c99432f9dd22a63f745165ba 100644 --- a/util/log.h +++ b/util/log.h @@ -21,10 +21,13 @@ #define UI_WARNING(fmt, ...) DEBUG_LEVEL("\r\n", ui, warning, "[%s:%d]: " fmt, __func__, __LINE__, ##__VA_ARGS__) #define UI_ERROR(fmt, ...) DEBUG_LEVEL("\r\n\r\n", ui, error, "[%s:%d][%s]: " fmt "\r\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__) -#define LIB_LOG(fmt, ...) DEBUG_LEVEL("", lib, log, ": " fmt, ##__VA_ARGS__) -#define LIB_INFO(fmt, ...) DEBUG_LEVEL("", lib, info, "[%s]: " fmt, __func__, ##__VA_ARGS__) -#define LIB_WARNING(fmt, ...) DEBUG_LEVEL("\r\n", lib, warning, "[%s:%d]: " fmt, __func__, __LINE__, ##__VA_ARGS__) -#define LIB_ERROR(fmt, ...) DEBUG_LEVEL("\r\n\r\n", lib, error, "[%s:%d][%s]: " fmt "\r\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#define LIB_DEBUG_OUTPUT qDebug +#define LIB_DEBUG_LEVEL(pre, mod, level, fmt, ...) LIB_DEBUG_OUTPUT(pre "[" #level "]" "[" #mod "]" fmt "\r\n", ##__VA_ARGS__) + +#define LIB_LOG(fmt, ...) LIB_DEBUG_LEVEL("", lib, log, ": " fmt, ##__VA_ARGS__) +#define LIB_INFO(fmt, ...) LIB_DEBUG_LEVEL("", lib, info, "[%s]: " fmt, __func__, ##__VA_ARGS__) +#define LIB_WARNING(fmt, ...) LIB_DEBUG_LEVEL("\r\n", lib, warning, "[%s:%d]: " fmt, __func__, __LINE__, ##__VA_ARGS__) +#define LIB_ERROR(fmt, ...) LIB_DEBUG_LEVEL("\r\n\r\n", lib, error, "[%s:%d][%s]: " fmt "\r\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__) #ifndef __max #define __max(a,b) (((a) > (b)) ? (a) : (b))