mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-28 18:18:38 +00:00
audioamplify: Add noclip method and support for more formats
Fixes bug #585828 and #585831.
This commit is contained in:
parent
8ecd5f1a06
commit
afccf53ace
2 changed files with 233 additions and 165 deletions
|
@ -74,6 +74,7 @@ enum
|
||||||
METHOD_CLIP = 0,
|
METHOD_CLIP = 0,
|
||||||
METHOD_WRAP_NEGATIVE,
|
METHOD_WRAP_NEGATIVE,
|
||||||
METHOD_WRAP_POSITIVE,
|
METHOD_WRAP_POSITIVE,
|
||||||
|
METHOD_NOCLIP,
|
||||||
NUM_METHODS
|
NUM_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,12 +86,13 @@ gst_audio_amplify_clipping_method_get_type (void)
|
||||||
|
|
||||||
if (gtype == 0) {
|
if (gtype == 0) {
|
||||||
static const GEnumValue values[] = {
|
static const GEnumValue values[] = {
|
||||||
{METHOD_CLIP, "Normal Clipping (default)", "clip"},
|
{METHOD_CLIP, "Normal clipping (default)", "clip"},
|
||||||
{METHOD_WRAP_NEGATIVE,
|
{METHOD_WRAP_NEGATIVE,
|
||||||
"Push overdriven values back from the opposite side",
|
"Push overdriven values back from the opposite side",
|
||||||
"wrap-negative"},
|
"wrap-negative"},
|
||||||
{METHOD_WRAP_POSITIVE, "Push overdriven values back from the same side",
|
{METHOD_WRAP_POSITIVE, "Push overdriven values back from the same side",
|
||||||
"wrap-positive"},
|
"wrap-positive"},
|
||||||
|
{METHOD_NOCLIP, "No clipping", "none"},
|
||||||
{0, NULL, NULL}
|
{0, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,6 +103,13 @@ gst_audio_amplify_clipping_method_get_type (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ALLOWED_CAPS \
|
#define ALLOWED_CAPS \
|
||||||
|
"audio/x-raw-int," \
|
||||||
|
" depth=(int)8," \
|
||||||
|
" width=(int)8," \
|
||||||
|
" endianness=(int)BYTE_ORDER," \
|
||||||
|
" signed=(bool)TRUE," \
|
||||||
|
" rate=(int)[1,MAX]," \
|
||||||
|
" channels=(int)[1,MAX]; " \
|
||||||
"audio/x-raw-int," \
|
"audio/x-raw-int," \
|
||||||
" depth=(int)16," \
|
" depth=(int)16," \
|
||||||
" width=(int)16," \
|
" width=(int)16," \
|
||||||
|
@ -108,9 +117,16 @@ gst_audio_amplify_clipping_method_get_type (void)
|
||||||
" signed=(bool)TRUE," \
|
" signed=(bool)TRUE," \
|
||||||
" rate=(int)[1,MAX]," \
|
" rate=(int)[1,MAX]," \
|
||||||
" channels=(int)[1,MAX]; " \
|
" channels=(int)[1,MAX]; " \
|
||||||
"audio/x-raw-float," \
|
"audio/x-raw-int," \
|
||||||
|
" depth=(int)32," \
|
||||||
" width=(int)32," \
|
" width=(int)32," \
|
||||||
" endianness=(int)BYTE_ORDER," \
|
" endianness=(int)BYTE_ORDER," \
|
||||||
|
" signed=(bool)TRUE," \
|
||||||
|
" rate=(int)[1,MAX]," \
|
||||||
|
" channels=(int)[1,MAX]; " \
|
||||||
|
"audio/x-raw-float," \
|
||||||
|
" width=(int){32,64}," \
|
||||||
|
" endianness=(int)BYTE_ORDER," \
|
||||||
" rate=(int)[1,MAX]," \
|
" rate=(int)[1,MAX]," \
|
||||||
" channels=(int)[1,MAX]"
|
" channels=(int)[1,MAX]"
|
||||||
|
|
||||||
|
@ -120,6 +136,8 @@ gst_audio_amplify_clipping_method_get_type (void)
|
||||||
GST_BOILERPLATE_FULL (GstAudioAmplify, gst_audio_amplify, GstAudioFilter,
|
GST_BOILERPLATE_FULL (GstAudioAmplify, gst_audio_amplify, GstAudioFilter,
|
||||||
GST_TYPE_AUDIO_FILTER, DEBUG_INIT);
|
GST_TYPE_AUDIO_FILTER, DEBUG_INIT);
|
||||||
|
|
||||||
|
static gboolean gst_audio_amplify_set_process_function (GstAudioAmplify *
|
||||||
|
filter, gint clipping, gint format, gint width);
|
||||||
static void gst_audio_amplify_set_property (GObject * object, guint prop_id,
|
static void gst_audio_amplify_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
static void gst_audio_amplify_get_property (GObject * object, guint prop_id,
|
static void gst_audio_amplify_get_property (GObject * object, guint prop_id,
|
||||||
|
@ -130,34 +148,137 @@ static gboolean gst_audio_amplify_setup (GstAudioFilter * filter,
|
||||||
static GstFlowReturn gst_audio_amplify_transform_ip (GstBaseTransform * base,
|
static GstFlowReturn gst_audio_amplify_transform_ip (GstBaseTransform * base,
|
||||||
GstBuffer * buf);
|
GstBuffer * buf);
|
||||||
|
|
||||||
static void gst_audio_amplify_transform_int_clip (GstAudioAmplify * filter,
|
#define MIN_gint8 G_MININT8
|
||||||
gint16 * data, guint num_samples);
|
#define MAX_gint8 G_MAXINT8
|
||||||
static void gst_audio_amplify_transform_int_wrap_negative (GstAudioAmplify *
|
#define MIN_gint16 G_MININT16
|
||||||
filter, gint16 * data, guint num_samples);
|
#define MAX_gint16 G_MAXINT16
|
||||||
static void gst_audio_amplify_transform_int_wrap_positive (GstAudioAmplify *
|
#define MIN_gint32 G_MININT32
|
||||||
filter, gint16 * data, guint num_samples);
|
#define MAX_gint32 G_MAXINT32
|
||||||
static void gst_audio_amplify_transform_float_clip (GstAudioAmplify * filter,
|
|
||||||
gfloat * data, guint num_samples);
|
|
||||||
static void gst_audio_amplify_transform_float_wrap_negative (GstAudioAmplify *
|
|
||||||
filter, gfloat * data, guint num_samples);
|
|
||||||
static void gst_audio_amplify_transform_float_wrap_positive (GstAudioAmplify *
|
|
||||||
filter, gfloat * data, guint num_samples);
|
|
||||||
|
|
||||||
/* table of processing functions: [format][clipping_method] */
|
#define MAKE_INT_FUNCS(type) \
|
||||||
static GstAudioAmplifyProcessFunc processing_functions[2][3] = {
|
static void \
|
||||||
{
|
gst_audio_amplify_transform_##type##_clip (GstAudioAmplify * filter, \
|
||||||
(GstAudioAmplifyProcessFunc) gst_audio_amplify_transform_int_clip,
|
void * data, guint num_samples) \
|
||||||
(GstAudioAmplifyProcessFunc)
|
{ \
|
||||||
gst_audio_amplify_transform_int_wrap_negative,
|
type *d = data; \
|
||||||
(GstAudioAmplifyProcessFunc)
|
\
|
||||||
gst_audio_amplify_transform_int_wrap_positive},
|
while (num_samples--) { \
|
||||||
{
|
glong val = *d * filter->amplification; \
|
||||||
(GstAudioAmplifyProcessFunc) gst_audio_amplify_transform_float_clip,
|
*d++ = CLAMP (val, MIN_##type, MAX_##type); \
|
||||||
(GstAudioAmplifyProcessFunc)
|
} \
|
||||||
gst_audio_amplify_transform_float_wrap_negative,
|
} \
|
||||||
(GstAudioAmplifyProcessFunc)
|
static void \
|
||||||
gst_audio_amplify_transform_float_wrap_positive}
|
gst_audio_amplify_transform_##type##_wrap_negative (GstAudioAmplify * filter, \
|
||||||
};
|
void * data, guint num_samples) \
|
||||||
|
{ \
|
||||||
|
type *d = data; \
|
||||||
|
\
|
||||||
|
while (num_samples--) { \
|
||||||
|
glong val = *d * filter->amplification; \
|
||||||
|
if (val > MAX_##type) \
|
||||||
|
val = MIN_##type + (val - MIN_##type) % ((glong) MAX_##type - \
|
||||||
|
MIN_##type); \
|
||||||
|
else if (val < MIN_##type) \
|
||||||
|
val = MAX_##type - (MAX_##type - val) % ((glong) MAX_##type - \
|
||||||
|
MIN_##type); \
|
||||||
|
*d++ = val; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static void \
|
||||||
|
gst_audio_amplify_transform_##type##_wrap_positive (GstAudioAmplify * filter, \
|
||||||
|
void * data, guint num_samples) \
|
||||||
|
{ \
|
||||||
|
type *d = data; \
|
||||||
|
\
|
||||||
|
while (num_samples--) { \
|
||||||
|
glong val = *d * filter->amplification; \
|
||||||
|
do { \
|
||||||
|
if (val > MAX_##type) \
|
||||||
|
val = MAX_##type - (val - MAX_##type); \
|
||||||
|
else if (val < MIN_##type) \
|
||||||
|
val = MIN_##type + (MIN_##type - val); \
|
||||||
|
else \
|
||||||
|
break; \
|
||||||
|
} while (1); \
|
||||||
|
*d++ = val; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static void \
|
||||||
|
gst_audio_amplify_transform_##type##_noclip (GstAudioAmplify * filter, \
|
||||||
|
void * data, guint num_samples) \
|
||||||
|
{ \
|
||||||
|
type *d = data; \
|
||||||
|
\
|
||||||
|
while (num_samples--) \
|
||||||
|
*d++ *= filter->amplification; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAKE_FLOAT_FUNCS(type) \
|
||||||
|
static void \
|
||||||
|
gst_audio_amplify_transform_##type##_clip (GstAudioAmplify * filter, \
|
||||||
|
void * data, guint num_samples) \
|
||||||
|
{ \
|
||||||
|
type *d = data; \
|
||||||
|
\
|
||||||
|
while (num_samples--) { \
|
||||||
|
type val = *d* filter->amplification; \
|
||||||
|
*d++ = CLAMP (val, -1.0, +1.0); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static void \
|
||||||
|
gst_audio_amplify_transform_##type##_wrap_negative (GstAudioAmplify * \
|
||||||
|
filter, void * data, guint num_samples) \
|
||||||
|
{ \
|
||||||
|
type *d = data; \
|
||||||
|
\
|
||||||
|
while (num_samples--) { \
|
||||||
|
type val = *d * filter->amplification; \
|
||||||
|
do { \
|
||||||
|
if (val > 1.0) \
|
||||||
|
val = -1.0 + (val - 1.0); \
|
||||||
|
else if (val < -1.0) \
|
||||||
|
val = 1.0 - (1.0 - val); \
|
||||||
|
else \
|
||||||
|
break; \
|
||||||
|
} while (1); \
|
||||||
|
*d++ = val; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static void \
|
||||||
|
gst_audio_amplify_transform_##type##_wrap_positive (GstAudioAmplify * filter, \
|
||||||
|
void * data, guint num_samples) \
|
||||||
|
{ \
|
||||||
|
type *d = data; \
|
||||||
|
\
|
||||||
|
while (num_samples--) { \
|
||||||
|
type val = *d* filter->amplification; \
|
||||||
|
do { \
|
||||||
|
if (val > 1.0) \
|
||||||
|
val = 1.0 - (val - 1.0); \
|
||||||
|
else if (val < -1.0) \
|
||||||
|
val = -1.0 + (-1.0 - val); \
|
||||||
|
else \
|
||||||
|
break; \
|
||||||
|
} while (1); \
|
||||||
|
*d++ = val; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static void \
|
||||||
|
gst_audio_amplify_transform_##type##_noclip (GstAudioAmplify * filter, \
|
||||||
|
void * data, guint num_samples) \
|
||||||
|
{ \
|
||||||
|
type *d = data; \
|
||||||
|
\
|
||||||
|
while (num_samples--) \
|
||||||
|
*d++ *= filter->amplification; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
MAKE_INT_FUNCS (gint8)
|
||||||
|
MAKE_INT_FUNCS (gint16)
|
||||||
|
MAKE_INT_FUNCS (gint32)
|
||||||
|
MAKE_FLOAT_FUNCS (gfloat)
|
||||||
|
MAKE_FLOAT_FUNCS (gdouble)
|
||||||
|
|
||||||
/* GObject vmethod implementations */
|
/* GObject vmethod implementations */
|
||||||
|
|
||||||
|
@ -213,24 +334,90 @@ static void
|
||||||
gst_audio_amplify_init (GstAudioAmplify * filter, GstAudioAmplifyClass * klass)
|
gst_audio_amplify_init (GstAudioAmplify * filter, GstAudioAmplifyClass * klass)
|
||||||
{
|
{
|
||||||
filter->amplification = 1.0;
|
filter->amplification = 1.0;
|
||||||
filter->clipping_method = METHOD_CLIP;
|
gst_audio_amplify_set_process_function (filter, METHOD_CLIP,
|
||||||
filter->format_index = 0;
|
GST_BUFTYPE_LINEAR, 16);
|
||||||
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), TRUE);
|
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), TRUE);
|
||||||
gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (filter), TRUE);
|
gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (filter), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static GstAudioAmplifyProcessFunc
|
||||||
gst_audio_amplify_set_process_function (GstAudioAmplify * filter)
|
gst_audio_amplify_process_function (gint clipping, gint format, gint width)
|
||||||
{
|
{
|
||||||
gint method_index;
|
static const struct {
|
||||||
|
gint format;
|
||||||
|
gint width;
|
||||||
|
gint clipping;
|
||||||
|
GstAudioAmplifyProcessFunc func;
|
||||||
|
} *p, process[] = {
|
||||||
|
{GST_BUFTYPE_FLOAT, 32, METHOD_CLIP,
|
||||||
|
gst_audio_amplify_transform_gfloat_clip},
|
||||||
|
{GST_BUFTYPE_FLOAT, 32, METHOD_WRAP_NEGATIVE,
|
||||||
|
gst_audio_amplify_transform_gfloat_wrap_negative},
|
||||||
|
{GST_BUFTYPE_FLOAT, 32, METHOD_WRAP_POSITIVE,
|
||||||
|
gst_audio_amplify_transform_gfloat_wrap_positive},
|
||||||
|
{GST_BUFTYPE_FLOAT, 32, METHOD_NOCLIP,
|
||||||
|
gst_audio_amplify_transform_gfloat_noclip},
|
||||||
|
{GST_BUFTYPE_FLOAT, 64, METHOD_CLIP,
|
||||||
|
gst_audio_amplify_transform_gdouble_clip},
|
||||||
|
{GST_BUFTYPE_FLOAT, 64, METHOD_WRAP_NEGATIVE,
|
||||||
|
gst_audio_amplify_transform_gdouble_wrap_negative},
|
||||||
|
{GST_BUFTYPE_FLOAT, 64, METHOD_WRAP_POSITIVE,
|
||||||
|
gst_audio_amplify_transform_gdouble_wrap_positive},
|
||||||
|
{GST_BUFTYPE_FLOAT, 64, METHOD_NOCLIP,
|
||||||
|
gst_audio_amplify_transform_gdouble_noclip},
|
||||||
|
{GST_BUFTYPE_LINEAR, 8, METHOD_CLIP,
|
||||||
|
gst_audio_amplify_transform_gint8_clip},
|
||||||
|
{GST_BUFTYPE_LINEAR, 8, METHOD_WRAP_NEGATIVE,
|
||||||
|
gst_audio_amplify_transform_gint8_wrap_negative},
|
||||||
|
{GST_BUFTYPE_LINEAR, 8, METHOD_WRAP_POSITIVE,
|
||||||
|
gst_audio_amplify_transform_gint8_wrap_positive},
|
||||||
|
{GST_BUFTYPE_LINEAR, 8, METHOD_NOCLIP,
|
||||||
|
gst_audio_amplify_transform_gint8_noclip},
|
||||||
|
{GST_BUFTYPE_LINEAR, 16, METHOD_CLIP,
|
||||||
|
gst_audio_amplify_transform_gint16_clip},
|
||||||
|
{GST_BUFTYPE_LINEAR, 16, METHOD_WRAP_NEGATIVE,
|
||||||
|
gst_audio_amplify_transform_gint16_wrap_negative},
|
||||||
|
{GST_BUFTYPE_LINEAR, 16, METHOD_WRAP_POSITIVE,
|
||||||
|
gst_audio_amplify_transform_gint16_wrap_positive},
|
||||||
|
{GST_BUFTYPE_LINEAR, 16, METHOD_NOCLIP,
|
||||||
|
gst_audio_amplify_transform_gint16_noclip},
|
||||||
|
{GST_BUFTYPE_LINEAR, 32, METHOD_CLIP,
|
||||||
|
gst_audio_amplify_transform_gint32_clip},
|
||||||
|
{GST_BUFTYPE_LINEAR, 32, METHOD_WRAP_NEGATIVE,
|
||||||
|
gst_audio_amplify_transform_gint32_wrap_negative},
|
||||||
|
{GST_BUFTYPE_LINEAR, 32, METHOD_WRAP_POSITIVE,
|
||||||
|
gst_audio_amplify_transform_gint32_wrap_positive},
|
||||||
|
{GST_BUFTYPE_LINEAR, 32, METHOD_NOCLIP,
|
||||||
|
gst_audio_amplify_transform_gint32_noclip},
|
||||||
|
{0, 0, 0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (p = process; p->func; p++)
|
||||||
|
if (p->format == format && p->width == width && p->clipping == clipping)
|
||||||
|
return p->func;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_audio_amplify_set_process_function (GstAudioAmplify * filter, gint
|
||||||
|
clipping_method, gint format, gint width)
|
||||||
|
{
|
||||||
|
GstAudioAmplifyProcessFunc process;
|
||||||
|
|
||||||
/* set processing function */
|
/* set processing function */
|
||||||
|
|
||||||
method_index = filter->clipping_method;
|
process = gst_audio_amplify_process_function (clipping_method, format,
|
||||||
if (method_index >= NUM_METHODS || method_index < 0)
|
width);
|
||||||
method_index = METHOD_CLIP;
|
if (!process) {
|
||||||
|
GST_DEBUG ("wrong format");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
filter->process = process;
|
||||||
|
filter->clipping_method = clipping_method;
|
||||||
|
filter->format = format;
|
||||||
|
filter->width = width;
|
||||||
|
|
||||||
filter->process = processing_functions[filter->format_index][method_index];
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,8 +434,8 @@ gst_audio_amplify_set_property (GObject * object, guint prop_id,
|
||||||
filter->amplification == 1.0);
|
filter->amplification == 1.0);
|
||||||
break;
|
break;
|
||||||
case PROP_CLIPPING_METHOD:
|
case PROP_CLIPPING_METHOD:
|
||||||
filter->clipping_method = g_value_get_enum (value);
|
gst_audio_amplify_set_process_function (filter, g_value_get_enum (value),
|
||||||
gst_audio_amplify_set_process_function (filter);
|
filter->format, filter->width);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
@ -280,129 +467,9 @@ static gboolean
|
||||||
gst_audio_amplify_setup (GstAudioFilter * base, GstRingBufferSpec * format)
|
gst_audio_amplify_setup (GstAudioFilter * base, GstRingBufferSpec * format)
|
||||||
{
|
{
|
||||||
GstAudioAmplify *filter = GST_AUDIO_AMPLIFY (base);
|
GstAudioAmplify *filter = GST_AUDIO_AMPLIFY (base);
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
if (format->type == GST_BUFTYPE_LINEAR && format->width == 16)
|
return gst_audio_amplify_set_process_function (filter,
|
||||||
filter->format_index = 0;
|
filter->clipping_method, format->type, format->width);
|
||||||
else if (format->type == GST_BUFTYPE_FLOAT && format->width == 32)
|
|
||||||
filter->format_index = 1;
|
|
||||||
else
|
|
||||||
goto wrong_format;
|
|
||||||
|
|
||||||
ret = gst_audio_amplify_set_process_function (filter);
|
|
||||||
if (!ret)
|
|
||||||
GST_WARNING ("can't process input");
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
wrong_format:
|
|
||||||
GST_DEBUG ("wrong format");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_audio_amplify_transform_int_clip (GstAudioAmplify * filter,
|
|
||||||
gint16 * data, guint num_samples)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
glong val;
|
|
||||||
|
|
||||||
for (i = 0; i < num_samples; i++) {
|
|
||||||
val = (*data) * filter->amplification;
|
|
||||||
*data++ = (gint16) CLAMP (val, G_MININT16, G_MAXINT16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_audio_amplify_transform_int_wrap_negative (GstAudioAmplify * filter,
|
|
||||||
gint16 * data, guint num_samples)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
glong val;
|
|
||||||
|
|
||||||
for (i = 0; i < num_samples; i++) {
|
|
||||||
val = (*data) * filter->amplification;
|
|
||||||
if (val > G_MAXINT16)
|
|
||||||
val = ((val - G_MININT16) & 0xffff) + G_MININT16;
|
|
||||||
else if (val < G_MININT16)
|
|
||||||
val = ((val - G_MAXINT16) & 0xffff) + G_MAXINT16;
|
|
||||||
*data++ = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_audio_amplify_transform_int_wrap_positive (GstAudioAmplify * filter,
|
|
||||||
gint16 * data, guint num_samples)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
glong val;
|
|
||||||
|
|
||||||
for (i = 0; i < num_samples; i++) {
|
|
||||||
val = (*data) * filter->amplification;
|
|
||||||
while (val > G_MAXINT16 || val < G_MININT16) {
|
|
||||||
if (val > G_MAXINT16)
|
|
||||||
val = G_MAXINT16 - (val - G_MAXINT16);
|
|
||||||
else if (val < G_MININT16)
|
|
||||||
val = G_MININT16 - (val - G_MININT16);
|
|
||||||
}
|
|
||||||
*data++ = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_audio_amplify_transform_float_clip (GstAudioAmplify * filter,
|
|
||||||
gfloat * data, guint num_samples)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
gfloat val;
|
|
||||||
|
|
||||||
for (i = 0; i < num_samples; i++) {
|
|
||||||
val = (*data) * filter->amplification;
|
|
||||||
if (val > 1.0)
|
|
||||||
val = 1.0;
|
|
||||||
else if (val < -1.0)
|
|
||||||
val = -1.0;
|
|
||||||
|
|
||||||
*data++ = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_audio_amplify_transform_float_wrap_negative (GstAudioAmplify * filter,
|
|
||||||
gfloat * data, guint num_samples)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
gfloat val;
|
|
||||||
|
|
||||||
for (i = 0; i < num_samples; i++) {
|
|
||||||
val = (*data) * filter->amplification;
|
|
||||||
while (val > 1.0 || val < -1.0) {
|
|
||||||
if (val > 1.0)
|
|
||||||
val = -1.0 + (val - 1.0);
|
|
||||||
else if (val < -1.0)
|
|
||||||
val = 1.0 + (val + 1.0);
|
|
||||||
}
|
|
||||||
*data++ = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_audio_amplify_transform_float_wrap_positive (GstAudioAmplify * filter,
|
|
||||||
gfloat * data, guint num_samples)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
gfloat val;
|
|
||||||
|
|
||||||
for (i = 0; i < num_samples; i++) {
|
|
||||||
val = (*data) * filter->amplification;
|
|
||||||
while (val > 1.0 || val < -1.0) {
|
|
||||||
if (val > 1.0)
|
|
||||||
val = 1.0 - (val - 1.0);
|
|
||||||
else if (val < -1.0)
|
|
||||||
val = -1.0 - (val + 1.0);
|
|
||||||
}
|
|
||||||
*data++ = val;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GstBaseTransform vmethod implementations */
|
/* GstBaseTransform vmethod implementations */
|
||||||
|
|
|
@ -37,7 +37,7 @@ G_BEGIN_DECLS
|
||||||
typedef struct _GstAudioAmplify GstAudioAmplify;
|
typedef struct _GstAudioAmplify GstAudioAmplify;
|
||||||
typedef struct _GstAudioAmplifyClass GstAudioAmplifyClass;
|
typedef struct _GstAudioAmplifyClass GstAudioAmplifyClass;
|
||||||
|
|
||||||
typedef void (*GstAudioAmplifyProcessFunc) (GstAudioAmplify *, guint8 *, guint);
|
typedef void (*GstAudioAmplifyProcessFunc) (GstAudioAmplify *, void *, guint);
|
||||||
|
|
||||||
struct _GstAudioAmplify
|
struct _GstAudioAmplify
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,8 @@ struct _GstAudioAmplify
|
||||||
/* < private > */
|
/* < private > */
|
||||||
GstAudioAmplifyProcessFunc process;
|
GstAudioAmplifyProcessFunc process;
|
||||||
gint clipping_method;
|
gint clipping_method;
|
||||||
gint format_index;
|
gint format;
|
||||||
|
gint width;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstAudioAmplifyClass
|
struct _GstAudioAmplifyClass
|
||||||
|
|
Loading…
Reference in a new issue