Skip to content

Commit

Permalink
starboard/types.h: Replace kSbInt16Min/Max with std::numeric_limits e…
Browse files Browse the repository at this point in the history
…quivalents (#4177)

As said this CL replaces kSbInt16Min/Max with their
std::numeric_limits<> equivalent, and removes kSbUInt16Max entirely
because it's unused.

Verified bya local x64x11 build.

[1]
https://source.corp.google.com/search?q=kSb.%3FInt(16)&sq=&ss=h%2Flbshell-internal%2Fcobalt_src%2F%2B%2Frefs%2Fheads%2FCOBALT

b/366064934
  • Loading branch information
yell0wd0g authored Oct 1, 2024
1 parent 31cb72d commit 96e82a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "starboard/shared/starboard/player/filter/audio_channel_layout_mixer.h"

#include <limits>
#include <vector>

#include "starboard/common/log.h"
Expand Down Expand Up @@ -213,11 +214,11 @@ float ClipSample<float>(float sample) {

template <>
int16_t ClipSample<int16_t>(float sample) {
if (sample > kSbInt16Max) {
return kSbInt16Max;
if (sample > std::numeric_limits<int16_t>::max()) {
return std::numeric_limits<int16_t>::max();
}
if (sample < kSbInt16Min) {
return kSbInt16Min;
if (sample < std::numeric_limits<int16_t>::min()) {
return std::numeric_limits<int16_t>::min();
}
return sample;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <cmath>
#include <functional>
#include <limits>
#include <numeric>
#include <string>

Expand Down Expand Up @@ -104,7 +105,8 @@ class AudioChannelLayoutMixerTest
if (storage_type_ == kSbMediaAudioFrameStorageTypePlanar) {
src_index = i % kInputFrames * num_of_channels + i / kInputFrames;
}
dest_buffer[i] = data_buffer[src_index] * kSbInt16Max;
dest_buffer[i] =
data_buffer[src_index] * std::numeric_limits<int16_t>::max();
}
}
return decoded_audio;
Expand Down Expand Up @@ -146,10 +148,11 @@ class AudioChannelLayoutMixerTest
src_index = i % output->frames() * output_num_of_channels +
i / output->frames();
}
ASSERT_LE(fabs(expected_output[src_index] -
static_cast<float>(output_buffer[i]) /
static_cast<float>(kSbInt16Max)),
0.001f);
ASSERT_LE(
fabs(expected_output[src_index] -
static_cast<float>(output_buffer[i]) /
static_cast<float>(std::numeric_limits<int16_t>::max())),
0.001f);
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions starboard/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ typedef int64_t ssize_t;

// Simulate needed portions of limits.h for platforms that don't provide it.

static const int16_t kSbInt16Min = ((int16_t)0x8000);
static const int16_t kSbInt16Max = ((int16_t)0x7FFF);
static const uint16_t kSbUInt16Max = ((uint16_t)0xFFFF);

#define kSbInt32Min ((int32_t)0x80000000)
static const int32_t kSbInt32Max = ((int32_t)0x7FFFFFFF);
static const uint32_t kSbUInt32Max = ((uint32_t)0xFFFFFFFF);
Expand Down

0 comments on commit 96e82a5

Please sign in to comment.