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

Improving implementation of stream probe and fixing bug on first sample frame....

Improving implementation of stream probe and fixing bug on first sample frame. also little peak detector style changes.
parent 5885c095
......@@ -57,7 +57,7 @@ public:
virtual ~ITAPeakDetector();
//! Datenquelle zurückgeben
ITADatasource* GetDatasource() const { return m_pDatasource; }
ITADatasource* GetDatasource() const { return m_pDataSource; }
//! Messung zurücksetzen
void Reset();
......@@ -148,7 +148,7 @@ public:
virtual void IncrementBlockPointer();
protected:
ITADatasource* m_pDatasource; // Angeschlossene Datenquelle
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]
......
......@@ -22,62 +22,68 @@
#include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITASampleFrame.h>
#include <ITAAtomicPrimitives.h>
#include <ITAAudiofileCommon.h>
#include <string>
#include <vector>
// Vorwrtedeklarationen
class ITAAudiofileWriter;
//! Eine "Messspitze mit Lautsprecher" fr Audiostreams
//! 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.
*/
* Instanzen der Klasse ITAStreamProbe knnen als "Messspitze" in Audiostreams
* eingehngt werden. Sie schreiben dann alle vorbeigeflossenen Daten in eine Audiodatei.
*/
class ITA_DATA_SOURCES_API ITAStreamProbe : public ITADatasource
{
public:
//! Konstruktor
/**
* \param pDatasource Datenquelle
*
* \note Es darf kein Nullzeiger bergeben werden.
*/
ITAStreamProbe( ITADatasource* pDatasource, const std::string& sFilename, ITAQuantization iQuantization = ITAQuantization::ITA_FLOAT );
//! Destruktor
virtual ~ITAStreamProbe();
//! Datenquelle zurckgeben
ITADatasource* GetDatasource() const { return m_pDatasource; }
//! Dateiname zurckgeben
std::string GetFilename() const { return m_sFilename; }
inline ITADatasource* GetDatasource() const
{
return m_pDataSource;
}
//! Anzahl der aufgenommenen Samples zurckgeben
unsigned int GetNumRecordedSamples() const { return m_iRecordedSamples; }
inline std::string GetFilename() const
{
return GetFilePath();
};
// -= berladene Methoden von ITADatasource =-
inline std::string GetFilePath() const
{
return m_sFilePath;
};
inline unsigned int GetNumRecordedSamples() const
{
return m_iRecordedSamples;
}
unsigned int GetBlocklength() const;
unsigned int GetNumberOfChannels() const;
double GetSampleRate() const;
virtual const float* GetBlockPointer(unsigned int uiChannel, const ITAStreamInfo* pStreamInfo);
virtual const float* GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* pStreamInfo );
virtual void IncrementBlockPointer();
protected:
ITADatasource* m_pDatasource; //!< Angeschlossene Datenquelle
std::string m_sFilename; //!< Dateiname
double m_dSamplerate; //!< Abtastrate [Hz]
unsigned int m_uiChannels; //!< Anzahl Kanle
unsigned int m_uiBlocklength; //!< Streaming Puffergre [Samples]
ITAAtomicInt m_iRecordedSamples; //!< Anzahl aufgenommene Samples
ITADatasource* m_pDataSource; //!< Incoming data source
double m_dSampleRate; //!< Sampling rate [Hz]
int m_iChannels; //!< Number of channels
int m_iBlockLength; //!< Streaming buffer size [Samples]
ITAAtomicInt m_iRecordedSamples; //!< Number of recorded samples
ITASampleFrame m_sfBuffer;
std::vector< bool > m_vbDataPresent;
std::string m_sFilePath; //!< File path
ITAAudiofileWriter* m_pWriter;
float* m_pfBuffer;
std::vector<float*> m_vpfAlias;
bool* m_pbDataPresent;
};
......
#include "ITAPeakDetector.h"
#include <cmath>
#include <ITAException.h>
#include <ITANumericUtils.h>
ITAPeakDetector::ITAPeakDetector(ITADatasource* pDatasource)
#include <cmath>
ITAPeakDetector::ITAPeakDetector( ITADatasource* pDataSource )
: m_pDataSource( pDataSource )
{
m_pDatasource = pDatasource;
m_dSamplerate = pDatasource->GetSampleRate();
m_uiChannels = pDatasource->GetNumberOfChannels();
m_uiBlocklength = pDatasource->GetBlocklength();
m_dSamplerate = pDataSource->GetSampleRate();
m_uiChannels = pDataSource->GetNumberOfChannels();
m_uiBlocklength = pDataSource->GetBlocklength();
m_pfPeaks = 0;
// Unspezifizierte Parameter werden nicht erlaubt!
......@@ -132,7 +133,7 @@ void ITAPeakDetector::GetPeaksDecibel(std::vector<double>& vdDestDecibel, bool b
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);
const float* pfData = m_pDataSource->GetBlockPointer(uiChannel, pStreamInfo);
if (pfData) {
// TODO: Ist es wirklich ntig bei jedem GBP die CS zu betreten? :-(
......@@ -159,5 +160,5 @@ const float* ITAPeakDetector::GetBlockPointer(unsigned int uiChannel, const ITAS
void ITAPeakDetector::IncrementBlockPointer() {
// Blockzeiger der angeschlossenen Datenquelle inkrementieren
m_pDatasource->IncrementBlockPointer();
m_pDataSource->IncrementBlockPointer();
}
#include "ITAStreamProbe.h"
#include <ITABufferedAudioFileWriter.h>
#include <cassert>
#include <ITABufferedAudioFileWriter.h>
#ifndef WIN32
#include <memory.h>
#endif
ITAStreamProbe::ITAStreamProbe(ITADatasource* pDatasource, const std::string& sFilename, ITAQuantization iQuantization)
ITAStreamProbe::ITAStreamProbe( ITADatasource* pDatasource, const std::string& sFilePath, ITAQuantization iQuantization )
: m_pDataSource( pDatasource )
, m_pWriter( NULL )
, m_sFilePath( sFilePath )
{
assert( pDatasource != NULL );
m_pDatasource = pDatasource;
m_sFilename = sFilename;
m_dSampleRate = pDatasource->GetSampleRate();
m_iChannels = int( pDatasource->GetNumberOfChannels() );
m_iBlockLength = int( pDatasource->GetBlocklength() );
m_dSamplerate = pDatasource->GetSampleRate();
m_uiChannels = pDatasource->GetNumberOfChannels();
m_uiBlocklength = pDatasource->GetBlocklength();
m_sfBuffer.init( m_iChannels, m_iBlockLength, true );
for( int i = 0; i < m_iChannels; i++ )
m_vbDataPresent.push_back( false );
m_iRecordedSamples = 0;
ITAAudiofileProperties props;
props.iChannels = m_uiChannels;
props.dSampleRate = m_dSamplerate;
props.iChannels = m_iChannels;
props.dSampleRate = m_dSampleRate;
props.eDomain = ITADomain::ITA_TIME_DOMAIN;
props.eQuantization = iQuantization;
m_pWriter = ITABufferedAudiofileWriter::create(sFilename, props);
m_pfBuffer = new float[m_uiChannels * m_uiBlocklength];
m_pbDataPresent = new bool[m_uiChannels];
for (unsigned int i=0; i<m_uiChannels; i++) {
m_pbDataPresent[i] = false;
m_vpfAlias.push_back(m_pfBuffer + (i*m_uiBlocklength));
}
m_iRecordedSamples = 0;
m_pWriter = ITABufferedAudiofileWriter::create( m_sFilePath, props );
}
ITAStreamProbe::~ITAStreamProbe() {
ITAStreamProbe::~ITAStreamProbe()
{
delete m_pWriter;
delete[] m_pfBuffer;
delete[] m_pbDataPresent;
}
unsigned int ITAStreamProbe::GetBlocklength() const {
return m_uiBlocklength;
unsigned int ITAStreamProbe::GetBlocklength() const
{
return ( unsigned int ) ( m_iBlockLength );
}
unsigned int ITAStreamProbe::GetNumberOfChannels() const {
return m_uiChannels;
unsigned int ITAStreamProbe::GetNumberOfChannels() const
{
return ( unsigned int ) ( m_iChannels );
}
double ITAStreamProbe::GetSampleRate() const {
return m_dSamplerate;
double ITAStreamProbe::GetSampleRate() const
{
return m_dSampleRate;
}
const float* ITAStreamProbe::GetBlockPointer(unsigned int uiChannel, const ITAStreamInfo* pStreamInfo) {
const float* pfData = m_pDatasource->GetBlockPointer(uiChannel, pStreamInfo);
const float* ITAStreamProbe::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* pStreamInfo )
{
const float* pfData = m_pDataSource->GetBlockPointer( uiChannel, pStreamInfo );
// Nur den ersten Block bei Leseanforderung speichern
if (pfData && !m_pbDataPresent[uiChannel]) {
memcpy(m_vpfAlias[uiChannel], pfData, m_uiBlocklength * sizeof(float));
m_pbDataPresent[uiChannel] = true;
if( pfData == nullptr )
return NULL;
// Only use first block pointer call on this channel
if( m_vbDataPresent[ uiChannel ] == false )
{
m_sfBuffer[ uiChannel ].write( pfData, GetBlocklength() );
m_vbDataPresent[ uiChannel ] = true;
}
else
assert( false );
return pfData;
}
void ITAStreamProbe::IncrementBlockPointer() {
// Gepufferte Daten in die Audiodatei schreiben
m_pWriter->write(m_uiBlocklength, m_vpfAlias);
m_iRecordedSamples = m_iRecordedSamples + (int) m_uiBlocklength;
void ITAStreamProbe::IncrementBlockPointer()
{
// Moves the internal buffer of a single block into the file writer
m_pWriter->write( &m_sfBuffer );
m_iRecordedSamples = m_iRecordedSamples + GetBlocklength();
// Data reset indication
for( int i = 0; i < m_iChannels; i++ )
m_vbDataPresent[ i ] = false;
// Internen Puffer lschen
for (unsigned int i=0; i<m_uiChannels; i++) m_pbDataPresent[i] = false;
memset(m_pfBuffer, 0, m_uiChannels * m_uiBlocklength * sizeof(float));
m_sfBuffer.zero(); // jst: necessary?
m_pDatasource->IncrementBlockPointer();
m_pDataSource->IncrementBlockPointer();
}
Markdown is supported
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