From 1f0c76cefaa9359b9fc74ff4b9ed93214486205a Mon Sep 17 00:00:00 2001 From: Wenbing Li <10278425+wenbingl@users.noreply.github.com> Date: Wed, 7 Jun 2023 16:26:45 -0700 Subject: [PATCH] fix some prefast warnings (#467) --- cmake/ext_ortlib.cmake | 2 +- operators/audio/audio_decoder.hpp | 2 +- operators/audio/sampling.h | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmake/ext_ortlib.cmake b/cmake/ext_ortlib.cmake index edd0d3059..391b6411d 100644 --- a/cmake/ext_ortlib.cmake +++ b/cmake/ext_ortlib.cmake @@ -9,7 +9,7 @@ else() message(STATUS "CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}") # default to 1.11.1 if not specified - set(ONNXRUNTIME_VER "1.11.1" CACHE STRING "ONNX Runtime version") + set(ONNXRUNTIME_VER "1.12.1" CACHE STRING "ONNX Runtime version") if(APPLE) set(ONNXRUNTIME_URL "v${ONNXRUNTIME_VER}/onnxruntime-osx-universal2-${ONNXRUNTIME_VER}.tgz") diff --git a/operators/audio/audio_decoder.hpp b/operators/audio/audio_decoder.hpp index bf8dbb7e1..d62453826 100644 --- a/operators/audio/audio_decoder.hpp +++ b/operators/audio/audio_decoder.hpp @@ -170,7 +170,7 @@ struct KernelAudioDecoder : public BaseKernel { if (downsample_rate_ != 0 && downsample_rate_ != orig_sample_rate) { // A lowpass filter on buf audio data to remove high frequency noise - ButterworthLowpass filter(1.0f * orig_sample_rate, 0.5f * downsample_rate_); + ButterworthLowpass filter(1.0 * orig_sample_rate, 0.5 * downsample_rate_); std::vector filtered_buf = filter.Process(buf); // downsample the audio data KaiserWindowInterpolation::Process(filtered_buf, buf, diff --git a/operators/audio/sampling.h b/operators/audio/sampling.h index e6b11c9f9..c69e367a0 100644 --- a/operators/audio/sampling.h +++ b/operators/audio/sampling.h @@ -78,12 +78,12 @@ class ButterworthLowpass { b[POLE_DATA_SIZE - 1] = 0.0; - for (auto i = 0; i <= num_pole; ++i) { + for (size_t i = 0; i <= num_pole; ++i) { a[i] = a[i + 2]; b[i] = -b[i + 2]; } - for (auto i = 0; i <= num_pole; ++i) { + for (size_t i = 0; i <= num_pole; ++i) { sa += a[i]; sb += b[i]; } @@ -166,7 +166,7 @@ class KaiserWindowInterpolation { int outputSize = static_cast(std::ceil(static_cast(input.size()) * factor)); output.resize(outputSize); - for (int i = 0; i < outputSize; i++) { + for (size_t i = 0; i < outputSize; i++) { float index = i / factor; // Fractional index for interpolation // Calculate the integer and fractional parts of the index @@ -175,20 +175,20 @@ class KaiserWindowInterpolation { // Calculate the range of input samples for interpolation int range = static_cast(std::ceil(kBeta / (2.0 * factor))); - int startSample = std::max(0, integerPart - range); - int endSample = std::min(static_cast(input.size()) - 1, integerPart + range); + size_t startSample = std::max(0, integerPart - range); + size_t endSample = std::min(static_cast(input.size()) - 1, integerPart + range); // Calculate the Kaiser window weights for the input samples std::vector weights = KaiserWin(static_cast(endSample - startSample + 1)); - for (int j = startSample; j <= endSample; j++) { - double distance = std::abs(j - index); + for (size_t j = startSample; j <= endSample; j++) { + double distance = std::abs(static_cast(j) - index); double sincValue = (distance < 1e-6f) ? 1.0f : std::sin(M_PI * distance) / (M_PI * distance); weights[j - startSample] *= sincValue; } // Perform the interpolation double interpolatedValue = 0.0f; - for (int j = startSample; j <= endSample; j++) { + for (size_t j = startSample; j <= endSample; j++) { interpolatedValue += input[j] * weights[j - startSample]; }