From 716d89dc7da142ffd7a2776b85afb13d40ac410b Mon Sep 17 00:00:00 2001 From: ZZH <1462207500@qq.com> Date: Wed, 4 Jan 2023 06:47:56 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96read=5Ffile=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=BA=95=E5=B1=82=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZZH <1462207500@qq.com> --- lib/basic.cpp | 10 ++++++++++ lib/io.cpp | 21 +++++++++++++++++---- util/log.h | 11 +++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/basic.cpp b/lib/basic.cpp index 791213f..7554b62 100644 --- a/lib/basic.cpp +++ b/lib/basic.cpp @@ -152,6 +152,15 @@ 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]); +} + LibFunction_t funcs[] = { LIB_FUNCTION(__sin, 1, .name = "sin"), LIB_FUNCTION(__cos, 1, .name = "cos"), @@ -165,6 +174,7 @@ LibFunction_t funcs[] = { // LIB_FUNCTION(angle, 1), LIB_FUNCTION(conv, 4), LIB_FUNCTION(sum, 1), + LIB_FUNCTION(__sqrt, 1, .name = "sqrt"), END_OF_LIB }; diff --git a/lib/io.cpp b/lib/io.cpp index c2d9508..d92b05f 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/util/log.h b/util/log.h index 6bdadfa..bb6830f 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)) -- Gitee From b66e567dbc2941cc7e8e3125a28f809fc833a930 Mon Sep 17 00:00:00 2001 From: ZZH <1462207500@qq.com> Date: Fri, 6 Jan 2023 09:25:38 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BD=AC=E4=B8=BA?= =?UTF-8?q?=E6=97=A0=E7=AC=A6=E5=8F=B7=E6=95=B0=E5=92=8C=E8=BD=AC=E4=B8=BA?= =?UTF-8?q?=E6=9C=89=E7=AC=A6=E5=8F=B7=E6=95=B0=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZZH <1462207500@qq.com> --- lib/basic.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/basic.cpp b/lib/basic.cpp index 7554b62..f1dbd44 100644 --- a/lib/basic.cpp +++ b/lib/basic.cpp @@ -161,6 +161,32 @@ EXPORT void __sqrt(pFunCallArg_t pArgs, float* output) 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; +} + + LibFunction_t funcs[] = { LIB_FUNCTION(__sin, 1, .name = "sin"), LIB_FUNCTION(__cos, 1, .name = "cos"), @@ -175,6 +201,8 @@ LibFunction_t funcs[] = { LIB_FUNCTION(conv, 4), LIB_FUNCTION(sum, 1), LIB_FUNCTION(__sqrt, 1, .name = "sqrt"), + LIB_FUNCTION(to_signed, 2), + LIB_FUNCTION(to_unsigned, 2), END_OF_LIB }; -- Gitee From 3895588670fafece5cadc0ebf07997da750aa9d7 Mon Sep 17 00:00:00 2001 From: ZZH <1462207500@qq.com> Date: Mon, 9 Jan 2023 06:20:52 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0z-fft=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=92=8C=E5=BA=93=E7=9A=84=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZZH <1462207500@qq.com> --- external_libs/z-fft | 2 +- lib/transform.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/external_libs/z-fft b/external_libs/z-fft index 92ac919..ee987e4 160000 --- a/external_libs/z-fft +++ b/external_libs/z-fft @@ -1 +1 @@ -Subproject commit 92ac919442f0da215dd2162677563c9ec5b8da57 +Subproject commit ee987e491849d61589ffa6de0648af6cb5e8832a diff --git a/lib/transform.cpp b/lib/transform.cpp index d038117..8c7dff9 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++) { -- Gitee From 0eafe40d5194f353b9ab47c5743c99008ba4eefd Mon Sep 17 00:00:00 2001 From: ZZH <1462207500@qq.com> Date: Mon, 9 Jan 2023 06:38:58 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=8D=E6=95=B0?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZZH <1462207500@qq.com> --- lib/basic.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/basic.cpp b/lib/basic.cpp index f1dbd44..f0ea7ff 100644 --- a/lib/basic.cpp +++ b/lib/basic.cpp @@ -179,13 +179,54 @@ 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"), @@ -203,6 +244,9 @@ LibFunction_t funcs[] = { 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 }; -- Gitee