Commit 0f3cbf27 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Style

parent 6c34e714
......@@ -2,14 +2,14 @@
*
* VVV VVV A
* VVV VVV AAA Virtual Acoustics
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA
* VVVVVV AAA (c) Copyright Institut fr Technische Akustik (ITA)
* VVVV AAA RWTH Aachen (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* Datei: VAThirdOctaveFilterbank.cpp
* Datei: VAThirdOctaveFilterbank.cpp
*
* Zweck: Terzfilterbanken mittels Biquads
*
......@@ -17,7 +17,7 @@
*
* ---------------------------------------------------------------------------------
*/
// $Id: VAThirdOctaveFilterbank.cpp 2729 2012-06-26 13:23:36Z fwefers $
#include "VAThirdOctaveFilterbankIIR.h"
......@@ -31,256 +31,136 @@
#include <cassert>
CVAThirdOctaveFilterbankIIR::CVAThirdOctaveFilterbankIIR(double dSamplerate, int iBlocklength)
: m_dSamplerate(dSamplerate),
m_iBlocklength(iBlocklength),
m_nBandsInternal(FB_NUM_BANDS),
m_nBiquadsPerBand(FB_NUM_BIQUADS_PER_BAND),
m_pfTempFilterBuf(nullptr),
m_pfTempOutputBuf(nullptr)
CVAThirdOctaveFilterbankIIR::CVAThirdOctaveFilterbankIIR( double dSamplerate, int iBlocklength )
: m_dSamplerate( dSamplerate ),
m_iBlocklength( iBlocklength ),
m_nBandsInternal( FB_NUM_BANDS ),
m_nBiquadsPerBand( FB_NUM_BIQUADS_PER_BAND ),
m_pfTempFilterBuf( nullptr ),
m_pfTempOutputBuf( nullptr )
{
if (dSamplerate != FB_SAMPLINGRATE)
VA_EXCEPT1("Filterbank does not support this samplingrate");
if( dSamplerate != FB_SAMPLINGRATE )
VA_EXCEPT1( "Filterbank does not support this samplingrate" );
// Initialize biquads
int nBiquads = m_nBandsInternal*m_nBiquadsPerBand;
m_vBiquads.resize(nBiquads);
for (int i=0; i<m_nBandsInternal; i++) {
for (int j=0; j<m_nBiquadsPerBand; j++) {
m_vBiquads[i*m_nBiquadsPerBand+j].SetParameters(FB_BIQUAD_PARAMS[i][j]);
m_vBiquads.resize( nBiquads );
for( int i = 0; i < m_nBandsInternal; i++ )
{
for( int j = 0; j < m_nBiquadsPerBand; j++ )
{
m_vBiquads[ i*m_nBiquadsPerBand + j ].oParams.SetParameters( FB_BIQUAD_PARAMS[ i ][ j ] );
}
}
m_pfTempFilterBuf = fm_falloc(m_iBlocklength, true );
m_pfTempFilterBuf = fm_falloc( m_iBlocklength, true );
m_pfTempOutputBuf = fm_falloc( m_iBlocklength, true );
}
CVAThirdOctaveFilterbankIIR::~CVAThirdOctaveFilterbankIIR() {
fm_free(m_pfTempFilterBuf);
fm_free(m_pfTempOutputBuf);
CVAThirdOctaveFilterbankIIR::~CVAThirdOctaveFilterbankIIR()
{
fm_free( m_pfTempFilterBuf );
fm_free( m_pfTempOutputBuf );
}
int CVAThirdOctaveFilterbankIIR::GetLatency() const {
int CVAThirdOctaveFilterbankIIR::GetLatency() const
{
return 0; // [stienen] sicher?
}
void CVAThirdOctaveFilterbankIIR::SetGains(const CVAThirdOctaveMagnitudes& oGains, bool bSmoothChangeover) {
void CVAThirdOctaveFilterbankIIR::SetGains( const CVAThirdOctaveMagnitudes& oGains, bool bSmoothChangeover )
{
GainUpdate oUpdate;
oUpdate.oGains = oGains;
oUpdate.iBlendSamples = (bSmoothChangeover ? 1 : 0);
m_qGains.push(oUpdate);
oUpdate.iBlendSamples = ( bSmoothChangeover ? 1 : 0 );
m_qGains.push( oUpdate );
}
void CVAThirdOctaveFilterbankIIR::Clear() {
for (int i=0; i<(int) m_vBiquads.size(); i++) m_vBiquads[i].Clear();
void CVAThirdOctaveFilterbankIIR::Clear()
{
for( int i = 0; i < ( int )
m_vBiquads.size(); i++ ) m_vBiquads[ i ].Clear();
}
void CVAThirdOctaveFilterbankIIR::Process(const float* pfInputSamples, float* pfOutputSamples) {
void CVAThirdOctaveFilterbankIIR::Process( const float* pfInputSamples, float* pfOutputSamples )
{
assert( pfInputSamples != nullptr );
assert( pfOutputSamples != nullptr );
// Fr Schleifen unten
assert( m_nBiquadsPerBand >= 2 );
// TODO: Fehler lsen. Warum kommt aus den hohen Bndern nix? Scheinen nicht stabil zu sein?!
const int iMaxBand = m_nBandsInternal-1;
const int iMaxBand = m_nBandsInternal - 1;
//const int iMaxBand = 10;
const int k = m_nBiquadsPerBand-1; // Index des letzten Biquads pro Band
//VA_DEBUG_PRINTF("Bands internal %d, biquads/band %d\n", iMaxBand, k);
if (m_nBandsInternal == 0) return; // [stienen] lieber assert? Filter ohne Bnder?
//float tmp;
//for (int n=0; n<m_iBlocklength; n++) {
// for (int i=0; i<iMaxBand; i++) {
// /*
// m_vBiquads[i][0].Filter1(pfInputSamples[i], tmp);
// // Biquads dazwischen: tmp => tmp
// for (int j=1; j<k; j++)
// m_vBiquads[i][k].Filter1(tmp, tmp);
// m_vBiquads[i][0].Filter1(tmp, pfOutputSamples[i]);
// */
// m_vBiquads[i][0].Filter1(pfInputSamples[i], tmp);
// m_vBiquads[i][1].Filter1(tmp, tmp);
// m_vBiquads[i][2].Filter1(tmp, tmp);
// m_vBiquads[i][3].Filter1(tmp, tmp);
// m_vBiquads[i][4].Filter1(tmp, pfOutputSamples[i]);
// }
//}
const int k = m_nBiquadsPerBand - 1; // Index des letzten Biquads pro Band
// No change in gains
//for (int i=0; i<iMaxBand; i++) {
// // Erster Biquad in der Sequenz: input => tmp
// //m_vBiquads[i][0].Filter(pfInputSamples,
// // m_pfTempFilterBuf,
// // m_iBlocklength);
// // Biquads dazwischen: tmp => tmp
// for (int j=1; j<k; j++)
// m_vBiquads[i][j].Filter(m_pfTempFilterBuf,
// m_pfTempFilterBuf,
// m_iBlocklength);
// // Letztes Biquad mit Gain: tmp => output
// m_vBiquads[i][k].Filter(m_pfTempFilterBuf,
// m_pfTempOutputBuf,
// m_iBlocklength,
// m_fGainsInternal[i],
// (i==0 ? CVABiquad::OUTPUT_OVERWRITE : CVABiquad::OUTPUT_ADD));
//}
//
//// Ausgabe bereitstellen
//memcpy(pfOutputSamples, m_pfTempOutputBuf, m_iBlocklength*sizeof(float));
if( m_nBandsInternal == 0 )
return; // [stienen] lieber assert? Filter ohne Bnder?
// Gains bernehmen
GainUpdate oUpdate;
bool bUpdateGains = false;
while (m_qGains.try_pop(oUpdate)) {
while( m_qGains.try_pop( oUpdate ) )
{
bUpdateGains = true;
}
//VA_DEBUG_PRINTF("Ptr = 0x%08Xh\n", pfInputSamples);
//ITAStopWatch sw1;
//sw1.start();
//fm_copy(m_pfTempFilterBuf, pfInputSamples, m_iBlocklength);
//double t = sw1.stop();
////VA_DEBUG_PRINTF("Copy = %0.3f ms\n", t*1000);
//ITAStopWatch sw2, sw3, sw4;
if( bUpdateGains )
{
bool bSwitchGains = ( oUpdate.iBlendSamples == 0 );
//for (int i=0; i<iMaxBand; i++) {
// sw2.start();
// // Erster Biquad in der Sequenz: input => tmp
// m_vBiquads[i][0].Filter(m_pfTempFilterBuf,
// m_pfTempFilterBuf,
// m_iBlocklength);
// double t2 = sw2.stop()*1000;
// sw3.start();
// //// Biquads dazwischen: tmp => tmp
// for (int j=1; j<k; j++)
// m_vBiquads[i][j].Filter(m_pfTempFilterBuf,
// m_pfTempFilterBuf,
// m_iBlocklength);
// double t3 = sw2.stop()*1000;
// sw4.start();
// //// Letztes Biquad mit Gain: tmp => output
// m_vBiquads[i][k].Filter(m_pfTempFilterBuf,
// m_pfTempOutputBuf,
// m_iBlocklength,
// oNewGains.fGains[i],
// (i==0 ? CVABiquad::OUTPUT_OVERWRITE : CVABiquad::OUTPUT_ADD));
// double t4 = sw4.stop()*1000;
// //VA_DEBUG_PRINTF("1 = %0.3f ms, 2 = %0.3f ms, 3 = %0.3f ms\n", t2, t3, t4);
//}
//ITAStopWatch sw1;
////sw1.start();
////fm_copy(m_pfTempFilterBuf, pfInputSamples, m_iBlocklength);
////double t = sw1.stop();
//////VA_DEBUG_PRINTF("Copy = %0.3f ms\n", t*1000);
////ITAStopWatch sw2, sw3, sw4;
//for (int i=0; i<iMaxBand; i++) {
// // Erster Biquad in der Sequenz: input => tmp
// m_vBiquads[i][0].Filter(pfInputSamples,
// m_pfTempFilterBuf,
// m_iBlocklength);
// //// Biquads dazwischen: tmp => tmp
// for (int j=1; j<k; j++)
// m_vBiquads[i][j].Filter(m_pfTempFilterBuf,
// m_pfTempFilterBuf,
// m_iBlocklength);
//
// //// Letztes Biquad mit Gain: tmp => output
// m_vBiquads[i][k].Filter(m_pfTempFilterBuf,
// m_pfTempOutputBuf,
// m_iBlocklength,
// oNewGains.fGains[i],
// (i==0 ? CVABiquad::OUTPUT_OVERWRITE : CVABiquad::OUTPUT_ADD));
//
//}
//memcpy(pfOutputSamples, m_pfTempOutputBuf, m_iBlocklength*sizeof(float));
//return;
if (bUpdateGains) {
bool bSwitchGains = (oUpdate.iBlendSamples == 0);
if (bSwitchGains) {
for (int i=0; i<iMaxBand; i++) {
if( bSwitchGains )
{
for( int i = 0; i < iMaxBand; i++ )
{
// Erster Biquad in der Sequenz: input => tmp
m_vBiquads[i*m_nBiquadsPerBand+0].Filter(pfInputSamples,
m_pfTempFilterBuf,
m_iBlocklength);
m_vBiquads[ i*m_nBiquadsPerBand + 0 ].Process( pfInputSamples, m_pfTempFilterBuf, m_iBlocklength );
// Biquads dazwischen: tmp => tmp
for (int j=1; j<k; j++)
m_vBiquads[i*m_nBiquadsPerBand+j].Filter(m_pfTempFilterBuf,
m_pfTempFilterBuf,
m_iBlocklength);
for( int j = 1; j < k; j++ )
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].Filter(m_pfTempFilterBuf,
m_pfTempOutputBuf,
m_iBlocklength,
oUpdate.oGains.fGains[i],
(i==0 ? CVABiquad::OUTPUT_OVERWRITE : CVABiquad::OUTPUT_ADD));
m_vBiquads[ i*m_nBiquadsPerBand + k ].Process( m_pfTempFilterBuf, m_pfTempOutputBuf, m_iBlocklength, oUpdate.oGains.fGains[ i ], ( i == 0 ? CITABiquad::OUTPUT_OVERWRITE : CITABiquad::OUTPUT_ADD ) );
}
} else {
}
else
{
// Smooth gain changeover
for (int i=0; i<iMaxBand; i++) {
for( int i = 0; i < iMaxBand; i++ )
{
// Erster Biquad in der Sequenz: input => tmp
m_vBiquads[i*m_nBiquadsPerBand+0].Filter(pfInputSamples,
m_pfTempFilterBuf,
m_iBlocklength);
m_vBiquads[ i*m_nBiquadsPerBand + 0 ].Process( pfInputSamples, m_pfTempFilterBuf, m_iBlocklength );
// Biquads dazwischen: tmp => tmp
for (int j=1; j<k; j++)
m_vBiquads[i*m_nBiquadsPerBand+j].Filter(m_pfTempFilterBuf,
m_pfTempFilterBuf,
m_iBlocklength);
for( int j = 1; j < k; j++ )
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].Filter(m_pfTempFilterBuf,
m_pfTempOutputBuf,
m_iBlocklength,
m_oGainsInternal.fGains[i],
oUpdate.oGains.fGains[i],
(i==0 ? CVABiquad::OUTPUT_OVERWRITE : CVABiquad::OUTPUT_ADD));
m_vBiquads[ i*m_nBiquadsPerBand + k ].Process( m_pfTempFilterBuf, m_pfTempOutputBuf, m_iBlocklength, m_oGainsInternal.fGains[ i ], oUpdate.oGains.fGains[ i ], ( i == 0 ? CITABiquad::OUTPUT_OVERWRITE : CITABiquad::OUTPUT_ADD ) );
}
}
m_oGainsInternal = oUpdate.oGains;
} else {
}
else
{
// No change in gains
for (int i=0; i<iMaxBand; i++) {
for( int i = 0; i < iMaxBand; i++ )
{
// Erster Biquad in der Sequenz: input => tmp
m_vBiquads[i*m_nBiquadsPerBand+0].Filter(pfInputSamples,
m_pfTempFilterBuf,
m_iBlocklength);
m_vBiquads[ i*m_nBiquadsPerBand + 0 ].Process( pfInputSamples, m_pfTempFilterBuf, m_iBlocklength );
// Biquads dazwischen: tmp => tmp
for (int j=1; j<k; j++)
m_vBiquads[i*m_nBiquadsPerBand+j].Filter(m_pfTempFilterBuf,
m_pfTempFilterBuf,
m_iBlocklength);
for( int j = 1; j < k; j++ )
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].Filter(m_pfTempFilterBuf,
m_pfTempOutputBuf,
m_iBlocklength,
m_oGainsInternal.fGains[i],
(i==0 ? CVABiquad::OUTPUT_OVERWRITE : CVABiquad::OUTPUT_ADD));
m_vBiquads[ i*m_nBiquadsPerBand + k ].Process( m_pfTempFilterBuf, m_pfTempOutputBuf, m_iBlocklength, m_oGainsInternal.fGains[ i ], ( i == 0 ? CITABiquad::OUTPUT_OVERWRITE : CITABiquad::OUTPUT_ADD ) );
}
}
// Ausgabe bereitstellen
memcpy(pfOutputSamples, m_pfTempOutputBuf, m_iBlocklength*sizeof(float));
memcpy( pfOutputSamples, m_pfTempOutputBuf, m_iBlocklength*sizeof( float ) );
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment