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 c7e8d70
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tools/audio/source/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,37 @@
#include <MNN/expr/MathOp.hpp>
#include <MNN/expr/NeuralNetWorkOp.hpp>
#include <cmath>
#include <algorithm>
#include <complex>
#include <fstream>
#include <iostream>
#include <limits>
#ifndef M_PI
#define M_PI 3.141592654
#endif
#ifdef _MSC_VER
#define NOMINMAX
#include <intrin.h>
#include <windows.h>
#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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c7e8d70

Please sign in to comment.