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
4043f320
Commit
4043f320
authored
Dec 22, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm/Dither: generic sample dithering using template
parent
32b834aa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
13 deletions
+25
-13
PcmDither.cxx
src/pcm/PcmDither.cxx
+22
-13
PcmDither.hxx
src/pcm/PcmDither.hxx
+3
-0
No files found.
src/pcm/PcmDither.cxx
View file @
4043f320
...
@@ -21,17 +21,12 @@
...
@@ -21,17 +21,12 @@
#include "PcmDither.hxx"
#include "PcmDither.hxx"
#include "PcmPrng.hxx"
#include "PcmPrng.hxx"
inline
int16_t
template
<
typename
T
,
T
MIN
,
T
MAX
,
unsigned
scale_bits
>
PcmDither
::
Dither24To16
(
int_fast32_t
sample
)
T
PcmDither
::
Dither
(
T
sample
)
{
{
constexpr
unsigned
from_bits
=
24
;
constexpr
T
round
=
1
<<
(
scale_bits
-
1
);
constexpr
unsigned
to_bits
=
16
;
constexpr
T
mask
=
(
1
<<
scale_bits
)
-
1
;
constexpr
unsigned
scale_bits
=
from_bits
-
to_bits
;
constexpr
int_fast32_t
round
=
1
<<
(
scale_bits
-
1
);
constexpr
int_fast32_t
mask
=
(
1
<<
scale_bits
)
-
1
;
constexpr
int_fast32_t
ONE
=
1
<<
(
from_bits
-
1
);
constexpr
int_fast32_t
MIN
=
-
ONE
;
constexpr
int_fast32_t
MAX
=
ONE
-
1
;
sample
+=
error
[
0
]
-
error
[
1
]
+
error
[
2
];
sample
+=
error
[
0
]
-
error
[
1
]
+
error
[
2
];
...
@@ -39,9 +34,9 @@ PcmDither::Dither24To16(int_fast32_t sample)
...
@@ -39,9 +34,9 @@ PcmDither::Dither24To16(int_fast32_t sample)
error
[
1
]
=
error
[
0
]
/
2
;
error
[
1
]
=
error
[
0
]
/
2
;
/* round */
/* round */
int_fast32_t
output
=
sample
+
round
;
T
output
=
sample
+
round
;
int_fast32_t
rnd
=
pcm_prng
(
random
);
const
T
rnd
=
pcm_prng
(
random
);
output
+=
(
rnd
&
mask
)
-
(
random
&
mask
);
output
+=
(
rnd
&
mask
)
-
(
random
&
mask
);
random
=
rnd
;
random
=
rnd
;
...
@@ -63,7 +58,21 @@ PcmDither::Dither24To16(int_fast32_t sample)
...
@@ -63,7 +58,21 @@ PcmDither::Dither24To16(int_fast32_t sample)
error
[
0
]
=
sample
-
output
;
error
[
0
]
=
sample
-
output
;
return
(
int16_t
)(
output
>>
scale_bits
);
return
output
;
}
inline
int16_t
PcmDither
::
Dither24To16
(
int_fast32_t
sample
)
{
typedef
decltype
(
sample
)
T
;
constexpr
unsigned
from_bits
=
24
;
constexpr
unsigned
to_bits
=
16
;
constexpr
unsigned
scale_bits
=
from_bits
-
to_bits
;
constexpr
int_fast32_t
ONE
=
1
<<
(
from_bits
-
1
);
constexpr
int_fast32_t
MIN
=
-
ONE
;
constexpr
int_fast32_t
MAX
=
ONE
-
1
;
return
Dither
<
T
,
MIN
,
MAX
,
scale_bits
>
(
sample
)
>>
scale_bits
;
}
}
void
void
...
...
src/pcm/PcmDither.hxx
View file @
4043f320
...
@@ -30,6 +30,9 @@ public:
...
@@ -30,6 +30,9 @@ public:
constexpr
PcmDither
()
constexpr
PcmDither
()
:
error
{
0
,
0
,
0
},
random
(
0
)
{}
:
error
{
0
,
0
,
0
},
random
(
0
)
{}
template
<
typename
T
,
T
MIN
,
T
MAX
,
unsigned
scale_bits
>
T
Dither
(
T
sample
);
void
Dither24To16
(
int16_t
*
dest
,
const
int32_t
*
src
,
void
Dither24To16
(
int16_t
*
dest
,
const
int32_t
*
src
,
const
int32_t
*
src_end
);
const
int32_t
*
src_end
);
...
...
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