Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JNIEXPORT jint JNICALL Java_com_musicmuni_fluidsynth_FluidSynth_getFileFromMIDIAndSoundFont
- (JNIEnv *env, jobject obj, jstring outFile, jstring midiFile, jstring soundfontFile,
- jint sampleRate) {
- const char *outFileChar = env->GetStringUTFChars(outFile, 0);
- const char *midiFileChar = env->GetStringUTFChars(midiFile, 0);
- const char *soundfontFileChar = env->GetStringUTFChars(soundfontFile, 0);
- fluid_settings_t* settings;
- fluid_synth_t* synth;
- fluid_player_t* player;
- fluid_file_renderer_t* renderer;
- settings = new_fluid_settings();
- // specify the file to store the audio to
- // make sure you compiled fluidsynth with libsndfile to get a real wave file
- // otherwise this file will only contain raw s16 stereo PCM
- int success = fluid_settings_setstr(settings, "audio.file.name", outFileChar);
- if(FLUID_OK == success) {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Successful in setting the out file name\n");
- } else {
- __android_log_print(ANDROID_LOG_ERROR, "NDK_LOG","Unable in setting the out file name\n");
- return 0;
- }
- // Setting the sample rate
- success = fluid_settings_setnum(settings, "synth.sample-rate", sampleRate);
- if(FLUID_OK == success) {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Successful in setting sample rate\n");
- } else {
- __android_log_print(ANDROID_LOG_ERROR, "NDK_LOG","Unable in setting the sample rate\n");
- return 0;
- }
- // use number of samples processed as timing source, rather than the system timer
- success = fluid_settings_setstr(settings, "player.timing-source", "sample");
- if(FLUID_OK == success) {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Successful in setting timing source\n");
- } else {
- __android_log_print(ANDROID_LOG_ERROR, "NDK_LOG","Unable in setting the timing source\n");
- return 0;
- }
- // since this is a non-realtime szenario, there is no need to pin the sample data
- success = fluid_settings_setint(settings, "synth.lock-memory", 0);
- if(FLUID_OK == success) {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Successful in setting lock memory\n");
- } else {
- __android_log_print(ANDROID_LOG_ERROR, "NDK_LOG","Unable in setting the lock memory\n");
- return 0;
- }
- synth = new_fluid_synth(settings);
- // Setting the soundfont ..
- success = fluid_synth_sfload(synth, soundfontFileChar, 0);
- if(FLUID_FAILED == success) {
- __android_log_print(ANDROID_LOG_ERROR, "NDK_LOG","Unable in setting the soundfont file\n");
- return 0;
- } else {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Successful in setting the soundfont file\n");
- }
- player = new_fluid_player(synth);
- success = fluid_player_add(player, midiFileChar);
- if(FLUID_OK == success) {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Successful in fluid_player_add\n");
- } else {
- __android_log_print(ANDROID_LOG_ERROR, "NDK_LOG","Unable in fluid_player_add\n");
- return 0;
- }
- success = fluid_player_play(player);
- if(FLUID_OK == success) {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Successful in fluid_player_play\n");
- } else {
- __android_log_print(ANDROID_LOG_ERROR, "NDK_LOG","Unable in fluid_player_play\n");
- return 0;
- }
- renderer = new_fluid_file_renderer (synth);
- while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING)
- {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","FLUID_PLAYER_PLAYING\n");
- if (fluid_file_renderer_process_block(renderer) != FLUID_OK)
- {
- break;
- } else {
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","fluid_file_renderer_process_block != FLUID_OK\n");
- }
- }
- // just for sure: stop the playback explicitly and wait until finished
- fluid_player_stop(player);
- fluid_player_join(player);
- delete_fluid_file_renderer(renderer);
- delete_fluid_player(player);
- delete_fluid_synth(synth);
- delete_fluid_settings(settings);
- env->ReleaseStringUTFChars(outFile, outFileChar);
- env->ReleaseStringUTFChars(midiFile, midiFileChar);
- env->ReleaseStringUTFChars(soundfontFile, soundfontFileChar);
- __android_log_print(ANDROID_LOG_VERBOSE, "NDK_LOG","Success in going over the function for generating file\n");
- return 1;
- }
Add Comment
Please, Sign In to add comment