f64eaa4688671735c1001e2286e5d6feee69cf48
[framework/multimedia/gst-plugins-good0.10.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 #define DEBUG_INIT(bla) \
121   GST_DEBUG_CATEGORY_INIT (gst_audio_panorama_debug, "audiopanorama", 0, "audiopanorama element");
122
123 GST_BOILERPLATE_FULL (GstAudioPanorama, gst_audio_panorama, GstBaseTransform,
124     GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
125
126 static void gst_audio_panorama_set_property (GObject * object, guint prop_id,
127     const GValue * value, GParamSpec * pspec);
128 static void gst_audio_panorama_get_property (GObject * object, guint prop_id,
129     GValue * value, GParamSpec * pspec);
130
131 static gboolean gst_audio_panorama_get_unit_size (GstBaseTransform * base,
132     GstCaps * caps, guint * size);
133 static GstCaps *gst_audio_panorama_transform_caps (GstBaseTransform * base,
134     GstPadDirection direction, GstCaps * caps);
135 static gboolean gst_audio_panorama_set_caps (GstBaseTransform * base,
136     GstCaps * incaps, GstCaps * outcaps);
137
138 static void gst_audio_panorama_transform_m2s_int (GstAudioPanorama * filter,
139     gint16 * idata, gint16 * odata, guint num_samples);
140 static void gst_audio_panorama_transform_s2s_int (GstAudioPanorama * filter,
141     gint16 * idata, gint16 * odata, guint num_samples);
142 static void gst_audio_panorama_transform_m2s_float (GstAudioPanorama * filter,
143     gfloat * idata, gfloat * odata, guint num_samples);
144 static void gst_audio_panorama_transform_s2s_float (GstAudioPanorama * filter,
145     gfloat * idata, gfloat * odata, guint num_samples);
146
147 static void gst_audio_panorama_transform_m2s_int_simple (GstAudioPanorama *
148     filter, gint16 * idata, gint16 * odata, guint num_samples);
149 static void gst_audio_panorama_transform_s2s_int_simple (GstAudioPanorama *
150     filter, gint16 * idata, gint16 * odata, guint num_samples);
151 static void gst_audio_panorama_transform_m2s_float_simple (GstAudioPanorama *
152     filter, gfloat * idata, gfloat * odata, guint num_samples);
153 static void gst_audio_panorama_transform_s2s_float_simple (GstAudioPanorama *
154     filter, gfloat * idata, gfloat * odata, guint num_samples);
155
156 static GstFlowReturn gst_audio_panorama_transform (GstBaseTransform * base,
157     GstBuffer * inbuf, GstBuffer * outbuf);
158
159
160 /* Table with processing functions: [channels][format][method] */
161 static GstAudioPanoramaProcessFunc panorama_process_functions[2][2][2] = {
162   {
163         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_m2s_int,
164               (GstAudioPanoramaProcessFunc)
165             gst_audio_panorama_transform_m2s_int_simple},
166         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_m2s_float,
167               (GstAudioPanoramaProcessFunc)
168             gst_audio_panorama_transform_m2s_float_simple}
169       },
170   {
171         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_s2s_int,
172               (GstAudioPanoramaProcessFunc)
173             gst_audio_panorama_transform_s2s_int_simple},
174         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_s2s_float,
175               (GstAudioPanoramaProcessFunc)
176             gst_audio_panorama_transform_s2s_float_simple}
177       }
178 };
179
180 /* GObject vmethod implementations */
181
182 static void
183 gst_audio_panorama_base_init (gpointer klass)
184 {
185   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
186
187   gst_element_class_add_static_pad_template (element_class, &src_template);
188   gst_element_class_add_static_pad_template (element_class,
189       &sink_template);
190   gst_element_class_set_details_simple (element_class, "Stereo positioning",
191       "Filter/Effect/Audio",
192       "Positions audio streams in the stereo panorama",
193       "Stefan Kost <ensonic@users.sf.net>");
194 }
195
196 static void
197 gst_audio_panorama_class_init (GstAudioPanoramaClass * klass)
198 {
199   GObjectClass *gobject_class;
200
201   gobject_class = (GObjectClass *) klass;
202   gobject_class->set_property = gst_audio_panorama_set_property;
203   gobject_class->get_property = gst_audio_panorama_get_property;
204
205   g_object_class_install_property (gobject_class, PROP_PANORAMA,
206       g_param_spec_float ("panorama", "Panorama",
207           "Position in stereo panorama (-1.0 left -> 1.0 right)", -1.0, 1.0,
208           0.0,
209           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
210   /**
211    * GstAudioPanorama:method
212    *
213    * Panning method: psychoacoustic mode keeps the same perceived loudness,
214    * while simple mode just controls the volume of one channel. It's merely
215    * a matter of taste which method should be chosen. 
216    *
217    * Since: 0.10.6
218    **/
219   g_object_class_install_property (gobject_class, PROP_METHOD,
220       g_param_spec_enum ("method", "Panning method",
221           "Psychoacoustic mode keeps same perceived loudness, "
222           "simple mode just controls volume of one channel.",
223           GST_TYPE_AUDIO_PANORAMA_METHOD, METHOD_PSYCHOACOUSTIC,
224           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
225
226   GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
227       GST_DEBUG_FUNCPTR (gst_audio_panorama_get_unit_size);
228   GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
229       GST_DEBUG_FUNCPTR (gst_audio_panorama_transform_caps);
230   GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
231       GST_DEBUG_FUNCPTR (gst_audio_panorama_set_caps);
232   GST_BASE_TRANSFORM_CLASS (klass)->transform =
233       GST_DEBUG_FUNCPTR (gst_audio_panorama_transform);
234 }
235
236 static void
237 gst_audio_panorama_init (GstAudioPanorama * filter,
238     GstAudioPanoramaClass * klass)
239 {
240
241   filter->panorama = 0;
242   filter->method = METHOD_PSYCHOACOUSTIC;
243   filter->width = 0;
244   filter->channels = 0;
245   filter->format_float = FALSE;
246   filter->process = NULL;
247
248   gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (filter), TRUE);
249 }
250
251 static gboolean
252 gst_audio_panorama_set_process_function (GstAudioPanorama * filter)
253 {
254   gint channel_index, format_index, method_index;
255
256   /* set processing function */
257   channel_index = filter->channels - 1;
258   if (channel_index > 1 || channel_index < 0) {
259     filter->process = NULL;
260     return FALSE;
261   }
262
263   format_index = (filter->format_float) ? 1 : 0;
264
265   method_index = filter->method;
266   if (method_index >= NUM_METHODS || method_index < 0)
267     method_index = METHOD_PSYCHOACOUSTIC;
268
269   filter->process =
270       panorama_process_functions[channel_index][format_index][method_index];
271   return TRUE;
272 }
273
274 static void
275 gst_audio_panorama_set_property (GObject * object, guint prop_id,
276     const GValue * value, GParamSpec * pspec)
277 {
278   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (object);
279
280   switch (prop_id) {
281     case PROP_PANORAMA:
282       filter->panorama = g_value_get_float (value);
283       break;
284     case PROP_METHOD:
285       filter->method = g_value_get_enum (value);
286       gst_audio_panorama_set_process_function (filter);
287       break;
288     default:
289       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
290       break;
291   }
292 }
293
294 static void
295 gst_audio_panorama_get_property (GObject * object, guint prop_id,
296     GValue * value, GParamSpec * pspec)
297 {
298   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (object);
299
300   switch (prop_id) {
301     case PROP_PANORAMA:
302       g_value_set_float (value, filter->panorama);
303       break;
304     case PROP_METHOD:
305       g_value_set_enum (value, filter->method);
306       break;
307     default:
308       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
309       break;
310   }
311 }
312
313 /* GstBaseTransform vmethod implementations */
314
315 static gboolean
316 gst_audio_panorama_get_unit_size (GstBaseTransform * base, GstCaps * caps,
317     guint * size)
318 {
319   gint width, channels;
320   GstStructure *structure;
321   gboolean ret;
322
323   g_assert (size);
324
325   /* this works for both float and int */
326   structure = gst_caps_get_structure (caps, 0);
327   ret = gst_structure_get_int (structure, "width", &width);
328   ret &= gst_structure_get_int (structure, "channels", &channels);
329
330   *size = width * channels / 8;
331
332   return ret;
333 }
334
335 static GstCaps *
336 gst_audio_panorama_transform_caps (GstBaseTransform * base,
337     GstPadDirection direction, GstCaps * caps)
338 {
339   GstCaps *res;
340   GstStructure *structure;
341
342   /* transform caps gives one single caps so we can just replace
343    * the channel property with our range. */
344   res = gst_caps_copy (caps);
345   structure = gst_caps_get_structure (res, 0);
346   if (direction == GST_PAD_SRC) {
347     GST_INFO ("allow 1-2 channels");
348     gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
349   } else {
350     GST_INFO ("allow 2 channels");
351     gst_structure_set (structure, "channels", G_TYPE_INT, 2, NULL);
352   }
353
354   return res;
355 }
356
357 static gboolean
358 gst_audio_panorama_set_caps (GstBaseTransform * base, GstCaps * incaps,
359     GstCaps * outcaps)
360 {
361   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
362   const GstStructure *structure;
363   gboolean ret;
364   gint width;
365   const gchar *fmt;
366
367   /*GST_INFO ("incaps are %" GST_PTR_FORMAT, incaps); */
368
369   structure = gst_caps_get_structure (incaps, 0);
370   ret = gst_structure_get_int (structure, "channels", &filter->channels);
371   if (!ret)
372     goto no_channels;
373
374   ret = gst_structure_get_int (structure, "width", &width);
375   if (!ret)
376     goto no_width;
377   filter->width = width / 8;
378
379   fmt = gst_structure_get_name (structure);
380   if (!strcmp (fmt, "audio/x-raw-int"))
381     filter->format_float = FALSE;
382   else
383     filter->format_float = TRUE;
384
385   GST_DEBUG ("try to process %s input with %d channels", fmt, filter->channels);
386
387   ret = gst_audio_panorama_set_process_function (filter);
388
389   if (!ret)
390     GST_WARNING ("can't process input with %d channels", filter->channels);
391
392   return ret;
393
394 no_channels:
395   GST_DEBUG ("no channels in caps");
396   return ret;
397 no_width:
398   GST_DEBUG ("no width in caps");
399   return ret;
400 }
401
402 /* psychoacoustic processing functions */
403 static void
404 gst_audio_panorama_transform_m2s_int (GstAudioPanorama * filter, gint16 * idata,
405     gint16 * odata, guint num_samples)
406 {
407   guint i;
408   gdouble val;
409   glong lval, rval;
410   gdouble rpan, lpan;
411
412   /* pan:  -1.0  0.0  1.0
413    * lpan:  1.0  0.5  0.0  
414    * rpan:  0.0  0.5  1.0
415    *
416    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
417    */
418   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
419   lpan = 1.0 - rpan;
420
421   for (i = 0; i < num_samples; i++) {
422     val = (gdouble) * idata++;
423
424     lval = (glong) (val * lpan);
425     rval = (glong) (val * rpan);
426
427     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
428     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
429   }
430 }
431
432 static void
433 gst_audio_panorama_transform_s2s_int (GstAudioPanorama * filter, gint16 * idata,
434     gint16 * odata, guint num_samples)
435 {
436   guint i;
437   glong lval, rval;
438   gdouble lival, rival;
439   gdouble lrpan, llpan, rrpan, rlpan;
440
441   /* pan:  -1.0  0.0  1.0
442    * llpan: 1.0  1.0  0.0
443    * lrpan: 1.0  0.0  0.0
444    * rrpan: 0.0  1.0  1.0
445    * rlpan: 0.0  0.0  1.0
446    */
447   if (filter->panorama > 0) {
448     rlpan = (gdouble) filter->panorama;
449     llpan = 1.0 - rlpan;
450     lrpan = 0.0;
451     rrpan = 1.0;
452   } else {
453     rrpan = (gdouble) (1.0 + filter->panorama);
454     lrpan = 1.0 - rrpan;
455     rlpan = 0.0;
456     llpan = 1.0;
457   }
458
459   for (i = 0; i < num_samples; i++) {
460     lival = (gdouble) * idata++;
461     rival = (gdouble) * idata++;
462
463     lval = lival * llpan + rival * lrpan;
464     rval = lival * rlpan + rival * rrpan;
465
466     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
467     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
468   }
469 }
470
471 static void
472 gst_audio_panorama_transform_m2s_float (GstAudioPanorama * filter,
473     gfloat * idata, gfloat * odata, guint num_samples)
474 {
475   guint i;
476   gfloat val;
477   gdouble rpan, lpan;
478
479   /* pan:  -1.0  0.0  1.0
480    * lpan:  1.0  0.5  0.0  
481    * rpan:  0.0  0.5  1.0
482    *
483    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
484    */
485   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
486   lpan = 1.0 - rpan;
487
488   for (i = 0; i < num_samples; i++) {
489     val = *idata++;
490
491     *odata++ = val * lpan;
492     *odata++ = val * rpan;
493   }
494 }
495
496 static void
497 gst_audio_panorama_transform_s2s_float (GstAudioPanorama * filter,
498     gfloat * idata, gfloat * odata, guint num_samples)
499 {
500   guint i;
501   gfloat lival, rival;
502   gdouble lrpan, llpan, rrpan, rlpan;
503
504   /* pan:  -1.0  0.0  1.0
505    * llpan: 1.0  1.0  0.0
506    * lrpan: 1.0  0.0  0.0
507    * rrpan: 0.0  1.0  1.0
508    * rlpan: 0.0  0.0  1.0
509    */
510   if (filter->panorama > 0) {
511     rlpan = (gdouble) filter->panorama;
512     llpan = 1.0 - rlpan;
513     lrpan = 0.0;
514     rrpan = 1.0;
515   } else {
516     rrpan = (gdouble) (1.0 + filter->panorama);
517     lrpan = 1.0 - rrpan;
518     rlpan = 0.0;
519     llpan = 1.0;
520   }
521
522   for (i = 0; i < num_samples; i++) {
523     lival = *idata++;
524     rival = *idata++;
525
526     *odata++ = lival * llpan + rival * lrpan;
527     *odata++ = lival * rlpan + rival * rrpan;
528   }
529 }
530
531 /* simple processing functions */
532 static void
533 gst_audio_panorama_transform_m2s_int_simple (GstAudioPanorama * filter,
534     gint16 * idata, gint16 * odata, guint num_samples)
535 {
536   guint i;
537   gdouble pan;
538   glong lval, rval;
539
540   if (filter->panorama > 0.0) {
541     pan = 1.0 - filter->panorama;
542     for (i = 0; i < num_samples; i++) {
543       rval = *idata++;
544       lval = (glong) ((gdouble) rval * pan);
545
546       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
547       *odata++ = (gint16) rval;
548     }
549   } else {
550     pan = 1.0 + filter->panorama;
551     for (i = 0; i < num_samples; i++) {
552       lval = *idata++;
553       rval = (glong) ((gdouble) lval * pan);
554
555       *odata++ = (gint16) lval;
556       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
557     }
558   }
559 }
560
561 static void
562 gst_audio_panorama_transform_s2s_int_simple (GstAudioPanorama * filter,
563     gint16 * idata, gint16 * odata, guint num_samples)
564 {
565   guint i;
566   glong lval, rval;
567   gdouble lival, rival, pan;
568
569   if (filter->panorama > 0.0) {
570     pan = 1.0 - filter->panorama;
571     for (i = 0; i < num_samples; i++) {
572       lival = (gdouble) * idata++;
573       rival = (gdouble) * idata++;
574
575       lval = (glong) (lival * pan);
576       rval = (glong) rival;
577
578       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
579       *odata++ = (gint16) rval;
580     }
581   } else {
582     pan = 1.0 + filter->panorama;
583     for (i = 0; i < num_samples; i++) {
584       lival = (gdouble) * idata++;
585       rival = (gdouble) * idata++;
586
587       lval = (glong) lival;
588       rval = (glong) (rival * pan);
589
590       *odata++ = (gint16) lval;
591       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
592     }
593   }
594 }
595
596 static void
597 gst_audio_panorama_transform_m2s_float_simple (GstAudioPanorama * filter,
598     gfloat * idata, gfloat * odata, guint num_samples)
599 {
600   guint i;
601   gfloat val, pan;
602
603   if (filter->panorama > 0.0) {
604     pan = 1.0 - filter->panorama;
605     for (i = 0; i < num_samples; i++) {
606       val = *idata++;
607
608       *odata++ = val * pan;
609       *odata++ = val;
610     }
611   } else {
612     pan = 1.0 + filter->panorama;
613     for (i = 0; i < num_samples; i++) {
614       val = *idata++;
615
616       *odata++ = val;
617       *odata++ = val * pan;
618     }
619   }
620 }
621
622 static void
623 gst_audio_panorama_transform_s2s_float_simple (GstAudioPanorama * filter,
624     gfloat * idata, gfloat * odata, guint num_samples)
625 {
626   guint i;
627   gfloat lival, rival, pan;
628
629   if (filter->panorama > 0.0) {
630     pan = 1.0 - filter->panorama;
631     for (i = 0; i < num_samples; i++) {
632       lival = *idata++;
633       rival = *idata++;
634
635       *odata++ = lival * pan;
636       *odata++ = rival;
637     }
638   } else {
639     pan = 1.0 + filter->panorama;
640     for (i = 0; i < num_samples; i++) {
641       lival = *idata++;
642       rival = *idata++;
643
644       *odata++ = lival;
645       *odata++ = rival * pan;
646     }
647   }
648 }
649
650 /* this function does the actual processing
651  */
652 static GstFlowReturn
653 gst_audio_panorama_transform (GstBaseTransform * base, GstBuffer * inbuf,
654     GstBuffer * outbuf)
655 {
656   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
657   guint num_samples = GST_BUFFER_SIZE (outbuf) / (2 * filter->width);
658   GstClockTime timestamp, stream_time;
659
660   timestamp = GST_BUFFER_TIMESTAMP (inbuf);
661   stream_time =
662       gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
663
664   GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
665       GST_TIME_ARGS (timestamp));
666
667   if (GST_CLOCK_TIME_IS_VALID (stream_time))
668     gst_object_sync_values (G_OBJECT (filter), stream_time);
669
670   if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP))) {
671     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
672     memset (GST_BUFFER_DATA (outbuf), 0, GST_BUFFER_SIZE (outbuf));
673     return GST_FLOW_OK;
674   }
675
676   filter->process (filter, GST_BUFFER_DATA (inbuf),
677       GST_BUFFER_DATA (outbuf), num_samples);
678
679   return GST_FLOW_OK;
680 }