X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Ffluidsynth.c;h=0f25c89818dba34aa3c5dec5d305380d1d688b56;hb=5e896a268cc1c11ad1934aa70c378e0f94d12372;hp=0e3224944c11d61c26a6bc0398d2cdf5ca6c2456;hpb=be5d9107a6ba2160a0baa5ea51fc3c121265d5d2;p=vlc diff --git a/modules/codec/fluidsynth.c b/modules/codec/fluidsynth.c index 0e3224944c..0f25c89818 100644 --- a/modules/codec/fluidsynth.c +++ b/modules/codec/fluidsynth.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include /* On Win32, we link statically */ #ifdef WIN32 @@ -36,6 +38,13 @@ #include +#if (FLUIDSYNTH_VERSION_MAJOR < 1) \ + || (FLUIDSYNTH_VERSION_MAJOR == 1 && FLUIDSYNTH_VERSION_MINOR < 1) +# define fluid_synth_sysex(synth, ptr, len, d, e, f, g) (FLUID_FAILED) +# define fluid_synth_system_reset(synth) (FLUID_FAILED) +# define fluid_synth_channel_pressure(synth, channel, p) (FLUID_FAILED) +#endif + #define SOUNDFONT_TEXT N_("Sound fonts (required)") #define SOUNDFONT_LONGTEXT N_( \ "A sound fonts file is required for software synthesis." ) @@ -76,10 +85,14 @@ static int Open (vlc_object_t *p_this) if (p_dec->fmt_in.i_codec != VLC_CODEC_MIDI) return VLC_EGENERIC; - char *font_path = var_CreateGetNonEmptyString (p_this, "soundfont"); + char *font_path = var_InheritString (p_this, "soundfont"); if (font_path == NULL) { - msg_Err (p_this, "sound fonts file required for synthesis"); + msg_Err (p_this, "sound font file required for synthesis"); + dialog_Fatal (p_this, _("MIDI synthesis not set up"), + _("A sound font file (.SF2) is required for MIDI synthesis.\n" + "Please install a sound font and configure it " + "from the VLC preferences (Codecs / Audio / FluidSynth).\n")); return VLC_EGENERIC; } @@ -94,14 +107,22 @@ static int Open (vlc_object_t *p_this) p_sys->settings = new_fluid_settings (); p_sys->synth = new_fluid_synth (p_sys->settings); /* FIXME: I bet this is not thread-safe */ + const char *lpath = ToLocale (font_path); p_sys->soundfont = fluid_synth_sfload (p_sys->synth, font_path, 1); - free (font_path); + LocaleFree (lpath); if (p_sys->soundfont == -1) { - msg_Err (p_this, "cannot load sound fonts file"); + msg_Err (p_this, "cannot load sound fonts file %s", font_path); Close (p_this); + dialog_Fatal (p_this, _("MIDI synthesis not set up"), + _("The specified sound font file (%s) is incorrect.\n" + "Please install a valid sound font and reconfigure it " + "from the VLC preferences (Codecs / Audio / FluidSynth).\n"), + font_path); + free (font_path); return VLC_EGENERIC; } + free (font_path); p_dec->fmt_out.i_cat = AUDIO_ES; p_dec->fmt_out.audio.i_rate = 44100; @@ -109,7 +130,7 @@ static int Open (vlc_object_t *p_this) p_dec->fmt_out.audio.i_original_channels = p_dec->fmt_out.audio.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; - if (vlc_CPU () & CPU_CAPABILITY_FPU) + if (HAVE_FPU) { p_dec->fmt_out.i_codec = VLC_CODEC_FL32; p_dec->fmt_out.audio.i_bitspersample = 32; @@ -153,7 +174,7 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block) return NULL; *pp_block = NULL; - if (p_block->i_pts && !date_Get (&p_sys->end_date)) + if (p_block->i_pts > VLC_TS_INVALID && !date_Get (&p_sys->end_date)) date_Set (&p_sys->end_date, p_block->i_pts); else if (p_block->i_pts < date_Get (&p_sys->end_date)) @@ -165,11 +186,32 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block) if (p_block->i_buffer < 1) goto drop; + uint8_t event = p_block->p_buffer[0]; uint8_t channel = p_block->p_buffer[0] & 0xf; + event &= 0xF0; + + if (event == 0xF0) + switch (channel) + { + case 0: + if (p_block->p_buffer[p_block->i_buffer - 1] != 0xF7) + { + case 7: + msg_Warn (p_dec, "fragmented SysEx not implemented"); + goto drop; + } + fluid_synth_sysex (p_sys->synth, (char *)p_block->p_buffer + 1, + p_block->i_buffer - 2, NULL, NULL, NULL, 0); + break; + case 0xF: + fluid_synth_system_reset (p_sys->synth); + break; + } + uint8_t p1 = (p_block->i_buffer > 1) ? (p_block->p_buffer[1] & 0x7f) : 0; uint8_t p2 = (p_block->i_buffer > 2) ? (p_block->p_buffer[2] & 0x7f) : 0; - switch (p_block->p_buffer[0] & 0xf0) + switch (event & 0xF0) { case 0x80: fluid_synth_noteoff (p_sys->synth, channel, p1); @@ -177,14 +219,18 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block) case 0x90: fluid_synth_noteon (p_sys->synth, channel, p1, p2); break; + /*case 0xA0: note aftertouch not implemented */ case 0xB0: fluid_synth_cc (p_sys->synth, channel, p1, p2); break; case 0xC0: fluid_synth_program_change (p_sys->synth, channel, p1); break; + case 0xD0: + fluid_synth_channel_pressure (p_sys->synth, channel, p1); + break; case 0xE0: - fluid_synth_pitch_bend (p_sys->synth, channel, (p1 << 7) | p2); + fluid_synth_pitch_bend (p_sys->synth, channel, (p2 << 7) | p1); break; } @@ -197,8 +243,9 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block) if (p_out == NULL) goto drop; - p_out->start_date = date_Get (&p_sys->end_date ); - p_out->end_date = date_Increment (&p_sys->end_date, samples); + p_out->i_pts = date_Get (&p_sys->end_date ); + p_out->i_length = date_Increment (&p_sys->end_date, samples) + - p_out->i_pts; if (!p_sys->fixed) fluid_synth_write_float (p_sys->synth, samples, p_out->p_buffer, 0, 2,