]> git.sesse.net Git - vlc/blobdiff - modules/codec/fluidsynth.c
Cosmetics.
[vlc] / modules / codec / fluidsynth.c
index 600353fa3ca9604f34bade2c72691a79ce6fecc3..8590de93a88541e9e740463b2224320e625e1a04 100644 (file)
 #include <vlc_plugin.h>
 #include <vlc_aout.h>
 #include <vlc_codec.h>
+#include <vlc_cpu.h>
+
+/* On Win32, we link statically */
+#ifdef WIN32
+# define FLUIDSYNTH_NOT_A_DLL
+#endif
 
 #include <fluidsynth.h>
 
 static int  Open  (vlc_object_t *);
 static void Close (vlc_object_t *);
 
-vlc_module_begin();
-    set_description (N_("FluidSynth MIDI synthetizer"));
-    set_capability ("decoder", 100);
-    set_category (CAT_INPUT);
-    set_subcategory (SUBCAT_INPUT_ACODEC);
-    set_callbacks (Open, Close);
+vlc_module_begin ()
+    set_description (N_("FluidSynth MIDI synthetizer"))
+    set_capability ("decoder", 100)
+    set_shortname (N_("FluidSynth"))
+    set_category (CAT_INPUT)
+    set_subcategory (SUBCAT_INPUT_ACODEC)
+    set_callbacks (Open, Close)
     add_file ("soundfont", "", NULL,
               SOUNDFONT_TEXT, SOUNDFONT_LONGTEXT, false);
-vlc_module_end();
+vlc_module_end ()
 
 
 struct decoder_sys_t
@@ -53,7 +60,8 @@ struct decoder_sys_t
     fluid_settings_t *settings;
     fluid_synth_t    *synth;
     int               soundfont;
-    audio_date_t      end_date;
+    bool              fixed;
+    date_t            end_date;
 };
 
 
@@ -65,7 +73,7 @@ static int Open (vlc_object_t *p_this)
     decoder_t *p_dec = (decoder_t *)p_this;
     decoder_sys_t *p_sys;
 
-    if (p_dec->fmt_in.i_codec != VLC_FOURCC ('M', 'I', 'D', 'I'))
+    if (p_dec->fmt_in.i_codec != VLC_CODEC_MIDI)
         return VLC_EGENERIC;
 
     char *font_path = var_CreateGetNonEmptyString (p_this, "soundfont");
@@ -75,15 +83,6 @@ static int Open (vlc_object_t *p_this)
         return VLC_EGENERIC;
     }
 
-    p_dec->fmt_out.i_cat = AUDIO_ES;
-    p_dec->fmt_out.audio.i_rate = 44100;
-    p_dec->fmt_out.audio.i_channels = 2;
-    p_dec->fmt_out.audio.i_original_channels =
-    p_dec->fmt_out.audio.i_physical_channels =
-        AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
-    p_dec->fmt_out.i_codec = VLC_FOURCC('f', 'l', '3', '2');
-    p_dec->fmt_out.audio.i_bitspersample = 32;
-
     p_dec->pf_decode_audio = DecodeBlock;
     p_sys = p_dec->p_sys = malloc (sizeof (*p_sys));
     if (p_sys == NULL)
@@ -104,8 +103,26 @@ static int Open (vlc_object_t *p_this)
         return VLC_EGENERIC;
     }
 
-    aout_DateInit (&p_sys->end_date, p_dec->fmt_out.audio.i_rate);
-    aout_DateSet (&p_sys->end_date, 0);
+    p_dec->fmt_out.i_cat = AUDIO_ES;
+    p_dec->fmt_out.audio.i_rate = 44100;
+    p_dec->fmt_out.audio.i_channels = 2;
+    p_dec->fmt_out.audio.i_original_channels =
+    p_dec->fmt_out.audio.i_physical_channels =
+        AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
+    if (HAVE_FPU)
+    {
+        p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
+        p_dec->fmt_out.audio.i_bitspersample = 32;
+        p_sys->fixed = false;
+    }
+    else
+    {
+        p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
+        p_dec->fmt_out.audio.i_bitspersample = 16;
+        p_sys->fixed = true;
+    }
+    date_Init (&p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1);
+    date_Set (&p_sys->end_date, 0);
 
     return VLC_SUCCESS;
 }
@@ -127,25 +144,26 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
 {
     block_t *p_block;
     decoder_sys_t *p_sys = p_dec->p_sys;
+    aout_buffer_t *p_out = NULL;
 
     if (pp_block == NULL)
         return NULL;
     p_block = *pp_block;
     if (p_block == NULL)
         return NULL;
+    *pp_block = NULL;
 
-    if (p_block->i_pts && !aout_DateGet (&p_sys->end_date))
-        aout_DateSet (&p_sys->end_date, p_block->i_pts);
+    if (p_block->i_pts && !date_Get (&p_sys->end_date))
+        date_Set (&p_sys->end_date, p_block->i_pts);
     else
-    if (p_block->i_pts < aout_DateGet (&p_sys->end_date))
+    if (p_block->i_pts < date_Get (&p_sys->end_date))
     {
         msg_Warn (p_dec, "MIDI message in the past?");
-        block_Release (p_block);
-        return NULL;
+        goto drop;
     }
 
     if (p_block->i_buffer < 1)
-        return NULL;
+        goto drop;
 
     uint8_t channel = p_block->p_buffer[0] & 0xf;
     uint8_t p1 = (p_block->i_buffer > 1) ? (p_block->p_buffer[1] & 0x7f) : 0;
@@ -169,25 +187,28 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
             fluid_synth_pitch_bend (p_sys->synth, channel, (p1 << 7) | p2);
             break;
     }
-    p_block->p_buffer += p_block->i_buffer;
-    p_block->i_buffer = 0;
 
     unsigned samples =
-        (p_block->i_pts - aout_DateGet (&p_sys->end_date)) * 441 / 10000;
+        (p_block->i_pts - date_Get (&p_sys->end_date)) * 441 / 10000;
     if (samples == 0)
         return NULL;
 
-    aout_buffer_t *p_out = p_dec->pf_aout_buffer_new (p_dec, samples);
+    p_out = decoder_NewAudioBuffer (p_dec, samples);
     if (p_out == NULL)
-    {
-        block_Release (p_block);
-        return NULL;
-    }
-
-    p_out->start_date = aout_DateGet (&p_sys->end_date );
-    p_out->end_date   = aout_DateIncrement (&p_sys->end_date, samples);
-    fluid_synth_write_float (p_sys->synth, samples,
-                             p_out->p_buffer, 0, 2,
-                             p_out->p_buffer, 1, 2);
+        goto drop;
+
+    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,
+                                 p_out->p_buffer, 1, 2);
+    else
+        fluid_synth_write_s16 (p_sys->synth, samples,
+                               (int16_t *)p_out->p_buffer, 0, 2,
+                               (int16_t *)p_out->p_buffer, 1, 2);
+drop:
+    block_Release (p_block);
     return p_out;
 }