Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst / audiofx / audiopanorama.c
1 /*
2  * GStreamer
3  * Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
4  * Copyright (C) 2006 Sebastian Dröge <slomo@circular-chaos.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 /**
23  * SECTION:element-audiopanorama
24  *
25  * Stereo panorama effect with controllable pan position. One can choose between the default psychoacoustic panning method,
26  * which keeps the same perceived loudness, and a simple panning method that just controls the volume on one channel.
27  *
28  * <refsect2>
29  * <title>Example launch line</title>
30  * |[
31  * gst-launch audiotestsrc wave=saw ! audiopanorama panorama=-1.00 ! alsasink
32  * gst-launch filesrc location="melo1.ogg" ! oggdemux ! vorbisdec ! audioconvert ! audiopanorama panorama=-1.00 ! alsasink
33  * gst-launch audiotestsrc wave=saw ! audioconvert ! audiopanorama panorama=-1.00 ! audioconvert ! alsasink
34  * gst-launch audiotestsrc wave=saw ! audioconvert ! audiopanorama method=simple panorama=-0.50 ! audioconvert ! alsasink
35  * ]|
36  * </refsect2>
37  */
38
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42
43 #include <gst/gst.h>
44 #include <gst/base/gstbasetransform.h>
45 #include <gst/controller/gstcontroller.h>
46
47 #include "audiopanorama.h"
48
49 #define GST_CAT_DEFAULT gst_audio_panorama_debug
50 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
51
52 /* Filter signals and args */
53 enum
54 {
55   /* FILL ME */
56   LAST_SIGNAL
57 };
58
59 enum
60 {
61   PROP_0,
62   PROP_PANORAMA,
63   PROP_METHOD
64 };
65
66 enum
67 {
68   METHOD_PSYCHOACOUSTIC = 0,
69   METHOD_SIMPLE,
70   NUM_METHODS
71 };
72
73 #define GST_TYPE_AUDIO_PANORAMA_METHOD (gst_audio_panorama_method_get_type ())
74 static GType
75 gst_audio_panorama_method_get_type (void)
76 {
77   static GType gtype = 0;
78
79   if (gtype == 0) {
80     static const GEnumValue values[] = {
81       {METHOD_PSYCHOACOUSTIC, "Psychoacoustic Panning (default)",
82           "psychoacoustic"},
83       {METHOD_SIMPLE, "Simple Panning", "simple"},
84       {0, NULL, NULL}
85     };
86
87     gtype = g_enum_register_static ("GstAudioPanoramaMethod", values);
88   }
89   return gtype;
90 }
91
92 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
93     GST_PAD_SINK,
94     GST_PAD_ALWAYS,
95     GST_STATIC_CAPS ("audio/x-raw-float, "
96         "rate = (int) [ 1, MAX ], "
97         "channels = (int) [ 1, 2 ], "
98         "endianness = (int) BYTE_ORDER, " "width = (int) 32; "
99         "audio/x-raw-int, "
100         "rate = (int) [ 1, MAX ], "
101         "channels = (int) [ 1, 2 ], "
102         "endianness = (int) BYTE_ORDER, "
103         "width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
104     );
105
106 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
107     GST_PAD_SRC,
108     GST_PAD_ALWAYS,
109     GST_STATIC_CAPS ("audio/x-raw-float, "
110         "rate = (int) [ 1, MAX ], "
111         "channels = (int) 2, "
112         "endianness = (int) BYTE_ORDER, " "width = (int) 32; "
113         "audio/x-raw-int, "
114         "rate = (int) [ 1, MAX ], "
115         "channels = (int) 2, "
116         "endianness = (int) BYTE_ORDER, "
117         "width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
118     );
119
120 G_DEFINE_TYPE (GstAudioPanorama, gst_audio_panorama, GST_TYPE_BASE_TRANSFORM);
121
122 static void gst_audio_panorama_set_property (GObject * object, guint prop_id,
123     const GValue * value, GParamSpec * pspec);
124 static void gst_audio_panorama_get_property (GObject * object, guint prop_id,
125     GValue * value, GParamSpec * pspec);
126
127 static gboolean gst_audio_panorama_get_unit_size (GstBaseTransform * base,
128     GstCaps * caps, gsize * size);
129 static GstCaps *gst_audio_panorama_transform_caps (GstBaseTransform * base,
130     GstPadDirection direction, GstCaps * caps, GstCaps * filter);
131 static gboolean gst_audio_panorama_set_caps (GstBaseTransform * base,
132     GstCaps * incaps, GstCaps * outcaps);
133
134 static void gst_audio_panorama_transform_m2s_int (GstAudioPanorama * filter,
135     gint16 * idata, gint16 * odata, guint num_samples);
136 static void gst_audio_panorama_transform_s2s_int (GstAudioPanorama * filter,
137     gint16 * idata, gint16 * odata, guint num_samples);
138 static void gst_audio_panorama_transform_m2s_float (GstAudioPanorama * filter,
139     gfloat * idata, gfloat * odata, guint num_samples);
140 static void gst_audio_panorama_transform_s2s_float (GstAudioPanorama * filter,
141     gfloat * idata, gfloat * odata, guint num_samples);
142
143 static void gst_audio_panorama_transform_m2s_int_simple (GstAudioPanorama *
144     filter, gint16 * idata, gint16 * odata, guint num_samples);
145 static void gst_audio_panorama_transform_s2s_int_simple (GstAudioPanorama *
146     filter, gint16 * idata, gint16 * odata, guint num_samples);
147 static void gst_audio_panorama_transform_m2s_float_simple (GstAudioPanorama *
148     filter, gfloat * idata, gfloat * odata, guint num_samples);
149 static void gst_audio_panorama_transform_s2s_float_simple (GstAudioPanorama *
150     filter, gfloat * idata, gfloat * odata, guint num_samples);
151
152 static GstFlowReturn gst_audio_panorama_transform (GstBaseTransform * base,
153     GstBuffer * inbuf, GstBuffer * outbuf);
154
155
156 /* Table with processing functions: [channels][format][method] */
157 static GstAudioPanoramaProcessFunc panorama_process_functions[2][2][2] = {
158   {
159         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_m2s_int,
160               (GstAudioPanoramaProcessFunc)
161             gst_audio_panorama_transform_m2s_int_simple},
162         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_m2s_float,
163               (GstAudioPanoramaProcessFunc)
164             gst_audio_panorama_transform_m2s_float_simple}
165       },
166   {
167         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_s2s_int,
168               (GstAudioPanoramaProcessFunc)
169             gst_audio_panorama_transform_s2s_int_simple},
170         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_s2s_float,
171               (GstAudioPanoramaProcessFunc)
172             gst_audio_panorama_transform_s2s_float_simple}
173       }
174 };
175
176 /* GObject vmethod implementations */
177
178 static void
179 gst_audio_panorama_class_init (GstAudioPanoramaClass * klass)
180 {
181   GObjectClass *gobject_class;
182   GstElementClass *gstelement_class;
183
184   GST_DEBUG_CATEGORY_INIT (gst_audio_panorama_debug, "audiopanorama", 0,
185       "audiopanorama element");
186
187   gobject_class = (GObjectClass *) klass;
188   gstelement_class = (GstElementClass *) klass;
189
190   gobject_class->set_property = gst_audio_panorama_set_property;
191   gobject_class->get_property = gst_audio_panorama_get_property;
192
193   g_object_class_install_property (gobject_class, PROP_PANORAMA,
194       g_param_spec_float ("panorama", "Panorama",
195           "Position in stereo panorama (-1.0 left -> 1.0 right)", -1.0, 1.0,
196           0.0,
197           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
198   /**
199    * GstAudioPanorama:method
200    *
201    * Panning method: psychoacoustic mode keeps the same perceived loudness,
202    * while simple mode just controls the volume of one channel. It's merely
203    * a matter of taste which method should be chosen. 
204    *
205    * Since: 0.10.6
206    **/
207   g_object_class_install_property (gobject_class, PROP_METHOD,
208       g_param_spec_enum ("method", "Panning method",
209           "Psychoacoustic mode keeps same perceived loudness, "
210           "simple mode just controls volume of one channel.",
211           GST_TYPE_AUDIO_PANORAMA_METHOD, METHOD_PSYCHOACOUSTIC,
212           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
213
214   gst_element_class_set_details_simple (gstelement_class, "Stereo positioning",
215       "Filter/Effect/Audio",
216       "Positions audio streams in the stereo panorama",
217       "Stefan Kost <ensonic@users.sf.net>");
218
219   gst_element_class_add_pad_template (gstelement_class,
220       gst_static_pad_template_get (&src_template));
221   gst_element_class_add_pad_template (gstelement_class,
222       gst_static_pad_template_get (&sink_template));
223
224   GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
225       GST_DEBUG_FUNCPTR (gst_audio_panorama_get_unit_size);
226   GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
227       GST_DEBUG_FUNCPTR (gst_audio_panorama_transform_caps);
228   GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
229       GST_DEBUG_FUNCPTR (gst_audio_panorama_set_caps);
230   GST_BASE_TRANSFORM_CLASS (klass)->transform =
231       GST_DEBUG_FUNCPTR (gst_audio_panorama_transform);
232 }
233
234 static void
235 gst_audio_panorama_init (GstAudioPanorama * filter)
236 {
237
238   filter->panorama = 0;
239   filter->method = METHOD_PSYCHOACOUSTIC;
240   filter->width = 0;
241   filter->channels = 0;
242   filter->format_float = FALSE;
243   filter->process = NULL;
244
245   gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (filter), TRUE);
246 }
247
248 static gboolean
249 gst_audio_panorama_set_process_function (GstAudioPanorama * filter)
250 {
251   gint channel_index, format_index, method_index;
252
253   /* set processing function */
254   channel_index = filter->channels - 1;
255   if (channel_index > 1 || channel_index < 0) {
256     filter->process = NULL;
257     return FALSE;
258   }
259
260   format_index = (filter->format_float) ? 1 : 0;
261
262   method_index = filter->method;
263   if (method_index >= NUM_METHODS || method_index < 0)
264     method_index = METHOD_PSYCHOACOUSTIC;
265
266   filter->process =
267       panorama_process_functions[channel_index][format_index][method_index];
268   return TRUE;
269 }
270
271 static void
272 gst_audio_panorama_set_property (GObject * object, guint prop_id,
273     const GValue * value, GParamSpec * pspec)
274 {
275   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (object);
276
277   switch (prop_id) {
278     case PROP_PANORAMA:
279       filter->panorama = g_value_get_float (value);
280       break;
281     case PROP_METHOD:
282       filter->method = g_value_get_enum (value);
283       gst_audio_panorama_set_process_function (filter);
284       break;
285     default:
286       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
287       break;
288   }
289 }
290
291 static void
292 gst_audio_panorama_get_property (GObject * object, guint prop_id,
293     GValue * value, GParamSpec * pspec)
294 {
295   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (object);
296
297   switch (prop_id) {
298     case PROP_PANORAMA:
299       g_value_set_float (value, filter->panorama);
300       break;
301     case PROP_METHOD:
302       g_value_set_enum (value, filter->method);
303       break;
304     default:
305       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
306       break;
307   }
308 }
309
310 /* GstBaseTransform vmethod implementations */
311
312 static gboolean
313 gst_audio_panorama_get_unit_size (GstBaseTransform * base, GstCaps * caps,
314     gsize * size)
315 {
316   gint width, channels;
317   GstStructure *structure;
318   gboolean ret;
319
320   g_assert (size);
321
322   /* this works for both float and int */
323   structure = gst_caps_get_structure (caps, 0);
324   ret = gst_structure_get_int (structure, "width", &width);
325   ret &= gst_structure_get_int (structure, "channels", &channels);
326
327   *size = width * channels / 8;
328
329   return ret;
330 }
331
332 static GstCaps *
333 gst_audio_panorama_transform_caps (GstBaseTransform * base,
334     GstPadDirection direction, GstCaps * caps, GstCaps * filter)
335 {
336   GstCaps *res;
337   GstStructure *structure;
338
339   /* transform caps gives one single caps so we can just replace
340    * the channel property with our range. */
341   res = gst_caps_copy (caps);
342   structure = gst_caps_get_structure (res, 0);
343   if (direction == GST_PAD_SRC) {
344     GST_INFO ("allow 1-2 channels");
345     gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
346   } else {
347     GST_INFO ("allow 2 channels");
348     gst_structure_set (structure, "channels", G_TYPE_INT, 2, NULL);
349   }
350
351   return res;
352 }
353
354 static gboolean
355 gst_audio_panorama_set_caps (GstBaseTransform * base, GstCaps * incaps,
356     GstCaps * outcaps)
357 {
358   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
359   const GstStructure *structure;
360   gboolean ret;
361   gint width;
362   const gchar *fmt;
363
364   /*GST_INFO ("incaps are %" GST_PTR_FORMAT, incaps); */
365
366   structure = gst_caps_get_structure (incaps, 0);
367   ret = gst_structure_get_int (structure, "channels", &filter->channels);
368   if (!ret)
369     goto no_channels;
370
371   ret = gst_structure_get_int (structure, "width", &width);
372   if (!ret)
373     goto no_width;
374   filter->width = width / 8;
375
376   fmt = gst_structure_get_name (structure);
377   if (!strcmp (fmt, "audio/x-raw-int"))
378     filter->format_float = FALSE;
379   else
380     filter->format_float = TRUE;
381
382   GST_DEBUG ("try to process %s input with %d channels", fmt, filter->channels);
383
384   ret = gst_audio_panorama_set_process_function (filter);
385
386   if (!ret)
387     GST_WARNING ("can't process input with %d channels", filter->channels);
388
389   return ret;
390
391 no_channels:
392   GST_DEBUG ("no channels in caps");
393   return ret;
394 no_width:
395   GST_DEBUG ("no width in caps");
396   return ret;
397 }
398
399 /* psychoacoustic processing functions */
400 static void
401 gst_audio_panorama_transform_m2s_int (GstAudioPanorama * filter, gint16 * idata,
402     gint16 * odata, guint num_samples)
403 {
404   guint i;
405   gdouble val;
406   glong lval, rval;
407   gdouble rpan, lpan;
408
409   /* pan:  -1.0  0.0  1.0
410    * lpan:  1.0  0.5  0.0  
411    * rpan:  0.0  0.5  1.0
412    *
413    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
414    */
415   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
416   lpan = 1.0 - rpan;
417
418   for (i = 0; i < num_samples; i++) {
419     val = (gdouble) * idata++;
420
421     lval = (glong) (val * lpan);
422     rval = (glong) (val * rpan);
423
424     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
425     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
426   }
427 }
428
429 static void
430 gst_audio_panorama_transform_s2s_int (GstAudioPanorama * filter, gint16 * idata,
431     gint16 * odata, guint num_samples)
432 {
433   guint i;
434   glong lval, rval;
435   gdouble lival, rival;
436   gdouble lrpan, llpan, rrpan, rlpan;
437
438   /* pan:  -1.0  0.0  1.0
439    * llpan: 1.0  1.0  0.0
440    * lrpan: 1.0  0.0  0.0
441    * rrpan: 0.0  1.0  1.0
442    * rlpan: 0.0  0.0  1.0
443    */
444   if (filter->panorama > 0) {
445     rlpan = (gdouble) filter->panorama;
446     llpan = 1.0 - rlpan;
447     lrpan = 0.0;
448     rrpan = 1.0;
449   } else {
450     rrpan = (gdouble) (1.0 + filter->panorama);
451     lrpan = 1.0 - rrpan;
452     rlpan = 0.0;
453     llpan = 1.0;
454   }
455
456   for (i = 0; i < num_samples; i++) {
457     lival = (gdouble) * idata++;
458     rival = (gdouble) * idata++;
459
460     lval = lival * llpan + rival * lrpan;
461     rval = lival * rlpan + rival * rrpan;
462
463     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
464     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
465   }
466 }
467
468 static void
469 gst_audio_panorama_transform_m2s_float (GstAudioPanorama * filter,
470     gfloat * idata, gfloat * odata, guint num_samples)
471 {
472   guint i;
473   gfloat val;
474   gdouble rpan, lpan;
475
476   /* pan:  -1.0  0.0  1.0
477    * lpan:  1.0  0.5  0.0  
478    * rpan:  0.0  0.5  1.0
479    *
480    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
481    */
482   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
483   lpan = 1.0 - rpan;
484
485   for (i = 0; i < num_samples; i++) {
486     val = *idata++;
487
488     *odata++ = val * lpan;
489     *odata++ = val * rpan;
490   }
491 }
492
493 static void
494 gst_audio_panorama_transform_s2s_float (GstAudioPanorama * filter,
495     gfloat * idata, gfloat * odata, guint num_samples)
496 {
497   guint i;
498   gfloat lival, rival;
499   gdouble lrpan, llpan, rrpan, rlpan;
500
501   /* pan:  -1.0  0.0  1.0
502    * llpan: 1.0  1.0  0.0
503    * lrpan: 1.0  0.0  0.0
504    * rrpan: 0.0  1.0  1.0
505    * rlpan: 0.0  0.0  1.0
506    */
507   if (filter->panorama > 0) {
508     rlpan = (gdouble) filter->panorama;
509     llpan = 1.0 - rlpan;
510     lrpan = 0.0;
511     rrpan = 1.0;
512   } else {
513     rrpan = (gdouble) (1.0 + filter->panorama);
514     lrpan = 1.0 - rrpan;
515     rlpan = 0.0;
516     llpan = 1.0;
517   }
518
519   for (i = 0; i < num_samples; i++) {
520     lival = *idata++;
521     rival = *idata++;
522
523     *odata++ = lival * llpan + rival * lrpan;
524     *odata++ = lival * rlpan + rival * rrpan;
525   }
526 }
527
528 /* simple processing functions */
529 static void
530 gst_audio_panorama_transform_m2s_int_simple (GstAudioPanorama * filter,
531     gint16 * idata, gint16 * odata, guint num_samples)
532 {
533   guint i;
534   gdouble pan;
535   glong lval, rval;
536
537   if (filter->panorama > 0.0) {
538     pan = 1.0 - filter->panorama;
539     for (i = 0; i < num_samples; i++) {
540       rval = *idata++;
541       lval = (glong) ((gdouble) rval * pan);
542
543       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
544       *odata++ = (gint16) rval;
545     }
546   } else {
547     pan = 1.0 + filter->panorama;
548     for (i = 0; i < num_samples; i++) {
549       lval = *idata++;
550       rval = (glong) ((gdouble) lval * pan);
551
552       *odata++ = (gint16) lval;
553       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
554     }
555   }
556 }
557
558 static void
559 gst_audio_panorama_transform_s2s_int_simple (GstAudioPanorama * filter,
560     gint16 * idata, gint16 * odata, guint num_samples)
561 {
562   guint i;
563   glong lval, rval;
564   gdouble lival, rival, pan;
565
566   if (filter->panorama > 0.0) {
567     pan = 1.0 - filter->panorama;
568     for (i = 0; i < num_samples; i++) {
569       lival = (gdouble) * idata++;
570       rival = (gdouble) * idata++;
571
572       lval = (glong) (lival * pan);
573       rval = (glong) rival;
574
575       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
576       *odata++ = (gint16) rval;
577     }
578   } else {
579     pan = 1.0 + filter->panorama;
580     for (i = 0; i < num_samples; i++) {
581       lival = (gdouble) * idata++;
582       rival = (gdouble) * idata++;
583
584       lval = (glong) lival;
585       rval = (glong) (rival * pan);
586
587       *odata++ = (gint16) lval;
588       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
589     }
590   }
591 }
592
593 static void
594 gst_audio_panorama_transform_m2s_float_simple (GstAudioPanorama * filter,
595     gfloat * idata, gfloat * odata, guint num_samples)
596 {
597   guint i;
598   gfloat val, pan;
599
600   if (filter->panorama > 0.0) {
601     pan = 1.0 - filter->panorama;
602     for (i = 0; i < num_samples; i++) {
603       val = *idata++;
604
605       *odata++ = val * pan;
606       *odata++ = val;
607     }
608   } else {
609     pan = 1.0 + filter->panorama;
610     for (i = 0; i < num_samples; i++) {
611       val = *idata++;
612
613       *odata++ = val;
614       *odata++ = val * pan;
615     }
616   }
617 }
618
619 static void
620 gst_audio_panorama_transform_s2s_float_simple (GstAudioPanorama * filter,
621     gfloat * idata, gfloat * odata, guint num_samples)
622 {
623   guint i;
624   gfloat lival, rival, pan;
625
626   if (filter->panorama > 0.0) {
627     pan = 1.0 - filter->panorama;
628     for (i = 0; i < num_samples; i++) {
629       lival = *idata++;
630       rival = *idata++;
631
632       *odata++ = lival * pan;
633       *odata++ = rival;
634     }
635   } else {
636     pan = 1.0 + filter->panorama;
637     for (i = 0; i < num_samples; i++) {
638       lival = *idata++;
639       rival = *idata++;
640
641       *odata++ = lival;
642       *odata++ = rival * pan;
643     }
644   }
645 }
646
647 /* this function does the actual processing
648  */
649 static GstFlowReturn
650 gst_audio_panorama_transform (GstBaseTransform * base, GstBuffer * inbuf,
651     GstBuffer * outbuf)
652 {
653   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
654   GstClockTime timestamp, stream_time;
655   guint8 *indata, *outdata;
656   gsize insize, outsize;
657
658   timestamp = GST_BUFFER_TIMESTAMP (inbuf);
659   stream_time =
660       gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
661
662   GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
663       GST_TIME_ARGS (timestamp));
664
665   if (GST_CLOCK_TIME_IS_VALID (stream_time))
666     gst_object_sync_values (G_OBJECT (filter), stream_time);
667
668   indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
669   outdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE);
670
671   if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP))) {
672     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
673     memset (outdata, 0, outsize);
674   } else {
675     guint num_samples = outsize / (2 * filter->width);
676
677     filter->process (filter, indata, outdata, num_samples);
678   }
679
680   gst_buffer_unmap (inbuf, indata, insize);
681   gst_buffer_unmap (outbuf, outdata, outsize);
682
683   return GST_FLOW_OK;
684 }