cwAudioFile : Fixed memory leak. Added alloc/freeFloatBuf().
This commit is contained in:
parent
43c8737d73
commit
1440a4f55f
@ -78,6 +78,7 @@ namespace cw
|
|||||||
p->fp = nullptr;
|
p->fp = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mem::release(p->fn);
|
||||||
mem::release(p);
|
mem::release(p);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1296,6 +1297,62 @@ cw::rc_t cw::audiofile::getSumFloat( const char* fn, unsigned begFrmIdx, un
|
|||||||
cw::rc_t cw::audiofile::getSumDouble( const char* fn, unsigned begFrmIdx, unsigned frmCnt, unsigned chIdx, unsigned chCnt, double** buf, unsigned* actualFrmCntPtr, info_t* afInfoPtr )
|
cw::rc_t cw::audiofile::getSumDouble( const char* fn, unsigned begFrmIdx, unsigned frmCnt, unsigned chIdx, unsigned chCnt, double** buf, unsigned* actualFrmCntPtr, info_t* afInfoPtr )
|
||||||
{ return _getDouble( fn, begFrmIdx, frmCnt, chIdx, chCnt, buf, actualFrmCntPtr, afInfoPtr, true ); }
|
{ return _getDouble( fn, begFrmIdx, frmCnt, chIdx, chCnt, buf, actualFrmCntPtr, afInfoPtr, true ); }
|
||||||
|
|
||||||
|
cw::rc_t cw::audiofile::allocFloatBuf( const char* fn, float**& chBufRef, unsigned& chCntRef, unsigned& frmCntRef, info_t& afInfo, unsigned begFrmIdx, unsigned frmCnt, unsigned chIdx, unsigned chCnt )
|
||||||
|
{
|
||||||
|
rc_t rc;
|
||||||
|
|
||||||
|
unsigned actualFrmCnt = 0;
|
||||||
|
|
||||||
|
frmCntRef = 0;
|
||||||
|
chCntRef = 0;
|
||||||
|
|
||||||
|
if((rc = getInfo(fn, &afInfo )) != kOkRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
if( chCnt == 0 )
|
||||||
|
chCnt = afInfo.chCnt;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( chIdx + chCnt > afInfo.chCnt )
|
||||||
|
{
|
||||||
|
cwLogError(kInvalidArgRC,"Requested channel indexes %i to %i exceeds available channel count %i.",chIdx,chIdx+chCnt-1,afInfo,chCnt);
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( frmCnt == 0 )
|
||||||
|
frmCnt = afInfo.frameCnt;
|
||||||
|
|
||||||
|
if( begFrmIdx + frmCnt > afInfo.frameCnt )
|
||||||
|
{
|
||||||
|
cwLogError(kInvalidArgRC,"Requested frames %i to %i exceeds available frame count %i.",begFrmIdx,begFrmIdx+frmCnt,afInfo.frameCnt);
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
chBufRef = mem::allocZ< float* >(chCnt);
|
||||||
|
for(unsigned i=0; i<chCnt; ++i)
|
||||||
|
chBufRef[i] = mem::alloc<float>(frmCnt);
|
||||||
|
|
||||||
|
|
||||||
|
if((rc = getFloat(fn, begFrmIdx, frmCnt, chIdx, chCnt, chBufRef, &actualFrmCnt, nullptr)) != kOkRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
frmCntRef = actualFrmCnt;
|
||||||
|
chCntRef = chCnt;
|
||||||
|
|
||||||
|
errLabel:
|
||||||
|
if( rc != kOkRC )
|
||||||
|
cwLogError(rc,"Audio file allocFloat() failed.");
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
cw::rc_t cw::audiofile::freeFloatBuf( float** floatBuf, unsigned chCnt )
|
||||||
|
{
|
||||||
|
for(unsigned i=0; i<chCnt; ++i)
|
||||||
|
mem::release(floatBuf[i]);
|
||||||
|
mem::release(floatBuf);
|
||||||
|
return kOkRC;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
cw::rc_t cw::audiofile::writeInt( handle_t h, unsigned frmCnt, unsigned chCnt, int** srcPtrPtr )
|
cw::rc_t cw::audiofile::writeInt( handle_t h, unsigned frmCnt, unsigned chCnt, int** srcPtrPtr )
|
||||||
@ -1623,6 +1680,21 @@ void cw::audiofile::printInfo( const info_t* infoPtr, log::handle_t logH )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cw::rc_t cw::audiofile::reportInfo( const char* audioFn )
|
||||||
|
{
|
||||||
|
rc_t rc;
|
||||||
|
info_t info;
|
||||||
|
|
||||||
|
if((rc = getInfo(audioFn,&info)) != kOkRC )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
printInfo(&info,log::globalHandle());
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cw::rc_t cw::audiofile::report( handle_t h, log::handle_t logH, unsigned frmIdx, unsigned frmCnt )
|
cw::rc_t cw::audiofile::report( handle_t h, log::handle_t logH, unsigned frmIdx, unsigned frmCnt )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
|
@ -129,6 +129,10 @@ namespace cw
|
|||||||
rc_t getSumFloat( const char* fn, unsigned begFrmIdx, unsigned frmCnt, unsigned chIdx, unsigned chCnt, float** buf, unsigned* actualFrmCntPtr, info_t* afInfoPtr);
|
rc_t getSumFloat( const char* fn, unsigned begFrmIdx, unsigned frmCnt, unsigned chIdx, unsigned chCnt, float** buf, unsigned* actualFrmCntPtr, info_t* afInfoPtr);
|
||||||
rc_t getSumDouble( const char* fn, unsigned begFrmIdx, unsigned frmCnt, unsigned chIdx, unsigned chCnt, double** buf, unsigned* actualFrmCntPtr, info_t* afInfoPtr);
|
rc_t getSumDouble( const char* fn, unsigned begFrmIdx, unsigned frmCnt, unsigned chIdx, unsigned chCnt, double** buf, unsigned* actualFrmCntPtr, info_t* afInfoPtr);
|
||||||
|
|
||||||
|
// Allocate a buffer and read the file into it
|
||||||
|
rc_t allocFloatBuf( const char* fn, float**& chBufRef, unsigned& chCntRef, unsigned& frmCntRef, info_t& afInfoPtrRef, unsigned begFrmIdx=0, unsigned frmCnt=0, unsigned chIdx=0, unsigned chCnt=0 );
|
||||||
|
rc_t freeFloatBuf( float** floatBufRef, unsigned chCnt );
|
||||||
|
|
||||||
// Sample Writing Functions
|
// Sample Writing Functions
|
||||||
rc_t writeInt( handle_t h, unsigned frmCnt, unsigned chCnt, int** bufPtrPtr );
|
rc_t writeInt( handle_t h, unsigned frmCnt, unsigned chCnt, int** bufPtrPtr );
|
||||||
rc_t writeFloat( handle_t h, unsigned frmCnt, unsigned chCnt, float** bufPtrPtr );
|
rc_t writeFloat( handle_t h, unsigned frmCnt, unsigned chCnt, float** bufPtrPtr );
|
||||||
|
Loading…
Reference in New Issue
Block a user