Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
b43ec3d6
Commit
b43ec3d6
authored
Dec 22, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm/Traits: add MIN and MAX
Move from PcmClamp().
parent
316a25de
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
9 deletions
+28
-9
PcmUtils.hxx
src/pcm/PcmUtils.hxx
+6
-9
Traits.hxx
src/pcm/Traits.hxx
+22
-0
No files found.
src/pcm/PcmUtils.hxx
View file @
b43ec3d6
...
...
@@ -51,19 +51,16 @@ static inline typename Traits::value_type
PcmClamp
(
typename
Traits
::
long_type
x
)
{
typedef
typename
Traits
::
value_type
T
;
typedef
typename
Traits
::
long_type
U
;
constexpr
U
MIN_VALUE
=
-
(
U
(
1
)
<<
(
Traits
::
BITS
-
1
));
constexpr
U
MAX_VALUE
=
(
U
(
1
)
<<
(
Traits
::
BITS
-
1
))
-
1
;
typedef
std
::
numeric_limits
<
T
>
limits
;
static_assert
(
MIN_VALUE
>=
limits
::
min
(),
"out of range"
);
static_assert
(
MAX_VALUE
<=
limits
::
max
(),
"out of range"
);
static_assert
(
Traits
::
MIN
>=
limits
::
min
(),
"out of range"
);
static_assert
(
Traits
::
MAX
<=
limits
::
max
(),
"out of range"
);
if
(
gcc_unlikely
(
x
<
MIN_VALUE
))
return
T
(
MIN_VALUE
);
if
(
gcc_unlikely
(
x
<
Traits
::
MIN
))
return
T
(
Traits
::
MIN
);
if
(
gcc_unlikely
(
x
>
MAX_VALUE
))
return
T
(
MAX_VALUE
);
if
(
gcc_unlikely
(
x
>
Traits
::
MAX
))
return
T
(
Traits
::
MAX
);
return
T
(
x
);
}
...
...
src/pcm/Traits.hxx
View file @
b43ec3d6
...
...
@@ -74,6 +74,16 @@ struct SampleTraits<SampleFormat::S8> {
* not exist if this is not an integer sample format.
*/
static
constexpr
unsigned
BITS
=
sizeof
(
value_type
)
*
8
;
/**
* The minimum sample value.
*/
static
constexpr
value_type
MIN
=
-
(
sum_type
(
1
)
<<
(
BITS
-
1
));
/**
* The maximum sample value.
*/
static
constexpr
value_type
MAX
=
(
sum_type
(
1
)
<<
(
BITS
-
1
))
-
1
;
};
template
<>
...
...
@@ -87,6 +97,9 @@ struct SampleTraits<SampleFormat::S16> {
static
constexpr
size_t
SAMPLE_SIZE
=
sizeof
(
value_type
);
static
constexpr
unsigned
BITS
=
sizeof
(
value_type
)
*
8
;
static
constexpr
value_type
MIN
=
-
(
sum_type
(
1
)
<<
(
BITS
-
1
));
static
constexpr
value_type
MAX
=
(
sum_type
(
1
)
<<
(
BITS
-
1
))
-
1
;
};
template
<>
...
...
@@ -100,6 +113,9 @@ struct SampleTraits<SampleFormat::S32> {
static
constexpr
size_t
SAMPLE_SIZE
=
sizeof
(
value_type
);
static
constexpr
unsigned
BITS
=
sizeof
(
value_type
)
*
8
;
static
constexpr
value_type
MIN
=
-
(
sum_type
(
1
)
<<
(
BITS
-
1
));
static
constexpr
value_type
MAX
=
(
sum_type
(
1
)
<<
(
BITS
-
1
))
-
1
;
};
template
<>
...
...
@@ -113,6 +129,9 @@ struct SampleTraits<SampleFormat::S24_P32> {
static
constexpr
size_t
SAMPLE_SIZE
=
sizeof
(
value_type
);
static
constexpr
unsigned
BITS
=
24
;
static
constexpr
value_type
MIN
=
-
(
sum_type
(
1
)
<<
(
BITS
-
1
));
static
constexpr
value_type
MAX
=
(
sum_type
(
1
)
<<
(
BITS
-
1
))
-
1
;
};
template
<>
...
...
@@ -125,6 +144,9 @@ struct SampleTraits<SampleFormat::FLOAT> {
typedef
float
long_type
;
static
constexpr
size_t
SAMPLE_SIZE
=
sizeof
(
value_type
);
static
constexpr
value_type
MIN
=
-
1
;
static
constexpr
value_type
MAX
=
1
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment