2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 /* This effect is borrowed from xmms-0.6.1, though I mangled it so badly in
21 * the process of copying it over that the xmms people probably won't want
22 * any credit for it ;-)
25 * SECTION:element-stereo
27 * Create a wide stereo effect.
30 * <title>Example pipelines</title>
32 * gst-launch-1.0 -v filesrc location=sine.ogg ! oggdemux ! vorbisdec ! audioconvert ! stereo ! audioconvert ! audioresample ! alsasink
33 * ]| Play an Ogg/Vorbis file.
40 #include "gststereo.h"
43 #include <gst/base/gstbasetransform.h>
44 #include <gst/audio/audio.h>
45 #include <gst/audio/gstaudiofilter.h>
47 #define ALLOWED_CAPS \
49 " format = "GST_AUDIO_NE (S16) "," \
50 " rate = (int) [ 1, MAX ]," \
53 /* Stereo signals and args */
67 static void gst_stereo_set_property (GObject * object, guint prop_id,
68 const GValue * value, GParamSpec * pspec);
69 static void gst_stereo_get_property (GObject * object, guint prop_id,
70 GValue * value, GParamSpec * pspec);
72 static GstFlowReturn gst_stereo_transform_ip (GstBaseTransform * base,
75 G_DEFINE_TYPE (GstStereo, gst_stereo, GST_TYPE_AUDIO_FILTER);
78 gst_stereo_class_init (GstStereoClass * klass)
80 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
81 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
82 GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass);
83 GstAudioFilterClass *audiofilter_class = GST_AUDIO_FILTER_CLASS (klass);
86 gst_element_class_set_static_metadata (element_class, "Stereo effect",
87 "Filter/Effect/Audio",
88 "Muck with the stereo signal to enhance its 'stereo-ness'",
89 "Erik Walthinsen <omega@cse.ogi.edu>");
91 caps = gst_caps_from_string (ALLOWED_CAPS);
92 gst_audio_filter_class_add_pad_templates (audiofilter_class, caps);
93 gst_caps_unref (caps);
95 gobject_class->set_property = gst_stereo_set_property;
96 gobject_class->get_property = gst_stereo_get_property;
98 g_object_class_install_property (gobject_class, PROP_ACTIVE,
99 g_param_spec_boolean ("active", "active", "active",
101 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
103 g_object_class_install_property (gobject_class, PROP_STEREO,
104 g_param_spec_float ("stereo", "stereo", "stereo",
106 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
108 trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_stereo_transform_ip);
112 gst_stereo_init (GstStereo * stereo)
114 stereo->active = TRUE;
115 stereo->stereo = 0.1f;
119 gst_stereo_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
121 GstStereo *stereo = GST_STEREO (base);
124 gdouble avg, ldiff, rdiff, tmp;
125 gdouble mul = stereo->stereo;
129 if (!gst_buffer_map (outbuf, &info, GST_MAP_READWRITE))
130 return GST_FLOW_ERROR;
132 data = (gint16 *) info.data;
133 samples = info.size / 2;
135 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (outbuf)))
136 gst_object_sync_values (GST_OBJECT (stereo), GST_BUFFER_TIMESTAMP (outbuf));
138 if (stereo->active) {
139 for (i = 0; i < samples / 2; i += 2) {
140 avg = (data[i] + data[i + 1]) / 2;
141 ldiff = data[i] - avg;
142 rdiff = data[i + 1] - avg;
144 tmp = avg + ldiff * mul;
151 tmp = avg + rdiff * mul;
160 gst_buffer_unmap (outbuf, &info);
166 gst_stereo_set_property (GObject * object, guint prop_id, const GValue * value,
169 GstStereo *stereo = GST_STEREO (object);
173 stereo->active = g_value_get_boolean (value);
176 stereo->stereo = g_value_get_float (value) * 10.0;
179 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
185 gst_stereo_get_property (GObject * object, guint prop_id, GValue * value,
188 GstStereo *stereo = GST_STEREO (object);
192 g_value_set_boolean (value, stereo->active);
195 g_value_set_float (value, stereo->stereo / 10.0);
198 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204 plugin_init (GstPlugin * plugin)
206 return gst_element_register (plugin, "stereo", GST_RANK_NONE,
210 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
213 "Muck with the stereo signal, enhance it's 'stereo-ness'",
214 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)