cwAudioFileOps.cpp : selecToFile(cfg) now has generates optional Audacity marker file.

This commit is contained in:
kevin 2021-02-26 13:34:37 -05:00
parent 9a7461a147
commit cb48b2bf81

View File

@ -434,6 +434,7 @@ cw::rc_t cw::afop::selectToFile( const char* srcFn, double beg0Sec, double beg1
cwLogInfo("beg:%f %f end: %f %f : src:%s dst:%s", beg0Sec,beg1Sec,end0Sec,end1Sec,iFn,oFn); cwLogInfo("beg:%f %f end: %f %f : src:%s dst:%s", beg0Sec,beg1Sec,end0Sec,end1Sec,iFn,oFn);
cwLogInfo("beg:%f %f end: %f %f", beg0FrmIdx/info.srate,beg1FrmIdx/info.srate,end0FrmIdx/info.srate,end1FrmIdx/info.srate);
// Seek to the start of the read location // Seek to the start of the read location
if((rc = audiofile::seek( iH, beg0FrmIdx )) != kOkRC ) if((rc = audiofile::seek( iH, beg0FrmIdx )) != kOkRC )
@ -452,8 +453,6 @@ cw::rc_t cw::afop::selectToFile( const char* srcFn, double beg0Sec, double beg1
} }
// if there is a fade-in then generate it // if there is a fade-in then generate it
if( beg1FrmIdx > beg0FrmIdx ) if( beg1FrmIdx > beg0FrmIdx )
_fadeAllChannels( chBuf, info.chCnt, ttlFrmN, beg1FrmIdx-beg0FrmIdx, kLinearFadeFl | kFadeInFl ); _fadeAllChannels( chBuf, info.chCnt, ttlFrmN, beg1FrmIdx-beg0FrmIdx, kLinearFadeFl | kFadeInFl );
@ -496,24 +495,32 @@ cw::rc_t cw::afop::selectToFile( const object_t* cfg )
const object_t* selectL = nullptr; const object_t* selectL = nullptr;
const char* oDir = nullptr; const char* oDir = nullptr;
const char* src0Fn = nullptr; const char* src0Fn = nullptr;
char* markerFn = nullptr;
double fadeInSec = 0; double fadeInSec = 0;
double fadeOutSec = 0; double fadeOutSec = 0;
bool fadeInPreFl = false; bool fadeInPreFl = false;
bool fadeOutPostFl = false; bool fadeOutPostFl = false;
unsigned outBits = 16; unsigned outBits = 16;
file::handle_t markerFh;
// read the top level cfg record // read the top level cfg record
if((rc = cfg->getv("outDir",oDir,"outBits",outBits,"selectL",selectL)) != kOkRC ) if((rc = cfg->getv("outDir",oDir,"outBits",outBits,"selectL",selectL)) != kOkRC )
goto errLabel; goto errLabel;
else
if((rc = cfg->getv_opt("srcFn",src0Fn,"fadeInSec",fadeInSec,"fadeOutSec",fadeOutSec,"fadeInPreFl",fadeInPreFl,"fadeOutPreFl",fadeOutPostFl)) != kOkRC )
goto errLabel;
else
{
unsigned selN = selectL->child_count();
for(unsigned i=0; i<selN; ++i) if((rc = cfg->getv_opt("srcFn",src0Fn,"markerFn",markerFn,"fadeInSec",fadeInSec,"fadeOutSec",fadeOutSec,"fadeInPreFl",fadeInPreFl,"fadeOutPreFl",fadeOutPostFl)) != kOkRC )
goto errLabel;
if( markerFn != nullptr )
{
if((rc = file::open(markerFh, markerFn, file::kWriteFl )) != kOkRC )
{
rc = cwLogError(rc,"Marker file '%s' create failed.", cwStringNullGuard(markerFn));
goto errLabel;
}
}
for(unsigned i=0; i<selectL->child_count(); ++i)
{ {
double begSec = 0; double begSec = 0;
double endSec = -1; double endSec = -1;
@ -541,19 +548,27 @@ cw::rc_t cw::afop::selectToFile( const object_t* cfg )
double beg0Sec = fadeInPreFl ? std::max(0.0,begSec-fadeInSec) : begSec; double beg0Sec = fadeInPreFl ? std::max(0.0,begSec-fadeInSec) : begSec;
double beg1Sec = fadeInPreFl ? begSec : begSec + fadeInSec; double beg1Sec = fadeInPreFl ? begSec : begSec + fadeInSec;
double end0Sec = fadeOutPostFl ? endSec : std::max(0.0,endSec - fadeOutSec); double end0Sec = fadeOutPostFl ? std::max(0.0,endSec - fadeOutSec) : endSec;
double end1Sec = fadeOutPostFl ? endSec+fadeOutSec : endSec; double end1Sec = fadeOutPostFl ? endSec : endSec+fadeOutSec;
beg1Sec = std::max(beg0Sec,beg1Sec); beg1Sec = std::max(beg0Sec,beg1Sec);
end1Sec = std::max(end0Sec,end1Sec); end1Sec = std::max(end0Sec,end1Sec);
if( markerFh.isValid() )
{
file::printf(markerFh,"%f\t%f\t%i\n",begSec,begSec,i+1);
}
if((rc = selectToFile( src1Fn==nullptr ? src0Fn : src1Fn, beg0Sec, beg1Sec, end0Sec, end1Sec, outBits, oDir, dstFn )) != kOkRC ) if((rc = selectToFile( src1Fn==nullptr ? src0Fn : src1Fn, beg0Sec, beg1Sec, end0Sec, end1Sec, outBits, oDir, dstFn )) != kOkRC )
goto errLabel; goto errLabel;
}
} }
errLabel: errLabel:
if( markerFh.isValid() )
{
file::close(markerFh);
}
return rc; return rc;
} }