Skip to content

Commit

Permalink
fix some prefast warnings (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenbingl authored Jun 7, 2023
1 parent 1cbebb0 commit 1f0c76c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmake/ext_ortlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion operators/audio/audio_decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> filtered_buf = filter.Process(buf);
// downsample the audio data
KaiserWindowInterpolation::Process(filtered_buf, buf,
Expand Down
16 changes: 8 additions & 8 deletions operators/audio/sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class KaiserWindowInterpolation {
int outputSize = static_cast<int>(std::ceil(static_cast<float>(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
Expand All @@ -175,20 +175,20 @@ class KaiserWindowInterpolation {

// Calculate the range of input samples for interpolation
int range = static_cast<int>(std::ceil(kBeta / (2.0 * factor)));
int startSample = std::max(0, integerPart - range);
int endSample = std::min(static_cast<int>(input.size()) - 1, integerPart + range);
size_t startSample = std::max(0, integerPart - range);
size_t endSample = std::min(static_cast<int>(input.size()) - 1, integerPart + range);

// Calculate the Kaiser window weights for the input samples
std::vector<double> weights = KaiserWin(static_cast<size_t>(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<double>(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];
}

Expand Down

0 comments on commit 1f0c76c

Please sign in to comment.