fluidsynth-emscripten
fluidsynth-emscripten copied to clipboard
Error compiling the file fluidsynth_simple.c with emscripten
Hello:
I'm trying to compile the file fluidsynth_simple.c using emscripten without using the functions of libfluidsynth-<version>.js
When I execute this command in the main directory:
emcc fluidsynth_simple.c -O1 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s WASM_ASYNC_COMPILATION=0 -s SINGLE_FILE=1 -s MODULARIZE=1 --bind -o prueba.js -I '/home/zay/Documents/fluidsynth-master/src/utils/fluid_settings.h'
I receive the next error:
In file included from fluidsynth_simple.c:16: ./include/fluidsynth/settings.h:101:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API fluid_settings_t *new_fluid_settings(void); ^ ./include/fluidsynth/settings.h:101:32: error: expected ';' after top level declarator FLUIDSYNTH_API fluid_settings_t *new_fluid_settings(void); ^ ; ./include/fluidsynth/settings.h:102:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API void delete_fluid_settings(fluid_settings_t *settings); ^ ./include/fluidsynth/settings.h:102:43: error: unknown type name 'fluid_settings_t' FLUIDSYNTH_API void delete_fluid_settings(fluid_settings_t *settings); ^ ./include/fluidsynth/settings.h:104:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ ./include/fluidsynth/settings.h:105:29: error: unknown type name 'fluid_settings_t' int fluid_settings_get_type(fluid_settings_t *settings, const char *name); ^ ./include/fluidsynth/settings.h:107:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ ./include/fluidsynth/settings.h:108:30: error: unknown type name 'fluid_settings_t' int fluid_settings_get_hints(fluid_settings_t *settings, const char *name, int *val); ^ ./include/fluidsynth/settings.h:110:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ ./include/fluidsynth/settings.h:111:32: error: unknown type name 'fluid_settings_t' int fluid_settings_is_realtime(fluid_settings_t *settings, const char *name); ^ ./include/fluidsynth/settings.h:113:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ ./include/fluidsynth/settings.h:114:27: error: unknown type name 'fluid_settings_t' int fluid_settings_setstr(fluid_settings_t *settings, const char *name, const char *str); ^ ./include/fluidsynth/settings.h:116:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ ./include/fluidsynth/settings.h:117:28: error: unknown type name 'fluid_settings_t' int fluid_settings_copystr(fluid_settings_t *settings, const char *name, char *str, int len); ^ ./include/fluidsynth/settings.h:119:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ ./include/fluidsynth/settings.h:120:27: error: unknown type name 'fluid_settings_t' int fluid_settings_dupstr(fluid_settings_t *settings, const char *name, char **str); ^ ./include/fluidsynth/settings.h:122:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ ./include/fluidsynth/settings.h:123:35: error: unknown type name 'fluid_settings_t' int fluid_settings_getstr_default(fluid_settings_t *settings, const char *name, char **def); ^ ./include/fluidsynth/settings.h:125:1: error: unknown type name 'FLUIDSYNTH_API' FLUIDSYNTH_API ^ fatal error: too many errors emitted, stopping now [-ferror-limit=]
Any Idea of the problem?
Thank you
Thanks for the report.
I did not build sources under the doc directory before, but I investigated and found that fluidsynth-emscripten should be built as a static library (related: #1).
To support building as a static library, I pushed 4c1e007, and I could build fluidsynth_simple.c successfully with following commands:
mkdir build
cd build
emcmake cmake -D BUILD_SHARED_LIBS=off ..
cd doc && make fluidsynth_simple -j16
Please make sure that this resolves your issue.
Thanks! Now I could compile and I got the fluidsynth_simple.js. The question now is: How can I reproduce a soundfont with fluidsynth_simple.js. I mean, I would like to do the same that
* To run
* fluidsynth_simple soundfont`
```
How can I reproduce a soundfont with fluidsynth_simple.js
You can call main manually with using Module.noInitialRun and callMain:
<script type="text/javascript">
var Module = { noInitialRun: true };
</script>
<script type="text/javascript" src="fluidsynth_simple.js"></script>
<script type="text/javascript">
function myMain() {
// see: https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.writeFile
FS.writeFile('/my-soundfont.sf2', <ArrayBufferView of sound found>);
// 'callMain' is defined in fluidsynth_simple.js as 'function callMain(args)'
callMain(['/my-soundfont.sf2']);
}
</script>
But I think fluidsynth_simple.js cannot play sound because there is no usable audio drivers. (The driver using Web Audio is not implemented in this project, so we should use libfluidsynth.js just for generating audio frames.)
fluidsynth.h is missing when i build the static lib how did you build simple demo ?
just copied verion.h and fluidsynth.h from other project and it seemed to work. when compiling the simple demo i tried with my codeblocks project and media folder with if(fluid_synth_sfload(synth, './media/example.sf2', 1) == -1) instead of argv will this work because its not giving sound yet
after reading closer i see that its missing audio drivers. i will wait for working demo. fluid_settings_setstr(settings, "audio.driver", "alsa");
fluidsynth.h is missing when i build the static lib how did you build simple demo ?
I used commands commented in https://github.com/jet2jet/fluidsynth-emscripten/issues/4#issuecomment-817105737.
I retried and fluidsynth_simple had been generated successfully.
its missing audio drivers.
Yes, there is no audio drivers for Emscripten version of FluidSynth. Unfortunately I have no idea to implement it with Web Audio now. (the PR of audio-driver implementation is welcome.)
a quick hack could be to export to wav file then play with openal or sdl audio someexamples for audio here https://github.com/netpipe/emscripten-projects https://github.com/netpipe/emscripten-projects/blob/master/media/openal-test/openal_playback.cpp https://github.com/netpipe/emscripten-projects/tree/master/SDL https://gist.github.com/take-cheeze/43f026d07547b9399738 this could be ported to get working