[vlc-devel] [PATCH 04/16] aout: handle Ambisonics conversions

Thomas Guillem thomas at gllm.fr
Fri Jul 7 16:02:50 CEST 2017


---
 src/audio_output/dec.c     |  8 +++++++-
 src/audio_output/filters.c | 31 ++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index dbf707113a..54d58fe818 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -86,16 +86,22 @@ int aout_DecNew( audio_output_t *p_aout,
     owner->input_format = *p_format;
     owner->mixer_format = owner->input_format;
 
-    if (i_map_channels == 0)
+    if (p_format->channels_type == AUDIO_CHANNELS_TYPE_AMBISONICS)
+    {
+        /* Ambisonics filters are FL32 only */
+        owner->mixer_format.i_format = VLC_CODEC_FL32;
+    } else if (i_map_channels == 0)
     {
         /* The output channel map is unknown, use the default one (wg4) */
         assert(owner->mixer_format.i_channels > 0);
         aout_SetDefaultPhysicalChannels(&owner->mixer_format);
     }
+
     owner->request_vout = *p_request_vout;
 
     if (aout_OutputNew (p_aout, &owner->mixer_format))
         goto error;
+
     aout_volume_SetFormat (owner->volume, owner->mixer_format.i_format);
 
     /* Create the audio filtering "input" pipeline */
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index ec868d4a43..661bfb78a6 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -143,7 +143,8 @@ static int aout_FiltersPipelineCreate(vlc_object_t *obj, filter_t **filters,
 
     /* Remix channels */
     if (infmt->i_physical_channels != outfmt->i_physical_channels
-     || infmt->i_original_channels != outfmt->i_original_channels)
+     || infmt->i_original_channels != outfmt->i_original_channels
+     || infmt->channels_type != outfmt->channels_type)
     {   /* Remixing currently requires FL32... TODO: S16N */
         if (input.i_format != VLC_CODEC_FL32)
         {
@@ -171,7 +172,12 @@ static int aout_FiltersPipelineCreate(vlc_object_t *obj, filter_t **filters,
         output.i_original_channels = outfmt->i_original_channels;
         aout_FormatPrepare (&output);
 
-        filter_t *f = FindConverter (obj, &input, &output);
+        const char *filter_type =
+            infmt->channels_type != outfmt->channels_type ?
+            "audio renderer" : "audio converter";
+
+        filter_t *f = CreateFilter (obj, filter_type, NULL, NULL,
+                                    &input, &output);
         if (f == NULL)
         {
             msg_Err (obj, "cannot find %s for conversion pipeline",
@@ -448,7 +454,24 @@ aout_filters_t *aout_FiltersNew (vlc_object_t *obj,
         goto error;
     }
 
-    if (aout_FormatNbChannels(&input_format) == 0)
+    assert(output_format.channels_type == AUDIO_CHANNELS_TYPE_PHYSICAL);
+    if (input_format.channels_type != output_format.channels_type)
+    {
+        /* Do the channel type conversion before any filters since audio converters
+         * and filters handle only AUDIO_CHANNELS_TYPE_PHYSICAL */
+
+        /* convert to the output format (minus resampling) if necessary */
+        output_format.i_rate = input_format.i_rate;
+        if (aout_FiltersPipelineCreate (obj, filters->tab, &filters->count,
+                                  AOUT_MAX_FILTERS, &input_format, &output_format))
+        {
+            msg_Err (obj, "cannot setup audio renderer pipeline");
+            goto error;
+        }
+        input_format = output_format;
+        output_format.i_rate = outfmt->i_rate;
+    }
+    else if (aout_FormatNbChannels(&input_format) == 0)
     {
         /* The input channel map is unknown, use the default one (wg4) and add
          * a converter that will drop extra channels that are not handled by
@@ -470,6 +493,8 @@ aout_filters_t *aout_FiltersNew (vlc_object_t *obj,
         filters->tab[filters->count++] = f;
     }
 
+    assert(input_format.channels_type == AUDIO_CHANNELS_TYPE_PHYSICAL);
+
     /* parse user filter lists */
     if (var_InheritBool (obj, "audio-time-stretch"))
     {
-- 
2.11.0



More information about the vlc-devel mailing list