Skip to content

Commit

Permalink
Audio:Bugfix: Fix bug for use clz error in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaying committed Dec 20, 2024
1 parent 54fe65f commit 6ebad3c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tools/audio/source/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// Copyright © 2018, Alibaba Group Holding Limited
//

#ifdef _MSC_VER
#include <intrin.h>
#include <windows.h>
#endif
#include "audio/audio.hpp"
#include <MNN/expr/MathOp.hpp>
#include <MNN/expr/NeuralNetWorkOp.hpp>
Expand All @@ -20,7 +24,21 @@

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
Expand Down Expand Up @@ -263,7 +281,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) {
Expand Down

0 comments on commit 6ebad3c

Please sign in to comment.