scaletempo: Fix timestamp tracking
[platform/upstream/gst-plugins-good.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., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, 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-1.0 audiotestsrc wave=saw ! audiopanorama panorama=-1.00 ! alsasink
32  * gst-launch-1.0 filesrc location="melo1.ogg" ! oggdemux ! vorbisdec ! audioconvert ! audiopanorama panorama=-1.00 ! alsasink
33  * gst-launch-1.0 audiotestsrc wave=saw ! audioconvert ! audiopanorama panorama=-1.00 ! audioconvert ! alsasink
34  * gst-launch-1.0 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 <string.h>
44
45 #include <gst/gst.h>
46 #include <gst/base/gstbasetransform.h>
47
48 #include "audiopanorama.h"
49
50 #define GST_CAT_DEFAULT gst_audio_panorama_debug
51 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
52
53 /* Filter signals and args */
54 enum
55 {
56   /* FILL ME */
57   LAST_SIGNAL
58 };
59
60 enum
61 {
62   PROP_0,
63   PROP_PANORAMA,
64   PROP_METHOD
65 };
66
67 enum
68 {
69   METHOD_PSYCHOACOUSTIC = 0,
70   METHOD_SIMPLE,
71   NUM_METHODS
72 };
73
74 #define GST_TYPE_AUDIO_PANORAMA_METHOD (gst_audio_panorama_method_get_type ())
75 static GType
76 gst_audio_panorama_method_get_type (void)
77 {
78   static GType gtype = 0;
79
80   if (gtype == 0) {
81     static const GEnumValue values[] = {
82       {METHOD_PSYCHOACOUSTIC, "Psychoacoustic Panning (default)",
83           "psychoacoustic"},
84       {METHOD_SIMPLE, "Simple Panning", "simple"},
85       {0, NULL, NULL}
86     };
87
88     gtype = g_enum_register_static ("GstAudioPanoramaMethod", values);
89   }
90   return gtype;
91 }
92
93 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
94     GST_PAD_SINK,
95     GST_PAD_ALWAYS,
96     GST_STATIC_CAPS ("audio/x-raw, "
97         "format = (string) { " GST_AUDIO_NE (F32) ", " GST_AUDIO_NE (S16) "}, "
98         "rate = (int) [ 1, MAX ], " "channels = (int) 1, "
99         "layout = (string) interleaved;"
100         "audio/x-raw, "
101         "format = (string) { " GST_AUDIO_NE (F32) ", " GST_AUDIO_NE (S16) "}, "
102         "rate = (int) [ 1, MAX ], " "channels = (int) 2, "
103         "layout = (string) interleaved, " "channel-mask = (bitmask) 0x3")
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, "
110         "format = (string) { " GST_AUDIO_NE (S32) ", " GST_AUDIO_NE (S16) "}, "
111         "rate = (int) [ 1, MAX ], " "channels = (int) 2, "
112         "layout = (string) interleaved, " "channel-mask = (bitmask)0x3")
113     );
114
115 G_DEFINE_TYPE (GstAudioPanorama, gst_audio_panorama, GST_TYPE_BASE_TRANSFORM);
116
117 static void gst_audio_panorama_set_property (GObject * object, guint prop_id,
118     const GValue * value, GParamSpec * pspec);
119 static void gst_audio_panorama_get_property (GObject * object, guint prop_id,
120     GValue * value, GParamSpec * pspec);
121
122 static gboolean gst_audio_panorama_get_unit_size (GstBaseTransform * base,
123     GstCaps * caps, gsize * size);
124 static GstCaps *gst_audio_panorama_transform_caps (GstBaseTransform * base,
125     GstPadDirection direction, GstCaps * caps, GstCaps * filter);
126 static gboolean gst_audio_panorama_set_caps (GstBaseTransform * base,
127     GstCaps * incaps, GstCaps * outcaps);
128
129 static void gst_audio_panorama_transform_m2s_int (GstAudioPanorama * filter,
130     gint16 * idata, gint16 * odata, guint num_samples);
131 static void gst_audio_panorama_transform_s2s_int (GstAudioPanorama * filter,
132     gint16 * idata, gint16 * odata, guint num_samples);
133 static void gst_audio_panorama_transform_m2s_float (GstAudioPanorama * filter,
134     gfloat * idata, gfloat * odata, guint num_samples);
135 static void gst_audio_panorama_transform_s2s_float (GstAudioPanorama * filter,
136     gfloat * idata, gfloat * odata, guint num_samples);
137
138 static void gst_audio_panorama_transform_m2s_int_simple (GstAudioPanorama *
139     filter, gint16 * idata, gint16 * odata, guint num_samples);
140 static void gst_audio_panorama_transform_s2s_int_simple (GstAudioPanorama *
141     filter, gint16 * idata, gint16 * odata, guint num_samples);
142 static void gst_audio_panorama_transform_m2s_float_simple (GstAudioPanorama *
143     filter, gfloat * idata, gfloat * odata, guint num_samples);
144 static void gst_audio_panorama_transform_s2s_float_simple (GstAudioPanorama *
145     filter, gfloat * idata, gfloat * odata, guint num_samples);
146
147 static GstFlowReturn gst_audio_panorama_transform (GstBaseTransform * base,
148     GstBuffer * inbuf, GstBuffer * outbuf);
149
150
151 /* Table with processing functions: [channels][format][method] */
152 static GstAudioPanoramaProcessFunc panorama_process_functions[2][2][2] = {
153   {
154         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_m2s_int,
155               (GstAudioPanoramaProcessFunc)
156             gst_audio_panorama_transform_m2s_int_simple},
157         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_m2s_float,
158               (GstAudioPanoramaProcessFunc)
159             gst_audio_panorama_transform_m2s_float_simple}
160       },
161   {
162         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_s2s_int,
163               (GstAudioPanoramaProcessFunc)
164             gst_audio_panorama_transform_s2s_int_simple},
165         {(GstAudioPanoramaProcessFunc) gst_audio_panorama_transform_s2s_float,
166               (GstAudioPanoramaProcessFunc)
167             gst_audio_panorama_transform_s2s_float_simple}
168       }
169 };
170
171 /* GObject vmethod implementations */
172
173 static void
174 gst_audio_panorama_class_init (GstAudioPanoramaClass * klass)
175 {
176   GObjectClass *gobject_class;
177   GstElementClass *gstelement_class;
178
179   GST_DEBUG_CATEGORY_INIT (gst_audio_panorama_debug, "audiopanorama", 0,
180       "audiopanorama element");
181
182   gobject_class = (GObjectClass *) klass;
183   gstelement_class = (GstElementClass *) klass;
184
185   gobject_class->set_property = gst_audio_panorama_set_property;
186   gobject_class->get_property = gst_audio_panorama_get_property;
187
188   g_object_class_install_property (gobject_class, PROP_PANORAMA,
189       g_param_spec_float ("panorama", "Panorama",
190           "Position in stereo panorama (-1.0 left -> 1.0 right)", -1.0, 1.0,
191           0.0,
192           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
193   /**
194    * GstAudioPanorama:method
195    *
196    * Panning method: psychoacoustic mode keeps the same perceived loudness,
197    * while simple mode just controls the volume of one channel. It's merely
198    * a matter of taste which method should be chosen. 
199    *
200    * Since: 0.10.6
201    **/
202   g_object_class_install_property (gobject_class, PROP_METHOD,
203       g_param_spec_enum ("method", "Panning method",
204           "Psychoacoustic mode keeps same perceived loudness, "
205           "simple mode just controls volume of one channel.",
206           GST_TYPE_AUDIO_PANORAMA_METHOD, METHOD_PSYCHOACOUSTIC,
207           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
208
209   gst_element_class_set_static_metadata (gstelement_class, "Stereo positioning",
210       "Filter/Effect/Audio",
211       "Positions audio streams in the stereo panorama",
212       "Stefan Kost <ensonic@users.sf.net>");
213
214   gst_element_class_add_pad_template (gstelement_class,
215       gst_static_pad_template_get (&src_template));
216   gst_element_class_add_pad_template (gstelement_class,
217       gst_static_pad_template_get (&sink_template));
218
219   GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
220       GST_DEBUG_FUNCPTR (gst_audio_panorama_get_unit_size);
221   GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
222       GST_DEBUG_FUNCPTR (gst_audio_panorama_transform_caps);
223   GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
224       GST_DEBUG_FUNCPTR (gst_audio_panorama_set_caps);
225   GST_BASE_TRANSFORM_CLASS (klass)->transform =
226       GST_DEBUG_FUNCPTR (gst_audio_panorama_transform);
227 }
228
229 static void
230 gst_audio_panorama_init (GstAudioPanorama * filter)
231 {
232
233   filter->panorama = 0;
234   filter->method = METHOD_PSYCHOACOUSTIC;
235   gst_audio_info_init (&filter->info);
236   filter->process = NULL;
237
238   gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (filter), TRUE);
239 }
240
241 static gboolean
242 gst_audio_panorama_set_process_function (GstAudioPanorama * filter,
243     GstAudioInfo * info)
244 {
245   gint channel_index, format_index, method_index;
246   const GstAudioFormatInfo *finfo = info->finfo;
247
248   /* set processing function */
249   channel_index = GST_AUDIO_INFO_CHANNELS (info) - 1;
250   if (channel_index > 1 || channel_index < 0) {
251     filter->process = NULL;
252     return FALSE;
253   }
254
255   format_index = GST_AUDIO_FORMAT_INFO_IS_FLOAT (finfo) ? 1 : 0;
256
257   method_index = filter->method;
258   if (method_index >= NUM_METHODS || method_index < 0)
259     method_index = METHOD_PSYCHOACOUSTIC;
260
261   filter->process =
262       panorama_process_functions[channel_index][format_index][method_index];
263   return TRUE;
264 }
265
266 static void
267 gst_audio_panorama_set_property (GObject * object, guint prop_id,
268     const GValue * value, GParamSpec * pspec)
269 {
270   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (object);
271
272   switch (prop_id) {
273     case PROP_PANORAMA:
274       filter->panorama = g_value_get_float (value);
275       break;
276     case PROP_METHOD:
277       filter->method = g_value_get_enum (value);
278       gst_audio_panorama_set_process_function (filter, &filter->info);
279       break;
280     default:
281       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
282       break;
283   }
284 }
285
286 static void
287 gst_audio_panorama_get_property (GObject * object, guint prop_id,
288     GValue * value, GParamSpec * pspec)
289 {
290   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (object);
291
292   switch (prop_id) {
293     case PROP_PANORAMA:
294       g_value_set_float (value, filter->panorama);
295       break;
296     case PROP_METHOD:
297       g_value_set_enum (value, filter->method);
298       break;
299     default:
300       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
301       break;
302   }
303 }
304
305 /* GstBaseTransform vmethod implementations */
306
307 static gboolean
308 gst_audio_panorama_get_unit_size (GstBaseTransform * base, GstCaps * caps,
309     gsize * size)
310 {
311   GstAudioInfo info;
312
313   g_assert (size);
314
315   if (!gst_audio_info_from_caps (&info, caps))
316     return FALSE;
317
318   *size = GST_AUDIO_INFO_BPF (&info);
319
320   return TRUE;
321 }
322
323 static GstCaps *
324 gst_audio_panorama_transform_caps (GstBaseTransform * base,
325     GstPadDirection direction, GstCaps * caps, GstCaps * filter)
326 {
327   GstCaps *res;
328   GstStructure *structure;
329
330   /* transform caps gives one single caps so we can just replace
331    * the channel property with our range. */
332   res = gst_caps_copy (caps);
333   structure = gst_caps_get_structure (res, 0);
334   if (direction == GST_PAD_SRC) {
335     GST_INFO ("allow 1-2 channels");
336     gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
337     gst_structure_remove_field (structure, "channel-mask");
338   } else {
339     GST_INFO ("allow 2 channels");
340     gst_structure_set (structure, "channels", G_TYPE_INT, 2, NULL);
341     gst_structure_remove_field (structure, "channel-mask");
342   }
343
344   return res;
345 }
346
347 static gboolean
348 gst_audio_panorama_set_caps (GstBaseTransform * base, GstCaps * incaps,
349     GstCaps * outcaps)
350 {
351   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
352   GstAudioInfo info;
353
354   /*GST_INFO ("incaps are %" GST_PTR_FORMAT, incaps); */
355   if (!gst_audio_info_from_caps (&info, incaps))
356     goto no_format;
357
358   GST_DEBUG ("try to process %d input with %d channels",
359       GST_AUDIO_INFO_FORMAT (&info), GST_AUDIO_INFO_CHANNELS (&info));
360
361   if (!gst_audio_panorama_set_process_function (filter, &info))
362     goto no_format;
363
364   filter->info = info;
365
366   return TRUE;
367
368 no_format:
369   {
370     GST_DEBUG ("invalid caps");
371     return FALSE;
372   }
373 }
374
375 /* psychoacoustic processing functions */
376 static void
377 gst_audio_panorama_transform_m2s_int (GstAudioPanorama * filter, gint16 * idata,
378     gint16 * odata, guint num_samples)
379 {
380   guint i;
381   gdouble val;
382   glong lval, rval;
383   gdouble rpan, lpan;
384
385   /* pan:  -1.0  0.0  1.0
386    * lpan:  1.0  0.5  0.0  
387    * rpan:  0.0  0.5  1.0
388    *
389    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
390    */
391   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
392   lpan = 1.0 - rpan;
393
394   for (i = 0; i < num_samples; i++) {
395     val = (gdouble) * idata++;
396
397     lval = (glong) (val * lpan);
398     rval = (glong) (val * rpan);
399
400     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
401     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
402   }
403 }
404
405 static void
406 gst_audio_panorama_transform_s2s_int (GstAudioPanorama * filter, gint16 * idata,
407     gint16 * odata, guint num_samples)
408 {
409   guint i;
410   glong lval, rval;
411   gdouble lival, rival;
412   gdouble lrpan, llpan, rrpan, rlpan;
413
414   /* pan:  -1.0  0.0  1.0
415    * llpan: 1.0  1.0  0.0
416    * lrpan: 1.0  0.0  0.0
417    * rrpan: 0.0  1.0  1.0
418    * rlpan: 0.0  0.0  1.0
419    */
420   if (filter->panorama > 0) {
421     rlpan = (gdouble) filter->panorama;
422     llpan = 1.0 - rlpan;
423     lrpan = 0.0;
424     rrpan = 1.0;
425   } else {
426     rrpan = (gdouble) (1.0 + filter->panorama);
427     lrpan = 1.0 - rrpan;
428     rlpan = 0.0;
429     llpan = 1.0;
430   }
431
432   for (i = 0; i < num_samples; i++) {
433     lival = (gdouble) * idata++;
434     rival = (gdouble) * idata++;
435
436     lval = lival * llpan + rival * lrpan;
437     rval = lival * rlpan + rival * rrpan;
438
439     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
440     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
441   }
442 }
443
444 static void
445 gst_audio_panorama_transform_m2s_float (GstAudioPanorama * filter,
446     gfloat * idata, gfloat * odata, guint num_samples)
447 {
448   guint i;
449   gfloat val;
450   gdouble rpan, lpan;
451
452   /* pan:  -1.0  0.0  1.0
453    * lpan:  1.0  0.5  0.0  
454    * rpan:  0.0  0.5  1.0
455    *
456    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
457    */
458   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
459   lpan = 1.0 - rpan;
460
461   for (i = 0; i < num_samples; i++) {
462     val = *idata++;
463
464     *odata++ = val * lpan;
465     *odata++ = val * rpan;
466   }
467 }
468
469 static void
470 gst_audio_panorama_transform_s2s_float (GstAudioPanorama * filter,
471     gfloat * idata, gfloat * odata, guint num_samples)
472 {
473   guint i;
474   gfloat lival, rival;
475   gdouble lrpan, llpan, rrpan, rlpan;
476
477   /* pan:  -1.0  0.0  1.0
478    * llpan: 1.0  1.0  0.0
479    * lrpan: 1.0  0.0  0.0
480    * rrpan: 0.0  1.0  1.0
481    * rlpan: 0.0  0.0  1.0
482    */
483   if (filter->panorama > 0) {
484     rlpan = (gdouble) filter->panorama;
485     llpan = 1.0 - rlpan;
486     lrpan = 0.0;
487     rrpan = 1.0;
488   } else {
489     rrpan = (gdouble) (1.0 + filter->panorama);
490     lrpan = 1.0 - rrpan;
491     rlpan = 0.0;
492     llpan = 1.0;
493   }
494
495   for (i = 0; i < num_samples; i++) {
496     lival = *idata++;
497     rival = *idata++;
498
499     *odata++ = lival * llpan + rival * lrpan;
500     *odata++ = lival * rlpan + rival * rrpan;
501   }
502 }
503
504 /* simple processing functions */
505 static void
506 gst_audio_panorama_transform_m2s_int_simple (GstAudioPanorama * filter,
507     gint16 * idata, gint16 * odata, guint num_samples)
508 {
509   guint i;
510   gdouble pan;
511   glong lval, rval;
512
513   if (filter->panorama > 0.0) {
514     pan = 1.0 - filter->panorama;
515     for (i = 0; i < num_samples; i++) {
516       rval = *idata++;
517       lval = (glong) ((gdouble) rval * pan);
518
519       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
520       *odata++ = (gint16) rval;
521     }
522   } else {
523     pan = 1.0 + filter->panorama;
524     for (i = 0; i < num_samples; i++) {
525       lval = *idata++;
526       rval = (glong) ((gdouble) lval * pan);
527
528       *odata++ = (gint16) lval;
529       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
530     }
531   }
532 }
533
534 static void
535 gst_audio_panorama_transform_s2s_int_simple (GstAudioPanorama * filter,
536     gint16 * idata, gint16 * odata, guint num_samples)
537 {
538   guint i;
539   glong lval, rval;
540   gdouble lival, rival, pan;
541
542   if (filter->panorama > 0.0) {
543     pan = 1.0 - filter->panorama;
544     for (i = 0; i < num_samples; i++) {
545       lival = (gdouble) * idata++;
546       rival = (gdouble) * idata++;
547
548       lval = (glong) (lival * pan);
549       rval = (glong) rival;
550
551       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
552       *odata++ = (gint16) rval;
553     }
554   } else {
555     pan = 1.0 + filter->panorama;
556     for (i = 0; i < num_samples; i++) {
557       lival = (gdouble) * idata++;
558       rival = (gdouble) * idata++;
559
560       lval = (glong) lival;
561       rval = (glong) (rival * pan);
562
563       *odata++ = (gint16) lval;
564       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
565     }
566   }
567 }
568
569 static void
570 gst_audio_panorama_transform_m2s_float_simple (GstAudioPanorama * filter,
571     gfloat * idata, gfloat * odata, guint num_samples)
572 {
573   guint i;
574   gfloat val, pan;
575
576   if (filter->panorama > 0.0) {
577     pan = 1.0 - filter->panorama;
578     for (i = 0; i < num_samples; i++) {
579       val = *idata++;
580
581       *odata++ = val * pan;
582       *odata++ = val;
583     }
584   } else {
585     pan = 1.0 + filter->panorama;
586     for (i = 0; i < num_samples; i++) {
587       val = *idata++;
588
589       *odata++ = val;
590       *odata++ = val * pan;
591     }
592   }
593 }
594
595 static void
596 gst_audio_panorama_transform_s2s_float_simple (GstAudioPanorama * filter,
597     gfloat * idata, gfloat * odata, guint num_samples)
598 {
599   guint i;
600   gfloat lival, rival, pan;
601
602   if (filter->panorama > 0.0) {
603     pan = 1.0 - filter->panorama;
604     for (i = 0; i < num_samples; i++) {
605       lival = *idata++;
606       rival = *idata++;
607
608       *odata++ = lival * pan;
609       *odata++ = rival;
610     }
611   } else {
612     pan = 1.0 + filter->panorama;
613     for (i = 0; i < num_samples; i++) {
614       lival = *idata++;
615       rival = *idata++;
616
617       *odata++ = lival;
618       *odata++ = rival * pan;
619     }
620   }
621 }
622
623 /* this function does the actual processing
624  */
625 static GstFlowReturn
626 gst_audio_panorama_transform (GstBaseTransform * base, GstBuffer * inbuf,
627     GstBuffer * outbuf)
628 {
629   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
630   GstClockTime timestamp, stream_time;
631   GstMapInfo inmap, outmap;
632
633   timestamp = GST_BUFFER_TIMESTAMP (inbuf);
634   stream_time =
635       gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
636
637   GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
638       GST_TIME_ARGS (timestamp));
639
640   if (GST_CLOCK_TIME_IS_VALID (stream_time))
641     gst_object_sync_values (GST_OBJECT (filter), stream_time);
642
643   gst_buffer_map (inbuf, &inmap, GST_MAP_READ);
644   gst_buffer_map (outbuf, &outmap, GST_MAP_WRITE);
645
646   if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP))) {
647     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
648     memset (outmap.data, 0, outmap.size);
649   } else {
650     /* output always stereo, input mono or stereo,
651      * and info describes input format */
652     guint num_samples = outmap.size / (2 * GST_AUDIO_INFO_BPS (&filter->info));
653
654     filter->process (filter, inmap.data, outmap.data, num_samples);
655   }
656
657   gst_buffer_unmap (inbuf, &inmap);
658   gst_buffer_unmap (outbuf, &outmap);
659
660   return GST_FLOW_OK;
661 }