Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
36710c40
Commit
36710c40
authored
May 3, 2012
by
Alexandre Savard
Browse files
Options
Downloads
Patches
Plain Diff
#10230: Test for triangular and sine signals
parent
fb832a49
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
daemon/test/resamplertest.cpp
+107
-60
107 additions, 60 deletions
daemon/test/resamplertest.cpp
daemon/test/resamplertest.h
+16
-1
16 additions, 1 deletion
daemon/test/resamplertest.h
with
123 additions
and
61 deletions
daemon/test/resamplertest.cpp
+
107
−
60
View file @
36710c40
...
@@ -46,133 +46,154 @@ void ResamplerTest::tearDown()
...
@@ -46,133 +46,154 @@ void ResamplerTest::tearDown()
void
ResamplerTest
::
testUpsamplingRamp
()
void
ResamplerTest
::
testUpsamplingRamp
()
{
{
std
::
tr1
::
array
<
SFLDataFormat
,
160
>
tmpInputBuffer
;
std
::
tr1
::
array
<
SFLDataFormat
,
320
>
tmpOutputBuffer
;
// generate input samples and store them in inputBuffer
// generate input samples and store them in inputBuffer
generateRamp
();
generateRamp
();
std
::
cout
<<
"Test Upsampling Ramp"
<<
std
::
endl
;
std
::
cout
<<
"Test Upsampling Ramp"
<<
std
::
endl
;
converter
=
new
SamplerateConverter
(
44100
);
SamplerateConverter
converter
(
44100
);
CPPUNIT_ASSERT
(
converter
!=
NULL
);
performUpsampling
(
converter
);
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
160
,
tmpInputBuffer
.
begin
());
LowSmplrBuffer
tmpInputBuffer
;
converter
->
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
8000
,
16000
,
tmpInputBuffer
.
size
());
HighSmplrBuffer
tmpOutputBuffer
;
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
(),
tmpInputBuffer
.
begin
());
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
delete
converter
;
std
::
copy
(
outputBuffer
.
begin
(),
outputBuffer
.
begin
()
+
tmpOutputBuffer
.
size
(),
tmpOutputBuffer
.
begin
());
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
}
}
void
ResamplerTest
::
testDownsamplingRamp
()
void
ResamplerTest
::
testDownsamplingRamp
()
{
{
std
::
tr1
::
array
<
SFLDataFormat
,
320
>
tmpInputBuffer
;
std
::
tr1
::
array
<
SFLDataFormat
,
160
>
tmpOutputBuffer
;
generateRamp
();
generateRamp
();
std
::
cout
<<
"Test Downsampling Ramp"
<<
std
::
endl
;
std
::
cout
<<
"Test Downsampling Ramp"
<<
std
::
endl
;
converter
=
new
SamplerateConverter
(
44100
);
SamplerateConverter
converter
(
44100
);
CPPUNIT_ASSERT
(
converter
!=
NULL
);
performDownsampling
(
converter
);
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
320
,
tmpInputBuffer
.
begin
());
HighSmplrBuffer
tmpInputBuffer
;
converter
->
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
16000
,
8000
,
tmpInputBuffer
.
size
());
LowSmplrBuffer
tmpOutputBuffer
;
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
(),
tmpInputBuffer
.
begin
());
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
delete
converter
;
std
::
copy
(
outputBuffer
.
begin
(),
outputBuffer
.
begin
()
+
tmpOutputBuffer
.
size
(),
tmpOutputBuffer
.
begin
());
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
}
}
void
ResamplerTest
::
testUpsamplingTriangle
()
void
ResamplerTest
::
testUpsamplingTriangle
()
{
{
std
::
tr1
::
array
<
SFLDataFormat
,
160
>
tmpInputBuffer
;
std
::
tr1
::
array
<
SFLDataFormat
,
320
>
tmpOutputBuffer
;
generateTriangularSignal
();
generateTriangularSignal
();
std
::
cout
<<
"Test Upsampling Triangle"
<<
std
::
endl
;
std
::
cout
<<
"Test Upsampling Triangle"
<<
std
::
endl
;
converter
=
new
SamplerateConverter
(
44100
);
SamplerateConverter
converter
(
44100
);
CPPUNIT_ASSERT
(
converter
!=
NULL
);
performUpsampling
(
converter
);
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
160
,
tmpInputBuffer
.
begin
())
;
LowSmplrBuffer
tmpInputBuffer
;
converter
->
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
8000
,
16000
,
tmpInputBuffer
.
size
())
;
HighSmplrBuffer
tmpOutputBuffer
;
delete
converter
;
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
(),
tmpInputBuffer
.
begin
());
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
copy
(
outputBuffer
.
begin
(),
outputBuffer
.
begin
()
+
tmpOutputBuffer
.
size
(),
tmpOutputBuffer
.
begin
());
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
}
}
void
ResamplerTest
::
testDownsamplingTriangle
()
void
ResamplerTest
::
testDownsamplingTriangle
()
{
{
std
::
tr1
::
array
<
SFLDataFormat
,
320
>
tmpInputBuffer
;
std
::
tr1
::
array
<
SFLDataFormat
,
160
>
tmpOutputBuffer
;
generateTriangularSignal
();
generateTriangularSignal
();
std
::
cout
<<
"Test Downsampling Triangle"
<<
std
::
endl
;
std
::
cout
<<
"Test Downsampling Triangle"
<<
std
::
endl
;
converter
=
new
SamplerateConverter
(
44100
);
SamplerateConverter
converter
(
44100
);
CPPUNIT_ASSERT
(
converter
!=
NULL
);
performDownsampling
(
converter
);
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
end
()
+
320
,
tmpInputBuffer
.
begin
())
;
HighSmplrBuffer
tmpInputBuffer
;
converter
->
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
16000
,
8000
,
tmpInputBuffer
.
size
())
;
LowSmplrBuffer
tmpOutputBuffer
;
delete
converter
;
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
(),
tmpInputBuffer
.
begin
());
}
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
copy
(
outputBuffer
.
begin
(),
outputBuffer
.
begin
()
+
tmpOutputBuffer
.
size
(),
tmpOutputBuffer
.
begin
());
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
}
void
ResamplerTest
::
testUpsamplingSine
()
void
ResamplerTest
::
testUpsamplingSine
()
{
{
std
::
tr1
::
array
<
SFLDataFormat
,
160
>
tmpInputBuffer
;
std
::
tr1
::
array
<
SFLDataFormat
,
320
>
tmpOutputBuffer
;
// generate input samples and store them in inputBuffer
// generate input samples and store them in inputBuffer
generateSineSignal
();
generateSineSignal
();
std
::
cout
<<
"Test Upsampling Sine"
<<
std
::
endl
;
std
::
cout
<<
"Test Upsampling Sine"
<<
std
::
endl
;
converter
=
new
SamplerateConverter
(
44100
);
SamplerateConverter
converter
(
44100
);
CPPUNIT_ASSERT
(
converter
!=
NULL
);
performUpsampling
(
converter
);
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
160
,
tmpInputBuffer
.
begin
())
;
LowSmplrBuffer
tmpInputBuffer
;
converter
->
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
8000
,
16000
,
tmpInputBuffer
.
size
())
;
HighSmplrBuffer
tmpOutputBuffer
;
delete
converter
;
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
(),
tmpInputBuffer
.
begin
());
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
copy
(
outputBuffer
.
begin
(),
outputBuffer
.
begin
()
+
tmpOutputBuffer
.
size
(),
tmpOutputBuffer
.
begin
());
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
}
}
void
ResamplerTest
::
testDownsamplingSine
()
void
ResamplerTest
::
testDownsamplingSine
()
{
{
std
::
tr1
::
array
<
SFLDataFormat
,
320
>
tmpInputBuffer
;
std
::
tr1
::
array
<
SFLDataFormat
,
160
>
tmpOutputBuffer
;
// generate input samples and store them in inputBuffer
// generate input samples and store them in inputBuffer
generateSineSignal
();
generateSineSignal
();
std
::
cout
<<
"Test Downsampling Sine"
<<
std
::
endl
;
std
::
cout
<<
"Test Downsampling Sine"
<<
std
::
endl
;
converter
=
new
SamplerateConverter
(
44100
);
SamplerateConverter
converter
(
44100
);
CPPUNIT_ASSERT
(
converter
!=
NULL
);
performDownsampling
(
converter
);
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
320
,
tmpInputBuffer
.
begin
())
;
HighSmplrBuffer
tmpInputBuffer
;
converter
->
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
8000
,
16000
,
tmpInputBuffer
.
size
())
;
LowSmplrBuffer
tmpOutputBuffer
;
delete
converter
;
std
::
copy
(
inputBuffer
.
begin
(),
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
(),
tmpInputBuffer
.
begin
());
std
::
cout
<<
"Input Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpInputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpInputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
std
::
copy
(
outputBuffer
.
begin
(),
outputBuffer
.
begin
()
+
tmpOutputBuffer
.
size
(),
tmpOutputBuffer
.
begin
());
std
::
cout
<<
"Output Buffer"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tmpOutputBuffer
.
size
();
i
++
)
std
::
cout
<<
tmpOutputBuffer
[
i
]
<<
", "
;
std
::
cout
<<
std
::
endl
;
}
}
void
ResamplerTest
::
generateRamp
()
void
ResamplerTest
::
generateRamp
()
...
@@ -192,6 +213,32 @@ void ResamplerTest::generateTriangularSignal()
...
@@ -192,6 +213,32 @@ void ResamplerTest::generateTriangularSignal()
void
ResamplerTest
::
generateSineSignal
()
void
ResamplerTest
::
generateSineSignal
()
{
{
for
(
int
i
=
0
;
i
<
inputBuffer
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
inputBuffer
.
size
();
i
++
)
{
//inputBuffer[i] = (SFLDataFormat)(
inputBuffer
[
i
]
=
(
SFLDataFormat
)(
1000.0
*
sin
((
double
)
i
));
}
}
void
ResamplerTest
::
performUpsampling
(
SamplerateConverter
&
converter
)
{
LowSmplrBuffer
tmpInputBuffer
;
HighSmplrBuffer
tmpOutputBuffer
;
int
i
,
j
;
for
(
i
=
0
,
j
=
0
;
i
<
(
inputBuffer
.
size
()
/
2
);
i
+=
tmpInputBuffer
.
size
(),
j
+=
tmpOutputBuffer
.
size
())
{
std
::
copy
(
inputBuffer
.
begin
()
+
i
,
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
()
+
i
,
tmpInputBuffer
.
begin
());
converter
.
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
8000
,
16000
,
tmpInputBuffer
.
size
());
std
::
copy
(
tmpOutputBuffer
.
begin
(),
tmpOutputBuffer
.
end
(),
outputBuffer
.
begin
()
+
j
);
}
}
void
ResamplerTest
::
performDownsampling
(
SamplerateConverter
&
converter
)
{
HighSmplrBuffer
tmpInputBuffer
;
LowSmplrBuffer
tmpOutputBuffer
;
int
i
,
j
;
for
(
i
=
0
,
j
=
0
;
i
<
inputBuffer
.
size
();
i
+=
tmpInputBuffer
.
size
(),
j
+=
tmpOutputBuffer
.
size
())
{
std
::
copy
(
inputBuffer
.
begin
()
+
i
,
inputBuffer
.
begin
()
+
tmpInputBuffer
.
size
()
+
i
,
tmpInputBuffer
.
begin
());
converter
.
resample
(
tmpInputBuffer
.
data
(),
tmpOutputBuffer
.
data
(),
tmpOutputBuffer
.
size
(),
16000
,
8000
,
tmpInputBuffer
.
size
());
std
::
copy
(
tmpOutputBuffer
.
begin
(),
tmpOutputBuffer
.
end
(),
outputBuffer
.
begin
()
+
j
);
}
}
}
}
This diff is collapsed.
Click to expand it.
daemon/test/resamplertest.h
+
16
−
1
View file @
36710c40
...
@@ -41,6 +41,11 @@
...
@@ -41,6 +41,11 @@
#include
"audio/samplerateconverter.h"
#include
"audio/samplerateconverter.h"
#define MAX_BUFFER_LENGTH 40000
#define MAX_BUFFER_LENGTH 40000
#define TMP_LOWSMPLR_BUFFER_LENGTH 160
#define TMP_HIGHSMPLR_BUFFER_LENGTH 320
typedef
std
::
tr1
::
array
<
SFLDataFormat
,
TMP_LOWSMPLR_BUFFER_LENGTH
>
LowSmplrBuffer
;
typedef
std
::
tr1
::
array
<
SFLDataFormat
,
TMP_HIGHSMPLR_BUFFER_LENGTH
>
HighSmplrBuffer
;
class
ResamplerTest
:
public
CppUnit
::
TestCase
{
class
ResamplerTest
:
public
CppUnit
::
TestCase
{
...
@@ -51,7 +56,7 @@ class ResamplerTest : public CppUnit::TestCase {
...
@@ -51,7 +56,7 @@ class ResamplerTest : public CppUnit::TestCase {
CPPUNIT_TEST
(
testUpsamplingRamp
);
CPPUNIT_TEST
(
testUpsamplingRamp
);
CPPUNIT_TEST
(
testDownsamplingRamp
);
CPPUNIT_TEST
(
testDownsamplingRamp
);
CPPUNIT_TEST
(
testUpsamplingTriangle
);
CPPUNIT_TEST
(
testUpsamplingTriangle
);
//
CPPUNIT_TEST(testDownsamplingTriangle);
CPPUNIT_TEST
(
testDownsamplingTriangle
);
CPPUNIT_TEST
(
testUpsamplingSine
);
CPPUNIT_TEST
(
testUpsamplingSine
);
CPPUNIT_TEST
(
testDownsamplingSine
);
CPPUNIT_TEST
(
testDownsamplingSine
);
CPPUNIT_TEST_SUITE_END
();
CPPUNIT_TEST_SUITE_END
();
...
@@ -118,6 +123,16 @@ private:
...
@@ -118,6 +123,16 @@ private:
*/
*/
void
generateSineSignal
();
void
generateSineSignal
();
/*
* Perform upsampling on the whole input buffer
*/
void
performUpsampling
(
SamplerateConverter
&
converter
);
/*
* Perform downsampling on the whold input buffer
*/
void
performDownsampling
(
SamplerateConverter
&
converter
);
/**
/**
* Used to store input samples
* Used to store input samples
*/
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment