mirror of
https://github.com/tildearrow/furnace.git
synced 2025-01-03 14:11:11 +00:00
preliminary audio file output
This commit is contained in:
parent
7649b845aa
commit
f71ee6b45d
6 changed files with 40 additions and 4 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -9,3 +9,7 @@
|
||||||
path = extern/Nuked-OPM
|
path = extern/Nuked-OPM
|
||||||
url = https://github.com/nukeykt/Nuked-OPM
|
url = https://github.com/nukeykt/Nuked-OPM
|
||||||
branch = main
|
branch = main
|
||||||
|
[submodule "extern/libsndfile"]
|
||||||
|
path = extern/libsndfile
|
||||||
|
url = https://github.com/libsndfile/libsndfile.git
|
||||||
|
branch = master
|
||||||
|
|
|
@ -3,6 +3,9 @@ project(furnace)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
set(BUILD_TESTING OFF)
|
||||||
|
add_subdirectory(extern/libsndfile)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
set(SDL_SHARED OFF)
|
set(SDL_SHARED OFF)
|
||||||
add_subdirectory(extern/SDL)
|
add_subdirectory(extern/SDL)
|
||||||
|
@ -16,6 +19,7 @@ else()
|
||||||
find_library(HAVE_JACK jack)
|
find_library(HAVE_JACK jack)
|
||||||
endif()
|
endif()
|
||||||
find_library(HAVE_Z z)
|
find_library(HAVE_Z z)
|
||||||
|
find_library(HAVE_SNDFILE sndfile)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(AUDIO_SOURCES src/audio/abstract.cpp)
|
set(AUDIO_SOURCES src/audio/abstract.cpp)
|
||||||
|
@ -82,7 +86,7 @@ src/engine/platform/dummy.cpp)
|
||||||
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES}
|
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES}
|
||||||
src/main.cpp)
|
src/main.cpp)
|
||||||
|
|
||||||
target_link_libraries(furnace ${HAVE_SDL2} ${HAVE_Z})
|
target_link_libraries(furnace ${HAVE_SDL2} ${HAVE_Z} sndfile)
|
||||||
|
|
||||||
if (HAVE_JACK)
|
if (HAVE_JACK)
|
||||||
target_link_libraries(furnace ${HAVE_JACK})
|
target_link_libraries(furnace ${HAVE_JACK})
|
||||||
|
|
1
extern/libsndfile
vendored
Submodule
1
extern/libsndfile
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit ca2008903f66f856de4cd86e83a387b56260d5b7
|
|
@ -15,6 +15,7 @@
|
||||||
#include "platform/dummy.h"
|
#include "platform/dummy.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
#include <sndfile.h>
|
||||||
|
|
||||||
void process(void* u, float** in, float** out, int inChans, int outChans, unsigned int size) {
|
void process(void* u, float** in, float** out, int inChans, int outChans, unsigned int size) {
|
||||||
((DivEngine*)u)->nextBuf(in,out,inChans,outChans,size);
|
((DivEngine*)u)->nextBuf(in,out,inChans,outChans,size);
|
||||||
|
@ -695,10 +696,22 @@ void DivEngine::setView(DivStatusView which) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DivEngine::init(String outName) {
|
bool DivEngine::init(String outName) {
|
||||||
|
SNDFILE* outFile;
|
||||||
|
SF_INFO outInfo;
|
||||||
if (outName!="") {
|
if (outName!="") {
|
||||||
// init out file
|
// init out file
|
||||||
got.bufsize=2048;
|
got.bufsize=2048;
|
||||||
got.rate=44100;
|
got.rate=44100;
|
||||||
|
|
||||||
|
outInfo.samplerate=got.rate;
|
||||||
|
outInfo.channels=1;
|
||||||
|
outInfo.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16;
|
||||||
|
|
||||||
|
outFile=sf_open(outName.c_str(),SFM_WRITE,&outInfo);
|
||||||
|
if (outFile==NULL) {
|
||||||
|
logE("could not open file for writing!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (audioEngine) {
|
switch (audioEngine) {
|
||||||
case DIV_AUDIO_JACK:
|
case DIV_AUDIO_JACK:
|
||||||
|
@ -800,6 +813,13 @@ bool DivEngine::init(String outName) {
|
||||||
|
|
||||||
if (outName!="") {
|
if (outName!="") {
|
||||||
// render to file
|
// render to file
|
||||||
|
remainingLoops=1;
|
||||||
|
while (remainingLoops) {
|
||||||
|
nextBuf(NULL,NULL,0,2,got.bufsize);
|
||||||
|
sf_writef_short(outFile,bbOut[0],got.bufsize);
|
||||||
|
}
|
||||||
|
sf_close(outFile);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (!output->setRun(true)) {
|
if (!output->setRun(true)) {
|
||||||
logE("error while activating!\n");
|
logE("error while activating!\n");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "dispatch.h"
|
#include "dispatch.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "../ta-log.h"
|
#include "../ta-log.h"
|
||||||
|
#include <sndfile.h>
|
||||||
|
|
||||||
void DivEngine::nextOrder() {
|
void DivEngine::nextOrder() {
|
||||||
curRow=0;
|
curRow=0;
|
||||||
|
@ -716,6 +717,8 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
blip_read_samples(bb[1],bbOut[1],size,0);
|
blip_read_samples(bb[1],bbOut[1],size,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (out==NULL) return;
|
||||||
|
|
||||||
if (dispatch->isStereo()) {
|
if (dispatch->isStereo()) {
|
||||||
for (size_t i=0; i<size; i++) {
|
for (size_t i=0; i<size; i++) {
|
||||||
out[0][i]=(float)bbOut[0][i]/16384.0;
|
out[0][i]=(float)bbOut[0][i]/16384.0;
|
||||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
DivEngine e;
|
DivEngine e;
|
||||||
|
|
||||||
|
String outName;
|
||||||
|
|
||||||
std::vector<TAParam> params;
|
std::vector<TAParam> params;
|
||||||
|
|
||||||
bool pHelp(String) {
|
bool pHelp(String) {
|
||||||
|
@ -116,7 +118,8 @@ bool pLoops(String val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pOutput(String val) {
|
bool pOutput(String val) {
|
||||||
return false;
|
outName=val;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needsValue(String param) {
|
bool needsValue(String param) {
|
||||||
|
@ -143,6 +146,7 @@ void initParams() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
outName="";
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE winin=GetStdHandle(STD_INPUT_HANDLE);
|
HANDLE winin=GetStdHandle(STD_INPUT_HANDLE);
|
||||||
HANDLE winout=GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE winout=GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
@ -244,11 +248,11 @@ int main(int argc, char** argv) {
|
||||||
logE("could not open file!\n");
|
logE("could not open file!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!e.init()) {
|
if (!e.init(outName)) {
|
||||||
logE("could not initialize engine!\n");
|
logE("could not initialize engine!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
logI("loaded! :o\n");
|
if (outName!="") return 0;
|
||||||
logI("playing...\n");
|
logI("playing...\n");
|
||||||
e.play();
|
e.play();
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
Loading…
Reference in a new issue