audio export: fix channel count in per-chan export

This commit is contained in:
tildearrow 2024-05-11 02:32:35 -05:00
parent fc66fe1b15
commit 68383869d3
2 changed files with 25 additions and 17 deletions

View file

@ -243,10 +243,12 @@ void DivEngine::runExportThread() {
// take control of audio output // take control of audio output
deinitAudioBackend(); deinitAudioBackend();
float* outBuf[3]; float* outBuf[DIV_MAX_OUTPUTS];
outBuf[0]=new float[EXPORT_BUFSIZE]; float* outBufFinal;
outBuf[1]=new float[EXPORT_BUFSIZE]; for (int i=0; i<exportOutputs; i++) {
outBuf[2]=new float[EXPORT_BUFSIZE*2]; outBuf[i]=new float[EXPORT_BUFSIZE];
}
outBufFinal=new float[EXPORT_BUFSIZE*exportOutputs];
logI("rendering to files..."); logI("rendering to files...");
@ -257,7 +259,7 @@ void DivEngine::runExportThread() {
String fname=fmt::sprintf("%s_c%02d.wav",exportPath,i+1); String fname=fmt::sprintf("%s_c%02d.wav",exportPath,i+1);
logI("- %s",fname.c_str()); logI("- %s",fname.c_str());
si.samplerate=got.rate; si.samplerate=got.rate;
si.channels=2; si.channels=exportOutputs;
si.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16; si.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16;
sf=sfWrap.doOpen(fname.c_str(),SFM_WRITE,&si); sf=sfWrap.doOpen(fname.c_str(),SFM_WRITE,&si);
@ -293,24 +295,27 @@ void DivEngine::runExportThread() {
while (playing) { while (playing) {
size_t total=0; size_t total=0;
nextBuf(NULL,outBuf,0,2,EXPORT_BUFSIZE); nextBuf(NULL,outBuf,0,exportOutputs,EXPORT_BUFSIZE);
if (totalProcessed>EXPORT_BUFSIZE) { if (totalProcessed>EXPORT_BUFSIZE) {
logE("error: total processed is bigger than export bufsize! %d>%d",totalProcessed,EXPORT_BUFSIZE); logE("error: total processed is bigger than export bufsize! %d>%d",totalProcessed,EXPORT_BUFSIZE);
totalProcessed=EXPORT_BUFSIZE; totalProcessed=EXPORT_BUFSIZE;
} }
int fi=0;
for (int j=0; j<(int)totalProcessed; j++) { for (int j=0; j<(int)totalProcessed; j++) {
total++; total++;
if (isFadingOut) { if (isFadingOut) {
double mul=(1.0-((double)curFadeOutSample/(double)fadeOutSamples)); double mul=(1.0-((double)curFadeOutSample/(double)fadeOutSamples));
outBuf[2][j<<1]=MAX(-1.0f,MIN(1.0f,outBuf[0][j]))*mul; for (int k=0; k<exportOutputs; k++) {
outBuf[2][1+(j<<1)]=MAX(-1.0f,MIN(1.0f,outBuf[1][j]))*mul; outBufFinal[fi++]=MAX(-1.0f,MIN(1.0f,outBuf[k][j]))*mul;
}
if (++curFadeOutSample>=fadeOutSamples) { if (++curFadeOutSample>=fadeOutSamples) {
playing=false; playing=false;
break; break;
} }
} else { } else {
outBuf[2][j<<1]=MAX(-1.0f,MIN(1.0f,outBuf[0][j])); for (int k=0; k<exportOutputs; k++) {
outBuf[2][1+(j<<1)]=MAX(-1.0f,MIN(1.0f,outBuf[1][j])); outBufFinal[fi++]=MAX(-1.0f,MIN(1.0f,outBuf[k][j]));
}
if (lastLoopPos>-1 && j>=lastLoopPos && totalLoops>=exportLoopCount) { if (lastLoopPos>-1 && j>=lastLoopPos && totalLoops>=exportLoopCount) {
logD("start fading out..."); logD("start fading out...");
isFadingOut=true; isFadingOut=true;
@ -318,7 +323,7 @@ void DivEngine::runExportThread() {
} }
} }
} }
if (sf_writef_float(sf,outBuf[2],total)!=(int)total) { if (sf_writef_float(sf,outBufFinal,total)!=(int)total) {
logE("error: failed to write entire buffer!"); logE("error: failed to write entire buffer!");
break; break;
} }
@ -341,9 +346,10 @@ void DivEngine::runExportThread() {
if (stopExport) break; if (stopExport) break;
} }
delete[] outBuf[0]; delete[] outBufFinal;
delete[] outBuf[1]; for (int i=0; i<exportOutputs; i++) {
delete[] outBuf[2]; delete[] outBuf[i];
}
for (int i=0; i<chans; i++) { for (int i=0; i<chans; i++) {
isMuted[i]=false; isMuted[i]=false;

View file

@ -45,9 +45,11 @@ void FurnaceGUI::drawExportAudio(bool onWindow) {
if (audioExportOptions.sampleRate>384000) audioExportOptions.sampleRate=384000; if (audioExportOptions.sampleRate>384000) audioExportOptions.sampleRate=384000;
} }
if (ImGui::InputInt("Channels in file",&audioExportOptions.chans,1,1)) { if (audioExportOptions.mode!=DIV_EXPORT_MODE_MANY_SYS) {
if (audioExportOptions.chans<1) audioExportOptions.chans=1; if (ImGui::InputInt("Channels in file",&audioExportOptions.chans,1,1)) {
if (audioExportOptions.chans>16) audioExportOptions.chans=16; if (audioExportOptions.chans<1) audioExportOptions.chans=1;
if (audioExportOptions.chans>16) audioExportOptions.chans=16;
}
} }
if (ImGui::InputInt("Loops",&audioExportOptions.loops,1,2)) { if (ImGui::InputInt("Loops",&audioExportOptions.loops,1,2)) {