Skip to content
GitLab
Menu
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
c74d9f0c
Commit
c74d9f0c
authored
May 08, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Adding spectrum header and source files
parent
fe6d1cb5
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/ITAMagnitudeSpectrum.h
0 → 100644
View file @
c74d9f0c
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_MAGNITUDE_SPECTRUM
#define INCLUDE_WATCHER_ITA_MAGNITUDE_SPECTRUM
#include
<ITABaseDefinitions.h>
#include
<ITASpectrum.h>
//! Magnitude spectrum of arbitrary size and base frequencies
/**
* Class for magnitude spectra, that is intended to be used with decibel values (magnitudes).
*
* Will raise CITAException on errors.
*
* @sa CITAAmplitudeSpectrum, CITAPhaseSpectrum, CITAHDFTSpectrum
*
*/
class
ITA_BASE_API
CITAMagnitudeSpectrum
:
public
CITASpectrum
{
public:
CITAMagnitudeSpectrum
(
const
int
nNumBands
);
virtual
inline
~
CITAMagnitudeSpectrum
()
{};
std
::
vector
<
float
>
GetMagnitudesCopy
()
const
;
const
std
::
vector
<
float
>&
GetMagnitudes
()
const
;
const
std
::
vector
<
float
>&
GetFrequencies
()
const
;
void
SetMagnitudes
(
const
std
::
vector
<
float
>&
vfMagnitudes
);
void
SetMagnitude
(
const
int
iFrequencyBandIndex
,
const
float
fMagnitudeValue
);
void
SetIdentity
();
void
SetZero
();
bool
IsIdentity
()
const
;
bool
IsZero
()
const
;
bool
CompareEqual
(
const
CITAMagnitudeSpectrum
&
oOtherSpectrum
,
const
float
fThreshold
=
10.0e-10
)
const
;
};
#endif // INCLUDE_WATCHER_ITA_MAGNITUDE_SPECTRUM
include/ITASpectrum.h
0 → 100644
View file @
c74d9f0c
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_SPECTRUM
#define INCLUDE_WATCHER_ITA_SPECTRUM
#include
<ITABaseDefinitions.h>
#include
<string>
#include
<vector>
//! Partly abstract scalar spectrum of arbitrary size and base frequencies
/**
* Class for scalar spectra, intended to be used as a base class for decibel values (magnitudes) or
* amplitude values (gains) or phase values (radiants, degrees) or group delays etc.
*
* Will raise CITAException on errors, also in constructor.
*
* @sa CITAHDFTSpectrum for complex-valued spectrum
*
*/
class
ITA_BASE_API
CITASpectrum
{
public:
CITASpectrum
(
const
int
nNumBands
);
virtual
inline
~
CITASpectrum
()
{};
void
SetName
(
const
std
::
string
&
sVolatileName
);
std
::
string
GetName
()
const
;
int
GetNumBands
()
const
;
const
std
::
vector
<
float
>&
GetCenterFrequencies
()
const
;
void
SetCenterFrequencies
(
const
std
::
vector
<
float
>&
vfCenterFrequencies
);
void
SetValues
(
const
std
::
vector
<
float
>&
vfValues
);
void
SetValue
(
const
int
iFrequencyBandIndex
,
const
float
fValue
);
virtual
void
SetIdentity
()
=
0
;
virtual
void
SetZero
()
=
0
;
virtual
bool
IsIdentity
()
const
=
0
;
virtual
bool
IsZero
()
const
=
0
;
//! Get a copy of the values (slow, do not use for read access)
std
::
vector
<
float
>
GetValuesCopy
()
const
;
void
Multiply
(
const
float
fFactor
);
void
Add
(
const
float
fSummand
);
//! Compare equality of values (ignores center frequencies, but requires matching number of bands)
virtual
bool
CompareEqualValues
(
const
CITASpectrum
&
oOtherSpectrum
,
const
float
fThreshold
=
10.0e-10
)
const
=
0
;
//! Index operator for const values
const
float
&
operator
[](
int
iFrequencyBandIndex
)
const
;
//! 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
};
#endif // INCLUDE_WATCHER_ITA_SPECTRUM
include/ITAThirdOctaveMagnitudeSpectrum.h
0 → 100644
View file @
c74d9f0c
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
#define INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
#include
<ITABaseDefinitions.h>
#include
<ITAMagnitudeSpectrum.h>
//! Third octave Magnitude spectrum
/**
* Class for third octave magnitude spectra with predefined center frequencies.
*
* Will raise CITAException on errors.
*
* @sa CITAWholeOctaveMagnitudeSpectrum
*/
class
ITA_BASE_API
CITAThirdOctaveMagnitudeSpectrum
:
public
CITAMagnitudeSpectrum
{
public:
inline
CITAThirdOctaveMagnitudeSpectrum
()
:
CITAMagnitudeSpectrum
(
31
)
{
m_vfCenterFrequencies
=
{
20
,
25
,
31.5
f
,
40
,
50
,
63
,
80
,
100
,
125
,
160
,
200
,
250
,
315
,
400
,
500
,
630
,
800
,
1000
,
1250
,
1600
,
2000
,
2500
,
3150
,
4000
,
5000
,
6300
,
8000
,
10000
,
12500
,
16000
,
20000
};
};
virtual
inline
~
CITAThirdOctaveMagnitudeSpectrum
()
{};
protected:
void
SetCenterFrequencies
(
const
std
::
vector
<
float
>&
vfCenterFrequencies
);
};
#endif // INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
include/ITAWholeOctaveMagnitudeSpectrum.h
0 → 100644
View file @
c74d9f0c
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
#define INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
#include
<ITABaseDefinitions.h>
#include
<ITAMagnitudeSpectrum.h>
//! Third octave Magnitude spectrum
/**
* Class for third octave magnitude spectra with predefined center frequencies.
*
* Will raise CITAException on errors.
*
* @sa
*
*/
class
ITA_BASE_API
CITAThirdOctaveMagnitudeSpectrum
:
public
CITAMagnitudeSpectrum
{
public:
inline
CITAThirdOctaveMagnitudeSpectrum
()
:
CITAMagnitudeSpectrum
(
10
)
{
m_vfCenterFrequencies
=
{
31.5
f
,
63
,
125
,
250
,
500
,
1000
,
2000
,
4000
,
8000
,
16000
};
};
virtual
inline
~
CITAThirdOctaveMagnitudeSpectrum
()
{};
protected:
void
SetCenterFrequencies
(
const
std
::
vector
<
float
>&
vfCenterFrequencies
);
};
#endif // INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
src/ITAMagnitudeSpectrum.cpp
0 → 100644
View file @
c74d9f0c
#
include
<
ITAMagnitudeSpectrum
.
h
>
#include
<ITAConstants.h>
#include
<numeric>
CITAMagnitudeSpectrum
::
CITAMagnitudeSpectrum
(
const
int
nNumBands
)
:
CITASpectrum
(
nNumBands
)
{
}
void
CITAMagnitudeSpectrum
::
SetIdentity
()
{
std
::
fill
(
m_vfValues
.
begin
(),
m_vfValues
.
end
(),
0.0
f
);
}
void
CITAMagnitudeSpectrum
::
SetZero
()
{
std
::
fill
(
m_vfValues
.
begin
(),
m_vfValues
.
end
(),
-
std
::
numeric_limits
<
float
>::
infinity
()
);
}
bool
CITAMagnitudeSpectrum
::
IsIdentity
()
const
{
for
(
size_t
n
=
0
;
n
<
m_vfValues
.
size
();
n
++
)
{
if
(
m_vfValues
[
n
]
!=
0.0
f
)
return
false
;
}
return
true
;
}
bool
CITAMagnitudeSpectrum
::
IsZero
()
const
{
for
(
size_t
n
=
0
;
n
<
m_vfValues
.
size
();
n
++
)
{
if
(
m_vfValues
[
n
]
!=
-
std
::
numeric_limits
<
float
>::
infinity
()
)
return
false
;
}
return
true
;
}
src/ITASpectrum.cpp
0 → 100644
View file @
c74d9f0c
#
include
<
ITASpectrum
.
h
>
#include
<ITAException.h>
CITASpectrum
::
CITASpectrum
(
const
int
nNumBands
)
{
if
(
nNumBands
<=
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Spectrum has to have at least one band"
);
m_vfCenterFrequencies
.
resize
(
nNumBands
);
m_vfValues
.
resize
(
nNumBands
);
}
void
CITASpectrum
::
SetName
(
const
std
::
string
&
sVolatileName
)
{
m_sName
=
sVolatileName
;
}
std
::
string
CITASpectrum
::
GetName
()
const
{
return
m_sName
;
}
int
CITASpectrum
::
GetNumBands
()
const
{
return
int
(
m_vfCenterFrequencies
.
size
()
);
}
const
std
::
vector
<
float
>&
CITASpectrum
::
GetCenterFrequencies
()
const
{
return
m_vfCenterFrequencies
;
}
void
CITASpectrum
::
SetCenterFrequencies
(
const
std
::
vector
<
float
>&
vfCenterFrequencies
)
{
if
(
vfCenterFrequencies
.
size
()
!=
m_vfCenterFrequencies
.
size
()
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Number of bands mismatching, can not set center frequencies"
);
std
::
copy
(
vfCenterFrequencies
.
begin
(),
vfCenterFrequencies
.
end
(),
m_vfCenterFrequencies
.
begin
()
);
}
void
CITASpectrum
::
SetValues
(
const
std
::
vector
<
float
>&
vfValues
)
{
if
(
vfValues
.
size
()
!=
m_vfValues
.
size
()
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Number of values mismatching, can not set center frequencies"
);
std
::
copy
(
vfValues
.
begin
(),
vfValues
.
end
(),
m_vfValues
.
begin
()
);
}
void
CITASpectrum
::
SetValue
(
const
int
iFrequencyBandIndex
,
const
float
fValue
)
{
if
(
iFrequencyBandIndex
>=
GetNumBands
()
||
iFrequencyBandIndex
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Frequency band index out of range"
);
m_vfValues
[
iFrequencyBandIndex
]
=
fValue
;
}
std
::
vector
<
float
>
CITASpectrum
::
GetValuesCopy
()
const
{
return
m_vfValues
;
}
void
CITASpectrum
::
Multiply
(
const
float
fFactor
)
{
for
(
size_t
n
=
0
;
n
<
m_vfValues
.
size
();
n
++
)
m_vfValues
[
n
]
*=
fFactor
;
}
void
CITASpectrum
::
Add
(
const
float
fSummand
)
{
for
(
size_t
n
=
0
;
n
<
m_vfValues
.
size
();
n
++
)
m_vfValues
[
n
]
+=
fSummand
;
}
bool
CITASpectrum
::
CompareEqualValues
(
const
CITASpectrum
&
oOtherSpectrum
,
const
float
fThreshold
/*= 10.0e-10 */
)
const
{
if
(
GetNumBands
()
!=
oOtherSpectrum
.
GetNumBands
()
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Number of bands mismatching, can not compare"
);
for
(
size_t
n
=
0
;
n
<
m_vfValues
.
size
();
n
++
)
{
if
(
std
::
fabs
(
oOtherSpectrum
[
int
(
n
)
]
-
m_vfValues
[
n
]
)
>
fThreshold
)
return
false
;
}
return
true
;
}
const
float
&
CITASpectrum
::
operator
[](
int
iFrequencyBandIndex
)
const
{
if
(
iFrequencyBandIndex
>=
GetNumBands
()
||
iFrequencyBandIndex
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Frequency band index out of range"
);
const
float
&
rV
(
m_vfValues
[
iFrequencyBandIndex
]
);
return
rV
;
}
float
&
CITASpectrum
::
operator
[](
int
iFrequencyBandIndex
)
{
if
(
iFrequencyBandIndex
>=
GetNumBands
()
||
iFrequencyBandIndex
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Frequency band index out of range"
);
float
&
rV
(
m_vfValues
[
iFrequencyBandIndex
]
);
return
rV
;
}
Write
Preview
Supports
Markdown
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