Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starboard/types.h: Replace kSbInt16Min/Max with std::numeric_limits equivalents #4177

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading