|
From: | Владимир Рыжак |
Subject: | [fluid-dev] fluidsynth export single midi channel to wav |
Date: | Sat, 24 Oct 2020 00:12:04 +0300 |
Hi!
I'm very new to the music tech so bear with me.
There are 16 channels in a midi file. I'm trying to convert only 1 channel from a midi file to wav.
Here is how it works now:
extern "C" JNIEXPORT void JNICALL Java_com_test_MainActivity_convertMidiToWav(JNIEnv* env, jobject, jstring jSoundfontPath, jstring jOutputWavPath, jstring jMidiPath, jint jChannel) {
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
const char* outputWavPath = env->GetStringUTFChars(jOutputWavPath, nullptr);
fluid_settings_setstr(settings, "audio.file.name", outputWavPath);
// since this is a non-realtime scenario, there is no need to pin the sample data
fluid_settings_setint(settings, "synth.lock-memory", 0);
synth = new_fluid_synth(settings);
// set basic channel
fluid_synth_reset_basic_channel(synth, -1);
fluid_synth_set_basic_channel(synth, jChannel, FLUID_CHANNEL_MODE_OMNION_MONO, 1);
// Load sample soundfont
const char* soundfontPath = env->GetStringUTFChars(jSoundfontPath, nullptr);
fluid_synth_sfload(synth, soundfontPath, 1);
const char* midiPath = env->GetStringUTFChars(jMidiPath, nullptr);
player = new_fluid_player(synth);
fluid_player_add(player, midiPath);
fluid_player_play(player);
renderer = new_fluid_file_renderer (synth);
while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING)
{
if (fluid_file_renderer_process_block(renderer) != FLUID_OK)
{
break;
}
}
// 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);
}
Notice these 2 lines:
fluid_synth_reset_basic_channel(synth, -1);
fluid_synth_set_basic_channel(synth, jChannel, FLUID_CHANNEL_MODE_OMNION_MONO, 1);
jChannel
is the midi channel number(1-16). I'm not really sure whether I'm doing it right.
Could somebody tell me how to convert exactly 1 midi channel to wav? Does the above code convert only a single channel?
Thanks in advance
[Prev in Thread] | Current Thread | [Next in Thread] |