From c7e8d701fe6e776c69aa6f4ce325e2215b8c89b3 Mon Sep 17 00:00:00 2001 From: xiaying Date: Fri, 20 Dec 2024 12:01:22 +0800 Subject: [PATCH] Audio:Bugfix: Fix bug for use clz error in windows --- tools/audio/source/audio.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/audio/source/audio.cpp b/tools/audio/source/audio.cpp index 8b1be48c0..c91748723 100644 --- a/tools/audio/source/audio.cpp +++ b/tools/audio/source/audio.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -17,10 +18,29 @@ #ifndef M_PI #define M_PI 3.141592654 #endif +#ifdef _MSC_VER +#define NOMINMAX +#include +#include +#endif namespace MNN { namespace AUDIO { - +#ifdef _MSC_VER +inline uint32_t mnn_clz( uint32_t value ) { + DWORD leading_zero = 0; + if (_BitScanReverse(&leading_zero, value)) { + return 31 - leading_zero; + }else { + // Same remarks as above + return 32; + } +} +#else +inline uint32_t mnn_clz( uint32_t value ) { + return __builtin_clz(value); +} +#endif struct WaveHeader { void SeekToDataChunk(std::istream &is) { // a t a d @@ -263,7 +283,7 @@ unsigned int next_power_of_2(unsigned int x) { return 1; if ((x & (x - 1)) == 0) return x; - return 1U << (32 - __builtin_clz(x)); + return 1U << (32 - mnn_clz(x)); } VARP hamming_window(int n_fft, bool periodic, float alpha, float beta) {