2 * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) 2003,2004 David A. Schleef <ds@schleef.org>
4 * Copyright (C) 2007-2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>
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.
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.
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.
23 * SECTION:element-audioresample
25 * audioresample resamples raw audio buffers to different sample rates using
26 * a configurable windowing function to enhance quality.
29 * <title>Example launch line</title>
31 * gst-launch -v filesrc location=sine.ogg ! oggdemux ! vorbisdec ! audioconvert ! audioresample ! audio/x-raw-int, rate=8000 ! alsasink
32 * ]| Decode an Ogg/Vorbis downsample to 8Khz and play sound through alsa.
33 * To create the Ogg/Vorbis file refer to the documentation of vorbisenc.
38 * - Enable SSE/ARM optimizations and select at runtime
48 #include "gstaudioresample.h"
49 #include <gst/gstutils.h>
50 #include <gst/audio/audio.h>
51 #include <gst/base/gstbasetransform.h>
53 #if defined AUDIORESAMPLE_FORMAT_AUTO
54 #define OIL_ENABLE_UNSTABLE_API
55 #include <liboil/liboilprofile.h>
56 #include <liboil/liboil.h>
59 GST_DEBUG_CATEGORY (audio_resample_debug);
60 #define GST_CAT_DEFAULT audio_resample_debug
69 #define SUPPORTED_CAPS \
71 "audio/x-raw-float, " \
72 "rate = (int) [ 1, MAX ], " \
73 "channels = (int) [ 1, MAX ], " \
74 "endianness = (int) BYTE_ORDER, " \
75 "width = (int) { 32, 64 }; " \
77 "rate = (int) [ 1, MAX ], " \
78 "channels = (int) [ 1, MAX ], " \
79 "endianness = (int) BYTE_ORDER, " \
80 "width = (int) 32, " \
81 "depth = (int) 32, " \
82 "signed = (boolean) true; " \
84 "rate = (int) [ 1, MAX ], " \
85 "channels = (int) [ 1, MAX ], " \
86 "endianness = (int) BYTE_ORDER, " \
87 "width = (int) 24, " \
88 "depth = (int) 24, " \
89 "signed = (boolean) true; " \
91 "rate = (int) [ 1, MAX ], " \
92 "channels = (int) [ 1, MAX ], " \
93 "endianness = (int) BYTE_ORDER, " \
94 "width = (int) 16, " \
95 "depth = (int) 16, " \
96 "signed = (boolean) true; " \
98 "rate = (int) [ 1, MAX ], " \
99 "channels = (int) [ 1, MAX ], " \
100 "endianness = (int) BYTE_ORDER, " \
101 "width = (int) 8, " \
102 "depth = (int) 8, " \
103 "signed = (boolean) true" \
106 /* If TRUE integer arithmetic resampling is faster and will be used if appropiate */
107 #if defined AUDIORESAMPLE_FORMAT_INT
108 static gboolean gst_audio_resample_use_int = TRUE;
109 #elif defined AUDIORESAMPLE_FORMAT_FLOAT
110 static gboolean gst_audio_resample_use_int = FALSE;
112 static gboolean gst_audio_resample_use_int = FALSE;
115 static GstStaticPadTemplate gst_audio_resample_sink_template =
116 GST_STATIC_PAD_TEMPLATE ("sink",
117 GST_PAD_SINK, GST_PAD_ALWAYS, SUPPORTED_CAPS);
119 static GstStaticPadTemplate gst_audio_resample_src_template =
120 GST_STATIC_PAD_TEMPLATE ("src",
121 GST_PAD_SRC, GST_PAD_ALWAYS, SUPPORTED_CAPS);
123 static void gst_audio_resample_set_property (GObject * object,
124 guint prop_id, const GValue * value, GParamSpec * pspec);
125 static void gst_audio_resample_get_property (GObject * object,
126 guint prop_id, GValue * value, GParamSpec * pspec);
129 static gboolean gst_audio_resample_get_unit_size (GstBaseTransform * base,
130 GstCaps * caps, guint * size);
131 static GstCaps *gst_audio_resample_transform_caps (GstBaseTransform * base,
132 GstPadDirection direction, GstCaps * caps);
133 static void gst_audio_resample_fixate_caps (GstBaseTransform * base,
134 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
135 static gboolean gst_audio_resample_transform_size (GstBaseTransform * trans,
136 GstPadDirection direction, GstCaps * incaps, guint insize,
137 GstCaps * outcaps, guint * outsize);
138 static gboolean gst_audio_resample_set_caps (GstBaseTransform * base,
139 GstCaps * incaps, GstCaps * outcaps);
140 static GstFlowReturn gst_audio_resample_transform (GstBaseTransform * base,
141 GstBuffer * inbuf, GstBuffer * outbuf);
142 static gboolean gst_audio_resample_event (GstBaseTransform * base,
144 static gboolean gst_audio_resample_start (GstBaseTransform * base);
145 static gboolean gst_audio_resample_stop (GstBaseTransform * base);
146 static gboolean gst_audio_resample_query (GstPad * pad, GstQuery * query);
147 static const GstQueryType *gst_audio_resample_query_type (GstPad * pad);
149 GST_BOILERPLATE (GstAudioResample, gst_audio_resample, GstBaseTransform,
150 GST_TYPE_BASE_TRANSFORM);
153 gst_audio_resample_base_init (gpointer g_class)
155 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
157 gst_element_class_add_pad_template (gstelement_class,
158 gst_static_pad_template_get (&gst_audio_resample_src_template));
159 gst_element_class_add_pad_template (gstelement_class,
160 gst_static_pad_template_get (&gst_audio_resample_sink_template));
162 gst_element_class_set_details_simple (gstelement_class, "Audio resampler",
163 "Filter/Converter/Audio", "Resamples audio",
164 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
168 gst_audio_resample_class_init (GstAudioResampleClass * klass)
170 GObjectClass *gobject_class = (GObjectClass *) klass;
172 gobject_class->set_property = gst_audio_resample_set_property;
173 gobject_class->get_property = gst_audio_resample_get_property;
175 g_object_class_install_property (gobject_class, PROP_QUALITY,
176 g_param_spec_int ("quality", "Quality", "Resample quality with 0 being "
177 "the lowest and 10 being the best",
178 SPEEX_RESAMPLER_QUALITY_MIN, SPEEX_RESAMPLER_QUALITY_MAX,
179 SPEEX_RESAMPLER_QUALITY_DEFAULT,
180 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
182 /* FIXME 0.11: Remove this property, it's just for compatibility
183 * with old audioresample
186 * GstAudioResample:filter-length:
188 * Length of the resample filter
190 * Deprectated: Use #GstAudioResample:quality property instead
192 g_object_class_install_property (gobject_class, PROP_FILTER_LENGTH,
193 g_param_spec_int ("filter-length", "Filter length",
194 "Length of the resample filter", 0, G_MAXINT, 64, G_PARAM_READWRITE));
196 GST_BASE_TRANSFORM_CLASS (klass)->start =
197 GST_DEBUG_FUNCPTR (gst_audio_resample_start);
198 GST_BASE_TRANSFORM_CLASS (klass)->stop =
199 GST_DEBUG_FUNCPTR (gst_audio_resample_stop);
200 GST_BASE_TRANSFORM_CLASS (klass)->transform_size =
201 GST_DEBUG_FUNCPTR (gst_audio_resample_transform_size);
202 GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
203 GST_DEBUG_FUNCPTR (gst_audio_resample_get_unit_size);
204 GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
205 GST_DEBUG_FUNCPTR (gst_audio_resample_transform_caps);
206 GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps =
207 GST_DEBUG_FUNCPTR (gst_audio_resample_fixate_caps);
208 GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
209 GST_DEBUG_FUNCPTR (gst_audio_resample_set_caps);
210 GST_BASE_TRANSFORM_CLASS (klass)->transform =
211 GST_DEBUG_FUNCPTR (gst_audio_resample_transform);
212 GST_BASE_TRANSFORM_CLASS (klass)->event =
213 GST_DEBUG_FUNCPTR (gst_audio_resample_event);
215 GST_BASE_TRANSFORM_CLASS (klass)->passthrough_on_same_caps = TRUE;
219 gst_audio_resample_init (GstAudioResample * resample,
220 GstAudioResampleClass * klass)
222 GstBaseTransform *trans = GST_BASE_TRANSFORM (resample);
224 resample->quality = SPEEX_RESAMPLER_QUALITY_DEFAULT;
226 gst_pad_set_query_function (trans->srcpad, gst_audio_resample_query);
227 gst_pad_set_query_type_function (trans->srcpad,
228 gst_audio_resample_query_type);
233 gst_audio_resample_start (GstBaseTransform * base)
235 GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
237 resample->need_discont = TRUE;
239 resample->t0 = GST_CLOCK_TIME_NONE;
240 resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
241 resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
242 resample->next_in_offset = GST_BUFFER_OFFSET_NONE;
243 resample->next_out_offset = GST_BUFFER_OFFSET_NONE;
245 resample->tmp_in = NULL;
246 resample->tmp_in_size = 0;
247 resample->tmp_out = NULL;
248 resample->tmp_out_size = 0;
254 gst_audio_resample_stop (GstBaseTransform * base)
256 GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
258 if (resample->state) {
259 resample->funcs->destroy (resample->state);
260 resample->state = NULL;
263 resample->funcs = NULL;
265 g_free (resample->tmp_in);
266 resample->tmp_in = NULL;
267 resample->tmp_in_size = 0;
269 g_free (resample->tmp_out);
270 resample->tmp_out = NULL;
271 resample->tmp_out_size = 0;
273 gst_caps_replace (&resample->sinkcaps, NULL);
274 gst_caps_replace (&resample->srccaps, NULL);
280 gst_audio_resample_get_unit_size (GstBaseTransform * base, GstCaps * caps,
283 gint width, channels;
284 GstStructure *structure;
287 g_return_val_if_fail (size != NULL, FALSE);
289 /* this works for both float and int */
290 structure = gst_caps_get_structure (caps, 0);
291 ret = gst_structure_get_int (structure, "width", &width);
292 ret &= gst_structure_get_int (structure, "channels", &channels);
294 if (G_UNLIKELY (!ret))
297 *size = (width / 8) * channels;
303 gst_audio_resample_transform_caps (GstBaseTransform * base,
304 GstPadDirection direction, GstCaps * caps)
310 /* transform single caps into input_caps + input_caps with the rate
311 * field set to our supported range. This ensures that upstream knows
312 * about downstream's prefered rate(s) and can negotiate accordingly. */
313 res = gst_caps_copy (caps);
315 /* first, however, check if the caps contain a range for the rate field, in
316 * which case that side isn't going to care much about the exact sample rate
317 * chosen and we should just assume things will get fixated to something sane
318 * and we may just as well offer our full range instead of the range in the
319 * caps. If the rate is not an int range value, it's likely to express a
320 * real preference or limitation and we should maintain that structure as
321 * preference by putting it first into the transformed caps, and only add
322 * our full rate range as second option */
323 s = gst_caps_get_structure (res, 0);
324 val = gst_structure_get_value (s, "rate");
325 if (val == NULL || GST_VALUE_HOLDS_INT_RANGE (val)) {
326 /* overwrite existing range, or add field if it doesn't exist yet */
327 gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
329 /* append caps with full range to existing caps with non-range rate field */
330 s = gst_structure_copy (s);
331 gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
332 gst_caps_append_structure (res, s);
338 /* Fixate rate to the allowed rate that has the smallest difference */
340 gst_audio_resample_fixate_caps (GstBaseTransform * base,
341 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
346 s = gst_caps_get_structure (caps, 0);
347 if (G_UNLIKELY (!gst_structure_get_int (s, "rate", &rate)))
350 s = gst_caps_get_structure (othercaps, 0);
351 gst_structure_fixate_field_nearest_int (s, "rate", rate);
354 static const SpeexResampleFuncs *
355 gst_audio_resample_get_funcs (gint width, gboolean fp)
357 const SpeexResampleFuncs *funcs = NULL;
359 if (gst_audio_resample_use_int && (width == 8 || width == 16) && !fp)
361 else if ((!gst_audio_resample_use_int && (width == 8 || width == 16) && !fp)
362 || (width == 32 && fp))
363 funcs = &float_funcs;
364 else if ((width == 64 && fp) || ((width == 32 || width == 24) && !fp))
365 funcs = &double_funcs;
367 g_assert_not_reached ();
372 static SpeexResamplerState *
373 gst_audio_resample_init_state (GstAudioResample * resample, gint width,
374 gint channels, gint inrate, gint outrate, gint quality, gboolean fp)
376 SpeexResamplerState *ret = NULL;
377 gint err = RESAMPLER_ERR_SUCCESS;
378 const SpeexResampleFuncs *funcs = gst_audio_resample_get_funcs (width, fp);
380 ret = funcs->init (channels, inrate, outrate, quality, &err);
382 if (G_UNLIKELY (err != RESAMPLER_ERR_SUCCESS)) {
383 GST_ERROR_OBJECT (resample, "Failed to create resampler state: %s",
384 funcs->strerror (err));
388 funcs->skip_zeros (ret);
394 gst_audio_resample_update_state (GstAudioResample * resample, gint width,
395 gint channels, gint inrate, gint outrate, gint quality, gboolean fp)
398 gboolean updated_latency = FALSE;
400 updated_latency = (resample->inrate != inrate
401 || quality != resample->quality) && resample->state != NULL;
403 if (resample->state == NULL) {
405 } else if (resample->channels != channels || fp != resample->fp
406 || width != resample->width) {
407 resample->funcs->destroy (resample->state);
409 gst_audio_resample_init_state (resample, width, channels, inrate,
410 outrate, quality, fp);
412 resample->funcs = gst_audio_resample_get_funcs (width, fp);
413 ret = (resample->state != NULL);
414 } else if (resample->inrate != inrate || resample->outrate != outrate) {
415 gint err = RESAMPLER_ERR_SUCCESS;
417 err = resample->funcs->set_rate (resample->state, inrate, outrate);
419 if (G_UNLIKELY (err != RESAMPLER_ERR_SUCCESS))
420 GST_ERROR_OBJECT (resample, "Failed to update rate: %s",
421 resample->funcs->strerror (err));
423 ret = (err == RESAMPLER_ERR_SUCCESS);
424 } else if (quality != resample->quality) {
425 gint err = RESAMPLER_ERR_SUCCESS;
427 err = resample->funcs->set_quality (resample->state, quality);
429 if (G_UNLIKELY (err != RESAMPLER_ERR_SUCCESS))
430 GST_ERROR_OBJECT (resample, "Failed to update quality: %s",
431 resample->funcs->strerror (err));
433 ret = (err == RESAMPLER_ERR_SUCCESS);
436 resample->width = width;
437 resample->channels = channels;
439 resample->quality = quality;
440 resample->inrate = inrate;
441 resample->outrate = outrate;
444 gst_element_post_message (GST_ELEMENT (resample),
445 gst_message_new_latency (GST_OBJECT (resample)));
451 gst_audio_resample_reset_state (GstAudioResample * resample)
454 resample->funcs->reset_mem (resample->state);
458 gst_audio_resample_parse_caps (GstCaps * incaps,
459 GstCaps * outcaps, gint * width, gint * channels, gint * inrate,
460 gint * outrate, gboolean * fp)
462 GstStructure *structure;
464 gint mywidth, myinrate, myoutrate, mychannels;
467 GST_DEBUG ("incaps %" GST_PTR_FORMAT ", outcaps %"
468 GST_PTR_FORMAT, incaps, outcaps);
470 structure = gst_caps_get_structure (incaps, 0);
472 if (g_str_equal (gst_structure_get_name (structure), "audio/x-raw-float"))
477 ret = gst_structure_get_int (structure, "rate", &myinrate);
478 ret &= gst_structure_get_int (structure, "channels", &mychannels);
479 ret &= gst_structure_get_int (structure, "width", &mywidth);
480 if (G_UNLIKELY (!ret))
481 goto no_in_rate_channels;
483 structure = gst_caps_get_structure (outcaps, 0);
484 ret = gst_structure_get_int (structure, "rate", &myoutrate);
485 if (G_UNLIKELY (!ret))
489 *channels = mychannels;
493 *outrate = myoutrate;
504 GST_DEBUG ("could not get input rate and channels");
509 GST_DEBUG ("could not get output rate");
515 _gcd (gint a, gint b)
528 gst_audio_resample_transform_size (GstBaseTransform * base,
529 GstPadDirection direction, GstCaps * caps, guint size, GstCaps * othercaps,
533 guint32 ratio_den, ratio_num;
534 gint inrate, outrate, gcd;
535 gint bytes_per_samp, channels;
537 GST_LOG_OBJECT (base, "asked to transform size %d in direction %s",
538 size, direction == GST_PAD_SINK ? "SINK" : "SRC");
540 /* Get sample width -> bytes_per_samp, channels, inrate, outrate */
542 gst_audio_resample_parse_caps (caps, othercaps, &bytes_per_samp,
543 &channels, &inrate, &outrate, NULL);
544 if (G_UNLIKELY (!ret)) {
545 GST_ERROR_OBJECT (base, "Wrong caps");
548 /* Number of samples in either buffer is size / (width*channels) ->
549 * calculate the factor */
550 bytes_per_samp = bytes_per_samp * channels / 8;
551 /* Convert source buffer size to samples */
552 size /= bytes_per_samp;
554 /* Simplify the conversion ratio factors */
555 gcd = _gcd (inrate, outrate);
556 ratio_num = inrate / gcd;
557 ratio_den = outrate / gcd;
559 if (direction == GST_PAD_SINK) {
560 /* asked to convert size of an incoming buffer. Round up the output size */
561 *othersize = gst_util_uint64_scale_int_ceil (size, ratio_den, ratio_num);
562 *othersize *= bytes_per_samp;
564 /* asked to convert size of an outgoing buffer. Round down the input size */
565 *othersize = gst_util_uint64_scale_int (size, ratio_num, ratio_den);
566 *othersize *= bytes_per_samp;
569 GST_LOG_OBJECT (base, "transformed size %d to %d", size * bytes_per_samp,
576 gst_audio_resample_set_caps (GstBaseTransform * base, GstCaps * incaps,
580 gint width = 0, inrate = 0, outrate = 0, channels = 0;
582 GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
584 GST_LOG ("incaps %" GST_PTR_FORMAT ", outcaps %"
585 GST_PTR_FORMAT, incaps, outcaps);
587 ret = gst_audio_resample_parse_caps (incaps, outcaps,
588 &width, &channels, &inrate, &outrate, &fp);
590 if (G_UNLIKELY (!ret))
594 gst_audio_resample_update_state (resample, width, channels, inrate,
595 outrate, resample->quality, fp);
597 if (G_UNLIKELY (!ret))
600 /* save caps so we can short-circuit in the size_transform if the caps
602 gst_caps_replace (&resample->sinkcaps, incaps);
603 gst_caps_replace (&resample->srccaps, outcaps);
608 #define GST_MAXINT24 (8388607)
609 #define GST_MININT24 (-8388608)
611 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
612 #define GST_READ_UINT24 GST_READ_UINT24_LE
613 #define GST_WRITE_UINT24 GST_WRITE_UINT24_LE
615 #define GST_READ_UINT24 GST_READ_UINT24_BE
616 #define GST_WRITE_UINT24 GST_WRITE_UINT24_BE
620 gst_audio_resample_convert_buffer (GstAudioResample * resample,
621 const guint8 * in, guint8 * out, guint len, gboolean inverse)
623 len *= resample->channels;
626 if (gst_audio_resample_use_int && resample->width == 8 && !resample->fp) {
627 gint8 *o = (gint8 *) out;
628 gint16 *i = (gint16 *) in;
632 tmp = *i + (G_MAXINT8 >> 1);
633 *o = CLAMP (tmp >> 8, G_MININT8, G_MAXINT8);
638 } else if (!gst_audio_resample_use_int && resample->width == 8
640 gint8 *o = (gint8 *) out;
641 gfloat *i = (gfloat *) in;
646 *o = (gint8) CLAMP (tmp * G_MAXINT8 + 0.5, G_MININT8, G_MAXINT8);
651 } else if (!gst_audio_resample_use_int && resample->width == 16
653 gint16 *o = (gint16 *) out;
654 gfloat *i = (gfloat *) in;
659 *o = (gint16) CLAMP (tmp * G_MAXINT16 + 0.5, G_MININT16, G_MAXINT16);
664 } else if (resample->width == 24 && !resample->fp) {
665 guint8 *o = (guint8 *) out;
666 gdouble *i = (gdouble *) in;
671 GST_WRITE_UINT24 (o, (gint32) CLAMP (tmp * GST_MAXINT24 + 0.5,
672 GST_MININT24, GST_MAXINT24));
677 } else if (resample->width == 32 && !resample->fp) {
678 gint32 *o = (gint32 *) out;
679 gdouble *i = (gdouble *) in;
684 *o = (gint32) CLAMP (tmp * G_MAXINT32 + 0.5, G_MININT32, G_MAXINT32);
690 g_assert_not_reached ();
693 if (gst_audio_resample_use_int && resample->width == 8 && !resample->fp) {
694 gint8 *i = (gint8 *) in;
695 gint16 *o = (gint16 *) out;
705 } else if (!gst_audio_resample_use_int && resample->width == 8
707 gint8 *i = (gint8 *) in;
708 gfloat *o = (gfloat *) out;
713 *o = tmp / G_MAXINT8;
718 } else if (!gst_audio_resample_use_int && resample->width == 16
720 gint16 *i = (gint16 *) in;
721 gfloat *o = (gfloat *) out;
726 *o = tmp / G_MAXINT16;
731 } else if (resample->width == 24 && !resample->fp) {
732 guint8 *i = (guint8 *) in;
733 gdouble *o = (gdouble *) out;
738 tmp2 = GST_READ_UINT24 (i);
739 if (tmp2 & 0x00800000)
742 *o = tmp / GST_MAXINT24;
747 } else if (resample->width == 32 && !resample->fp) {
748 gint32 *i = (gint32 *) in;
749 gdouble *o = (gdouble *) out;
754 *o = tmp / G_MAXINT32;
760 g_assert_not_reached ();
766 gst_audio_resample_workspace_realloc (guint8 ** workspace, guint * size,
770 if (new_size <= *size)
771 /* no need to resize */
773 new = g_realloc (*workspace, new_size);
775 /* failure (re)allocating memeory */
784 gst_audio_resample_push_drain (GstAudioResample * resample)
789 guint history_len, out_len, out_processed;
793 if (!resample->state)
796 /* Don't drain samples if we were reset. */
797 if (!GST_CLOCK_TIME_IS_VALID (resample->t0))
800 resample->funcs->get_ratio (resample->state, &num, &den);
802 history_len = resample->funcs->get_input_latency (resample->state);
803 out_len = out_processed =
804 gst_util_uint64_scale_int_ceil (history_len, den, num);
805 outsize = out_len * resample->channels * (resample->width / 8);
808 gst_pad_alloc_buffer_and_set_caps (GST_BASE_TRANSFORM_SRC_PAD (resample),
809 GST_BUFFER_OFFSET_NONE, outsize,
810 GST_PAD_CAPS (GST_BASE_TRANSFORM_SRC_PAD (resample)), &outbuf);
811 if (G_UNLIKELY (res != GST_FLOW_OK)) {
812 GST_WARNING_OBJECT (resample, "failed allocating buffer of %d bytes",
817 if (resample->funcs->width != resample->width) {
818 /* need to convert data format; allocate workspace */
819 if (!gst_audio_resample_workspace_realloc (&resample->tmp_out,
820 &resample->tmp_out_size, (resample->funcs->width / 8) * out_len *
821 resample->channels)) {
822 GST_ERROR_OBJECT (resample, "failed to allocate workspace");
827 err = resample->funcs->process (resample->state, NULL, &out_len,
828 resample->tmp_out, &out_processed);
830 /* convert output format */
831 gst_audio_resample_convert_buffer (resample, resample->tmp_out,
832 GST_BUFFER_DATA (outbuf), out_processed, TRUE);
834 /* don't need to convert data format; process */
835 err = resample->funcs->process (resample->state, NULL, &history_len,
836 GST_BUFFER_DATA (outbuf), &out_processed);
839 /* If we wrote more than allocated something is really wrong now
840 * and we should better abort immediately */
841 g_assert (out_len >= out_processed);
843 if (G_UNLIKELY (err != RESAMPLER_ERR_SUCCESS)) {
844 GST_WARNING_OBJECT (resample, "Failed to process drain: %s",
845 resample->funcs->strerror (err));
846 gst_buffer_unref (outbuf);
850 if (G_UNLIKELY (out_processed == 0)) {
851 GST_WARNING_OBJECT (resample, "Failed to get drain, dropping buffer");
852 gst_buffer_unref (outbuf);
856 if (GST_CLOCK_TIME_IS_VALID (resample->t0)) {
857 GST_BUFFER_OFFSET (outbuf) = resample->next_out_offset;
858 GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET (outbuf) + out_processed;
859 GST_BUFFER_TIMESTAMP (outbuf) = resample->t0 +
860 gst_util_uint64_scale_int_round (GST_BUFFER_OFFSET (outbuf) -
861 resample->out_offset0, GST_SECOND, resample->outrate);
862 GST_BUFFER_DURATION (outbuf) = resample->t0 +
863 gst_util_uint64_scale_int_round (GST_BUFFER_OFFSET_END (outbuf) -
864 resample->out_offset0, GST_SECOND, resample->outrate) -
865 GST_BUFFER_TIMESTAMP (outbuf);
866 resample->next_out_offset += out_processed;
867 resample->next_in_offset += 0;
869 GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET_NONE;
870 GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET_NONE;
871 GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
872 GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
875 GST_BUFFER_SIZE (outbuf) =
876 out_processed * resample->channels * (resample->width / 8);
878 GST_LOG_OBJECT (resample,
879 "Pushing drain buffer of %u bytes with timestamp %" GST_TIME_FORMAT
880 " duration %" GST_TIME_FORMAT " offset %" G_GUINT64_FORMAT " offset_end %"
881 G_GUINT64_FORMAT, GST_BUFFER_SIZE (outbuf),
882 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
883 GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)), GST_BUFFER_OFFSET (outbuf),
884 GST_BUFFER_OFFSET_END (outbuf));
886 res = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (resample), outbuf);
888 if (G_UNLIKELY (res != GST_FLOW_OK))
889 GST_WARNING_OBJECT (resample, "Failed to push drain: %s",
890 gst_flow_get_name (res));
896 gst_audio_resample_event (GstBaseTransform * base, GstEvent * event)
898 GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
900 switch (GST_EVENT_TYPE (event)) {
901 case GST_EVENT_FLUSH_STOP:
902 gst_audio_resample_reset_state (resample);
903 resample->t0 = GST_CLOCK_TIME_NONE;
904 resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
905 resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
906 resample->next_in_offset = GST_BUFFER_OFFSET_NONE;
907 resample->next_out_offset = GST_BUFFER_OFFSET_NONE;
908 resample->need_discont = TRUE;
910 case GST_EVENT_NEWSEGMENT:
911 gst_audio_resample_push_drain (resample);
912 gst_audio_resample_reset_state (resample);
913 resample->t0 = GST_CLOCK_TIME_NONE;
914 resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
915 resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
916 resample->next_in_offset = GST_BUFFER_OFFSET_NONE;
917 resample->next_out_offset = GST_BUFFER_OFFSET_NONE;
918 resample->need_discont = TRUE;
921 gst_audio_resample_push_drain (resample);
922 gst_audio_resample_reset_state (resample);
928 return parent_class->event (base, event);
932 gst_audio_resample_check_discont (GstAudioResample * resample, GstBuffer * buf)
937 /* is the incoming buffer a discontinuity? */
938 if (G_UNLIKELY (GST_BUFFER_IS_DISCONT (buf)))
941 /* no valid timestamps or offsets to compare --> no discontinuity */
942 if (G_UNLIKELY (!(GST_BUFFER_TIMESTAMP_IS_VALID (buf) &&
943 GST_CLOCK_TIME_IS_VALID (resample->t0) &&
944 resample->in_offset0 != GST_BUFFER_OFFSET_NONE &&
945 resample->next_in_offset != GST_BUFFER_OFFSET_NONE)))
948 /* convert the inbound timestamp to an offset. */
950 resample->in_offset0 +
951 gst_util_uint64_scale_int_round (GST_BUFFER_TIMESTAMP (buf) -
952 resample->t0, resample->inrate, GST_SECOND);
954 /* many elements generate imperfect streams due to rounding errors, so we
955 * permit a small error (up to one sample) without triggering a filter
956 * flush/restart (if triggered incorrectly, this will be audible) */
957 delta = ABS ((gint64) (offset - resample->next_in_offset));
961 GST_WARNING_OBJECT (resample,
962 "encountered timestamp discontinuity of %lu samples = %" GST_TIME_FORMAT,
963 delta, GST_TIME_ARGS (gst_util_uint64_scale_int_round (delta, GST_SECOND,
969 gst_audio_resample_process (GstAudioResample * resample, GstBuffer * inbuf,
972 guint32 in_len, in_processed;
973 guint32 out_len, out_processed;
976 in_len = GST_BUFFER_SIZE (inbuf) / resample->channels;
977 out_len = GST_BUFFER_SIZE (outbuf) / resample->channels;
979 in_len /= (resample->width / 8);
980 out_len /= (resample->width / 8);
982 in_processed = in_len;
983 out_processed = out_len;
985 if (resample->funcs->width != resample->width) {
986 /* need to convert data format for processing; ensure we have enough
987 * workspace available */
988 if (!gst_audio_resample_workspace_realloc (&resample->tmp_in,
989 &resample->tmp_in_size, in_len * resample->channels *
990 (resample->funcs->width / 8)) ||
991 !gst_audio_resample_workspace_realloc (&resample->tmp_out,
992 &resample->tmp_out_size, out_len * resample->channels *
993 (resample->funcs->width / 8))) {
994 GST_ERROR_OBJECT (resample, "failed to allocate workspace");
995 return GST_FLOW_ERROR;
999 gst_audio_resample_convert_buffer (resample, GST_BUFFER_DATA (inbuf),
1000 resample->tmp_in, in_len, FALSE);
1003 err = resample->funcs->process (resample->state,
1004 resample->tmp_in, &in_processed, resample->tmp_out, &out_processed);
1006 /* convert output */
1007 gst_audio_resample_convert_buffer (resample, resample->tmp_out,
1008 GST_BUFFER_DATA (outbuf), out_processed, TRUE);
1010 /* no format conversion required; process */
1011 err = resample->funcs->process (resample->state,
1012 GST_BUFFER_DATA (inbuf), &in_processed,
1013 GST_BUFFER_DATA (outbuf), &out_processed);
1016 /* If we wrote more than allocated something is really wrong now and we
1017 * should better abort immediately */
1018 g_assert (out_len >= out_processed);
1020 if (G_UNLIKELY (err != RESAMPLER_ERR_SUCCESS)) {
1021 GST_ERROR_OBJECT (resample, "Failed to convert data: %s",
1022 resample->funcs->strerror (err));
1023 return GST_FLOW_ERROR;
1026 if (G_UNLIKELY (in_len != in_processed)) {
1027 GST_WARNING_OBJECT (resample, "converted %d of %d input samples",
1028 in_processed, in_len);
1031 if (GST_CLOCK_TIME_IS_VALID (resample->t0)) {
1032 GST_BUFFER_OFFSET (outbuf) = resample->next_out_offset;
1033 GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET (outbuf) + out_processed;
1034 GST_BUFFER_TIMESTAMP (outbuf) = resample->t0 +
1035 gst_util_uint64_scale_int_round (GST_BUFFER_OFFSET (outbuf) -
1036 resample->out_offset0, GST_SECOND, resample->outrate);
1037 GST_BUFFER_DURATION (outbuf) = resample->t0 +
1038 gst_util_uint64_scale_int_round (GST_BUFFER_OFFSET_END (outbuf) -
1039 resample->out_offset0, GST_SECOND, resample->outrate) -
1040 GST_BUFFER_TIMESTAMP (outbuf);
1041 resample->next_out_offset += out_processed;
1042 resample->next_in_offset += in_len;
1044 GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET_NONE;
1045 GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET_NONE;
1046 GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
1047 GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
1050 GST_BUFFER_SIZE (outbuf) =
1051 out_processed * resample->channels * (resample->width / 8);
1053 GST_LOG_OBJECT (resample,
1054 "Converted to buffer of %" G_GUINT32_FORMAT
1055 " samples (%u bytes) with timestamp %" GST_TIME_FORMAT ", duration %"
1056 GST_TIME_FORMAT ", offset %" G_GUINT64_FORMAT ", offset_end %"
1057 G_GUINT64_FORMAT, out_processed, GST_BUFFER_SIZE (outbuf),
1058 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1059 GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)),
1060 GST_BUFFER_OFFSET (outbuf), GST_BUFFER_OFFSET_END (outbuf));
1062 if (out_processed == 0) {
1063 GST_DEBUG_OBJECT (resample, "buffer dropped");
1064 return GST_BASE_TRANSFORM_FLOW_DROPPED;
1069 static GstFlowReturn
1070 gst_audio_resample_transform (GstBaseTransform * base, GstBuffer * inbuf,
1073 GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
1077 if (resample->state == NULL) {
1078 if (G_UNLIKELY (!(resample->state =
1079 gst_audio_resample_init_state (resample, resample->width,
1080 resample->channels, resample->inrate, resample->outrate,
1081 resample->quality, resample->fp))))
1082 return GST_FLOW_ERROR;
1085 gst_audio_resample_get_funcs (resample->width, resample->fp);
1088 size = GST_BUFFER_SIZE (inbuf);
1090 GST_LOG_OBJECT (resample, "transforming buffer of %ld bytes, ts %"
1091 GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT ", offset %"
1092 G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT,
1093 size, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (inbuf)),
1094 GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf)),
1095 GST_BUFFER_OFFSET (inbuf), GST_BUFFER_OFFSET_END (inbuf));
1097 /* check for timestamp discontinuities; flush/reset if needed, and set
1098 * flag to resync timestamp and offset counters and send event
1100 if (G_UNLIKELY (gst_audio_resample_check_discont (resample, inbuf))) {
1101 gst_audio_resample_reset_state (resample);
1102 resample->need_discont = TRUE;
1105 /* handle discontinuity */
1106 if (G_UNLIKELY (resample->need_discont)) {
1107 /* resync the timestamp and offset counters if possible */
1108 if (GST_BUFFER_TIMESTAMP_IS_VALID (inbuf) &&
1109 GST_BUFFER_OFFSET_IS_VALID (inbuf)) {
1110 resample->t0 = GST_BUFFER_TIMESTAMP (inbuf);
1111 resample->in_offset0 = GST_BUFFER_OFFSET (inbuf);
1112 resample->out_offset0 =
1113 gst_util_uint64_scale_int_round (resample->in_offset0,
1114 resample->outrate, resample->inrate);
1115 resample->next_in_offset = resample->in_offset0;
1116 resample->next_out_offset = resample->out_offset0;
1118 GST_DEBUG_OBJECT (resample, "found discontinuity but timestamp and/or "
1119 "offset is invalid, cannot sync output timestamp and offset counter");
1120 resample->t0 = GST_CLOCK_TIME_NONE;
1121 resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
1122 resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
1123 resample->next_in_offset = GST_BUFFER_OFFSET_NONE;
1124 resample->next_out_offset = GST_BUFFER_OFFSET_NONE;
1126 /* set DISCONT flag on output buffer */
1127 GST_DEBUG_OBJECT (resample, "marking this buffer with the DISCONT flag");
1128 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
1129 resample->need_discont = FALSE;
1132 ret = gst_audio_resample_process (resample, inbuf, outbuf);
1133 if (G_UNLIKELY (ret != GST_FLOW_OK))
1136 GST_DEBUG_OBJECT (resample, "input = samples [%" G_GUINT64_FORMAT ", %"
1137 G_GUINT64_FORMAT ") = [%" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT
1138 ") ns; output = samples [%" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT
1139 ") = [%" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT ") ns",
1140 GST_BUFFER_OFFSET (inbuf), GST_BUFFER_OFFSET_END (inbuf),
1141 GST_BUFFER_TIMESTAMP (inbuf), GST_BUFFER_TIMESTAMP (inbuf) +
1142 GST_BUFFER_DURATION (inbuf), GST_BUFFER_OFFSET (outbuf),
1143 GST_BUFFER_OFFSET_END (outbuf), GST_BUFFER_TIMESTAMP (outbuf),
1144 GST_BUFFER_TIMESTAMP (outbuf) + GST_BUFFER_DURATION (outbuf));
1150 gst_audio_resample_query (GstPad * pad, GstQuery * query)
1152 GstAudioResample *resample = GST_AUDIO_RESAMPLE (gst_pad_get_parent (pad));
1153 GstBaseTransform *trans = GST_BASE_TRANSFORM (resample);
1154 gboolean res = TRUE;
1156 switch (GST_QUERY_TYPE (query)) {
1157 case GST_QUERY_LATENCY:
1159 GstClockTime min, max;
1163 gint rate = resample->inrate;
1164 gint resampler_latency;
1166 if (resample->state)
1168 resample->funcs->get_input_latency (resample->state);
1170 resampler_latency = 0;
1172 if (gst_base_transform_is_passthrough (trans))
1173 resampler_latency = 0;
1175 if ((peer = gst_pad_get_peer (GST_BASE_TRANSFORM_SINK_PAD (trans)))) {
1176 if ((res = gst_pad_query (peer, query))) {
1177 gst_query_parse_latency (query, &live, &min, &max);
1179 GST_DEBUG_OBJECT (resample, "Peer latency: min %"
1180 GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
1181 GST_TIME_ARGS (min), GST_TIME_ARGS (max));
1183 /* add our own latency */
1184 if (rate != 0 && resampler_latency != 0)
1185 latency = gst_util_uint64_scale_round (resampler_latency,
1190 GST_DEBUG_OBJECT (resample, "Our latency: %" GST_TIME_FORMAT,
1191 GST_TIME_ARGS (latency));
1194 if (GST_CLOCK_TIME_IS_VALID (max))
1197 GST_DEBUG_OBJECT (resample, "Calculated total latency : min %"
1198 GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
1199 GST_TIME_ARGS (min), GST_TIME_ARGS (max));
1201 gst_query_set_latency (query, live, min, max);
1203 gst_object_unref (peer);
1208 res = gst_pad_query_default (pad, query);
1211 gst_object_unref (resample);
1215 static const GstQueryType *
1216 gst_audio_resample_query_type (GstPad * pad)
1218 static const GstQueryType types[] = {
1227 gst_audio_resample_set_property (GObject * object, guint prop_id,
1228 const GValue * value, GParamSpec * pspec)
1230 GstAudioResample *resample;
1232 resample = GST_AUDIO_RESAMPLE (object);
1236 GST_BASE_TRANSFORM_LOCK (resample);
1237 resample->quality = g_value_get_int (value);
1238 GST_DEBUG_OBJECT (resample, "new quality %d", resample->quality);
1240 gst_audio_resample_update_state (resample, resample->width,
1241 resample->channels, resample->inrate, resample->outrate,
1242 resample->quality, resample->fp);
1243 GST_BASE_TRANSFORM_UNLOCK (resample);
1245 case PROP_FILTER_LENGTH:{
1246 gint filter_length = g_value_get_int (value);
1248 GST_BASE_TRANSFORM_LOCK (resample);
1249 if (filter_length <= 8)
1250 resample->quality = 0;
1251 else if (filter_length <= 16)
1252 resample->quality = 1;
1253 else if (filter_length <= 32)
1254 resample->quality = 2;
1255 else if (filter_length <= 48)
1256 resample->quality = 3;
1257 else if (filter_length <= 64)
1258 resample->quality = 4;
1259 else if (filter_length <= 80)
1260 resample->quality = 5;
1261 else if (filter_length <= 96)
1262 resample->quality = 6;
1263 else if (filter_length <= 128)
1264 resample->quality = 7;
1265 else if (filter_length <= 160)
1266 resample->quality = 8;
1267 else if (filter_length <= 192)
1268 resample->quality = 9;
1270 resample->quality = 10;
1272 GST_DEBUG_OBJECT (resample, "new quality %d", resample->quality);
1274 gst_audio_resample_update_state (resample, resample->width,
1275 resample->channels, resample->inrate, resample->outrate,
1276 resample->quality, resample->fp);
1277 GST_BASE_TRANSFORM_UNLOCK (resample);
1281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1287 gst_audio_resample_get_property (GObject * object, guint prop_id,
1288 GValue * value, GParamSpec * pspec)
1290 GstAudioResample *resample;
1292 resample = GST_AUDIO_RESAMPLE (object);
1296 g_value_set_int (value, resample->quality);
1298 case PROP_FILTER_LENGTH:
1299 switch (resample->quality) {
1301 g_value_set_int (value, 8);
1304 g_value_set_int (value, 16);
1307 g_value_set_int (value, 32);
1310 g_value_set_int (value, 48);
1313 g_value_set_int (value, 64);
1316 g_value_set_int (value, 80);
1319 g_value_set_int (value, 96);
1322 g_value_set_int (value, 128);
1325 g_value_set_int (value, 160);
1328 g_value_set_int (value, 192);
1331 g_value_set_int (value, 256);
1336 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1341 #if defined AUDIORESAMPLE_FORMAT_AUTO
1342 #define BENCHMARK_SIZE 512
1345 _benchmark_int_float (SpeexResamplerState * st)
1347 gint16 in[BENCHMARK_SIZE] = { 0, }, out[BENCHMARK_SIZE / 2];
1348 gfloat in_tmp[BENCHMARK_SIZE], out_tmp[BENCHMARK_SIZE / 2];
1350 guint32 inlen = BENCHMARK_SIZE, outlen = BENCHMARK_SIZE / 2;
1352 for (i = 0; i < BENCHMARK_SIZE; i++) {
1354 in_tmp[i] = tmp / G_MAXINT16;
1357 resample_float_resampler_process_interleaved_float (st,
1358 (const guint8 *) in_tmp, &inlen, (guint8 *) out_tmp, &outlen);
1361 GST_ERROR ("Failed to use float resampler");
1365 for (i = 0; i < outlen; i++) {
1366 gfloat tmp = out_tmp[i];
1367 out[i] = CLAMP (tmp * G_MAXINT16 + 0.5, G_MININT16, G_MAXINT16);
1374 _benchmark_int_int (SpeexResamplerState * st)
1376 gint16 in[BENCHMARK_SIZE] = { 0, }, out[BENCHMARK_SIZE / 2];
1377 guint32 inlen = BENCHMARK_SIZE, outlen = BENCHMARK_SIZE / 2;
1379 resample_int_resampler_process_interleaved_int (st, (const guint8 *) in,
1380 &inlen, (guint8 *) out, &outlen);
1383 GST_ERROR ("Failed to use int resampler");
1391 _benchmark_integer_resampling (void)
1395 SpeexResamplerState *sta, *stb;
1398 oil_profile_init (&a);
1399 oil_profile_init (&b);
1401 sta = resample_float_resampler_init (1, 48000, 24000, 4, NULL);
1403 GST_ERROR ("Failed to create float resampler state");
1407 stb = resample_int_resampler_init (1, 48000, 24000, 4, NULL);
1409 resample_float_resampler_destroy (sta);
1410 GST_ERROR ("Failed to create int resampler state");
1415 for (i = 0; i < 10; i++) {
1416 oil_profile_start (&a);
1417 if (!_benchmark_int_float (sta))
1419 oil_profile_stop (&a);
1423 for (i = 0; i < 10; i++) {
1424 oil_profile_start (&b);
1425 if (!_benchmark_int_int (stb))
1427 oil_profile_stop (&b);
1430 /* Handle results */
1431 oil_profile_get_ave_std (&a, &av, NULL);
1432 oil_profile_get_ave_std (&b, &bv, NULL);
1434 /* Remember benchmark result in global variable */
1435 gst_audio_resample_use_int = (av > bv);
1436 resample_float_resampler_destroy (sta);
1437 resample_int_resampler_destroy (stb);
1440 GST_INFO ("Using integer resampler if appropiate: %lf < %lf", bv, av);
1442 GST_INFO ("Using float resampler for everything: %lf <= %lf", av, bv);
1447 resample_float_resampler_destroy (sta);
1448 resample_int_resampler_destroy (stb);
1455 plugin_init (GstPlugin * plugin)
1457 GST_DEBUG_CATEGORY_INIT (audio_resample_debug, "audioresample", 0,
1458 "audio resampling element");
1459 #if defined AUDIORESAMPLE_FORMAT_AUTO
1462 if (!_benchmark_integer_resampling ())
1466 if (!gst_element_register (plugin, "audioresample", GST_RANK_PRIMARY,
1467 GST_TYPE_AUDIO_RESAMPLE)) {
1474 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1477 "Resamples audio", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
1478 GST_PACKAGE_ORIGIN);