Switching to buffered audio file writer in stream probe and enabling lazy file path setting

parent 9d09ea12
......@@ -24,7 +24,7 @@
#include <ITASampleFrame.h>
#include <ITAAtomicPrimitives.h>
#include <ITAAudiofileCommon.h>
#include <ITABufferedAudiofileWriter.h>
#include <string>
#include <vector>
......@@ -34,13 +34,14 @@ class ITAAudiofileWriter;
//! A measuring sensor for audio streams
/**
* This class captures (records) the entire data stream passing through and stores
* the result into a file on the hard drive.
* This class captures (records) the entire data stream passing through. It uses
* a sample buffer and holds the data in the memory until destructor is called.
* The result is exported into a WAV file on the hard drive.
*/
class ITA_DATA_SOURCES_API ITAStreamProbe : public ITADatasource
{
public:
ITAStreamProbe( ITADatasource* pDatasource, const std::string& sFilePath, 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();
......@@ -56,10 +57,8 @@ public:
return GetFilePath();
};
inline std::string GetFilePath() const
{
return m_sFilePath;
};
std::string GetFilePath() const;
void SetFilePath( const std::string& sFilePath );
inline unsigned int GetNumRecordedSamples() const
{
......@@ -84,8 +83,7 @@ protected:
ITASampleFrame m_sfBuffer;
std::vector< bool > m_vbDataPresent;
std::string m_sFilePath; //!< File path
ITAAudiofileWriter* m_pWriter;
ITABufferedAudiofileWriter* m_pBufferedWriter; //!< Buffering audio file writer
};
......
......@@ -4,10 +4,9 @@
#include <cassert>
ITAStreamProbe::ITAStreamProbe( ITADatasource* pDatasource, const std::string& sFilePath, ITAQuantization iQuantization )
ITAStreamProbe::ITAStreamProbe( ITADatasource* pDatasource, const std::string& sFilePath /* = "" */, ITAQuantization iQuantization /* = ITAQuantization::ITA_FLOAT */ )
: m_pDataSource( pDatasource )
, m_pWriter( NULL )
, m_sFilePath( sFilePath )
, m_pBufferedWriter( NULL )
{
assert( pDatasource != NULL );
......@@ -28,12 +27,27 @@ ITAStreamProbe::ITAStreamProbe( ITADatasource* pDatasource, const std::string& s
props.eDomain = ITADomain::ITA_TIME_DOMAIN;
props.eQuantization = iQuantization;
m_pWriter = ITABufferedAudiofileWriter::create( m_sFilePath, props );
m_pBufferedWriter = ITABufferedAudiofileWriter::create( props );
if( !sFilePath.empty() )
m_pBufferedWriter->SetFilePath( sFilePath );
}
ITAStreamProbe::~ITAStreamProbe()
{
delete m_pWriter;
delete m_pBufferedWriter;
}
std::string ITAStreamProbe::GetFilePath() const
{
if( m_pBufferedWriter )
return m_pBufferedWriter->GetFilePath();
else
return "";
}
void ITAStreamProbe::SetFilePath( const std::string& sFilePath )
{
m_pBufferedWriter->SetFilePath( sFilePath );
}
unsigned int ITAStreamProbe::GetBlocklength() const
......@@ -71,7 +85,7 @@ const float* ITAStreamProbe::GetBlockPointer( unsigned int uiChannel, const ITAS
void ITAStreamProbe::IncrementBlockPointer()
{
// Moves the internal buffer of a single block into the file writer
m_pWriter->write( &m_sfBuffer );
m_pBufferedWriter->write( &m_sfBuffer );
m_iRecordedSamples = m_iRecordedSamples + GetBlocklength();
......
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