Adding new class 'ITAStreamDetector' gathereing statistics over peak

and/or RMS in a stream
parent c21d20e9
......@@ -53,8 +53,7 @@ set( ITADataSourcesHeader
"include/ITADataSourcesDefinitions.h"
"include/ITAFileDataSink.h"
"include/ITAFileDataSource.h"
"include/ITAPeakDetector.h"
"include/ITARMSDetector.h"
"include/ITAStreamDetector.h"
"include/ITAStreamAmplifier.h"
"include/ITAStreamFunctionGenerator.h"
"include/ITAStreamModalSynthesizer.h"
......@@ -72,8 +71,7 @@ set( ITADataSourcesSources
"src/ITADataSourceRealization.cpp"
"src/ITAFileDataSink.cpp"
"src/ITAFileDataSource.cpp"
"src/ITAPeakDetector.cpp"
"src/ITARMSDetector.cpp"
"src/ITAStreamDetector.cpp"
"src/ITAStreamAmplifier.cpp"
"src/ITAStreamFunctionGenerator.cpp"
"src/ITAStreamModalSynthesizer.cpp"
......
......@@ -23,13 +23,15 @@
#include <ITACriticalSection.h>
#include <ITADataSource.h>
#include <atomic>
#include <vector>
//! Detektor for peak values in audio stream (i.e. for level metering)
//! Detektor for statistic values in audio stream (i.e. for level metering)
/**
* Die Klasse ITAPeakDetector wird zwischen eine Datenquelle und einen
* Die Klasse ITAStreamDetector wird zwischen eine Datenquelle und einen
* Konsumenten fr die Datenquelle geschaltet und detektiert dabei
* die Spitzenwerte (peak values) in den Audiostreams der Kanäle der
* die Spitzenwerte (peak values) und Mittelwerte (RMS) in den Audiostreams der Kanle der
* Datenquelle. Die Klasse bekommt im Konstruktor ihre Datenquelle gesetzt
* und stellt selber die Schnittstelle ITADatasource zur Verfgung.
* Aufrufe von GetBlockPointer und IncrementBlockPointer werden an die
......@@ -44,17 +46,27 @@
*
* \note Die Klasse ist Thread-safe
*/
class ITA_DATA_SOURCES_API ITAPeakDetector : public ITADatasource
class ITA_DATA_SOURCES_API ITAStreamDetector : public ITADatasource
{
public:
//! Mode of detection
enum Mode
{
DEACTIVATED = -1,
PEAK_AND_RMS,
PEAK,
RMS
};
//! Konstruktor
/**
* \note Es darf kein Nullzeiger bergeben werden.
*/
ITAPeakDetector( ITADatasource* pDatasource );
ITAStreamDetector( ITADatasource* pDatasource, int iMode = PEAK_AND_RMS );
//! Destruktor
virtual ~ITAPeakDetector();
virtual inline ~ITAStreamDetector() {};
//! Datenquelle zurckgeben
inline ITADatasource* GetDatasource() const
......@@ -65,6 +77,10 @@ public:
//! Messung zurcksetzen
void Reset();
void SetMode( const int iMode );
int GetMode() const;
//! Spitzenwert ber alle Kanle abrufen
/**
* Diese Methode dient zum Abrufen des Spitzenwertes ber alle
......@@ -74,7 +90,7 @@ public:
* so bleibt der bisherige Spitzenwert und der Kanal im dem er auftrat
* fr die weitere Analyse erhalten.
*/
void GetOverallPeak( float* pfPeak, unsigned int* puiChannel = 0, bool bReset = true );
float GetOverallPeak( int& iPeakChannelIndex, const bool bReset = true );
//! Spitzenwert ber alle Kanle in Dezibel zurckgeben
/**
......@@ -82,14 +98,14 @@ public:
* symbolische Konstante DECIBEL_MINUS_INFINITY zurck
* (siehe ITANumericUtils.h)
*/
void GetOverallPeakDecibel( double* pdPeakDecibel, unsigned int* puiChannel = 0, bool bReset = true );
double GetOverallPeakDecibel( int& iPeakChannelIndex, const bool bReset = true );
//! Spitzenwert eines Kanals zurckgeben
/**
* \note Wenn Sie die Spitzenwerte aller Kanle abrufen mchten,
* so empfiehlt sich die Methode GetChannelPeaks, da diese schneller ist.
*/
float GetPeak( unsigned int uiChannel, bool bReset = true );
float GetPeak( const int iChannel, const bool bReset = true );
//! Spitzenwert eines Kanals in Dezibel zurckgeben
/**
......@@ -99,17 +115,7 @@ public:
* \note Wenn Sie die Spitzenwerte aller Kanle abrufen mchten,
* so empfiehlt sich die Methode GetChannelPeaksDecibel, da diese schneller ist.
*/
double GetPeakDecibel( unsigned int uiChannel, bool bReset = true );
//! Spitzenwerte aller Kanäle abrufen
/**
* Diese Methode speichert die Spitzenwerte aller Kanäle im
* angegebenen Zielarray.
*
* \note Das Zielarray muß mindestens so viele Felder haben,
* wie die Datenquelle Kanäle hat
*/
void GetPeaks( float* pfDest, bool bReset = true );
double GetPeakDecibel( const int iChannel, bool bReset = true );
//! Spitzenwerte aller Kanle abrufen
/**
......@@ -119,18 +125,8 @@ public:
* \note Falls der Vektor weniger Felder als Kanle hat,
* so wird er automatisch vergrert.
*/
void GetPeaks( std::vector<float>& vfDest, bool bReset = true );
//! Spitzenwerte aller Kanäle in Dezibel abrufen
/**
* Diese Methode speichert die Spitzenwerte aller Kanäle
* in Dezibel im angegebenen Zielarray.
*
* \note Das Zielarray muß mindestens so viele Felder haben,
* wie die Datenquelle Kanäle hat
*/
void GetPeaksDecibel( double* pdDestDecibel, bool bReset = true );
void GetPeaks( std::vector< float >& vfDest, const bool bReset = true );
//! Spitzenwerte aller Kanle in Dezibel abrufen
/**
* Diese Methode speichert die Spitzenwerte aller Kanle
......@@ -139,19 +135,26 @@ public:
* \note Falls der Vektor weniger Felder als Kanle hat,
* so wird er automatisch vergrert.
*/
void GetPeaksDecibel( std::vector<double>& vdDestDecibel, bool bReset = true );
void GetPeaksDecibel( std::vector< double >& vdDestDecibel, const bool bReset = true );
float GetOverallRMS( const bool bReset = true );
double GetOverallRMSDecibel( const bool bReset = true );
float GetRMS( const int iChannel, const bool bReset = true );
double GetRMSDecibel( const int iChannel, const bool bReset = true );
void GetRMSs( std::vector< float >& vfDest, const bool bReset = true );
void GetRMSsDecibel( std::vector< float >& vfDestDecibel, const bool bReset = true );
inline unsigned int GetBlocklength() const
{
return m_uiBlocklength;
return m_iBlocklength;
};
inline unsigned int GetNumberOfChannels() const
{
return m_uiChannels;
return m_iChannels;
};
double GetSampleRate() const
inline double GetSampleRate() const
{
return m_dSamplerate;
};
......@@ -162,12 +165,15 @@ public:
protected:
ITADatasource* m_pDataSource; //!< Angeschlossene Datenquelle
double m_dSamplerate; //!< Abtastrate [Hz]
unsigned int m_uiChannels; //!< Anzahl Kanäle
unsigned int m_uiBlocklength; //!< Streaming Puffergröße [Samples]
int m_iChannels; //!< Anzahl Kanle
int m_iBlocklength; //!< Streaming Puffergre [Samples]
std::atomic< int > m_iMode;
ITACriticalSection m_cs; //!< Sichert exklusiven Zugriff auf die Daten (s.u.)
float* m_pfPeaks; //!< Spitzenwerte der einzelnen Kanäle
std::vector< float > m_vfPeaks; //!< Spitzenwerte der einzelnen Kanle
float m_fOverallPeak; //!< Spitzenwert ber alle Kanle
unsigned int m_uiOverallPeakChannel; //!< Kanal in dem der Spitzenwert auftrat
int m_iOverallPeakChannel; //!< Kanal in dem der Spitzenwert auftrat
std::vector< double > m_vdRMSSquaredSums;
int m_iRMSBlocks;
};
#endif // INCLUDE_WATCHER_ITA_PEAK_DETECTOR
......@@ -34,14 +34,15 @@ class ITAAudiofileWriter;
//! A measuring sensor for audio streams
/**
* Instanzen der Klasse ITAStreamProbe knnen als "Messspitze" in Audiostreams
* eingehngt werden. Sie schreiben dann alle vorbeigeflossenen Daten in eine Audiodatei.
* This class captures (records) the entire data stream passing through and stores
* the result into a file on the hard drive.
*/
class ITA_DATA_SOURCES_API ITAStreamProbe : public ITADatasource
{
public:
ITAStreamProbe( ITADatasource* pDatasource, const std::string& sFilename, ITAQuantization iQuantization = ITAQuantization::ITA_FLOAT );
ITAStreamProbe( ITADatasource* pDatasource, const std::string& sFilePath, ITAQuantization iQuantization = ITAQuantization::ITA_FLOAT );
//! Destructor also moves saples from memory to hard drive once.
virtual ~ITAStreamProbe();
inline ITADatasource* GetDatasource() const
......@@ -49,6 +50,7 @@ public:
return m_pDataSource;
}
//! Deprecated
inline std::string GetFilename() const
{
return GetFilePath();
......
#include "ITAPeakDetector.h"
#include <ITAException.h>
#include <ITANumericUtils.h>
#include <cmath>
ITAPeakDetector::ITAPeakDetector( ITADatasource* pDataSource )
: m_pDataSource( pDataSource )
{
m_dSamplerate = pDataSource->GetSampleRate();
m_uiChannels = pDataSource->GetNumberOfChannels();
m_uiBlocklength = pDataSource->GetBlocklength();
m_pfPeaks = 0;
// Unspezifizierte Parameter werden nicht erlaubt!
if ((m_uiBlocklength == 0) ||
(m_uiChannels == 0) ||
(m_dSamplerate == 0)) ITA_EXCEPT0(INVALID_PARAMETER);
// Analyse-Resourcen anlegen
m_pfPeaks = new float[m_uiChannels];
Reset();
}
ITAPeakDetector::~ITAPeakDetector() {
// Analyse-Resourcen freigeben
delete[] m_pfPeaks;
};
void ITAPeakDetector::Reset() {
m_cs.enter();
for (unsigned int c=0; c<m_uiChannels; c++) m_pfPeaks[c] = 0.00001f;
m_fOverallPeak = 0;
m_uiOverallPeakChannel = 0;
m_cs.leave();
}
void ITAPeakDetector::GetOverallPeak(float* pfPeak, unsigned int* puiChannel, bool bReset) {
m_cs.enter();
if (pfPeak) *pfPeak = m_fOverallPeak;
if (puiChannel) *puiChannel = m_uiOverallPeakChannel;
if (bReset) {
m_fOverallPeak = 0;
m_uiOverallPeakChannel = 0;
}
m_cs.leave();
}
void ITAPeakDetector::GetOverallPeakDecibel(double* pdPeakDecibel, unsigned int* puiChannel, bool bReset) {
m_cs.enter();
if (pdPeakDecibel) *pdPeakDecibel = ratio_to_db20(m_fOverallPeak);
if (puiChannel) *puiChannel = m_uiOverallPeakChannel;
if (bReset) {
m_fOverallPeak = 0;
m_uiOverallPeakChannel = 0;
}
m_cs.leave();
}
float ITAPeakDetector::GetPeak(unsigned int uiChannel, bool bReset) {
// Bereichsprfung des Kanalindex
if (uiChannel >= m_uiChannels) ITA_EXCEPT0(INVALID_PARAMETER);
m_cs.enter();
float fResult = m_pfPeaks[uiChannel];
if (bReset) m_pfPeaks[uiChannel] = 0;
m_cs.leave();
return fResult;
}
double ITAPeakDetector::GetPeakDecibel(unsigned int uiChannel, bool bReset) {
return ratio_to_db20(GetPeak(uiChannel));
}
void ITAPeakDetector::GetPeaks(float* pfDest, bool bReset) {
// Nullzeiger abfangen
if (!pfDest) ITA_EXCEPT0(INVALID_PARAMETER);
m_cs.enter();
for (unsigned int c=0; c<m_uiChannels; c++) {
pfDest[c] = m_pfPeaks[c];
if (bReset) m_pfPeaks[c] = 0;
}
m_cs.leave();
}
void ITAPeakDetector::GetPeaks(std::vector<float>& vfDest, bool bReset) {
// Vektor konditionieren
if (((unsigned int) vfDest.size()) < m_uiChannels) vfDest.resize(m_uiChannels);
m_cs.enter();
for (unsigned int c=0; c<m_uiChannels; c++) {
vfDest[c] = m_pfPeaks[c];
if (bReset) m_pfPeaks[c] = 0;
}
m_cs.leave();
}
void ITAPeakDetector::GetPeaksDecibel(double* pdDestDecibel, bool bReset) {
// Nullzeiger abfangen
if (!pdDestDecibel) ITA_EXCEPT0(INVALID_PARAMETER);
m_cs.enter();
for (unsigned int c=0; c<m_uiChannels; c++) {
pdDestDecibel[c] = ratio_to_db20(m_pfPeaks[c]);
if (bReset) m_pfPeaks[c] = 0;
}
m_cs.leave();
}
void ITAPeakDetector::GetPeaksDecibel(std::vector<double>& vdDestDecibel, bool bReset) {
// Vektor konditionieren
if (((unsigned int) vdDestDecibel.size()) < m_uiChannels) vdDestDecibel.resize(m_uiChannels);
m_cs.enter();
for (unsigned int c=0; c<m_uiChannels; c++) {
vdDestDecibel[c] = ratio_to_db20(m_pfPeaks[c]);
if (bReset) m_pfPeaks[c] = 0;
}
m_cs.leave();
}
const float* ITAPeakDetector::GetBlockPointer(unsigned int uiChannel, const ITAStreamInfo* pStreamInfo) {
// Datenzeiger seinerseits bei der angeschlossenen Datenquelle abrufen
const float* pfData = m_pDataSource->GetBlockPointer(uiChannel, pStreamInfo);
if (pfData) {
// TODO: Ist es wirklich ntig bei jedem GBP die CS zu betreten? :-(
m_cs.enter();
// Daten analysieren
for (unsigned int i=0; i<m_uiBlocklength; i++) {
float fAbs = std::abs(pfData[i]);
if (fAbs > m_pfPeaks[uiChannel]) m_pfPeaks[uiChannel] = fAbs;
if (fAbs > m_fOverallPeak) {
m_fOverallPeak = fAbs;
m_uiOverallPeakChannel = uiChannel;
}
}
m_cs.leave();
}
// Daten "weitergeben"
return pfData;
}
void ITAPeakDetector::IncrementBlockPointer() {
// Blockzeiger der angeschlossenen Datenquelle inkrementieren
m_pDataSource->IncrementBlockPointer();
}
#include "ITAStreamDetector.h"
#include <ITAConstants.h>
#include <ITAException.h>
#include <ITANumericUtils.h>
#include <cmath>
ITAStreamDetector::ITAStreamDetector( ITADatasource* pDataSource, const int iMode )
: m_pDataSource( pDataSource )
, m_iMode( iMode )
{
m_dSamplerate = pDataSource->GetSampleRate();
m_iChannels = int( pDataSource->GetNumberOfChannels() );
m_iBlocklength = int( pDataSource->GetBlocklength() );
// Unspezifizierte Parameter werden nicht erlaubt!
if( ( m_iBlocklength == 0 ) || ( m_iChannels == 0 ) || ( m_dSamplerate == 0 ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not create stream detector" );
m_vfPeaks.resize( m_iChannels, 0.0f );
m_vdRMSSquaredSums.resize( m_iChannels, 0.0f );
Reset();
}
void ITAStreamDetector::Reset()
{
m_cs.enter();
for( size_t c = 0; c < m_vfPeaks.size(); c++ )
{
m_vfPeaks[ c ] = 0.0f;
m_vdRMSSquaredSums[ c ] = 0.0f;
}
m_fOverallPeak = 0;
m_iOverallPeakChannel = 0;
m_iRMSBlocks = 0;
m_cs.leave();
}
int ITAStreamDetector::GetMode() const
{
return m_iMode;
}
void ITAStreamDetector::SetMode( const int iMode )
{
if( iMode < ITAStreamDetector::DEACTIVATED || iMode > ITAStreamDetector::RMS )
ITA_EXCEPT1( INVALID_PARAMETER, "Unkown mode for a stream detector" );
m_iMode = iMode;
}
float ITAStreamDetector::GetOverallPeak( int& iChannel, const bool bReset )
{
if( m_iMode != ITAStreamDetector::PEAK || m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
m_cs.enter();
iChannel = m_iOverallPeakChannel;
const float fOverallPeak = m_fOverallPeak;
if( bReset )
{
m_fOverallPeak = 0;
m_iOverallPeakChannel = 0;
}
m_cs.leave();
return fOverallPeak;
}
double ITAStreamDetector::GetOverallPeakDecibel( int& iChannel, const bool bReset )
{
if( m_iMode != ITAStreamDetector::PEAK && m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
m_cs.enter();
const double dOverallPeakDB = ratio_to_db20( m_fOverallPeak );
iChannel = m_iOverallPeakChannel;
if( bReset )
{
m_fOverallPeak = 0;
m_iOverallPeakChannel = 0;
}
m_cs.leave();
return dOverallPeakDB;
}
float ITAStreamDetector::GetPeak( const int iChannel, const bool bReset )
{
if( m_iMode != ITAStreamDetector::PEAK || m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
if( iChannel >= m_iChannels )
ITA_EXCEPT1( INVALID_PARAMETER, "Invalid channel number, can not get peak" );
m_cs.enter();
const float fResult = m_vfPeaks[ iChannel ];
if( bReset )
{
m_vfPeaks[ iChannel ] = 0.0f;
}
m_cs.leave();
return fResult;
}
double ITAStreamDetector::GetPeakDecibel( int iChannel, const bool bReset )
{
return ratio_to_db20( GetPeak( iChannel, bReset ) );
}
void ITAStreamDetector::GetPeaks( std::vector< float >& vfDest, const bool bReset )
{
if( m_iMode != ITAStreamDetector::PEAK || m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
m_cs.enter();
vfDest = m_vfPeaks;
if( bReset )
{
m_fOverallPeak = 0.0f;
for( size_t c = 0; c < m_iChannels; c++ )
m_vfPeaks[ c ] = 0.0f;
}
m_cs.leave();
}
void ITAStreamDetector::GetPeaksDecibel( std::vector< double >& vdDestDecibel, const bool bReset )
{
if( m_iMode != ITAStreamDetector::PEAK && m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
if( vdDestDecibel.size() != m_vfPeaks.size() )
vdDestDecibel.resize( m_vfPeaks.size() );
m_cs.enter();
for( size_t c = 0; c < m_vfPeaks.size(); c++ )
{
vdDestDecibel[ c ] = ratio_to_db20( m_vfPeaks[ c ] );
if( bReset )
m_vfPeaks[ c ] = 0.0f;
}
m_cs.leave();
}
float ITAStreamDetector::GetOverallRMS( const bool bReset )
{
if( m_iMode != ITAStreamDetector::RMS && m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
m_cs.enter();
if( m_iRMSBlocks == 0 )
return 0.0f;
double dOverallRMSSums = 0;
for( size_t i = 0; i < m_vdRMSSquaredSums.size(); i++ )
dOverallRMSSums += m_vdRMSSquaredSums[ i ] / double( m_iRMSBlocks * m_iBlocklength );
const float fOverallRMS = float( std::sqrt( dOverallRMSSums / double( m_iChannels ) ) ); // RMS over all channels
if( bReset )
{
m_iRMSBlocks = 0;
m_vdRMSSquaredSums.resize( m_iChannels, 0.0f );
}
m_cs.leave();
return fOverallRMS;
}
double ITAStreamDetector::GetOverallRMSDecibel( const bool bReset )
{
return ratio_to_db20( GetOverallRMS( bReset ) );
}
float ITAStreamDetector::GetRMS( const int iChannel, const bool bReset )
{
if( m_iMode != ITAStreamDetector::RMS && m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
if( iChannel >= m_iChannels )
ITA_EXCEPT1( INVALID_PARAMETER, "Invalid channel number, can not get peak" );
m_cs.enter();
const float fResult = std::sqrt( float( m_vdRMSSquaredSums[ iChannel ] / double( m_iRMSBlocks *m_iBlocklength ) ) );
if( bReset )
m_vdRMSSquaredSums[ iChannel ] = 0.0f;
m_cs.leave();
return fResult;
}
double ITAStreamDetector::GetRMSDecibel( int iChannel, const bool bReset )
{
return ratio_to_db20( GetRMS( iChannel, bReset ) );
}
void ITAStreamDetector::GetRMSs( std::vector< float >& vfDest, const bool bReset )
{
if( m_iMode != ITAStreamDetector::RMS && m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
m_cs.enter();
vfDest.resize( m_vdRMSSquaredSums.size(), 0.0f );
if( m_iRMSBlocks == 0 )
return;
for( size_t c = 0; c < m_vdRMSSquaredSums.size(); c++ )
vfDest[ c ] = float( std::sqrt( ( m_vdRMSSquaredSums[ c ] / double( m_iRMSBlocks ) ) ) ); // RMS
if( bReset )
m_vdRMSSquaredSums.resize( m_iChannels, 0.0f );
m_cs.leave();
}
void ITAStreamDetector::GetRMSsDecibel( std::vector< float >& vdDestDecibel, const bool bReset )
{
if( m_iMode != ITAStreamDetector::RMS && m_iMode != ITAStreamDetector::PEAK_AND_RMS )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not provide stream detector data because it is not calculated in this mode" );
vdDestDecibel.resize( m_vdRMSSquaredSums.size(), ITAConstants::MINUS_INFINITY_F );
if( m_iRMSBlocks == 0 )
return;
for( size_t c = 0; c < m_vdRMSSquaredSums.size(); c++ )
vdDestDecibel[ c ] = float( ratio_to_db20( std::sqrt( m_vdRMSSquaredSums[ c ] / double( m_iRMSBlocks * m_iBlocklength ) ) ) ); // RMS
if( bReset )
m_vdRMSSquaredSums.resize( m_iChannels, 0.0f );
m_cs.leave();
}
const float* ITAStreamDetector::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* pStreamInfo )
{
const float* pfData = m_pDataSource->GetBlockPointer( uiChannel, pStreamInfo );
if( pfData && m_iMode != ITAStreamDetector::DEACTIVATED )
{
m_cs.enter();
if( m_iMode == ITAStreamDetector::PEAK || m_iMode == ITAStreamDetector::PEAK_AND_RMS )
{
for( int i = 0; i < m_iBlocklength; i++ )
{
const float fAbs = std::abs( pfData[ i ] );
if( fAbs > m_vfPeaks[ uiChannel ] )
m_vfPeaks[ uiChannel ] = fAbs;
if( fAbs > m_fOverallPeak )
{
m_fOverallPeak = fAbs;
m_iOverallPeakChannel = uiChannel;
}
}
}
if( m_iMode == ITAStreamDetector::RMS || m_iMode == ITAStreamDetector::PEAK_AND_RMS )
{
for( int i = 0; i < m_iBlocklength; i++ )
{
const float fSampleValue = std::abs( pfData[ i ] );
m_vdRMSSquaredSums[ uiChannel ] += fSampleValue * fSampleValue; // square & sum
}
}
m_cs.leave();
}
return pfData;
}
void ITAStreamDetector::IncrementBlockPointer()
{
m_iRMSBlocks++;
m_pDataSource->IncrementBlockPointer();
}
......@@ -64,14 +64,14 @@ set_property( TARGET DatasourceUtilsTest PROPERTY FOLDER "ITACoreLibs/Tests/ITAD
# set_property( TARGET Patchbay1Test PROPERTY FOLDER "ITACoreLibs/Tests/ITADataSources" )
add_executable( PeakDetectorTest PeakDetectorTest.cpp )
target_link_libraries( PeakDetectorTest ${VISTA_USE_PACKAGE_LIBRARIES} )
add_executable( StreamDetectorTest StreamDetectorTest.cpp )
target_link_libraries( StreamDetectorTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( PeakDetectorTest )
vista_install( PeakDetectorTest )
vista_create_default_info_file( PeakDetectorTest )
vista_configure_app( StreamDetectorTest )
vista_install( StreamDetectorTest )
vista_create_default_info_file( StreamDetectorTest )
set_property( TARGET PeakDetectorTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADataSources" )
set_property( TARGET StreamDetectorTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADataSources" )
add_executable( StreamFunctionGeneratorTest StreamFunctionGeneratorTest.cpp )
......
#include <ITAException.h>
#include <ITAFileDataSource.h>
#include <ITAPeakDetector.h>
#include <ITAStringUtils.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
if (argc != 2) {
cerr << "Syntax: StreamAnalyzerTest INPUTFILE\n" << endl;
return 255;
}
ITAFileDatasource* pSource = 0;
ITAPeakDetector* pDetector = 0;
try {
cout << "Input file: \"" << argv[1] << "\"\n" << endl;
pSource = new ITAFileDatasource(argv[1], 1024);
pDetector = new ITAPeakDetector(pSource);
unsigned int n = pSource->GetCapacity() / pSource->GetBlocklength();
unsigned int c = pSource->GetNumberOfChannels();
for (unsigned int i=0; i<n; i++) {
for (unsigned int j=0; j<c; j++) pDetector->GetBlockPointer(j, 0);
pDetector->IncrementBlockPointer();
}
// Analyseinformationen ausgeben
</