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
a7a10d03
Commit
a7a10d03
authored
Feb 01, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/test_pcm: add unit test for pcm_mix()
parent
ef99d6ce
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
0 deletions
+119
-0
Makefile.am
Makefile.am
+1
-0
test_pcm_all.hxx
test/test_pcm_all.hxx
+12
-0
test_pcm_main.cxx
test/test_pcm_main.cxx
+5
-0
test_pcm_mix.cxx
test/test_pcm_mix.cxx
+84
-0
test_pcm_util.hxx
test/test_pcm_util.hxx
+17
-0
No files found.
Makefile.am
View file @
a7a10d03
...
...
@@ -1407,6 +1407,7 @@ test_test_pcm_SOURCES = \
test
/test_pcm_channels.cxx
\
test
/test_pcm_format.cxx
\
test
/test_pcm_volume.cxx
\
test
/test_pcm_mix.cxx
\
test
/test_pcm_all.hxx
\
test
/test_pcm_main.cxx
test_test_pcm_LDADD
=
\
...
...
test/test_pcm_all.hxx
View file @
a7a10d03
...
...
@@ -65,4 +65,16 @@ test_pcm_format_16_to_32();
void
test_pcm_format_float
();
void
test_pcm_mix_8
();
void
test_pcm_mix_16
();
void
test_pcm_mix_24
();
void
test_pcm_mix_32
();
#endif
test/test_pcm_main.cxx
View file @
a7a10d03
...
...
@@ -43,5 +43,10 @@ main(int argc, char **argv)
g_test_add_func
(
"/pcm/format/16_to_32"
,
test_pcm_format_16_to_32
);
g_test_add_func
(
"/pcm/format/float"
,
test_pcm_format_float
);
g_test_add_func
(
"/pcm/mix/8"
,
test_pcm_mix_8
);
g_test_add_func
(
"/pcm/mix/16"
,
test_pcm_mix_16
);
g_test_add_func
(
"/pcm/mix/24"
,
test_pcm_mix_24
);
g_test_add_func
(
"/pcm/mix/32"
,
test_pcm_mix_32
);
g_test_run
();
}
test/test_pcm_mix.cxx
0 → 100644
View file @
a7a10d03
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "test_pcm_all.hxx"
#include "test_pcm_util.hxx"
#include "PcmMix.hxx"
#include <glib.h>
template
<
typename
T
,
sample_format
format
,
typename
G
=
GlibRandomInt
<
T
>>
void
TestPcmMix
(
G
g
=
G
())
{
constexpr
unsigned
N
=
256
;
const
auto
src1
=
TestDataBuffer
<
T
,
N
>
(
g
);
const
auto
src2
=
TestDataBuffer
<
T
,
N
>
(
g
);
/* portion1=1.0: result must be equal to src1 */
auto
result
=
src1
;
bool
success
=
pcm_mix
(
result
.
begin
(),
src2
.
begin
(),
sizeof
(
result
),
format
,
1.0
);
g_assert
(
success
);
AssertEqualWithTolerance
(
result
,
src1
,
1
);
/* portion1=0.0: result must be equal to src2 */
result
=
src1
;
success
=
pcm_mix
(
result
.
begin
(),
src2
.
begin
(),
sizeof
(
result
),
format
,
0.0
);
g_assert
(
success
);
AssertEqualWithTolerance
(
result
,
src2
,
1
);
/* portion1=0.5 */
result
=
src1
;
success
=
pcm_mix
(
result
.
begin
(),
src2
.
begin
(),
sizeof
(
result
),
format
,
0.5
);
g_assert
(
success
);
auto
expected
=
src1
;
for
(
unsigned
i
=
0
;
i
<
N
;
++
i
)
expected
[
i
]
=
(
int64_t
(
src1
[
i
])
+
int64_t
(
src2
[
i
]))
/
2
;
AssertEqualWithTolerance
(
result
,
expected
,
1
);
}
void
test_pcm_mix_8
()
{
TestPcmMix
<
int8_t
,
SAMPLE_FORMAT_S8
>
();
}
void
test_pcm_mix_16
()
{
TestPcmMix
<
int16_t
,
SAMPLE_FORMAT_S16
>
();
}
void
test_pcm_mix_24
()
{
TestPcmMix
<
int32_t
,
SAMPLE_FORMAT_S24_P32
>
(
GlibRandomInt24
());
}
void
test_pcm_mix_32
()
{
TestPcmMix
<
int32_t
,
SAMPLE_FORMAT_S32
>
();
}
test/test_pcm_util.hxx
View file @
a7a10d03
...
...
@@ -51,6 +51,7 @@ template<typename T, size_t N>
class
TestDataBuffer
:
std
::
array
<
T
,
N
>
{
public
:
using
typename
std
::
array
<
T
,
N
>::
const_pointer
;
using
std
::
array
<
T
,
N
>::
size
;
using
std
::
array
<
T
,
N
>::
begin
;
using
std
::
array
<
T
,
N
>::
end
;
using
std
::
array
<
T
,
N
>::
operator
[];
...
...
@@ -66,3 +67,19 @@ public:
return
begin
();
}
};
template
<
typename
T
>
bool
AssertEqualWithTolerance
(
const
T
&
a
,
const
T
&
b
,
unsigned
tolerance
)
{
g_assert_cmpint
(
a
.
size
(),
==
,
b
.
size
());
for
(
unsigned
i
=
0
;
i
<
a
.
size
();
++
i
)
{
int64_t
x
=
a
[
i
],
y
=
b
[
i
];
g_assert_cmpint
(
x
,
>=
,
y
-
int64_t
(
tolerance
));
g_assert_cmpint
(
x
,
<=
,
y
+
int64_t
(
tolerance
));
}
return
true
;
}
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