Adding Store() function for ITASampleFrame (exports WAV file).

parent c684d74b
......@@ -136,6 +136,7 @@ if( VSNDFILE_FOUND AND ITA_BASE_WITH_SNDFILE )
"src/libsndfileAudiofileReader.cpp"
"src/libsndfileAudiofileWriter.cpp"
)
add_definitions( -DITABASE_WITH_SNDFILE )
endif( VSNDFILE_FOUND AND ITA_BASE_WITH_SNDFILE )
......
......@@ -116,7 +116,9 @@ public:
*/
void init( int iChannels, int iLength, bool bZeroinit);
void Load( const std::string& sFileName );
void Load( const std::string& sFilePath );
void Load( const std::string& sFilePath, double& dSampleRate );
void Store( const std::string& sFilePath, double dSampleRate = 44100.0f ) const;
//! Speicher freigeben
/**
......
// $Id: ITASampleFrame.cpp 4124 2015-07-14 13:00:26Z fwefers $
#include <ITASampleFrame.h>
#include <ITAAudiofileReader.h>
#include <ITAAudiofileWriter.h>
#include <assert.h>
#include <sstream>
......@@ -35,8 +34,8 @@ ITASampleFrame::ITASampleFrame( const std::string& sFileName )
Load( sFileName );
}
ITASampleFrame::~ITASampleFrame() {
// Die Kanle werden vom std::vector-Destruktor abgerumt
ITASampleFrame::~ITASampleFrame()
{
}
bool ITASampleFrame::empty() const {
......@@ -71,13 +70,21 @@ void ITASampleFrame::init( int iChannels, int iLength, bool bZeroinit)
m_iLength = iLength;
}
void ITASampleFrame::Load( const std::string& sFileName )
void ITASampleFrame::Load( const std::string& sFilePath )
{
double dSampleRate;
Load( sFilePath, dSampleRate );
}
void ITASampleFrame::Load( const std::string& sFilePath, double& dSampleRate )
{
ITAAudiofileReader* pReader( NULL );
try {
try
{
// Datei ffnen
pReader = ITAAudiofileReader::create( sFileName );
pReader = ITAAudiofileReader::create( sFilePath );
ITAAudiofileProperties oProps = pReader->getAudiofileProperties();
dSampleRate = oProps.dSampleRate;
init( ( int ) oProps.iChannels, ( int ) oProps.iLength, false );
// Zielzeiger zusammenstellen
......@@ -89,7 +96,8 @@ void ITASampleFrame::Load( const std::string& sFileName )
pReader->read( oProps.iLength, vpfDest );
}
catch( ... ) {
catch( ... )
{
// Alle Daten verwerfen
delete pReader;
free();
......@@ -106,67 +114,42 @@ void ITASampleFrame::free()
m_iLength = 0;
};
/* TODO move Code to ITAUtils (+VistaCoreLibs dependency for FileSystem stuff)
void ITASampleFrame::load(const std::string& sFilename) {
ITAAudiofileReader* pReader(NULL);
try {
// Datei ffnen
pReader = ITAAudiofileReader::create(sFilename);
ITAAudiofileProperties oProps = pReader->getAudiofileProperties();
init( (int) oProps.uiChannels, (int) oProps.uiLength, false);
// Zielzeiger zusammenstellen
std::vector<float*> vpfDest(oProps.uiChannels);
for (unsigned int i=0; i<oProps.uiChannels; i++)
vpfDest[i] = m_vChannels[i].GetData();
// Daten einlesen
pReader->read(oProps.uiLength, vpfDest);
} catch (...) {
// Alle Daten verwerfen
delete pReader;
free();
throw;
}
delete pReader;
}
*/
/* TODO move Code to ITAUtils (+VistaCoreLibs dependency for FileSystem stuff)
void ITASampleFrame::store(const std::string& sFilename) const {
if (!hasSamplerate())
ITA_EXCEPT1(MODAL_EXCEPTION, "Sampling rate undefined");
ITAAudiofileWriter* pWriter(NULL);
try {
void ITASampleFrame::Store( const std::string& sFilePath, double dSamplingRate ) const
{
#ifdef ITABASE_WITH_SNDFILE
ITAAudiofileWriter* pWriter( NULL );
try
{
ITAAudiofileProperties oProps;
oProps.dSamplerate = m_dSamplerate;
oProps.eDomain = ITA_TIME_DOMAIN;
oProps.eQuantization = ITA_INT16;
oProps.uiChannels = (unsigned int) m_iChannels;
oProps.uiLength = (unsigned int) m_iLength;
pWriter = ITAAudiofileWriter::create(sFilename, oProps);
// Zielzeiger zusammenstellen
std::vector<const float*> vpfDest(oProps.uiChannels);
for (unsigned int i=0; i<oProps.uiChannels; i++)
vpfDest[i] = m_vChannels[i].data();
oProps.dSampleRate = dSamplingRate;
oProps.eDomain = ITADomain::ITA_TIME_DOMAIN;
oProps.eQuantization = ITAQuantization::ITA_FLOAT;
oProps.iChannels = (unsigned int) m_iChannels;
oProps.iLength = (unsigned int) m_iLength;
pWriter = ITAAudiofileWriter::create( sFilePath, oProps );
std::vector< const float* > vpfDest( oProps.iChannels );
for( int i = 0; i < oProps.iChannels; i++ )
vpfDest[ i ] = m_vChannels[ i ].data();
// Daten schreiben
pWriter->write(oProps.uiLength, vpfDest);
pWriter->write( oProps.iLength, vpfDest );
} catch (...) {
}
catch (...)
{
delete pWriter;
throw;
}
delete pWriter;
#else
ITA_EXCEPT1( NOT_IMPLEMENTED, "ITASampleFrame::Store() function not available without libsndfile" );
#endif
}
*/
void ITASampleFrame::fill(float fValue) {
void ITASampleFrame::fill( float fValue )
{
for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it)
it->Fill(fValue);
}
......
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