[vlc-commits] [Git][videolan/vlc][master] audio_filter: add stereo_pan filter

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Jul 3 11:21:56 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
dd2456bf by Vedanta Nayak at 2021-07-03T11:21:51+00:00
audio_filter: add stereo_pan filter

- - - - -


5 changed files:

- modules/audio_filter/Makefile.am
- + modules/audio_filter/stereo_pan.c
- modules/gui/qt/dialogs/extended/extended.cpp
- modules/gui/qt/dialogs/extended/extended_panels.cpp
- modules/gui/qt/dialogs/extended/extended_panels.hpp


Changes:

=====================================
modules/audio_filter/Makefile.am
=====================================
@@ -35,6 +35,8 @@ libspatializer_plugin_la_SOURCES = \
 libspatializer_plugin_la_LIBADD = $(LIBM)
 libcenter_plugin_la_SOURCES = audio_filter/center.c
 libcenter_plugin_la_LIBADD  = $(LIBM)
+libstereopan_plugin_la_SOURCES = audio_filter/stereo_pan.c
+libstereopan_plugin_la_LIBADD = $(LIBM)
 
 audio_filter_LTLIBRARIES = \
 	libaudiobargraph_a_plugin.la \
@@ -49,7 +51,8 @@ audio_filter_LTLIBRARIES = \
 	libscaletempo_pitch_plugin.la \
 	libspatializer_plugin.la \
 	libstereo_widen_plugin.la \
-	libcenter_plugin.la
+	libcenter_plugin.la \
+	libstereopan_plugin.la
 
 # Channel mixers
 libdolby_surround_decoder_plugin_la_SOURCES = \


=====================================
modules/audio_filter/stereo_pan.c
=====================================
@@ -0,0 +1,121 @@
+/*****************************************************************************
+ * stereo_pan.c : Stereo panning filter
+ *****************************************************************************
+ * Copyright © 2021 VLC authors and VideoLAN
+ *
+ * Authors: Vedanta Nayak <vedantnayak2 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_aout.h>
+#include <vlc_filter.h>
+#include <vlc_plugin.h>
+#include <stdatomic.h>
+
+#define PAN_CONTROL_TEXT N_("Pan control")
+#define PAN_CONTROL_LONGTEXT N_(\
+        "Set pan control between 0 (left) and 1 (right). Default: 0.5")
+
+typedef struct
+{
+    _Atomic float f_pan;
+}filter_sys_t;
+
+static block_t *Process ( filter_t *p_filter, block_t *p_in_buf )
+{
+    filter_sys_t *p_sys = p_filter->p_sys;
+    float *p_in = (float *)p_in_buf->p_buffer;
+    size_t i_nb_samples = p_in_buf->i_nb_samples;
+    size_t i_nb_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
+    float f_pan = atomic_load( &p_sys->f_pan );
+
+    for ( size_t i = 0 ; i < i_nb_samples ; ++i )
+    {
+        float f_left = p_in[ i * i_nb_channels ];
+        float f_right = p_in[ i * i_nb_channels + 1 ];
+        p_in[ i * i_nb_channels ] = f_left * (1 - f_pan);
+        p_in[ i * i_nb_channels + 1 ] = f_right * f_pan;
+    }
+    return p_in_buf;
+}
+
+static int paramCallback( vlc_object_t *p_this, char const *psz_var,
+                          vlc_value_t oldval, vlc_value_t newval,
+                          void *p_data)
+{
+    filter_sys_t *p_sys = (filter_sys_t *) p_data;
+
+    VLC_UNUSED(oldval);
+    VLC_UNUSED(p_this);
+    VLC_UNUSED(psz_var);
+
+    atomic_store( &p_sys->f_pan, newval.f_float);
+
+    return VLC_SUCCESS;
+}
+
+static void Close (vlc_object_t *p_in)
+{
+    filter_t *p_filter = (filter_t *)p_in;
+    filter_sys_t *p_sys = p_filter->p_sys;
+    vlc_object_t *p_aout = vlc_object_parent(p_filter);
+    var_DelCallback( p_aout, "pan-control", paramCallback, p_sys );
+    var_Destroy( p_aout, "pan-control" );
+    free(p_sys);
+}
+
+static int Open (filter_t *p_filter)
+{
+    if (p_filter->fmt_out.audio.i_channels < 2) {
+        msg_Err( p_filter, "Atleast 2 audio channels are required" );
+        return VLC_EGENERIC;
+    }
+    vlc_object_t *p_aout = vlc_object_parent(p_filter);
+    filter_sys_t *p_sys = p_filter->p_sys = malloc( sizeof(*p_sys) );
+    if (unlikely(!p_sys))
+        return VLC_ENOMEM;
+
+    atomic_init( &p_sys->f_pan,
+            var_CreateGetFloat( p_aout, "pan-control" ) );
+    var_AddCallback( p_aout, "pan-control", paramCallback, p_sys );
+
+    p_filter->fmt_out.audio.i_format = VLC_CODEC_FL32;
+    p_filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
+    aout_FormatPrepare( &p_filter->fmt_in.audio );
+    aout_FormatPrepare( &p_filter->fmt_out.audio );
+
+    static const struct vlc_filter_operations filter_ops =
+    {
+        .filter_audio = Process,
+    };
+    p_filter->ops = &filter_ops;
+    return VLC_SUCCESS;
+}
+
+vlc_module_begin()
+    set_shortname ( N_("Stereo Pan") )
+    set_description ( N_("Perform Stereo Panning") )
+    set_category ( CAT_AUDIO )
+    set_subcategory ( SUBCAT_AUDIO_AFILTER )
+    add_float_with_range( "pan-control", 0.5, 0, 1,
+            PAN_CONTROL_TEXT, PAN_CONTROL_LONGTEXT )
+    set_capability ( "audio filter", 0 )
+    set_callbacks ( Open, Close )
+vlc_module_end ()


=====================================
modules/gui/qt/dialogs/extended/extended.cpp
=====================================
@@ -85,8 +85,12 @@ ExtendedDialog::ExtendedDialog( qt_intf_t *_p_intf )
     PitchShifter *pitchshifter = new PitchShifter( p_intf, audioTab );
     CONNECT( pitchshifter, configChanged(QString, QVariant), this, putAudioConfig(QString, QVariant) );
 
-    advancedTabLayout->setColumnStretch( 1, 10 );
+    StereoPanner *stereopanner = new StereoPanner( p_intf, audioTab );
+    CONNECT( stereopanner, configChanged(QString, QVariant), this, putAudioConfig(QString, QVariant) );
+
+    advancedTabLayout->setColumnStretch( 2, 10 );
     advancedTabLayout->addWidget( pitchshifter );
+    advancedTabLayout->addWidget( stereopanner );
 
     advancedTab->setLayout( advancedTabLayout );
     audioTab->addTab( advancedTab, qtr( "Advanced" ) );


=====================================
modules/gui/qt/dialogs/extended/extended_panels.cpp
=====================================
@@ -1326,6 +1326,15 @@ PitchShifter::PitchShifter( qt_intf_t *p_intf, QWidget *parent )
     build();
 }
 
+StereoPanner::StereoPanner( qt_intf_t *p_intf, QWidget *parent )
+    : AudioFilterControlWidget( p_intf, parent, "stereo_pan" )
+{
+    i_smallfont = -1;
+    controls.append( { "pan-control", qtr("Adjust pan"), "", 0.0, 1.0,
+            0.5, 0.1, 1.0 } );
+    build();
+}
+
 #include <QToolButton>
 #include <QGridLayout>
 


=====================================
modules/gui/qt/dialogs/extended/extended_panels.hpp
=====================================
@@ -224,6 +224,14 @@ public:
     PitchShifter( qt_intf_t *, QWidget * );
 };
 
+class StereoPanner: public AudioFilterControlWidget
+{
+    Q_OBJECT
+
+public:
+    StereoPanner( qt_intf_t *, QWidget * );
+};
+
 class SyncWidget : public QWidget
 {
     Q_OBJECT



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/dd2456bf56ffa9abbf6d7a154cf686deffacfc54

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/dd2456bf56ffa9abbf6d7a154cf686deffacfc54
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list