Adding Load/Store of WAV files for sample buffer, if libsndfile available

parent 5744175d
......@@ -334,6 +334,10 @@ public:
//! Werte als Zeichenkette zurckgeben
std::string ValuesToString() const;
void Load( const std::string& sFilePath );
void Load( const std::string& sFilePath, float& fSampleRate );
void Store( const std::string& sFilePath, const float fSampleRate = 44100.0f ) const;
//! berblendfunktionen
enum
{
......
......@@ -9,6 +9,8 @@
#include <ITAException.h>
#include <ITAFade.h>
#include <ITAFastMath.h>
#include <ITAAudiofileReader.h>
#include <ITAAudiofileWriter.h>
ITASampleBuffer::ITASampleBuffer()
......@@ -678,3 +680,71 @@ std::string ITASampleBuffer::ValuesToString() const
ss << "}";
return ss.str();
}
void ITASampleBuffer::Load( const std::string& sFilePath )
{
float fSampleRate;
Load( sFilePath, fSampleRate );
}
void ITASampleBuffer::Load( const std::string& sFilePath, float& fSampleRate )
{
#ifdef ITABASE_WITH_SNDFILE
ITAAudiofileReader* pReader( NULL );
try
{
pReader = ITAAudiofileReader::create( sFilePath );
const ITAAudiofileProperties oProps = pReader->getAudiofileProperties();
if( oProps.iChannels > 1 )
ITA_EXCEPT_INVALID_PARAMETER( "Could not load multi channel wav into sample buffer, use sample frame instead." );
fSampleRate = float( oProps.dSampleRate );
Init( oProps.iLength, false );
std::vector< float* > vpfDest( 1 );
vpfDest[ 0 ] = GetData();
pReader->read( oProps.iLength, vpfDest );
}
catch( ... )
{
delete pReader;
throw;
}
delete pReader;
#else
ITA_EXCEPT1( NOT_IMPLEMENTED, "ITASampleBuffer::Store() function not available without libsndfile" );
#endif
}
void ITASampleBuffer::Store( const std::string& sFilePath, const float fSampleRate /*= 44100.0f */ ) const
{
#ifdef ITABASE_WITH_SNDFILE
ITAAudiofileWriter* pWriter( NULL );
try
{
ITAAudiofileProperties oProps;
oProps.dSampleRate = double( fSampleRate );
oProps.eDomain = ITADomain::ITA_TIME_DOMAIN;
oProps.eQuantization = ITAQuantization::ITA_FLOAT;
oProps.iChannels = 1;
oProps.iLength = ( unsigned int ) GetLength();
pWriter = ITAAudiofileWriter::create( sFilePath, oProps );
std::vector< const float* > vpfDest( 1 );
vpfDest[ 0 ] = GetData();
pWriter->write( oProps.iLength, vpfDest );
}
catch( ... )
{
delete pWriter;
throw;
}
delete pWriter;
#else
ITA_EXCEPT1( NOT_IMPLEMENTED, "ITASampleBuffer::Store() function not available without libsndfile" );
#endif
}
......@@ -152,7 +152,6 @@ void ITASampleFrame::Store( const std::string& sFilePath, double dSamplingRate )
#else
ITA_EXCEPT1( NOT_IMPLEMENTED, "ITASampleFrame::Store() function not available without libsndfile" );
#endif
}
void ITASampleFrame::free()
......
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