|
Packit |
8ff292 |
/*
|
|
Packit |
8ff292 |
* GStreamer
|
|
Packit |
8ff292 |
* Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
|
|
Packit |
8ff292 |
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
8ff292 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
8ff292 |
* License as published by the Free Software Foundation; either
|
|
Packit |
8ff292 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
8ff292 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8ff292 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
8ff292 |
* Library General Public License for more details.
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
8ff292 |
* License along with this library; if not, write to the
|
|
Packit |
8ff292 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
8ff292 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
8ff292 |
*/
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/**
|
|
Packit |
8ff292 |
* SECTION:element-audioamplify
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* Amplifies an audio stream by a given factor and allows the selection of different clipping modes.
|
|
Packit |
8ff292 |
* The difference between the clipping modes is best evaluated by testing.
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* <refsect2>
|
|
Packit |
8ff292 |
* <title>Example launch line</title>
|
|
Packit |
8ff292 |
* |[
|
|
Packit |
8ff292 |
* gst-launch-1.0 audiotestsrc wave=saw ! audioamplify amplification=1.5 ! alsasink
|
|
Packit |
8ff292 |
* gst-launch-1.0 filesrc location="melo1.ogg" ! oggdemux ! vorbisdec ! audioconvert ! audioamplify amplification=1.5 clipping-method=wrap-negative ! alsasink
|
|
Packit |
8ff292 |
* gst-launch-1.0 audiotestsrc wave=saw ! audioconvert ! audioamplify amplification=1.5 clipping-method=wrap-positive ! audioconvert ! alsasink
|
|
Packit |
8ff292 |
* ]|
|
|
Packit |
8ff292 |
* </refsect2>
|
|
Packit |
8ff292 |
*/
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
8ff292 |
#include "config.h"
|
|
Packit |
8ff292 |
#endif
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#include <gst/gst.h>
|
|
Packit |
8ff292 |
#include <gst/base/gstbasetransform.h>
|
|
Packit |
8ff292 |
#include <gst/audio/audio.h>
|
|
Packit |
8ff292 |
#include <gst/audio/gstaudiofilter.h>
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#include "audioamplify.h"
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define GST_CAT_DEFAULT gst_audio_amplify_debug
|
|
Packit |
8ff292 |
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* Filter signals and args */
|
|
Packit |
8ff292 |
enum
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
/* FILL ME */
|
|
Packit |
8ff292 |
LAST_SIGNAL
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
enum
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
PROP_0,
|
|
Packit |
8ff292 |
PROP_AMPLIFICATION,
|
|
Packit |
8ff292 |
PROP_CLIPPING_METHOD
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
enum
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
METHOD_CLIP = 0,
|
|
Packit |
8ff292 |
METHOD_WRAP_NEGATIVE,
|
|
Packit |
8ff292 |
METHOD_WRAP_POSITIVE,
|
|
Packit |
8ff292 |
METHOD_NOCLIP,
|
|
Packit |
8ff292 |
NUM_METHODS
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define GST_TYPE_AUDIO_AMPLIFY_CLIPPING_METHOD (gst_audio_amplify_clipping_method_get_type ())
|
|
Packit |
8ff292 |
static GType
|
|
Packit |
8ff292 |
gst_audio_amplify_clipping_method_get_type (void)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
static GType gtype = 0;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
if (gtype == 0) {
|
|
Packit |
8ff292 |
static const GEnumValue values[] = {
|
|
Packit |
8ff292 |
{METHOD_CLIP, "Normal clipping (default)", "clip"},
|
|
Packit |
8ff292 |
{METHOD_WRAP_NEGATIVE,
|
|
Packit |
8ff292 |
"Push overdriven values back from the opposite side",
|
|
Packit |
8ff292 |
"wrap-negative"},
|
|
Packit |
8ff292 |
{METHOD_WRAP_POSITIVE, "Push overdriven values back from the same side",
|
|
Packit |
8ff292 |
"wrap-positive"},
|
|
Packit |
8ff292 |
{METHOD_NOCLIP, "No clipping", "none"},
|
|
Packit |
8ff292 |
{0, NULL, NULL}
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
gtype = g_enum_register_static ("GstAudioAmplifyClippingMethod", values);
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
return gtype;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define ALLOWED_CAPS \
|
|
Packit |
8ff292 |
"audio/x-raw," \
|
|
Packit |
8ff292 |
" format=(string) {S8,"GST_AUDIO_NE(S16)","GST_AUDIO_NE(S32)"," \
|
|
Packit |
8ff292 |
GST_AUDIO_NE(F32)","GST_AUDIO_NE(F64)"}," \
|
|
Packit |
8ff292 |
" rate=(int)[1,MAX]," \
|
|
Packit |
8ff292 |
" channels=(int)[1,MAX], " \
|
|
Packit |
8ff292 |
" layout=(string) {interleaved, non-interleaved}"
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
G_DEFINE_TYPE (GstAudioAmplify, gst_audio_amplify, GST_TYPE_AUDIO_FILTER);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static gboolean gst_audio_amplify_set_process_function (GstAudioAmplify *
|
|
Packit |
8ff292 |
filter, gint clipping, GstAudioFormat format);
|
|
Packit |
8ff292 |
static void gst_audio_amplify_set_property (GObject * object, guint prop_id,
|
|
Packit |
8ff292 |
const GValue * value, GParamSpec * pspec);
|
|
Packit |
8ff292 |
static void gst_audio_amplify_get_property (GObject * object, guint prop_id,
|
|
Packit |
8ff292 |
GValue * value, GParamSpec * pspec);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static gboolean gst_audio_amplify_setup (GstAudioFilter * filter,
|
|
Packit |
8ff292 |
const GstAudioInfo * info);
|
|
Packit |
8ff292 |
static GstFlowReturn gst_audio_amplify_transform_ip (GstBaseTransform * base,
|
|
Packit |
8ff292 |
GstBuffer * buf);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define MIN_gint8 G_MININT8
|
|
Packit |
8ff292 |
#define MAX_gint8 G_MAXINT8
|
|
Packit |
8ff292 |
#define MIN_gint16 G_MININT16
|
|
Packit |
8ff292 |
#define MAX_gint16 G_MAXINT16
|
|
Packit |
8ff292 |
#define MIN_gint32 G_MININT32
|
|
Packit |
8ff292 |
#define MAX_gint32 G_MAXINT32
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define MAKE_INT_FUNCS(type,largetype) \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_clip (GstAudioAmplify * filter, \
|
|
Packit |
8ff292 |
void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) { \
|
|
Packit |
8ff292 |
largetype val = *d * filter->amplification; \
|
|
Packit |
8ff292 |
*d++ = CLAMP (val, MIN_##type, MAX_##type); \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_wrap_negative (GstAudioAmplify * filter, \
|
|
Packit |
8ff292 |
void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) { \
|
|
Packit |
8ff292 |
largetype val = *d * filter->amplification; \
|
|
Packit |
8ff292 |
if (val > MAX_##type) \
|
|
Packit |
8ff292 |
val = MIN_##type + (val - MIN_##type) % ((largetype) MAX_##type + 1 - \
|
|
Packit |
8ff292 |
MIN_##type); \
|
|
Packit |
8ff292 |
else if (val < MIN_##type) \
|
|
Packit |
8ff292 |
val = MAX_##type - (MAX_##type - val) % ((largetype) MAX_##type + 1 - \
|
|
Packit |
8ff292 |
MIN_##type); \
|
|
Packit |
8ff292 |
*d++ = val; \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_wrap_positive (GstAudioAmplify * filter, \
|
|
Packit |
8ff292 |
void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) { \
|
|
Packit |
8ff292 |
largetype val = *d * filter->amplification; \
|
|
Packit |
8ff292 |
do { \
|
|
Packit |
8ff292 |
if (val > MAX_##type) \
|
|
Packit |
8ff292 |
val = MAX_##type - (val - MAX_##type); \
|
|
Packit |
8ff292 |
else if (val < MIN_##type) \
|
|
Packit |
8ff292 |
val = MIN_##type + (MIN_##type - val); \
|
|
Packit |
8ff292 |
else \
|
|
Packit |
8ff292 |
break; \
|
|
Packit |
8ff292 |
} while (1); \
|
|
Packit |
8ff292 |
*d++ = val; \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_noclip (GstAudioAmplify * filter, \
|
|
Packit |
8ff292 |
void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) \
|
|
Packit |
8ff292 |
*d++ *= filter->amplification; \
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define MAKE_FLOAT_FUNCS(type) \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_clip (GstAudioAmplify * filter, \
|
|
Packit |
8ff292 |
void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) { \
|
|
Packit |
8ff292 |
type val = *d* filter->amplification; \
|
|
Packit |
8ff292 |
*d++ = CLAMP (val, -1.0, +1.0); \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_wrap_negative (GstAudioAmplify * \
|
|
Packit |
8ff292 |
filter, void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) { \
|
|
Packit |
8ff292 |
type val = *d * filter->amplification; \
|
|
Packit |
8ff292 |
do { \
|
|
Packit |
8ff292 |
if (val > 1.0) \
|
|
Packit |
8ff292 |
val = -1.0 + (val - 1.0); \
|
|
Packit |
8ff292 |
else if (val < -1.0) \
|
|
Packit |
8ff292 |
val = 1.0 - (1.0 - val); \
|
|
Packit |
8ff292 |
else \
|
|
Packit |
8ff292 |
break; \
|
|
Packit |
8ff292 |
} while (1); \
|
|
Packit |
8ff292 |
*d++ = val; \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_wrap_positive (GstAudioAmplify * filter, \
|
|
Packit |
8ff292 |
void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) { \
|
|
Packit |
8ff292 |
type val = *d* filter->amplification; \
|
|
Packit |
8ff292 |
do { \
|
|
Packit |
8ff292 |
if (val > 1.0) \
|
|
Packit |
8ff292 |
val = 1.0 - (val - 1.0); \
|
|
Packit |
8ff292 |
else if (val < -1.0) \
|
|
Packit |
8ff292 |
val = -1.0 + (-1.0 - val); \
|
|
Packit |
8ff292 |
else \
|
|
Packit |
8ff292 |
break; \
|
|
Packit |
8ff292 |
} while (1); \
|
|
Packit |
8ff292 |
*d++ = val; \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
} \
|
|
Packit |
8ff292 |
static void \
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_##type##_noclip (GstAudioAmplify * filter, \
|
|
Packit |
8ff292 |
void * data, guint num_samples) \
|
|
Packit |
8ff292 |
{ \
|
|
Packit |
8ff292 |
type *d = data; \
|
|
Packit |
8ff292 |
\
|
|
Packit |
8ff292 |
while (num_samples--) \
|
|
Packit |
8ff292 |
*d++ *= filter->amplification; \
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* *INDENT-OFF* */
|
|
Packit |
8ff292 |
MAKE_INT_FUNCS (gint8,gint)
|
|
Packit |
8ff292 |
MAKE_INT_FUNCS (gint16,gint)
|
|
Packit |
8ff292 |
MAKE_INT_FUNCS (gint32,gint64)
|
|
Packit |
8ff292 |
MAKE_FLOAT_FUNCS (gfloat)
|
|
Packit |
8ff292 |
MAKE_FLOAT_FUNCS (gdouble)
|
|
Packit |
8ff292 |
/* *INDENT-ON* */
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* GObject vmethod implementations */
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_audio_amplify_class_init (GstAudioAmplifyClass * klass)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GObjectClass *gobject_class;
|
|
Packit |
8ff292 |
GstElementClass *gstelement_class;
|
|
Packit |
8ff292 |
GstCaps *caps;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
GST_DEBUG_CATEGORY_INIT (gst_audio_amplify_debug, "audioamplify", 0,
|
|
Packit |
8ff292 |
"audioamplify element");
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gobject_class = (GObjectClass *) klass;
|
|
Packit |
8ff292 |
gstelement_class = (GstElementClass *) klass;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gobject_class->set_property = gst_audio_amplify_set_property;
|
|
Packit |
8ff292 |
gobject_class->get_property = gst_audio_amplify_get_property;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
g_object_class_install_property (gobject_class, PROP_AMPLIFICATION,
|
|
Packit |
8ff292 |
g_param_spec_float ("amplification", "Amplification",
|
|
Packit |
8ff292 |
"Factor of amplification", -G_MAXFLOAT, G_MAXFLOAT,
|
|
Packit |
8ff292 |
1.0,
|
|
Packit |
8ff292 |
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/**
|
|
Packit |
8ff292 |
* GstAudioAmplify:clipping-method
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* Clipping method: clip mode set values higher than the maximum to the
|
|
Packit |
8ff292 |
* maximum. The wrap-negative mode pushes those values back from the
|
|
Packit |
8ff292 |
* opposite side, wrap-positive pushes them back from the same side.
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
**/
|
|
Packit |
8ff292 |
g_object_class_install_property (gobject_class, PROP_CLIPPING_METHOD,
|
|
Packit |
8ff292 |
g_param_spec_enum ("clipping-method", "Clipping method",
|
|
Packit |
8ff292 |
"Selects how to handle values higher than the maximum",
|
|
Packit |
8ff292 |
GST_TYPE_AUDIO_AMPLIFY_CLIPPING_METHOD, METHOD_CLIP,
|
|
Packit |
8ff292 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gst_element_class_set_static_metadata (gstelement_class, "Audio amplifier",
|
|
Packit |
8ff292 |
"Filter/Effect/Audio",
|
|
Packit |
8ff292 |
"Amplifies an audio stream by a given factor",
|
|
Packit |
8ff292 |
"Sebastian Dröge <slomo@circular-chaos.org>");
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
caps = gst_caps_from_string (ALLOWED_CAPS);
|
|
Packit |
8ff292 |
gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (klass),
|
|
Packit |
8ff292 |
caps);
|
|
Packit |
8ff292 |
gst_caps_unref (caps);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
GST_BASE_TRANSFORM_CLASS (klass)->transform_ip =
|
|
Packit |
8ff292 |
GST_DEBUG_FUNCPTR (gst_audio_amplify_transform_ip);
|
|
Packit |
8ff292 |
GST_BASE_TRANSFORM_CLASS (klass)->transform_ip_on_passthrough = FALSE;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
GST_AUDIO_FILTER_CLASS (klass)->setup =
|
|
Packit |
8ff292 |
GST_DEBUG_FUNCPTR (gst_audio_amplify_setup);
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_audio_amplify_init (GstAudioAmplify * filter)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
filter->amplification = 1.0;
|
|
Packit |
8ff292 |
gst_audio_amplify_set_process_function (filter, METHOD_CLIP,
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S16);
|
|
Packit |
8ff292 |
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), TRUE);
|
|
Packit |
8ff292 |
gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (filter), TRUE);
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static GstAudioAmplifyProcessFunc
|
|
Packit |
8ff292 |
gst_audio_amplify_process_function (gint clipping, GstAudioFormat format)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
static const struct process
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstAudioFormat format;
|
|
Packit |
8ff292 |
gint clipping;
|
|
Packit |
8ff292 |
GstAudioAmplifyProcessFunc func;
|
|
Packit |
8ff292 |
} process[] = {
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F32, METHOD_CLIP, gst_audio_amplify_transform_gfloat_clip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F32, METHOD_WRAP_NEGATIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gfloat_wrap_negative}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F32, METHOD_WRAP_POSITIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gfloat_wrap_positive}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F32, METHOD_NOCLIP,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gfloat_noclip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F64, METHOD_CLIP,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gdouble_clip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F64, METHOD_WRAP_NEGATIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gdouble_wrap_negative}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F64, METHOD_WRAP_POSITIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gdouble_wrap_positive}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_F64, METHOD_NOCLIP,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gdouble_noclip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S8, METHOD_CLIP, gst_audio_amplify_transform_gint8_clip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S8, METHOD_WRAP_NEGATIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint8_wrap_negative}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S8, METHOD_WRAP_POSITIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint8_wrap_positive}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S8, METHOD_NOCLIP,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint8_noclip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S16, METHOD_CLIP, gst_audio_amplify_transform_gint16_clip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S16, METHOD_WRAP_NEGATIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint16_wrap_negative}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S16, METHOD_WRAP_POSITIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint16_wrap_positive}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S16, METHOD_NOCLIP,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint16_noclip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S32, METHOD_CLIP, gst_audio_amplify_transform_gint32_clip}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S32, METHOD_WRAP_NEGATIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint32_wrap_negative}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S32, METHOD_WRAP_POSITIVE,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint32_wrap_positive}, {
|
|
Packit |
8ff292 |
GST_AUDIO_FORMAT_S32, METHOD_NOCLIP,
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_gint32_noclip}, {
|
|
Packit |
8ff292 |
0, 0, NULL}
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
const struct process *p;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
for (p = process; p->func; p++)
|
|
Packit |
8ff292 |
if (p->format == format && p->clipping == clipping)
|
|
Packit |
8ff292 |
return p->func;
|
|
Packit |
8ff292 |
return NULL;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static gboolean
|
|
Packit |
8ff292 |
gst_audio_amplify_set_process_function (GstAudioAmplify * filter, gint
|
|
Packit |
8ff292 |
clipping_method, GstAudioFormat format)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstAudioAmplifyProcessFunc process;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* set processing function */
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
process = gst_audio_amplify_process_function (clipping_method, format);
|
|
Packit |
8ff292 |
if (!process) {
|
|
Packit |
8ff292 |
GST_DEBUG ("wrong format");
|
|
Packit |
8ff292 |
return FALSE;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
filter->process = process;
|
|
Packit |
8ff292 |
filter->clipping_method = clipping_method;
|
|
Packit |
8ff292 |
filter->format = format;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
return TRUE;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_audio_amplify_set_property (GObject * object, guint prop_id,
|
|
Packit |
8ff292 |
const GValue * value, GParamSpec * pspec)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstAudioAmplify *filter = GST_AUDIO_AMPLIFY (object);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
switch (prop_id) {
|
|
Packit |
8ff292 |
case PROP_AMPLIFICATION:
|
|
Packit |
8ff292 |
filter->amplification = g_value_get_float (value);
|
|
Packit |
8ff292 |
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter),
|
|
Packit |
8ff292 |
filter->amplification == 1.0);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
case PROP_CLIPPING_METHOD:
|
|
Packit |
8ff292 |
gst_audio_amplify_set_process_function (filter, g_value_get_enum (value),
|
|
Packit |
8ff292 |
filter->format);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
default:
|
|
Packit |
8ff292 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_audio_amplify_get_property (GObject * object, guint prop_id,
|
|
Packit |
8ff292 |
GValue * value, GParamSpec * pspec)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstAudioAmplify *filter = GST_AUDIO_AMPLIFY (object);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
switch (prop_id) {
|
|
Packit |
8ff292 |
case PROP_AMPLIFICATION:
|
|
Packit |
8ff292 |
g_value_set_float (value, filter->amplification);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
case PROP_CLIPPING_METHOD:
|
|
Packit |
8ff292 |
g_value_set_enum (value, filter->clipping_method);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
default:
|
|
Packit |
8ff292 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* GstAudioFilter vmethod implementations */
|
|
Packit |
8ff292 |
static gboolean
|
|
Packit |
8ff292 |
gst_audio_amplify_setup (GstAudioFilter * base, const GstAudioInfo * info)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstAudioAmplify *filter = GST_AUDIO_AMPLIFY (base);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
return gst_audio_amplify_set_process_function (filter,
|
|
Packit |
8ff292 |
filter->clipping_method, GST_AUDIO_INFO_FORMAT (info));
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* GstBaseTransform vmethod implementations */
|
|
Packit |
8ff292 |
static GstFlowReturn
|
|
Packit |
8ff292 |
gst_audio_amplify_transform_ip (GstBaseTransform * base, GstBuffer * buf)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstAudioAmplify *filter = GST_AUDIO_AMPLIFY (base);
|
|
Packit |
8ff292 |
guint num_samples;
|
|
Packit |
8ff292 |
GstClockTime timestamp, stream_time;
|
|
Packit |
8ff292 |
GstMapInfo map;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
timestamp = GST_BUFFER_TIMESTAMP (buf);
|
|
Packit |
8ff292 |
stream_time =
|
|
Packit |
8ff292 |
gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
|
|
Packit |
8ff292 |
GST_TIME_ARGS (timestamp));
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
if (GST_CLOCK_TIME_IS_VALID (stream_time))
|
|
Packit |
8ff292 |
gst_object_sync_values (GST_OBJECT (filter), stream_time);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP)))
|
|
Packit |
8ff292 |
return GST_FLOW_OK;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gst_buffer_map (buf, &map, GST_MAP_READWRITE);
|
|
Packit |
8ff292 |
num_samples = map.size / GST_AUDIO_FILTER_BPS (filter);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
filter->process (filter, map.data, num_samples);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gst_buffer_unmap (buf, &map);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
return GST_FLOW_OK;
|
|
Packit |
8ff292 |
}
|