diff --git a/TODO.md b/TODO.md index edf0caf65..5bd4e8925 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ # to-do for 0.6pre1 -- fade out in audio export - rewrite the system name detection function anyway - add another FM editor layout - add ability to move selection by dragging diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 5c73817ac..76b2cd11a 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -229,9 +229,6 @@ void DivEngine::runExportThread() { logE("error: total processed is bigger than export bufsize! %d>%d",totalProcessed,EXPORT_BUFSIZE); totalProcessed=EXPORT_BUFSIZE; } - if (totalProcessed!=EXPORT_BUFSIZE) { - logW("wait what? %d != %d",totalProcessed,EXPORT_BUFSIZE); - } for (int i=0; i<(int)totalProcessed; i++) { total++; if (isFadingOut) { @@ -310,7 +307,10 @@ void DivEngine::runExportThread() { float* outBuf[2]; outBuf[0]=new float[EXPORT_BUFSIZE]; outBuf[1]=new float[EXPORT_BUFSIZE]; - short* sysBuf=new short[EXPORT_BUFSIZE*2]; + short* sysBuf[32]; + for (int i=0; iisStereo()) { - sysBuf[j]=disCont[i].bbOut[0][j]; - } else { - sysBuf[j<<1]=disCont[i].bbOut[0][j]; - sysBuf[1+(j<<1)]=disCont[i].bbOut[1][j]; + if (totalProcessed>EXPORT_BUFSIZE) { + logE("error: total processed is bigger than export bufsize! %d>%d",totalProcessed,EXPORT_BUFSIZE); + totalProcessed=EXPORT_BUFSIZE; + } + for (int j=0; j<(int)totalProcessed; j++) { + total++; + if (isFadingOut) { + double mul=(1.0-((double)curFadeOutSample/(double)fadeOutSamples)); + for (int i=0; iisStereo()) { + sysBuf[i][j]=(double)disCont[i].bbOut[0][j]*mul; + } else { + sysBuf[i][j<<1]=(double)disCont[i].bbOut[0][j]*mul; + sysBuf[i][1+(j<<1)]=(double)disCont[i].bbOut[1][j]*mul; + } + } + if (++curFadeOutSample>=fadeOutSamples) { + playing=false; + break; + } + } else { + for (int i=0; iisStereo()) { + sysBuf[i][j]=disCont[i].bbOut[0][j]; + } else { + sysBuf[i][j<<1]=disCont[i].bbOut[0][j]; + sysBuf[i][1+(j<<1)]=disCont[i].bbOut[1][j]; + } + } + if (lastLoopPos>-1 && j>=lastLoopPos && totalLoops>=exportLoopCount) { + logD("start fading out..."); + isFadingOut=true; } } - if (totalProcessed>EXPORT_BUFSIZE) { - logE("error: total processed is bigger than export bufsize! (%d) %d>%d",i,totalProcessed,EXPORT_BUFSIZE); - } - if (sf_writef_short(sf[i],sysBuf,totalProcessed)!=(int)totalProcessed) { + } + for (int i=0; iEXPORT_BUFSIZE) { logE("error: total processed is bigger than export bufsize! %d>%d",totalProcessed,EXPORT_BUFSIZE); + totalProcessed=EXPORT_BUFSIZE; } - if (sf_writef_float(sf,outBuf[2],totalProcessed)!=(int)totalProcessed) { + for (int j=0; j<(int)totalProcessed; j++) { + total++; + if (isFadingOut) { + double mul=(1.0-((double)curFadeOutSample/(double)fadeOutSamples)); + outBuf[2][j<<1]=MAX(-1.0f,MIN(1.0f,outBuf[0][j]))*mul; + outBuf[2][1+(j<<1)]=MAX(-1.0f,MIN(1.0f,outBuf[1][j]))*mul; + if (++curFadeOutSample>=fadeOutSamples) { + playing=false; + break; + } + } else { + outBuf[2][j<<1]=MAX(-1.0f,MIN(1.0f,outBuf[0][j])); + outBuf[2][1+(j<<1)]=MAX(-1.0f,MIN(1.0f,outBuf[1][j])); + if (lastLoopPos>-1 && j>=lastLoopPos && totalLoops>=exportLoopCount) { + logD("start fading out..."); + isFadingOut=true; + } + } + } + if (sf_writef_float(sf,outBuf[2],total)!=(int)total) { logE("error: failed to write entire buffer!"); break; }