cwAudioFile.h/cpp : Added writeFlowInterleaved()

This commit is contained in:
kevin 2023-02-14 20:50:29 -05:00
parent 0b5458ca7b
commit d46101f4b9
2 changed files with 19 additions and 4 deletions

View File

@ -1083,11 +1083,11 @@ namespace cw
return rc; return rc;
} }
rc_t _write_samples_to_file( af_t* p, unsigned bytesPerSmp, unsigned bufSmpCnt, void* buf ) rc_t _write_samples_to_file( af_t* p, unsigned bytesPerSmp, unsigned bufSmpCnt, const void* buf )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
if( fwrite( buf, bufSmpCnt*bytesPerSmp, 1, p->fp ) != 1) if( fwrite( (void*)buf, bufSmpCnt*bytesPerSmp, 1, p->fp ) != 1)
rc = cwLogError(kWriteFailRC,"Audio file write failed on '%s'.",cwStringNullGuard(p->fn)); rc = cwLogError(kWriteFailRC,"Audio file write failed on '%s'.",cwStringNullGuard(p->fn));
return rc; return rc;
@ -1245,8 +1245,9 @@ namespace cw
// float->float // float->float
rc_t _write_samples( af_t* p, unsigned bufSmpCnt, const float* sbuf, float* dbuf ) rc_t _write_samples( af_t* p, unsigned bufSmpCnt, const float* sbuf, float* dbuf )
{ {
memcpy(dbuf,sbuf,bufSmpCnt*sizeof(float)); //memcpy(dbuf,sbuf,bufSmpCnt*sizeof(float));
return _write_samples_to_file(p,sizeof(dbuf[0]),bufSmpCnt,dbuf); //return _write_samples_to_file(p,sizeof(dbuf[0]),bufSmpCnt,dbuf);
return _write_samples_to_file(p,sizeof(sbuf[0]),bufSmpCnt,sbuf);
} }
// double->float // double->float
@ -1851,6 +1852,18 @@ cw::rc_t cw::audiofile::writeDouble( handle_t h, unsigned frmCnt, unsigned ch
//return _writeRealSamples(h,frmCnt,chCnt,bufPtrPtr,sizeof(double)); //return _writeRealSamples(h,frmCnt,chCnt,bufPtrPtr,sizeof(double));
} }
cw::rc_t cw::audiofile::writeFloatInterleaved( handle_t h, unsigned frmCnt, unsigned chCnt, const float* bufPtr )
{
rc_t rc = kOkRC;
af_t* p = _handleToPtr(h);
if((rc = _write_samples_to_file(p,sizeof(float),frmCnt*chCnt,bufPtr)) == kOkRC )
{
p->info.frameCnt += frmCnt;
}
return rc;
}
cw::rc_t cw::audiofile::minMaxMean( handle_t h, unsigned chIdx, float* minPtr, float* maxPtr, float* meanPtr ) cw::rc_t cw::audiofile::minMaxMean( handle_t h, unsigned chIdx, float* minPtr, float* maxPtr, float* meanPtr )

View File

@ -139,6 +139,8 @@ namespace cw
rc_t writeFloat( handle_t h, unsigned frmCnt, unsigned chCnt, const float* const* bufPtrPtr ); rc_t writeFloat( handle_t h, unsigned frmCnt, unsigned chCnt, const float* const* bufPtrPtr );
rc_t writeDouble( handle_t h, unsigned frmCnt, unsigned chCnt, const double* const* bufPtrPtr ); rc_t writeDouble( handle_t h, unsigned frmCnt, unsigned chCnt, const double* const* bufPtrPtr );
rc_t writeFloatInterleaved( handle_t h, unsigned frmCnt, unsigned chCnt, const float* bufPtr );
// File Writing Functions // File Writing Functions
// Set 'bit' to 0 to write the file in IEEE float format. // Set 'bit' to 0 to write the file in IEEE float format.
rc_t writeFileInt( const char* fn, double srate, unsigned bit, unsigned frmCnt, unsigned chCnt, const int* const * bufPtrPtr); rc_t writeFileInt( const char* fn, double srate, unsigned bit, unsigned frmCnt, unsigned chCnt, const int* const * bufPtrPtr);