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

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