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
04ba4098
Commit
04ba4098
authored
Dec 01, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm/PcmMix: use the SampleTraits library
parent
fc10bdf2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
21 deletions
+29
-21
PcmMix.cxx
src/pcm/PcmMix.cxx
+29
-21
No files found.
src/pcm/PcmMix.cxx
View file @
04ba4098
...
...
@@ -22,40 +22,48 @@
#include "PcmVolume.hxx"
#include "PcmUtils.hxx"
#include "AudioFormat.hxx"
#include "Traits.hxx"
#include <assert.h>
#include <math.h>
template
<
typename
T
,
typename
U
,
unsigned
bits
>
static
T
PcmAddVolume
(
T
_a
,
T
_b
,
int
volume1
,
int
volume2
)
template
<
SampleFormat
F
,
class
Traits
=
SampleTraits
<
F
>>
static
typename
Traits
::
value_type
PcmAddVolume
(
typename
Traits
::
value_type
_a
,
typename
Traits
::
value_type
_b
,
int
volume1
,
int
volume2
)
{
U
a
(
_a
),
b
(
_b
);
typename
Traits
::
long_type
a
(
_a
),
b
(
_b
);
U
c
=
((
a
*
volume1
+
b
*
volume2
)
+
typename
Traits
::
value_type
c
=
((
a
*
volume1
+
b
*
volume2
)
+
pcm_volume_dither
()
+
PCM_VOLUME_1
/
2
)
/
PCM_VOLUME_1
;
return
PcmClamp
<
T
,
U
,
bits
>
(
c
);
return
PcmClamp
<
typename
Traits
::
value_type
,
typename
Traits
::
long_type
,
Traits
::
BITS
>
(
c
);
}
template
<
typename
T
,
typename
U
,
unsigned
bits
>
template
<
SampleFormat
F
,
class
Traits
=
SampleTraits
<
F
>
>
static
void
PcmAddVolume
(
T
*
a
,
const
T
*
b
,
unsigned
n
,
int
volume1
,
int
volume2
)
PcmAddVolume
(
typename
Traits
::
pointer_type
a
,
typename
Traits
::
const_pointer_type
b
,
size_t
n
,
int
volume1
,
int
volume2
)
{
for
(
size_t
i
=
0
;
i
!=
n
;
++
i
)
a
[
i
]
=
PcmAddVolume
<
T
,
U
,
b
its
>
(
a
[
i
],
b
[
i
],
volume1
,
volume2
);
a
[
i
]
=
PcmAddVolume
<
F
,
Tra
its
>
(
a
[
i
],
b
[
i
],
volume1
,
volume2
);
}
template
<
typename
T
,
typename
U
,
unsigned
bits
>
template
<
SampleFormat
F
,
class
Traits
=
SampleTraits
<
F
>
>
static
void
PcmAddVolumeVoid
(
void
*
a
,
const
void
*
b
,
size_t
size
,
int
volume1
,
int
volume2
)
{
constexpr
size_t
sample_size
=
sizeof
(
T
)
;
constexpr
size_t
sample_size
=
Traits
::
SAMPLE_SIZE
;
assert
(
size
%
sample_size
==
0
);
PcmAddVolume
<
T
,
U
,
bits
>
((
T
*
)
a
,
(
const
T
*
)
b
,
size
/
sample_size
,
volume1
,
volume2
);
PcmAddVolume
<
F
,
Traits
>
(
typename
Traits
::
pointer_type
(
a
),
typename
Traits
::
const_pointer_type
(
b
),
size
/
sample_size
,
volume1
,
volume2
);
}
static
void
...
...
@@ -84,23 +92,23 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size,
return
false
;
case
SampleFormat
:
:
S8
:
PcmAddVolumeVoid
<
int8_t
,
int32_t
,
8
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
PcmAddVolumeVoid
<
SampleFormat
::
S
8
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
return
true
;
case
SampleFormat
:
:
S16
:
PcmAddVolumeVoid
<
int16_t
,
int32_t
,
16
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
PcmAddVolumeVoid
<
SampleFormat
::
S
16
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
return
true
;
case
SampleFormat
:
:
S24_P32
:
PcmAddVolumeVoid
<
int32_t
,
int64_t
,
24
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
PcmAddVolumeVoid
<
SampleFormat
::
S24_P32
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
return
true
;
case
SampleFormat
:
:
S32
:
PcmAddVolumeVoid
<
int32_t
,
int64_t
,
32
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
PcmAddVolumeVoid
<
SampleFormat
::
S
32
>
(
buffer1
,
buffer2
,
size
,
vol1
,
vol2
);
return
true
;
case
SampleFormat
:
:
FLOAT
:
...
...
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