mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 19:20:35 +00:00
audiofx: Add plugin, add audiochannelmix
This commit is contained in:
parent
127fcf05a7
commit
35018ae632
5 changed files with 398 additions and 0 deletions
|
@ -357,6 +357,7 @@ AG_GST_CHECK_PLUGIN(adpcmdec)
|
|||
AG_GST_CHECK_PLUGIN(adpcmenc)
|
||||
AG_GST_CHECK_PLUGIN(aiff)
|
||||
AG_GST_CHECK_PLUGIN(asfmux)
|
||||
AG_GST_CHECK_PLUGIN(audiofxbad)
|
||||
AG_GST_CHECK_PLUGIN(audiovisualizers)
|
||||
AG_GST_CHECK_PLUGIN(autoconvert)
|
||||
AG_GST_CHECK_PLUGIN(bayer)
|
||||
|
@ -2339,6 +2340,7 @@ gst/adpcmdec/Makefile
|
|||
gst/adpcmenc/Makefile
|
||||
gst/aiff/Makefile
|
||||
gst/asfmux/Makefile
|
||||
gst/audiofxbad/Makefile
|
||||
gst/audiovisualizers/Makefile
|
||||
gst/autoconvert/Makefile
|
||||
gst/bayer/Makefile
|
||||
|
|
28
gst/audiofxbad/Makefile.am
Normal file
28
gst/audiofxbad/Makefile.am
Normal file
|
@ -0,0 +1,28 @@
|
|||
plugin_LTLIBRARIES = libgstaudiofxbad.la
|
||||
|
||||
libgstaudiofxbad_la_SOURCES = gstaudiofxbad.c \
|
||||
gstaudiochannelmix.c gstaudiochannelmix.h
|
||||
|
||||
libgstaudiofxbad_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) \
|
||||
$(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) \
|
||||
$(GST_CFLAGS)
|
||||
libgstaudiofxbad_la_LIBADD = \
|
||||
$(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_API_VERSION) \
|
||||
$(GST_BASE_LIBS) $(GST_LIBS) $(LIBM)
|
||||
libgstaudiofxbad_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||
libgstaudiofxbad_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
|
||||
|
||||
Android.mk: Makefile.am $(BUILT_SOURCES)
|
||||
androgenizer \
|
||||
-:PROJECT audiofxbad -:SHARED audiofxbad \
|
||||
-:TAGS eng debug \
|
||||
-:REL_TOP $(top_srcdir) -:ABS_TOP $(abs_top_srcdir) \
|
||||
-:SOURCES $(libgstaudiofxbad_la_SOURCES) \
|
||||
-:CFLAGS $(DEFS) $(DEFAULT_INCLUDES) $(libgstaudiofxbad_la_CFLAGS) \
|
||||
-:LDFLAGS $(libgstaudiofxbad_la_LDFLAGS) \
|
||||
$(libgstaudiofxbad_la_LIBADD) \
|
||||
-ldl \
|
||||
-:PASSTHROUGH LOCAL_ARM_MODE:=arm \
|
||||
LOCAL_MODULE_PATH:='$$(TARGET_OUT)/lib/gstreamer-1.0' \
|
||||
> $@
|
||||
|
276
gst/audiofxbad/gstaudiochannelmix.c
Normal file
276
gst/audiofxbad/gstaudiochannelmix.c
Normal file
|
@ -0,0 +1,276 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2013 David Schleef <ds@schleef.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
|
||||
* Boston, MA 02110-1335, USA.
|
||||
*/
|
||||
/**
|
||||
* SECTION:element-gstaudiochannelmix
|
||||
*
|
||||
* The audiochannelmix element mixes channels in stereo audio based on
|
||||
* properties set on the element. The primary purpose is reconstruct
|
||||
* equal left/right channels on an input stream that has audio in only
|
||||
* one channel.
|
||||
*
|
||||
* <refsect2>
|
||||
* <title>Example launch line</title>
|
||||
* |[
|
||||
* gst-launch -v audiotestsrc ! audiochannelmix ! autoaudiosink
|
||||
* ]|
|
||||
* </refsect2>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/audio/gstaudiofilter.h>
|
||||
#include "gstaudiochannelmix.h"
|
||||
#include <math.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_audio_channel_mix_debug_category);
|
||||
#define GST_CAT_DEFAULT gst_audio_channel_mix_debug_category
|
||||
|
||||
/* prototypes */
|
||||
|
||||
|
||||
static void gst_audio_channel_mix_set_property (GObject * object,
|
||||
guint property_id, const GValue * value, GParamSpec * pspec);
|
||||
static void gst_audio_channel_mix_get_property (GObject * object,
|
||||
guint property_id, GValue * value, GParamSpec * pspec);
|
||||
static void gst_audio_channel_mix_dispose (GObject * object);
|
||||
static void gst_audio_channel_mix_finalize (GObject * object);
|
||||
|
||||
static gboolean gst_audio_channel_mix_setup (GstAudioFilter * filter,
|
||||
const GstAudioInfo * info);
|
||||
static GstFlowReturn gst_audio_channel_mix_transform_ip (GstBaseTransform *
|
||||
trans, GstBuffer * buf);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_LEFT_TO_LEFT,
|
||||
PROP_LEFT_TO_RIGHT,
|
||||
PROP_RIGHT_TO_LEFT,
|
||||
PROP_RIGHT_TO_RIGHT
|
||||
};
|
||||
|
||||
/* pad templates */
|
||||
|
||||
static GstStaticPadTemplate gst_audio_channel_mix_src_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw,format=S16LE,rate=[1,max],"
|
||||
"channels=2,layout=interleaved")
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate gst_audio_channel_mix_sink_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw,format=S16LE,rate=[1,max],"
|
||||
"channels=2,layout=interleaved")
|
||||
);
|
||||
|
||||
|
||||
/* class initialization */
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GstAudioChannelMix, gst_audio_channel_mix,
|
||||
GST_TYPE_AUDIO_FILTER,
|
||||
GST_DEBUG_CATEGORY_INIT (gst_audio_channel_mix_debug_category,
|
||||
"audiochannelmix", 0, "debug category for audiochannelmix element"));
|
||||
|
||||
static void
|
||||
gst_audio_channel_mix_class_init (GstAudioChannelMixClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstBaseTransformClass *base_transform_class =
|
||||
GST_BASE_TRANSFORM_CLASS (klass);
|
||||
GstAudioFilterClass *audio_filter_class = GST_AUDIO_FILTER_CLASS (klass);
|
||||
|
||||
/* Setting up pads and setting metadata should be moved to
|
||||
base_class_init if you intend to subclass this class. */
|
||||
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
|
||||
gst_static_pad_template_get (&gst_audio_channel_mix_src_template));
|
||||
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
|
||||
gst_static_pad_template_get (&gst_audio_channel_mix_sink_template));
|
||||
|
||||
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
|
||||
"Simple stereo audio mixer", "Audio/Mixer", "Mixes left/right channels "
|
||||
"of stereo audio", "David Schleef <ds@schleef.org>");
|
||||
|
||||
gobject_class->set_property = gst_audio_channel_mix_set_property;
|
||||
gobject_class->get_property = gst_audio_channel_mix_get_property;
|
||||
gobject_class->dispose = gst_audio_channel_mix_dispose;
|
||||
gobject_class->finalize = gst_audio_channel_mix_finalize;
|
||||
audio_filter_class->setup = GST_DEBUG_FUNCPTR (gst_audio_channel_mix_setup);
|
||||
base_transform_class->transform_ip =
|
||||
GST_DEBUG_FUNCPTR (gst_audio_channel_mix_transform_ip);
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_LEFT_TO_LEFT,
|
||||
g_param_spec_double ("left-to-left", "Left to Left",
|
||||
"Left channel to left channel gain",
|
||||
-G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
|
||||
GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_LEFT_TO_RIGHT,
|
||||
g_param_spec_double ("left-to-right", "Left to Right",
|
||||
"Left channel to right channel gain",
|
||||
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
|
||||
GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_RIGHT_TO_LEFT,
|
||||
g_param_spec_double ("right-to-left", "Right to Left",
|
||||
"Right channel to left channel gain",
|
||||
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
|
||||
GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_RIGHT_TO_RIGHT,
|
||||
g_param_spec_double ("right-to-right", "Right to Right",
|
||||
"Right channel to right channel gain",
|
||||
-G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
|
||||
GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
gst_audio_channel_mix_init (GstAudioChannelMix * audiochannelmix)
|
||||
{
|
||||
audiochannelmix->left_to_left = 1.0;
|
||||
audiochannelmix->left_to_right = 0.0;
|
||||
audiochannelmix->right_to_left = 0.0;
|
||||
audiochannelmix->right_to_right = 1.0;
|
||||
}
|
||||
|
||||
void
|
||||
gst_audio_channel_mix_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstAudioChannelMix *audiochannelmix = GST_AUDIO_CHANNEL_MIX (object);
|
||||
|
||||
GST_DEBUG_OBJECT (audiochannelmix, "set_property");
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_LEFT_TO_LEFT:
|
||||
audiochannelmix->left_to_left = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_LEFT_TO_RIGHT:
|
||||
audiochannelmix->left_to_right = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_RIGHT_TO_LEFT:
|
||||
audiochannelmix->right_to_left = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_RIGHT_TO_RIGHT:
|
||||
audiochannelmix->right_to_right = g_value_get_double (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gst_audio_channel_mix_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstAudioChannelMix *audiochannelmix = GST_AUDIO_CHANNEL_MIX (object);
|
||||
|
||||
GST_DEBUG_OBJECT (audiochannelmix, "get_property");
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_LEFT_TO_LEFT:
|
||||
g_value_set_double (value, audiochannelmix->left_to_left);
|
||||
break;
|
||||
case PROP_LEFT_TO_RIGHT:
|
||||
g_value_set_double (value, audiochannelmix->left_to_right);
|
||||
break;
|
||||
case PROP_RIGHT_TO_LEFT:
|
||||
g_value_set_double (value, audiochannelmix->right_to_left);
|
||||
break;
|
||||
case PROP_RIGHT_TO_RIGHT:
|
||||
g_value_set_double (value, audiochannelmix->right_to_right);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gst_audio_channel_mix_dispose (GObject * object)
|
||||
{
|
||||
GstAudioChannelMix *audiochannelmix = GST_AUDIO_CHANNEL_MIX (object);
|
||||
|
||||
GST_DEBUG_OBJECT (audiochannelmix, "dispose");
|
||||
|
||||
/* clean up as possible. may be called multiple times */
|
||||
|
||||
G_OBJECT_CLASS (gst_audio_channel_mix_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
void
|
||||
gst_audio_channel_mix_finalize (GObject * object)
|
||||
{
|
||||
GstAudioChannelMix *audiochannelmix = GST_AUDIO_CHANNEL_MIX (object);
|
||||
|
||||
GST_DEBUG_OBJECT (audiochannelmix, "finalize");
|
||||
|
||||
/* clean up object here */
|
||||
|
||||
G_OBJECT_CLASS (gst_audio_channel_mix_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_audio_channel_mix_setup (GstAudioFilter * filter, const GstAudioInfo * info)
|
||||
{
|
||||
GstAudioChannelMix *audiochannelmix = GST_AUDIO_CHANNEL_MIX (filter);
|
||||
|
||||
GST_DEBUG_OBJECT (audiochannelmix, "setup");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_audio_channel_mix_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
||||
{
|
||||
GstAudioChannelMix *audiochannelmix = GST_AUDIO_CHANNEL_MIX (trans);
|
||||
int n;
|
||||
GstMapInfo map;
|
||||
int i;
|
||||
double ll = audiochannelmix->left_to_left;
|
||||
double lr = audiochannelmix->left_to_right;
|
||||
double rl = audiochannelmix->right_to_left;
|
||||
double rr = audiochannelmix->right_to_right;
|
||||
int l, r;
|
||||
gint16 *data;
|
||||
|
||||
GST_DEBUG_OBJECT (audiochannelmix, "transform_ip");
|
||||
|
||||
gst_buffer_map (buf, &map, GST_MAP_WRITE | GST_MAP_READ);
|
||||
|
||||
n = gst_buffer_get_size (buf) >> 2;
|
||||
data = (gint16 *) map.data;
|
||||
for (i = 0; i < n; i++) {
|
||||
l = data[2 * i + 0];
|
||||
r = data[2 * i + 1];
|
||||
data[2 * i + 0] = CLAMP (rint (ll * l + rl * r), -32768, 32767);
|
||||
data[2 * i + 1] = CLAMP (rint (lr * l + rr * r), -32768, 32767);
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buf, &map);
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
55
gst/audiofxbad/gstaudiochannelmix.h
Normal file
55
gst/audiofxbad/gstaudiochannelmix.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2013 FIXME <fixme@example.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GST_AUDIO_CHANNEL_MIX_H_
|
||||
#define _GST_AUDIO_CHANNEL_MIX_H_
|
||||
|
||||
#include <gst/audio/gstaudiofilter.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_AUDIO_CHANNEL_MIX (gst_audio_channel_mix_get_type())
|
||||
#define GST_AUDIO_CHANNEL_MIX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_CHANNEL_MIX,GstAudioChannelMix))
|
||||
#define GST_AUDIO_CHANNEL_MIX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_CHANNEL_MIX,GstAudioChannelMixClass))
|
||||
#define GST_IS_AUDIO_CHANNEL_MIX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_CHANNEL_MIX))
|
||||
#define GST_IS_AUDIO_CHANNEL_MIX_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_CHANNEL_MIX))
|
||||
|
||||
typedef struct _GstAudioChannelMix GstAudioChannelMix;
|
||||
typedef struct _GstAudioChannelMixClass GstAudioChannelMixClass;
|
||||
|
||||
struct _GstAudioChannelMix
|
||||
{
|
||||
GstAudioFilter base_audiochannelmix;
|
||||
|
||||
double left_to_left;
|
||||
double left_to_right;
|
||||
double right_to_left;
|
||||
double right_to_right;
|
||||
};
|
||||
|
||||
struct _GstAudioChannelMixClass
|
||||
{
|
||||
GstAudioFilterClass base_audiochannelmix_class;
|
||||
};
|
||||
|
||||
GType gst_audio_channel_mix_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
37
gst/audiofxbad/gstaudiofxbad.c
Normal file
37
gst/audiofxbad/gstaudiofxbad.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2013 David Schleef <ds@schleef.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
|
||||
* Boston, MA 02110-1335, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstaudiochannelmix.h"
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
return gst_element_register (plugin, "audiochannelmix", GST_RANK_NONE,
|
||||
GST_TYPE_AUDIO_CHANNEL_MIX);
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
audiochannelmix,
|
||||
"Audio filters from gst-plugins-bad",
|
||||
plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|
Loading…
Reference in a new issue