Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
ITABase
Commits
4510d825
Commit
4510d825
authored
May 10, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Restructuring ITBase tests and adding spectrum test
parent
a5a7e8c8
Changes
7
Hide whitespace changes
Inline
Side-by-side
include/ITASpectrum.h
View file @
4510d825
...
...
@@ -21,6 +21,7 @@
#include
<ITABaseDefinitions.h>
#include
<iostream>
#include
<string>
#include
<vector>
...
...
@@ -43,6 +44,9 @@ public:
void
SetName
(
const
std
::
string
&
sVolatileName
);
std
::
string
GetName
()
const
;
std
::
string
GetValueUnit
()
const
;
void
SetValueUnit
(
std
::
string
sUnit
);
int
GetNumBands
()
const
;
const
std
::
vector
<
float
>&
GetCenterFrequencies
()
const
;
...
...
@@ -79,14 +83,17 @@ public:
//! Index operator for actual values
float
&
operator
[](
int
iFrequencyBandIndex
);
protected:
std
::
vector
<
float
>
m_vfValues
;
//!< Scalar spectrum values of any kind
std
::
vector
<
float
>
m_vfCenterFrequencies
;
//!< Base or center frequencies for bands
private:
std
::
string
m_sName
;
//!< Volatile name for debugging / backtracking
std
::
string
m_sName
;
//!< Volatile name for output formatting
std
::
string
m_sValueUnit
;
//!< Value unit, such as dB, dB(A) ... for output formatting.
};
//! STL stream output operator
ITA_BASE_API
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
CITASpectrum
&
oSpectrum
);
#endif // INCLUDE_WATCHER_ITA_SPECTRUM
src/ITAMagnitudeSpectrum.cpp
View file @
4510d825
...
...
@@ -6,6 +6,7 @@
CITAMagnitudeSpectrum
::
CITAMagnitudeSpectrum
(
const
int
nNumBands
)
:
CITASpectrum
(
nNumBands
)
{
SetValueUnit
(
"dB"
);
}
void
CITAMagnitudeSpectrum
::
SetMagnitudes
(
const
std
::
vector
<
float
>&
vfMagnitudes
)
...
...
src/ITASpectrum.cpp
View file @
4510d825
...
...
@@ -20,6 +20,16 @@ std::string CITASpectrum::GetName() const
return
m_sName
;
}
void
CITASpectrum
::
SetValueUnit
(
std
::
string
sUnit
)
{
m_sValueUnit
=
sUnit
;
}
std
::
string
CITASpectrum
::
GetValueUnit
()
const
{
return
m_sValueUnit
;
}
int
CITASpectrum
::
GetNumBands
()
const
{
return
int
(
m_vfCenterFrequencies
.
size
()
);
...
...
@@ -120,3 +130,20 @@ float& CITASpectrum::operator[]( int iFrequencyBandIndex )
float
&
rV
(
m_vfValues
[
iFrequencyBandIndex
]
);
return
rV
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
CITASpectrum
&
oSpectrum
)
{
std
::
string
sName
=
"Unnamed spectrum"
;
if
(
!
oSpectrum
.
GetName
().
empty
()
)
sName
=
oSpectrum
.
GetName
();
os
<<
"[ ITASpectrum ] '"
<<
sName
<<
"' spectrum with "
<<
oSpectrum
.
GetNumBands
()
<<
" bands."
<<
std
::
endl
;
for
(
int
n
=
0
;
n
<
oSpectrum
.
GetNumBands
();
n
++
)
{
if
(
n
>
0
)
os
<<
", "
;
os
<<
oSpectrum
.
GetCenterFrequencies
()[
n
]
<<
" Hz = "
<<
oSpectrum
[
n
]
<<
" "
<<
oSpectrum
.
GetValueUnit
();
}
return
os
;
}
\ No newline at end of file
tests/CMakeLists.txt
View file @
4510d825
...
...
@@ -8,28 +8,38 @@ include( VistaCommon )
vista_use_package
(
ITABase REQUIRED FIND_DEPENDENCIES
)
add_executable
(
SampleBufferTest SampleBufferTest.cpp
)
target_link_libraries
(
SampleBufferTest
${
VISTA_USE_PACKAGE_LIBRARIES
}
)
add_executable
(
ITABase
SampleBufferTest
ITABase
SampleBufferTest.cpp
)
target_link_libraries
(
ITABase
SampleBufferTest
${
VISTA_USE_PACKAGE_LIBRARIES
}
)
vista_configure_app
(
SampleBufferTest
)
vista_install
(
SampleBufferTest
)
vista_create_default_info_file
(
SampleBufferTest
)
vista_configure_app
(
ITABase
SampleBufferTest
)
vista_install
(
ITABase
SampleBufferTest
)
vista_create_default_info_file
(
ITABase
SampleBufferTest
)
set_property
(
TARGET SampleBufferTest PROPERTY FOLDER
"ITACoreLibs/Tests/ITABase"
)
set_property
(
TARGET
ITABase
SampleBufferTest PROPERTY FOLDER
"ITACoreLibs/Tests/ITABase"
)
if
(
ITA_BASE_WITH_SNDFILE
)
add_executable
(
SampleFrameTest SampleFrameTest.cpp
)
target_link_libraries
(
SampleFrameTest
${
VISTA_USE_PACKAGE_LIBRARIES
}
)
add_executable
(
ITABase
SampleFrameTest
ITABase
SampleFrameTest.cpp
)
target_link_libraries
(
ITABase
SampleFrameTest
${
VISTA_USE_PACKAGE_LIBRARIES
}
)
vista_configure_app
(
SampleFrameTest
)
vista_install
(
SampleFrameTest
)
vista_create_default_info_file
(
SampleFrameTest
)
vista_configure_app
(
ITABase
SampleFrameTest
)
vista_install
(
ITABase
SampleFrameTest
)
vista_create_default_info_file
(
ITABase
SampleFrameTest
)
set_property
(
TARGET SampleFrameTest PROPERTY FOLDER
"ITACoreLibs/Tests/ITABase"
)
set_property
(
TARGET
ITABase
SampleFrameTest PROPERTY FOLDER
"ITACoreLibs/Tests/ITABase"
)
endif
(
)
add_executable
(
ITABaseSpectrumTests ITABaseSpectrumTests.cpp
)
target_link_libraries
(
ITABaseSpectrumTests
${
VISTA_USE_PACKAGE_LIBRARIES
}
)
vista_configure_app
(
ITABaseSpectrumTests
)
vista_install
(
ITABaseSpectrumTests
)
vista_create_default_info_file
(
ITABaseSpectrumTests
)
set_property
(
TARGET ITABaseSpectrumTests PROPERTY FOLDER
"ITACoreLibs/Tests/ITABase"
)
add_subdirectory
(
"VistaTests"
)
tests/SampleBufferTest.cpp
→
tests/
ITABase
SampleBufferTest.cpp
View file @
4510d825
File moved
tests/SampleFrameTest.cpp
→
tests/
ITABase
SampleFrameTest.cpp
View file @
4510d825
File moved
tests/ITABaseSpectrumTests.cpp
0 → 100644
View file @
4510d825
#include
<ITASpectrum.h>
#include
<ITAMagnitudeSpectrum.h>
#include
<ITAThirdOctaveMagnitudeSpectrum.h>
#include
<ITANumericUtils.h>
#include
<stdio.h>
using
namespace
std
;
void
test_third_octave_spectrum
();
void
test_db_to_ration
();
void
test_ratio_to_db
();
int
main
(
int
,
char
**
)
{
test_third_octave_spectrum
();
cout
<<
"-----------"
<<
endl
;
test_db_to_ration
();
cout
<<
"-----------"
<<
endl
;
test_ratio_to_db
();
cout
<<
"-----------"
<<
endl
;
return
0
;
}
void
test_db_to_ration
()
{
CITAThirdOctaveMagnitudeSpectrum
oTOSpectrumConvertToRatio
;
oTOSpectrumConvertToRatio
.
SetName
(
"Test unit magnitude spectrum to ratio"
);
oTOSpectrumConvertToRatio
.
SetIdentity
();
for
(
int
n
=
0
;
n
<
oTOSpectrumConvertToRatio
.
GetNumBands
();
n
++
)
oTOSpectrumConvertToRatio
[
n
]
=
db10_to_ratio
(
oTOSpectrumConvertToRatio
[
n
]
);
oTOSpectrumConvertToRatio
.
SetValueUnit
(
"(gain)"
);
cout
<<
oTOSpectrumConvertToRatio
<<
endl
;
oTOSpectrumConvertToRatio
.
SetZero
();
for
(
int
n
=
0
;
n
<
oTOSpectrumConvertToRatio
.
GetNumBands
();
n
++
)
oTOSpectrumConvertToRatio
[
n
]
=
db10_to_ratio
(
oTOSpectrumConvertToRatio
[
n
]
);
oTOSpectrumConvertToRatio
.
SetValueUnit
(
"(gain)"
);
cout
<<
oTOSpectrumConvertToRatio
<<
endl
;
}
void
test_ratio_to_db
()
{
CITAThirdOctaveMagnitudeSpectrum
oTOSpectrumConvertToRatio
;
oTOSpectrumConvertToRatio
.
SetName
(
"Test unit gain spectrum to db"
);
oTOSpectrumConvertToRatio
.
SetValueUnit
(
"(gain)"
);
oTOSpectrumConvertToRatio
.
SetZero
();
for
(
int
n
=
0
;
n
<
oTOSpectrumConvertToRatio
.
GetNumBands
();
n
++
)
oTOSpectrumConvertToRatio
[
n
]
=
ratio_to_db10
(
oTOSpectrumConvertToRatio
[
n
]
);
oTOSpectrumConvertToRatio
.
SetValueUnit
(
"dB"
);
cout
<<
oTOSpectrumConvertToRatio
<<
endl
;
}
void
test_third_octave_spectrum
()
{
CITAThirdOctaveMagnitudeSpectrum
oTOSpectrumIdent
;
oTOSpectrumIdent
.
SetName
(
"Test unit magnitude spectrum"
);
oTOSpectrumIdent
.
SetIdentity
();
cout
<<
"Third octave magnitude spectrum identity:"
<<
endl
;
cout
<<
oTOSpectrumIdent
<<
endl
;
CITAThirdOctaveMagnitudeSpectrum
oTOSpectrumZero
;
oTOSpectrumZero
.
SetName
(
"Test unit zero spectrum"
);
oTOSpectrumZero
.
SetZero
();
cout
<<
"Third octave magnitude spectrum zero:"
<<
endl
;
cout
<<
oTOSpectrumZero
<<
endl
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment