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
86e72ffe
Commit
86e72ffe
authored
Dec 22, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/Clamp: generic Clamp() function
parent
6416198e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
3 deletions
+54
-3
Makefile.am
Makefile.am
+1
-0
AlsaMixerPlugin.cxx
src/mixer/AlsaMixerPlugin.cxx
+2
-2
PcmMix.cxx
src/pcm/PcmMix.cxx
+2
-1
Clamp.hxx
src/util/Clamp.hxx
+49
-0
No files found.
Makefile.am
View file @
86e72ffe
...
...
@@ -248,6 +248,7 @@ endif
libutil_a_SOURCES
=
\
src/util/Macros.hxx
\
src/util/Clamp.hxx
\
src/util/Error.cxx src/util/Error.hxx
\
src/util/Domain.hxx
\
src/util/ReusableArray.hxx
\
...
...
src/mixer/AlsaMixerPlugin.cxx
View file @
86e72ffe
...
...
@@ -27,6 +27,7 @@
#include "event/Call.hxx"
#include "util/ASCII.hxx"
#include "util/ReusableArray.hxx"
#include "util/Clamp.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
...
...
@@ -372,8 +373,7 @@ AlsaMixer::SetVolume(unsigned volume, Error &error)
level
=
(
long
)(((
vol
/
100.0
)
*
(
volume_max
-
volume_min
)
+
volume_min
)
+
0.5
);
level
=
level
>
volume_max
?
volume_max
:
level
;
level
=
level
<
volume_min
?
volume_min
:
level
;
level
=
Clamp
(
level
,
volume_min
,
volume_max
);
err
=
snd_mixer_selem_set_playback_volume_all
(
elem
,
level
);
if
(
err
<
0
)
{
...
...
src/pcm/PcmMix.cxx
View file @
86e72ffe
...
...
@@ -23,6 +23,7 @@
#include "PcmUtils.hxx"
#include "AudioFormat.hxx"
#include "Traits.hxx"
#include "util/Clamp.hxx"
#include <assert.h>
#include <math.h>
...
...
@@ -215,7 +216,7 @@ pcm_mix(void *buffer1, const void *buffer2, size_t size,
s
*=
s
;
vol1
=
s
*
PCM_VOLUME_1
+
0.5
;
vol1
=
vol1
>
PCM_VOLUME_1
?
PCM_VOLUME_1
:
(
vol1
<
0
?
0
:
vol
1
);
vol1
=
Clamp
<
int
>
(
vol1
,
0
,
PCM_VOLUME_
1
);
return
pcm_add_vol
(
buffer1
,
buffer2
,
size
,
vol1
,
PCM_VOLUME_1
-
vol1
,
format
);
}
src/util/Clamp.hxx
0 → 100644
View file @
86e72ffe
/*
* Copyright (C) 2012 Max Kellermann <max@duempel.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CLAMP_HPP
#define CLAMP_HPP
#include "Compiler.h"
/**
* Clamps the specified value in a range. Returns #min or #max if the
* value is outside.
*/
template
<
typename
T
>
static
inline
constexpr
const
T
&
Clamp
(
const
T
&
value
,
const
T
&
min
,
const
T
&
max
)
{
return
gcc_unlikely
(
value
<
min
)
?
min
:
(
gcc_unlikely
(
value
>
max
)
?
max
:
value
);
}
#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