mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-15 01:05:06 +00:00
bring command-line audio export back!
This commit is contained in:
parent
5a2a3a03c0
commit
e79a1bd64d
4 changed files with 59 additions and 14 deletions
|
@ -27,7 +27,8 @@ bool TAAudio::setRun(bool run) {
|
|||
}
|
||||
|
||||
bool TAAudio::init(TAAudioDesc& request, TAAudioDesc& response) {
|
||||
return false;
|
||||
response=request;
|
||||
return true;
|
||||
}
|
||||
|
||||
TAAudio::~TAAudio() {
|
||||
|
|
|
@ -1932,7 +1932,7 @@ void DivEngine::runExportThread() {
|
|||
|
||||
sf=sf_open(exportPath.c_str(),SFM_WRITE,&si);
|
||||
if (sf==NULL) {
|
||||
logE("could not open file for writing!\n");
|
||||
logE("could not open file for writing! (%s)\n",sf_strerror(NULL));
|
||||
exporting=false;
|
||||
return;
|
||||
}
|
||||
|
@ -1946,6 +1946,8 @@ void DivEngine::runExportThread() {
|
|||
deinitAudioBackend();
|
||||
playSub(false);
|
||||
|
||||
logI("rendering to file...\n");
|
||||
|
||||
while (playing) {
|
||||
nextBuf(NULL,outBuf,0,2,EXPORT_BUFSIZE);
|
||||
for (int i=0; i<EXPORT_BUFSIZE; i++) {
|
||||
|
@ -1979,6 +1981,7 @@ void DivEngine::runExportThread() {
|
|||
logE("error while activating audio!\n");
|
||||
}
|
||||
}
|
||||
logI("done!\n");
|
||||
break;
|
||||
}
|
||||
case DIV_EXPORT_MODE_MANY_SYS: {
|
||||
|
@ -1998,9 +2001,10 @@ void DivEngine::runExportThread() {
|
|||
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
fname[i]=fmt::sprintf("%s_s%d.wav",exportPath,i+1);
|
||||
logI("- %s\n",fname[i].c_str());
|
||||
sf[i]=sf_open(fname[i].c_str(),SFM_WRITE,&si[i]);
|
||||
if (sf[i]==NULL) {
|
||||
logE("could not open file for writing!\n");
|
||||
logE("could not open file for writing! (%s)\n",sf_strerror(NULL));
|
||||
for (int j=0; j<i; j++) {
|
||||
sf_close(sf[i]);
|
||||
}
|
||||
|
@ -2017,6 +2021,8 @@ void DivEngine::runExportThread() {
|
|||
deinitAudioBackend();
|
||||
playSub(false);
|
||||
|
||||
logI("rendering to files...\n");
|
||||
|
||||
while (playing) {
|
||||
nextBuf(NULL,outBuf,0,2,EXPORT_BUFSIZE);
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
|
@ -2058,6 +2064,7 @@ void DivEngine::runExportThread() {
|
|||
logE("error while activating audio!\n");
|
||||
}
|
||||
}
|
||||
logI("done!\n");
|
||||
break;
|
||||
}
|
||||
case DIV_EXPORT_MODE_MANY_CHAN: {
|
||||
|
@ -2069,18 +2076,21 @@ void DivEngine::runExportThread() {
|
|||
outBuf[1]=new float[EXPORT_BUFSIZE];
|
||||
outBuf[2]=new float[EXPORT_BUFSIZE*2];
|
||||
int loopCount=remainingLoops;
|
||||
|
||||
logI("rendering to files...\n");
|
||||
|
||||
for (int i=0; i<chans; i++) {
|
||||
SNDFILE* sf;
|
||||
SF_INFO si;
|
||||
String fname=fmt::sprintf("%s_c%d.wav",exportPath,i+1);
|
||||
logI("- %s\n",fname.c_str());
|
||||
si.samplerate=got.rate;
|
||||
si.channels=2;
|
||||
si.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16;
|
||||
|
||||
sf=sf_open(fname.c_str(),SFM_WRITE,&si);
|
||||
if (sf==NULL) {
|
||||
logE("could not open file for writing!\n");
|
||||
logE("could not open file for writing! (%s)\n",sf_strerror(NULL));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2137,6 +2147,7 @@ void DivEngine::runExportThread() {
|
|||
logE("error while activating audio!\n");
|
||||
}
|
||||
}
|
||||
logI("done!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3540,10 +3551,12 @@ void DivEngine::quitDispatch() {
|
|||
|
||||
bool DivEngine::initAudioBackend() {
|
||||
// load values
|
||||
if (getConfString("audioEngine","SDL")=="JACK") {
|
||||
audioEngine=DIV_AUDIO_JACK;
|
||||
} else {
|
||||
audioEngine=DIV_AUDIO_SDL;
|
||||
if (audioEngine==DIV_AUDIO_NULL) {
|
||||
if (getConfString("audioEngine","SDL")=="JACK") {
|
||||
audioEngine=DIV_AUDIO_JACK;
|
||||
} else {
|
||||
audioEngine=DIV_AUDIO_SDL;
|
||||
}
|
||||
}
|
||||
|
||||
lowQuality=getConfInt("audioQuality",0);
|
||||
|
@ -3562,6 +3575,9 @@ bool DivEngine::initAudioBackend() {
|
|||
case DIV_AUDIO_SDL:
|
||||
output=new TAAudioSDL;
|
||||
break;
|
||||
case DIV_AUDIO_DUMMY:
|
||||
output=new TAAudio;
|
||||
break;
|
||||
default:
|
||||
logE("invalid audio engine!\n");
|
||||
return false;
|
||||
|
@ -3576,7 +3592,6 @@ bool DivEngine::initAudioBackend() {
|
|||
|
||||
output->setCallback(process,this);
|
||||
|
||||
logI("initializing audio.\n");
|
||||
if (!output->init(want,got)) {
|
||||
logE("error while initializing audio!\n");
|
||||
delete output;
|
||||
|
|
|
@ -22,7 +22,9 @@ enum DivStatusView {
|
|||
|
||||
enum DivAudioEngines {
|
||||
DIV_AUDIO_JACK=0,
|
||||
DIV_AUDIO_SDL=1
|
||||
DIV_AUDIO_SDL=1,
|
||||
DIV_AUDIO_NULL=2,
|
||||
DIV_AUDIO_DUMMY=3
|
||||
};
|
||||
|
||||
enum DivAudioExportModes {
|
||||
|
@ -518,7 +520,7 @@ class DivEngine {
|
|||
speed1(3),
|
||||
speed2(3),
|
||||
view(DIV_STATUS_NOTHING),
|
||||
audioEngine(DIV_AUDIO_SDL),
|
||||
audioEngine(DIV_AUDIO_NULL),
|
||||
samp_bbInLen(0),
|
||||
samp_temp(0),
|
||||
samp_prevSample(0),
|
||||
|
|
33
src/main.cpp
33
src/main.cpp
|
@ -25,6 +25,8 @@ FurnaceGUI g;
|
|||
#endif
|
||||
|
||||
String outName;
|
||||
int loops=1;
|
||||
DivAudioExportModes outMode=DIV_EXPORT_MODE_ONE;
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
bool consoleMode=false;
|
||||
|
@ -48,6 +50,10 @@ bool pHelp(String) {
|
|||
}
|
||||
|
||||
bool pAudio(String val) {
|
||||
if (outName!="") {
|
||||
logE("can't use -audio and -output at the same time.\n");
|
||||
return false;
|
||||
}
|
||||
if (val=="jack") {
|
||||
e.setAudio(DIV_AUDIO_JACK);
|
||||
} else if (val=="sdl") {
|
||||
|
@ -143,9 +149,9 @@ bool pLoops(String val) {
|
|||
try {
|
||||
int count=std::stoi(val);
|
||||
if (count<0) {
|
||||
e.setLoops(-1);
|
||||
loops=0;
|
||||
} else {
|
||||
e.setLoops(count+1);
|
||||
loops=count+1;
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
logE("loop count shall be a number.\n");
|
||||
|
@ -154,8 +160,23 @@ bool pLoops(String val) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool pOutMode(String val) {
|
||||
if (val=="one") {
|
||||
outMode=DIV_EXPORT_MODE_ONE;
|
||||
} else if (val=="persys") {
|
||||
outMode=DIV_EXPORT_MODE_MANY_SYS;
|
||||
} else if (val=="perchan") {
|
||||
outMode=DIV_EXPORT_MODE_MANY_CHAN;
|
||||
} else {
|
||||
logE("invalid value for outmode! valid values are: one, persys and perchan.\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pOutput(String val) {
|
||||
outName=val;
|
||||
e.setAudio(DIV_AUDIO_DUMMY);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -178,6 +199,7 @@ void initParams() {
|
|||
params.push_back(TAParam("c","console",false,pConsole,"","enable console mode"));
|
||||
|
||||
params.push_back(TAParam("l","loops",true,pLoops,"<count>","set number of loops (-1 means loop forever)"));
|
||||
params.push_back(TAParam("o","outmode",true,pOutMode,"one|persys|perchan","set file output mode"));
|
||||
|
||||
params.push_back(TAParam("V","version",false,pVersion,"","view information about Furnace."));
|
||||
params.push_back(TAParam("W","warranty",false,pWarranty,"","view warranty disclaimer."));
|
||||
|
@ -298,7 +320,12 @@ int main(int argc, char** argv) {
|
|||
logE("could not initialize engine!\n");
|
||||
return 1;
|
||||
}
|
||||
if (outName!="") return 0;
|
||||
if (outName!="") {
|
||||
e.setConsoleMode(true);
|
||||
e.saveAudio(outName.c_str(),loops,outMode);
|
||||
e.waitAudioFile();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (consoleMode) {
|
||||
logI("playing...\n");
|
||||
|
|
Loading…
Reference in a new issue