Skip to content

Commit

Permalink
Replace kSbInt16Min/Max with their std::numeric_limits<> equivalent, …
Browse files Browse the repository at this point in the history
…inline
  • Loading branch information
yell0wd0g committed Oct 1, 2024
1 parent ab487e5 commit 46fca2a
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 @@ -66,10 +66,6 @@ static const int8_t kSbInt8Min = ((int8_t)0x80);
static const int8_t kSbInt8Max = ((int8_t)0x7F);
static const uint8_t kSbUInt8Max = ((uint8_t)0xFF);

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 46fca2a

Please sign in to comment.