6d4b62ab03ea17597deb02423be0e827f3716795
[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 <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 (S32) ", " 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 (S32) ", " 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_details_simple (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   } else {
338     GST_INFO ("allow 2 channels");
339     gst_structure_set (structure, "channels", G_TYPE_INT, 2, NULL);
340   }
341
342   return res;
343 }
344
345 static gboolean
346 gst_audio_panorama_set_caps (GstBaseTransform * base, GstCaps * incaps,
347     GstCaps * outcaps)
348 {
349   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
350   GstAudioInfo info;
351
352   /*GST_INFO ("incaps are %" GST_PTR_FORMAT, incaps); */
353   if (!gst_audio_info_from_caps (&info, incaps))
354     goto no_format;
355
356   GST_DEBUG ("try to process %d input with %d channels",
357       GST_AUDIO_INFO_FORMAT (&info), GST_AUDIO_INFO_CHANNELS (&info));
358
359   if (!gst_audio_panorama_set_process_function (filter, &info))
360     goto no_format;
361
362   filter->info = info;
363
364   return TRUE;
365
366 no_format:
367   {
368     GST_DEBUG ("invalid caps");
369     return FALSE;
370   }
371 }
372
373 /* psychoacoustic processing functions */
374 static void
375 gst_audio_panorama_transform_m2s_int (GstAudioPanorama * filter, gint16 * idata,
376     gint16 * odata, guint num_samples)
377 {
378   guint i;
379   gdouble val;
380   glong lval, rval;
381   gdouble rpan, lpan;
382
383   /* pan:  -1.0  0.0  1.0
384    * lpan:  1.0  0.5  0.0  
385    * rpan:  0.0  0.5  1.0
386    *
387    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
388    */
389   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
390   lpan = 1.0 - rpan;
391
392   for (i = 0; i < num_samples; i++) {
393     val = (gdouble) * idata++;
394
395     lval = (glong) (val * lpan);
396     rval = (glong) (val * rpan);
397
398     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
399     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
400   }
401 }
402
403 static void
404 gst_audio_panorama_transform_s2s_int (GstAudioPanorama * filter, gint16 * idata,
405     gint16 * odata, guint num_samples)
406 {
407   guint i;
408   glong lval, rval;
409   gdouble lival, rival;
410   gdouble lrpan, llpan, rrpan, rlpan;
411
412   /* pan:  -1.0  0.0  1.0
413    * llpan: 1.0  1.0  0.0
414    * lrpan: 1.0  0.0  0.0
415    * rrpan: 0.0  1.0  1.0
416    * rlpan: 0.0  0.0  1.0
417    */
418   if (filter->panorama > 0) {
419     rlpan = (gdouble) filter->panorama;
420     llpan = 1.0 - rlpan;
421     lrpan = 0.0;
422     rrpan = 1.0;
423   } else {
424     rrpan = (gdouble) (1.0 + filter->panorama);
425     lrpan = 1.0 - rrpan;
426     rlpan = 0.0;
427     llpan = 1.0;
428   }
429
430   for (i = 0; i < num_samples; i++) {
431     lival = (gdouble) * idata++;
432     rival = (gdouble) * idata++;
433
434     lval = lival * llpan + rival * lrpan;
435     rval = lival * rlpan + rival * rrpan;
436
437     *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
438     *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
439   }
440 }
441
442 static void
443 gst_audio_panorama_transform_m2s_float (GstAudioPanorama * filter,
444     gfloat * idata, gfloat * odata, guint num_samples)
445 {
446   guint i;
447   gfloat val;
448   gdouble rpan, lpan;
449
450   /* pan:  -1.0  0.0  1.0
451    * lpan:  1.0  0.5  0.0  
452    * rpan:  0.0  0.5  1.0
453    *
454    * FIXME: we should use -3db (1/sqtr(2)) for 50:50
455    */
456   rpan = (gdouble) (filter->panorama + 1.0) / 2.0;
457   lpan = 1.0 - rpan;
458
459   for (i = 0; i < num_samples; i++) {
460     val = *idata++;
461
462     *odata++ = val * lpan;
463     *odata++ = val * rpan;
464   }
465 }
466
467 static void
468 gst_audio_panorama_transform_s2s_float (GstAudioPanorama * filter,
469     gfloat * idata, gfloat * odata, guint num_samples)
470 {
471   guint i;
472   gfloat lival, rival;
473   gdouble lrpan, llpan, rrpan, rlpan;
474
475   /* pan:  -1.0  0.0  1.0
476    * llpan: 1.0  1.0  0.0
477    * lrpan: 1.0  0.0  0.0
478    * rrpan: 0.0  1.0  1.0
479    * rlpan: 0.0  0.0  1.0
480    */
481   if (filter->panorama > 0) {
482     rlpan = (gdouble) filter->panorama;
483     llpan = 1.0 - rlpan;
484     lrpan = 0.0;
485     rrpan = 1.0;
486   } else {
487     rrpan = (gdouble) (1.0 + filter->panorama);
488     lrpan = 1.0 - rrpan;
489     rlpan = 0.0;
490     llpan = 1.0;
491   }
492
493   for (i = 0; i < num_samples; i++) {
494     lival = *idata++;
495     rival = *idata++;
496
497     *odata++ = lival * llpan + rival * lrpan;
498     *odata++ = lival * rlpan + rival * rrpan;
499   }
500 }
501
502 /* simple processing functions */
503 static void
504 gst_audio_panorama_transform_m2s_int_simple (GstAudioPanorama * filter,
505     gint16 * idata, gint16 * odata, guint num_samples)
506 {
507   guint i;
508   gdouble pan;
509   glong lval, rval;
510
511   if (filter->panorama > 0.0) {
512     pan = 1.0 - filter->panorama;
513     for (i = 0; i < num_samples; i++) {
514       rval = *idata++;
515       lval = (glong) ((gdouble) rval * pan);
516
517       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
518       *odata++ = (gint16) rval;
519     }
520   } else {
521     pan = 1.0 + filter->panorama;
522     for (i = 0; i < num_samples; i++) {
523       lval = *idata++;
524       rval = (glong) ((gdouble) lval * pan);
525
526       *odata++ = (gint16) lval;
527       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
528     }
529   }
530 }
531
532 static void
533 gst_audio_panorama_transform_s2s_int_simple (GstAudioPanorama * filter,
534     gint16 * idata, gint16 * odata, guint num_samples)
535 {
536   guint i;
537   glong lval, rval;
538   gdouble lival, rival, pan;
539
540   if (filter->panorama > 0.0) {
541     pan = 1.0 - filter->panorama;
542     for (i = 0; i < num_samples; i++) {
543       lival = (gdouble) * idata++;
544       rival = (gdouble) * idata++;
545
546       lval = (glong) (lival * pan);
547       rval = (glong) rival;
548
549       *odata++ = (gint16) CLAMP (lval, G_MININT16, G_MAXINT16);
550       *odata++ = (gint16) rval;
551     }
552   } else {
553     pan = 1.0 + filter->panorama;
554     for (i = 0; i < num_samples; i++) {
555       lival = (gdouble) * idata++;
556       rival = (gdouble) * idata++;
557
558       lval = (glong) lival;
559       rval = (glong) (rival * pan);
560
561       *odata++ = (gint16) lval;
562       *odata++ = (gint16) CLAMP (rval, G_MININT16, G_MAXINT16);
563     }
564   }
565 }
566
567 static void
568 gst_audio_panorama_transform_m2s_float_simple (GstAudioPanorama * filter,
569     gfloat * idata, gfloat * odata, guint num_samples)
570 {
571   guint i;
572   gfloat val, pan;
573
574   if (filter->panorama > 0.0) {
575     pan = 1.0 - filter->panorama;
576     for (i = 0; i < num_samples; i++) {
577       val = *idata++;
578
579       *odata++ = val * pan;
580       *odata++ = val;
581     }
582   } else {
583     pan = 1.0 + filter->panorama;
584     for (i = 0; i < num_samples; i++) {
585       val = *idata++;
586
587       *odata++ = val;
588       *odata++ = val * pan;
589     }
590   }
591 }
592
593 static void
594 gst_audio_panorama_transform_s2s_float_simple (GstAudioPanorama * filter,
595     gfloat * idata, gfloat * odata, guint num_samples)
596 {
597   guint i;
598   gfloat lival, rival, pan;
599
600   if (filter->panorama > 0.0) {
601     pan = 1.0 - filter->panorama;
602     for (i = 0; i < num_samples; i++) {
603       lival = *idata++;
604       rival = *idata++;
605
606       *odata++ = lival * pan;
607       *odata++ = rival;
608     }
609   } else {
610     pan = 1.0 + filter->panorama;
611     for (i = 0; i < num_samples; i++) {
612       lival = *idata++;
613       rival = *idata++;
614
615       *odata++ = lival;
616       *odata++ = rival * pan;
617     }
618   }
619 }
620
621 /* this function does the actual processing
622  */
623 static GstFlowReturn
624 gst_audio_panorama_transform (GstBaseTransform * base, GstBuffer * inbuf,
625     GstBuffer * outbuf)
626 {
627   GstAudioPanorama *filter = GST_AUDIO_PANORAMA (base);
628   GstClockTime timestamp, stream_time;
629   GstMapInfo inmap, outmap;
630
631   timestamp = GST_BUFFER_TIMESTAMP (inbuf);
632   stream_time =
633       gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
634
635   GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
636       GST_TIME_ARGS (timestamp));
637
638   if (GST_CLOCK_TIME_IS_VALID (stream_time))
639     gst_object_sync_values (GST_OBJECT (filter), stream_time);
640
641   gst_buffer_map (inbuf, &inmap, GST_MAP_READ);
642   gst_buffer_map (outbuf, &outmap, GST_MAP_WRITE);
643
644   if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP))) {
645     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
646     memset (outmap.data, 0, outmap.size);
647   } else {
648     guint num_samples = outmap.size / GST_AUDIO_INFO_BPF (&filter->info);
649
650     filter->process (filter, inmap.data, outmap.data, num_samples);
651   }
652
653   gst_buffer_unmap (inbuf, &inmap);
654   gst_buffer_unmap (outbuf, &outmap);
655
656   return GST_FLOW_OK;
657 }