add export one audio file per system mode
This commit is contained in:
parent
a60eae00e5
commit
9b8044a401
|
@ -2133,6 +2133,8 @@ bool DivEngine::isExporting() {
|
||||||
#define EXPORT_BUFSIZE 2048
|
#define EXPORT_BUFSIZE 2048
|
||||||
|
|
||||||
void DivEngine::runExportThread() {
|
void DivEngine::runExportThread() {
|
||||||
|
switch (exportMode) {
|
||||||
|
case DIV_EXPORT_MODE_ONE: {
|
||||||
SNDFILE* sf;
|
SNDFILE* sf;
|
||||||
SF_INFO si;
|
SF_INFO si;
|
||||||
si.samplerate=got.rate;
|
si.samplerate=got.rate;
|
||||||
|
@ -2142,6 +2144,7 @@ void DivEngine::runExportThread() {
|
||||||
sf=sf_open(exportPath.c_str(),SFM_WRITE,&si);
|
sf=sf_open(exportPath.c_str(),SFM_WRITE,&si);
|
||||||
if (sf==NULL) {
|
if (sf==NULL) {
|
||||||
logE("could not open file for writing!\n");
|
logE("could not open file for writing!\n");
|
||||||
|
exporting=false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2183,10 +2186,92 @@ void DivEngine::runExportThread() {
|
||||||
logE("error while activating audio!\n");
|
logE("error while activating audio!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DIV_EXPORT_MODE_MANY_SYS: {
|
||||||
|
SNDFILE* sf[32];
|
||||||
|
SF_INFO si[32];
|
||||||
|
String fname[32];
|
||||||
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
|
sf[i]=NULL;
|
||||||
|
si[i].samplerate=got.rate;
|
||||||
|
if (disCont[i].dispatch->isStereo()) {
|
||||||
|
si[i].channels=2;
|
||||||
|
} else {
|
||||||
|
si[i].channels=1;
|
||||||
|
}
|
||||||
|
si[i].format=SF_FORMAT_WAV|SF_FORMAT_PCM_16;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
|
fname[i]=fmt::sprintf("%s_%d.wav",exportPath,i+1);
|
||||||
|
sf[i]=sf_open(fname[i].c_str(),SFM_WRITE,&si[i]);
|
||||||
|
if (sf[i]==NULL) {
|
||||||
|
logE("could not open file for writing!\n");
|
||||||
|
for (int j=0; j<i; j++) {
|
||||||
|
sf_close(sf[i]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float* outBuf[2];
|
||||||
|
outBuf[0]=new float[EXPORT_BUFSIZE];
|
||||||
|
outBuf[1]=new float[EXPORT_BUFSIZE];
|
||||||
|
short* sysBuf=new short[EXPORT_BUFSIZE*2];
|
||||||
|
|
||||||
|
// take control of audio output
|
||||||
|
deinitAudioBackend();
|
||||||
|
playSub(false);
|
||||||
|
|
||||||
|
while (playing) {
|
||||||
|
nextBuf(NULL,outBuf,0,2,EXPORT_BUFSIZE);
|
||||||
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
|
for (int j=0; j<EXPORT_BUFSIZE; j++) {
|
||||||
|
if (!disCont[i].dispatch->isStereo()) {
|
||||||
|
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>%d\n",i,totalProcessed,EXPORT_BUFSIZE);
|
||||||
|
}
|
||||||
|
if (sf_writef_short(sf[i],sysBuf,totalProcessed)!=(int)totalProcessed) {
|
||||||
|
logE("error: failed to write entire buffer! (%d)\n",i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
|
if (sf_close(sf[i])!=0) {
|
||||||
|
logE("could not close audio file!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exporting=false;
|
||||||
|
|
||||||
|
if (initAudioBackend()) {
|
||||||
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
|
disCont[i].setRates(got.rate);
|
||||||
|
disCont[i].setQuality(lowQuality);
|
||||||
|
}
|
||||||
|
if (!output->setRun(true)) {
|
||||||
|
logE("error while activating audio!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DIV_EXPORT_MODE_MANY_CHAN: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DivEngine::saveAudio(const char* path, int loops, DivAudioExportModes mode) {
|
bool DivEngine::saveAudio(const char* path, int loops, DivAudioExportModes mode) {
|
||||||
exportPath=path;
|
exportPath=path;
|
||||||
|
exportMode=mode;
|
||||||
exporting=true;
|
exporting=true;
|
||||||
stop();
|
stop();
|
||||||
setOrder(0);
|
setOrder(0);
|
||||||
|
|
Loading…
Reference in a new issue