diff --git a/cwAudioFile.cpp b/cwAudioFile.cpp index e2abe43..1f0e80b 100644 --- a/cwAudioFile.cpp +++ b/cwAudioFile.cpp @@ -77,7 +77,8 @@ namespace cw fclose(p->fp); p->fp = nullptr; } - + + mem::release(p->fn); 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 ) { 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(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