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)
ITADSP
Commits
7272e777
Commit
7272e777
authored
Jun 02, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Re-implementing gain setter for filter banks
parent
6d38d1b7
Changes
8
Hide whitespace changes
Inline
Side-by-side
include/ITAThirdOctaveFilterbank.h
View file @
7272e777
...
...
@@ -63,7 +63,8 @@ public:
virtual
inline
void
SetIdentity
(
const
bool
bSmoothChangeover
=
true
)
{
CITAThirdOctaveMagnitudeSpectrum
oIdentity
;
SetGains
(
oIdentity
,
bSmoothChangeover
);
oIdentity
.
SetIdentity
();
SetMagnitudes
(
oIdentity
,
bSmoothChangeover
);
};
//! Verstärkungsfaktoren setzen
...
...
@@ -71,7 +72,7 @@ public:
* \param oGains Neue Verstärkungsfaktoren
* \param bSmoothChangeover Überbenden (default, true) oder direktes Umschalten (false)
*/
virtual
void
Set
Gain
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
oGains
,
const
bool
bSmoothChangeover
=
true
)
=
0
;
virtual
void
Set
Magnitude
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
oGains
,
const
bool
bSmoothChangeover
=
true
)
=
0
;
//! Latenz (Verzögerung) der Filterbank zurückgeben
/**
...
...
include/ITAThirdOctaveFilterbankFIR.h
View file @
7272e777
...
...
@@ -70,7 +70,7 @@ public:
pFilter
->
Release
();
// Auto-release
}
inline
virtual
void
Set
Gain
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
oGains
,
const
bool
bSmoothChangeover
=
true
)
inline
virtual
void
Set
Magnitude
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
oGains
,
const
bool
bSmoothChangeover
=
true
)
{
m_pGenerator
->
GenerateFilter
(
oGains
,
m_pfFilter
);
ITAUPFilter
*
pFilter
=
m_pConvolver
->
RequestFilter
();
...
...
include/ITAThirdOctaveFilterbankIIR.h
View file @
7272e777
...
...
@@ -21,6 +21,7 @@
#include <ITADSPDefinitions.h>
#include <ITAThirdOctaveFilterbank.h>
#include <ITAAmplitudeSpectrum.h>
#include <ITABiquad.h>
#include <vector>
...
...
@@ -53,7 +54,7 @@ public:
* \param oGains Verstärkungsfaktoren
* \param bSmoothChangeover Wenn true, dann überblenden (default), sonst sofort internen Gain umschalten
*/
void
Set
Gain
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
oGains
,
const
bool
bSmoothChangeover
=
true
);
void
Set
Magnitude
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
oGains
,
const
bool
bSmoothChangeover
=
true
);
//! Alle internen Zustände zurücksetzen (Akkumulatoren der Biquads)
void
Clear
();
...
...
@@ -70,7 +71,7 @@ private:
class
GainUpdate
{
public:
CITAThirdOctaveMagnitudeSpectrum
o
Gain
s
;
//!
< Gain-Daten
CITAThirdOctaveMagnitudeSpectrum
o
Mag
s
;
//!
New magnitudes
int
iBlendSamples
;
//!< Anzahl Samples zum Überblenden
};
...
...
@@ -79,7 +80,7 @@ private:
int
m_nBandsInternal
;
//!< Anzahl der internen Bänder
int
m_nBiquadsPerBand
;
//!< Anzahl von Biqads pro Band
std
::
vector
<
CITABiquad
>
m_vBiquads
;
//!< Biquads, Zugriff: [Band][BiquadNummer]
tbb
::
strict_ppl
::
concurrent_queue
<
GainUpdate
>
m_qGains
;
//!< Liste von neuen Verstärkungsfaktoren
tbb
::
strict_ppl
::
concurrent_queue
<
CITAThirdOctaveFilterbankIIR
::
GainUpdate
>
m_qGains
;
//!< Liste von neuen Verstärkungsfaktoren
CITAThirdOctaveMagnitudeSpectrum
m_oGainsInternal
;
//!< Interne Verstärkungsfaktoren
float
*
m_pfTempFilterBuf
;
//!< Zwischenpuffer für Filter
float
*
m_pfTempOutputBuf
;
//!< Zwischenpuffer für Ausgabe
...
...
src/ITABiquad.cpp
View file @
7272e777
...
...
@@ -39,7 +39,7 @@ void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const i
return
;
}
void
CITABiquad
::
Process
(
const
float
*
pfInputData
,
float
*
out
,
int
nsamples
,
float
outputGain
,
int
outputMode
)
void
CITABiquad
::
Process
(
const
float
*
pfInputData
,
float
*
out
,
const
int
nsamples
,
const
float
outputGain
,
const
int
outputMode
)
{
// Lokale Akkumulatoren
float
z0
,
z1
,
z2
;
...
...
@@ -80,7 +80,7 @@ void CITABiquad::Process( const float* pfInputData, float* out, int nsamples, fl
return
;
}
void
CITABiquad
::
Process
(
const
float
*
pfInputData
,
float
*
out
,
int
nsamples
,
float
outputGain1
,
float
outputGain2
,
int
outputMode
)
void
CITABiquad
::
Process
(
const
float
*
pfInputData
,
float
*
out
,
const
int
nsamples
,
const
float
outputGain1
,
const
float
outputGain2
,
const
int
outputMode
)
{
if
(
nsamples
==
0
)
return
;
...
...
src/ITAThirdOctaveFIRFilterGenerator.cpp
View file @
7272e777
...
...
@@ -41,7 +41,7 @@ CITAThirdOctaveFIRFilterGenerator::CITAThirdOctaveFIRFilterGenerator( const doub
float
c
=
2
*
ITAConstants
::
PI_F
/
(
float
)
(
m_iFilterLength
-
1
);
for
(
int
i
=
0
;
i
<
m_iFilterLength
;
i
++
)
{
m_pfWindow
[
i
]
=
0.5
F
*
(
1
-
cos
(
c
*
i
)
);
m_pfWindow
[
i
]
=
0.5
F
*
(
1
-
cos
(
c
*
i
)
);
}
m_ifft
.
plan
(
ITAFFT
::
IFFT_C2R
,
iFilterLength
,
m_pfBuf1
,
m_pfBuf2
);
...
...
src/ITAThirdOctaveFilterbankIIR.cpp
View file @
7272e777
...
...
@@ -5,6 +5,7 @@
#include <ITAFastMath.h>
#include <ITAStopWatch.h>
#include <ITAException.h>
#include <ITANumericUtils.h>
#include <cassert>
...
...
@@ -45,10 +46,10 @@ int CITAThirdOctaveFilterbankIIR::GetLatency() const
return
0
;
// [stienen] sicher?
}
void
CITAThirdOctaveFilterbankIIR
::
Set
Gain
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
o
Gain
s
,
bool
bSmoothChangeover
)
void
CITAThirdOctaveFilterbankIIR
::
Set
Magnitude
s
(
const
CITAThirdOctaveMagnitudeSpectrum
&
o
Magnitude
s
,
bool
bSmoothChangeover
)
{
GainUpdate
oUpdate
;
oUpdate
.
o
Gain
s
=
o
Gain
s
;
CITAThirdOctaveFilterbankIIR
::
GainUpdate
oUpdate
;
oUpdate
.
o
Mag
s
=
o
Magnitude
s
;
oUpdate
.
iBlendSamples
=
(
bSmoothChangeover
?
1
:
0
);
m_qGains
.
push
(
oUpdate
);
}
...
...
@@ -76,12 +77,10 @@ void CITAThirdOctaveFilterbankIIR::Process( const float* pfInputSamples, float*
return
;
// [stienen] lieber assert? Filter ohne Bnder?
// Gains bernehmen
GainUpdate
oUpdate
;
CITAThirdOctaveFilterbankIIR
::
GainUpdate
oUpdate
;
bool
bUpdateGains
=
false
;
while
(
m_qGains
.
try_pop
(
oUpdate
)
)
{
bUpdateGains
=
true
;
}
if
(
bUpdateGains
)
{
...
...
@@ -99,7 +98,8 @@ void CITAThirdOctaveFilterbankIIR::Process( const float* pfInputSamples, float*
m_vBiquads
[
i
*
m_nBiquadsPerBand
+
j
].
Process
(
m_pfTempFilterBuf
,
m_pfTempFilterBuf
,
m_iBlockLength
);
// Letztes Biquad mit Gain: tmp => output
m_vBiquads
[
i
*
m_nBiquadsPerBand
+
k
].
Process
(
m_pfTempFilterBuf
,
m_pfTempOutputBuf
,
m_iBlockLength
,
oUpdate
.
oGains
[
i
],
(
i
==
0
?
CITABiquad
::
OUTPUT_OVERWRITE
:
CITABiquad
::
OUTPUT_ADD
)
);
const
float
fGain
=
float
(
db10_to_ratio
(
oUpdate
.
oMags
[
i
]
)
);
m_vBiquads
[
i
*
m_nBiquadsPerBand
+
k
].
Process
(
m_pfTempFilterBuf
,
m_pfTempOutputBuf
,
m_iBlockLength
,
fGain
,
(
i
==
0
?
CITABiquad
::
OUTPUT_OVERWRITE
:
CITABiquad
::
OUTPUT_ADD
)
);
}
}
else
...
...
@@ -115,11 +115,13 @@ void CITAThirdOctaveFilterbankIIR::Process( const float* pfInputSamples, float*
m_vBiquads
[
i
*
m_nBiquadsPerBand
+
j
].
Process
(
m_pfTempFilterBuf
,
m_pfTempFilterBuf
,
m_iBlockLength
);
// Letztes Biquad mit Gain: tmp => output
m_vBiquads
[
i
*
m_nBiquadsPerBand
+
k
].
Process
(
m_pfTempFilterBuf
,
m_pfTempOutputBuf
,
m_iBlockLength
,
m_oGainsInternal
[
i
],
oUpdate
.
oGains
[
i
],
(
i
==
0
?
CITABiquad
::
OUTPUT_OVERWRITE
:
CITABiquad
::
OUTPUT_ADD
)
);
const
float
fGain1
=
m_oGainsInternal
[
i
];
const
float
fGain2
=
float
(
db10_to_ratio
(
oUpdate
.
oMags
[
i
]
)
);
m_vBiquads
[
i
*
m_nBiquadsPerBand
+
k
].
Process
(
m_pfTempFilterBuf
,
m_pfTempOutputBuf
,
m_iBlockLength
,
fGain1
,
fGain2
,
(
i
==
0
?
CITABiquad
::
OUTPUT_OVERWRITE
:
CITABiquad
::
OUTPUT_ADD
)
);
}
}
m_oGainsInternal
=
oUpdate
.
o
Gain
s
;
m_oGainsInternal
=
oUpdate
.
o
Mag
s
;
}
else
{
...
...
tests/ITADSPThirdOctaveFilterGeneratorTest.cpp
View file @
7272e777
...
...
@@ -12,7 +12,8 @@
using
namespace
std
;
const
double
g_dSampleRate
=
44100
;
const
int
g_iFilterLength
=
int
(
ceil
(
g_dSampleRate
/
CITAThirdOctaveMagnitudeSpectrum
::
GetCenterFrequencies
()[
0
]
)
);
//const int g_iFilterLength = int( ceil( g_dSampleRate / CITAThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
const
int
g_iFilterLength
=
int
(
10
*
ceil
(
g_dSampleRate
/
CITAThirdOctaveMagnitudeSpectrum
::
GetCenterFrequencies
()[
0
]
)
);
void
TestThirdOctaveFilterGeneratorFIRIdentity
();
void
TestThirdOctaveFilterGeneratorFIRZero
();
...
...
tests/ITADSPThirdOctaveFilterbankTest.cpp
View file @
7272e777
...
...
@@ -31,7 +31,7 @@ void TestThirdOctaveFilterbankIIR()
CITAThirdOctaveMagnitudeSpectrum
oMags
;
oMags
.
SetIdentity
();
pIIRFilterbank
->
Set
Gain
s
(
oMags
);
pIIRFilterbank
->
Set
Magnitude
s
(
oMags
);
ITASampleBuffer
y
(
iSampleLength
);
...
...
@@ -42,14 +42,14 @@ void TestThirdOctaveFilterbankIIR()
cout
<<
"Runtime identity magnitudes:"
<<
sw
.
ToString
()
<<
endl
;
y
.
Normalize
();
writeAudiofile
(
"
bankout_zeros_iir
.wav"
,
&
y
,
g_dSampleRate
);
writeAudiofile
(
"
ITADSPThirdOctaveFilterbankTest_IIR_Identity
.wav"
,
&
y
,
g_dSampleRate
);
y
.
Zero
();
delete
pIIRFilterbank
;
pIIRFilterbank
=
CITAThirdOctaveFilterbank
::
Create
(
g_dSampleRate
,
iSampleLength
,
CITAThirdOctaveFilterbank
::
IIR_BIQUADS_ORDER10
);
oMags
.
SetZero
();
pIIRFilterbank
->
Set
Gain
s
(
oMags
);
pIIRFilterbank
->
Set
Magnitude
s
(
oMags
);
sw
.
start
();
pIIRFilterbank
->
Process
(
x
.
GetData
(),
y
.
GetData
()
);
...
...
@@ -57,19 +57,20 @@ void TestThirdOctaveFilterbankIIR()
cout
<<
"Runtime zero magnitude:"
<<
sw
.
ToString
()
<<
endl
;
y
.
Normalize
();
writeAudiofile
(
"
bankout_identity_iir
.wav"
,
&
y
,
g_dSampleRate
);
writeAudiofile
(
"
ITADSPThirdOctaveFilterbankTest_IIR_Zeros
.wav"
,
&
y
,
g_dSampleRate
);
delete
pIIRFilterbank
;
pIIRFilterbank
=
CITAThirdOctaveFilterbank
::
Create
(
g_dSampleRate
,
iSampleLength
,
CITAThirdOctaveFilterbank
::
IIR_BIQUADS_ORDER10
);
oMags
[
10
]
=
0.01
f
;
oMags
[
11
]
=
0.001
f
;
oMags
[
12
]
=
0.050
f
;
oMags
[
13
]
=
0.30
f
;
oMags
[
14
]
=
0.80
f
;
oMags
[
3
]
=
2.0
f
;
// dB values
oMags
[
3
]
=
3.0
f
;
oMags
[
10
]
=
-
3.0
f
;
oMags
[
11
]
=
-
6.0
f
;
oMags
[
12
]
=
-
9.0
f
;
oMags
[
13
]
=
-
9.0
f
;
oMags
[
14
]
=
-
7.0
f
;
pIIRFilterbank
->
Set
Gain
s
(
oMags
);
pIIRFilterbank
->
Set
Magnitude
s
(
oMags
);
sw
.
start
();
pIIRFilterbank
->
Process
(
x
.
GetData
(),
y
.
GetData
()
);
...
...
@@ -77,7 +78,7 @@ void TestThirdOctaveFilterbankIIR()
cout
<<
"Runtime real magnitudes:"
<<
sw
.
ToString
()
<<
endl
;
y
.
Normalize
();
writeAudiofile
(
"
bankout_realmags_iir
.wav"
,
&
y
,
g_dSampleRate
);
writeAudiofile
(
"
ITADSPThirdOctaveFilterbankTest_IIR_SomeBands
.wav"
,
&
y
,
g_dSampleRate
);
delete
pIIRFilterbank
;
}
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