summaryrefslogtreecommitdiffstats
path: root/gst/monoscope
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2004-03-14 22:34:33 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2004-03-14 22:34:33 +0000
commit5d25c00e4b613b9cdf2c04fa3a68dffa03834a68 (patch)
tree74a5b1eaf3a324b520e64e87404fd0b3018a7829 /gst/monoscope
parent1e83b097f7b732ae49e294a5a398bdc3e88854a8 (diff)
gst-indent
Original commit message from CVS: gst-indent
Diffstat (limited to 'gst/monoscope')
-rw-r--r--gst/monoscope/convolve.c438
-rw-r--r--gst/monoscope/convolve.h14
-rw-r--r--gst/monoscope/gstmonoscope.c124
-rw-r--r--gst/monoscope/monoscope.c184
-rw-r--r--gst/monoscope/monoscope.h21
5 files changed, 403 insertions, 378 deletions
diff --git a/gst/monoscope/convolve.c b/gst/monoscope/convolve.c
index b707621b..6b8cdd50 100644
--- a/gst/monoscope/convolve.c
+++ b/gst/monoscope/convolve.c
@@ -62,19 +62,28 @@
#include <stdlib.h>
#include "convolve.h"
-typedef union stack_entry_s {
- struct {const double * left, * right; double * out;} v;
- struct {double * main, * null;} b;
+typedef union stack_entry_s
+{
+ struct
+ {
+ const double *left, *right;
+ double *out;
+ } v;
+ struct
+ {
+ double *main, *null;
+ } b;
} stack_entry;
#define STACK_SIZE (CONVOLVE_DEPTH * 3)
-struct _struct_convolve_state {
- double left [CONVOLVE_BIG];
- double right [CONVOLVE_SMALL * 3];
- double scratch [CONVOLVE_SMALL * 3];
- stack_entry stack[STACK_SIZE];
+struct _struct_convolve_state
+{
+ double left[CONVOLVE_BIG];
+ double right[CONVOLVE_SMALL * 3];
+ double scratch[CONVOLVE_SMALL * 3];
+ stack_entry stack[STACK_SIZE];
};
/*
@@ -83,48 +92,53 @@ struct _struct_convolve_state {
* On error, returns NULL.
* The pointer should be freed when it is finished with, by convolve_close().
*/
-convolve_state *convolve_init(void)
+convolve_state *
+convolve_init (void)
{
- return (convolve_state *) malloc (sizeof(convolve_state));
+ return (convolve_state *) malloc (sizeof (convolve_state));
}
/*
* Free the state allocated with convolve_init().
*/
-void convolve_close(convolve_state *state)
+void
+convolve_close (convolve_state * state)
{
- if (state)
- free(state);
+ if (state)
+ free (state);
}
-static void convolve_4 (double * out, const double * left, const double * right)
+static void
+convolve_4 (double *out, const double *left, const double *right)
/* This does a 4x4 -> 7 convolution. For what it's worth, the slightly odd
* ordering gives about a 1% speed up on my Pentium II. */
{
- double l0, l1, l2, l3, r0, r1, r2, r3;
- double a;
- l0 = left[0];
- r0 = right[0];
- a = l0 * r0;
- l1 = left[1];
- r1 = right[1];
- out[0] = a;
- a = (l0 * r1) + (l1 * r0);
- l2 = left[2];
- r2 = right[2];
- out[1] = a;
- a = (l0 * r2) + (l1 * r1) + (l2 * r0);
- l3 = left[3];
- r3 = right[3];
- out[2] = a;
-
- out[3] = (l0 * r3) + (l1 * r2) + (l2 * r1) + (l3 * r0);
- out[4] = (l1 * r3) + (l2 * r2) + (l3 * r1);
- out[5] = (l2 * r3) + (l3 * r2);
- out[6] = l3 * r3;
+ double l0, l1, l2, l3, r0, r1, r2, r3;
+ double a;
+
+ l0 = left[0];
+ r0 = right[0];
+ a = l0 * r0;
+ l1 = left[1];
+ r1 = right[1];
+ out[0] = a;
+ a = (l0 * r1) + (l1 * r0);
+ l2 = left[2];
+ r2 = right[2];
+ out[1] = a;
+ a = (l0 * r2) + (l1 * r1) + (l2 * r0);
+ l3 = left[3];
+ r3 = right[3];
+ out[2] = a;
+
+ out[3] = (l0 * r3) + (l1 * r2) + (l2 * r1) + (l3 * r0);
+ out[4] = (l1 * r3) + (l2 * r2) + (l3 * r1);
+ out[5] = (l2 * r3) + (l3 * r2);
+ out[6] = l3 * r3;
}
-static void convolve_run (stack_entry * top, unsigned size, double * scratch)
+static void
+convolve_run (stack_entry * top, unsigned size, double *scratch)
/* Interpret a stack of commands. The stack starts with two entries; the
* convolution to do, and an illegal entry used to mark the stack top. The
* size is the number of entries in each input, and must be a power of 2,
@@ -132,102 +146,105 @@ static void convolve_run (stack_entry * top, unsigned size, double * scratch)
* scratch must have length 3*size. The number of stack entries needed is
* 3n-4 where size=2^n. */
{
- do {
- const double * left;
- const double * right;
- double * out;
-
- /* When we get here, the stack top is always a convolve,
- * with size > 4. So we will split it. We repeatedly split
- * the top entry until we get to size = 4. */
-
- left = top->v.left;
- right = top->v.right;
- out = top->v.out;
- top++;
-
- do {
- double * s_left, * s_right;
- int i;
-
- /* Halve the size. */
- size >>= 1;
-
- /* Allocate the scratch areas. */
- s_left = scratch + size * 3;
- /* s_right is a length 2*size buffer also used for
- * intermediate output. */
- s_right = scratch + size * 4;
-
- /* Create the intermediate factors. */
- for (i = 0; i < size; i++) {
- double l = left[i] + left[i + size];
- double r = right[i] + right[i + size];
- s_left[i + size] = r;
- s_left[i] = l;
- }
-
- /* Push the combine entry onto the stack. */
- top -= 3;
- top[2].b.main = out;
- top[2].b.null = NULL;
-
- /* Push the low entry onto the stack. This must be
- * the last of the three sub-convolutions, because
- * it may overwrite the arguments. */
- top[1].v.left = left;
- top[1].v.right = right;
- top[1].v.out = out;
-
- /* Push the mid entry onto the stack. */
- top[0].v.left = s_left;
- top[0].v.right = s_right;
- top[0].v.out = s_right;
-
- /* Leave the high entry in variables. */
- left += size;
- right += size;
- out += size * 2;
-
- } while (size > 4);
-
- /* When we get here, the stack top is a group of 3
- * convolves, with size = 4, followed by some combines. */
- convolve_4 (out, left, right);
- convolve_4 (top[0].v.out, top[0].v.left, top[0].v.right);
- convolve_4 (top[1].v.out, top[1].v.left, top[1].v.right);
- top += 2;
-
- /* Now process combines. */
- do {
- /* b.main is the output buffer, mid is the middle
- * part which needs to be adjusted in place, and
- * then folded back into the output. We do this in
- * a slightly strange way, so as to avoid having
- * two loops. */
- double * out = top->b.main;
- double * mid = scratch + size * 4;
- unsigned int i;
- top++;
- out[size * 2 - 1] = 0;
- for (i = 0; i < size-1; i++) {
- double lo;
- double hi;
- lo = mid[0] - (out[0] + out[2 * size]) + out[size];
- hi = mid[size] - (out[size] + out[3 * size]) + out[2 * size];
- out[size] = lo;
- out[2 * size] = hi;
- out++;
- mid++;
- }
- size <<= 1;
- } while (top->b.null == NULL);
- } while (top->b.main != NULL);
+ do {
+ const double *left;
+ const double *right;
+ double *out;
+
+ /* When we get here, the stack top is always a convolve,
+ * with size > 4. So we will split it. We repeatedly split
+ * the top entry until we get to size = 4. */
+
+ left = top->v.left;
+ right = top->v.right;
+ out = top->v.out;
+ top++;
+
+ do {
+ double *s_left, *s_right;
+ int i;
+
+ /* Halve the size. */
+ size >>= 1;
+
+ /* Allocate the scratch areas. */
+ s_left = scratch + size * 3;
+ /* s_right is a length 2*size buffer also used for
+ * intermediate output. */
+ s_right = scratch + size * 4;
+
+ /* Create the intermediate factors. */
+ for (i = 0; i < size; i++) {
+ double l = left[i] + left[i + size];
+ double r = right[i] + right[i + size];
+
+ s_left[i + size] = r;
+ s_left[i] = l;
+ }
+
+ /* Push the combine entry onto the stack. */
+ top -= 3;
+ top[2].b.main = out;
+ top[2].b.null = NULL;
+
+ /* Push the low entry onto the stack. This must be
+ * the last of the three sub-convolutions, because
+ * it may overwrite the arguments. */
+ top[1].v.left = left;
+ top[1].v.right = right;
+ top[1].v.out = out;
+
+ /* Push the mid entry onto the stack. */
+ top[0].v.left = s_left;
+ top[0].v.right = s_right;
+ top[0].v.out = s_right;
+
+ /* Leave the high entry in variables. */
+ left += size;
+ right += size;
+ out += size * 2;
+
+ } while (size > 4);
+
+ /* When we get here, the stack top is a group of 3
+ * convolves, with size = 4, followed by some combines. */
+ convolve_4 (out, left, right);
+ convolve_4 (top[0].v.out, top[0].v.left, top[0].v.right);
+ convolve_4 (top[1].v.out, top[1].v.left, top[1].v.right);
+ top += 2;
+
+ /* Now process combines. */
+ do {
+ /* b.main is the output buffer, mid is the middle
+ * part which needs to be adjusted in place, and
+ * then folded back into the output. We do this in
+ * a slightly strange way, so as to avoid having
+ * two loops. */
+ double *out = top->b.main;
+ double *mid = scratch + size * 4;
+ unsigned int i;
+
+ top++;
+ out[size * 2 - 1] = 0;
+ for (i = 0; i < size - 1; i++) {
+ double lo;
+ double hi;
+
+ lo = mid[0] - (out[0] + out[2 * size]) + out[size];
+ hi = mid[size] - (out[size] + out[3 * size]) + out[2 * size];
+ out[size] = lo;
+ out[2 * size] = hi;
+ out++;
+ mid++;
+ }
+ size <<= 1;
+ } while (top->b.null == NULL);
+ } while (top->b.main != NULL);
}
-int convolve_match (const int * lastchoice,
- const short * input,
- convolve_state * state)
+int
+convolve_match (const int *lastchoice,
+ const short *input, convolve_state * state)
/* lastchoice is a 256 sized array. input is a 512 array. We find the
* contiguous length 256 sub-array of input that best matches lastchoice.
* A measure of how good a sub-array is compared with the lastchoice is
@@ -236,85 +253,90 @@ int convolve_match (const int * lastchoice,
* entry in the convolutions. state is a (non-NULL) pointer returned by
* convolve_init. */
{
- double avg;
- double best;
- int p = 0;
- int i;
- double * left = state->left;
- double * right = state->right;
- double * scratch = state->scratch;
- stack_entry * top = state->stack + STACK_SIZE - 1;
+ double avg;
+ double best;
+ int p = 0;
+ int i;
+ double *left = state->left;
+ double *right = state->right;
+ double *scratch = state->scratch;
+ stack_entry *top = state->stack + STACK_SIZE - 1;
+
#if 1
- for (i = 0; i < 512; i++)
- left[i] = input[i];
-
- avg = 0;
- for (i = 0; i < 256; i++) {
- double a = lastchoice[255 - i];
- right[i] = a;
- avg += a;
- }
+ for (i = 0; i < 512; i++)
+ left[i] = input[i];
+
+ avg = 0;
+ for (i = 0; i < 256; i++) {
+ double a = lastchoice[255 - i];
+
+ right[i] = a;
+ avg += a;
+ }
#endif
- /* We adjust the smaller of the two input arrays to have average
- * value 0. This makes the eventual result insensitive to both
- * constant offsets and positive multipliers of the inputs. */
- avg /= 256;
- for (i = 0; i < 256; i++)
- right[i] -= avg;
- /* End-of-stack marker. */
-#if 0 /* The following line produces a CRASH, need to figure out why?!! */
- top[1].b.null = scratch;
-#endif
- top[1].b.main = NULL;
- /* The low 256x256, of which we want the high 256 outputs. */
- top->v.left = left;
- top->v.right = right;
- top->v.out = right + 256;
- convolve_run (top, 256, scratch);
-
- /* The high 256x256, of which we want the low 256 outputs. */
- top->v.left = left + 256;
- top->v.right = right;
- top->v.out = right;
- convolve_run (top, 256, scratch);
-
- /* Now find the best position amoungs this. Apart from the first
- * and last, the required convolution outputs are formed by adding
- * outputs from the two convolutions above. */
- best = right[511];
- right[767] = 0;
- p = -1;
- for (i = 0; i < 256; i++) {
- double a = right[i] + right[i + 512];
- if (a > best) {
- best = a;
- p = i;
- }
- }
- p++;
-
+ /* We adjust the smaller of the two input arrays to have average
+ * value 0. This makes the eventual result insensitive to both
+ * constant offsets and positive multipliers of the inputs. */
+ avg /= 256;
+ for (i = 0; i < 256; i++)
+ right[i] -= avg;
+ /* End-of-stack marker. */
+#if 0 /* The following line produces a CRASH, need to figure out why?!! */
+ top[1].b.null = scratch;
+#endif
+ top[1].b.main = NULL;
+ /* The low 256x256, of which we want the high 256 outputs. */
+ top->v.left = left;
+ top->v.right = right;
+ top->v.out = right + 256;
+ convolve_run (top, 256, scratch);
+
+ /* The high 256x256, of which we want the low 256 outputs. */
+ top->v.left = left + 256;
+ top->v.right = right;
+ top->v.out = right;
+ convolve_run (top, 256, scratch);
+
+ /* Now find the best position amoungs this. Apart from the first
+ * and last, the required convolution outputs are formed by adding
+ * outputs from the two convolutions above. */
+ best = right[511];
+ right[767] = 0;
+ p = -1;
+ for (i = 0; i < 256; i++) {
+ double a = right[i] + right[i + 512];
+
+ if (a > best) {
+ best = a;
+ p = i;
+ }
+ }
+ p++;
+
#if 0
- {
- /* This is some debugging code... */
- int bad = 0;
- best = 0;
- for (i = 0; i < 256; i++)
- best += ((double) input[i+p]) * ((double) lastchoice[i] - avg);
-
- for (i = 0; i < 257; i++) {
- double tot = 0;
- unsigned int j;
- for (j = 0; j < 256; j++)
- tot += ((double) input[i+j]) * ((double) lastchoice[j] - avg);
- if (tot > best)
- printf ("(%i)", i);
- if (tot != left[i + 255])
- printf ("!");
- }
-
- printf ("%i\n", p);
- }
-#endif
-
- return p;
+ {
+ /* This is some debugging code... */
+ int bad = 0;
+
+ best = 0;
+ for (i = 0; i < 256; i++)
+ best += ((double) input[i + p]) * ((double) lastchoice[i] - avg);
+
+ for (i = 0; i < 257; i++) {
+ double tot = 0;
+ unsigned int j;
+
+ for (j = 0; j < 256; j++)
+ tot += ((double) input[i + j]) * ((double) lastchoice[j] - avg);
+ if (tot > best)
+ printf ("(%i)", i);
+ if (tot != left[i + 255])
+ printf ("!");
+ }
+
+ printf ("%i\n", p);
+ }
+#endif
+
+ return p;
}
diff --git a/gst/monoscope/convolve.h b/gst/monoscope/convolve.h
index d9709edc..d5f34d2b 100644
--- a/gst/monoscope/convolve.h
+++ b/gst/monoscope/convolve.h
@@ -21,7 +21,8 @@
#define CONVOLVE_H
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
/* convolve_match takes two blocks, one twice the size of the other. The
@@ -31,14 +32,13 @@ extern "C" {
#define CONVOLVE_BIG (CONVOLVE_SMALL * 2)
/* Convolution stuff */
-typedef struct _struct_convolve_state convolve_state;
+ typedef struct _struct_convolve_state convolve_state;
-convolve_state *convolve_init (void);
-void convolve_close (convolve_state * state);
+ convolve_state *convolve_init (void);
+ void convolve_close (convolve_state * state);
-int convolve_match (const int * lastchoice,
- const short int * input,
- convolve_state * state);
+ int convolve_match (const int *lastchoice,
+ const short int *input, convolve_state * state);
#ifdef __cplusplus
}
diff --git a/gst/monoscope/gstmonoscope.c b/gst/monoscope/gstmonoscope.c
index d3157d97..f8e82b2f 100644
--- a/gst/monoscope/gstmonoscope.c
+++ b/gst/monoscope/gstmonoscope.c
@@ -35,11 +35,12 @@
typedef struct _GstMonoscope GstMonoscope;
typedef struct _GstMonoscopeClass GstMonoscopeClass;
-struct _GstMonoscope {
+struct _GstMonoscope
+{
GstElement element;
/* pads */
- GstPad *sinkpad,*srcpad;
+ GstPad *sinkpad, *srcpad;
/* the timestamp of the next frame */
guint64 next_time;
@@ -52,14 +53,15 @@ struct _GstMonoscope {
gboolean first_buffer;
/* visualisation state */
- struct monoscope_state * visstate;
+ struct monoscope_state *visstate;
};
-struct _GstMonoscopeClass {
+struct _GstMonoscopeClass
+{
GstElementClass parent_class;
};
-GType gst_monoscope_get_type(void);
+GType gst_monoscope_get_type (void);
/* elementfactory information */
@@ -71,41 +73,39 @@ static GstElementDetails gst_monoscope_details = {
};
/* signals and args */
-enum {
+enum
+{
/* FILL ME */
LAST_SIGNAL
};
-enum {
+enum
+{
ARG_0,
/* FILL ME */
};
-static GstStaticPadTemplate src_template =
-GST_STATIC_PAD_TEMPLATE (
- "src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN)
-);
+static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN)
+ );
-static GstStaticPadTemplate sink_template =
-GST_STATIC_PAD_TEMPLATE (
- "sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS)
-);
+static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS (GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS)
+ );
-static void gst_monoscope_class_init (GstMonoscopeClass *klass);
-static void gst_monoscope_base_init (GstMonoscopeClass *klass);
-static void gst_monoscope_init (GstMonoscope *monoscope);
+static void gst_monoscope_class_init (GstMonoscopeClass * klass);
+static void gst_monoscope_base_init (GstMonoscopeClass * klass);
+static void gst_monoscope_init (GstMonoscope * monoscope);
-static void gst_monoscope_chain (GstPad *pad, GstData *_data);
+static void gst_monoscope_chain (GstPad * pad, GstData * _data);
static GstPadLinkReturn
- gst_monoscope_srcconnect (GstPad *pad, const GstCaps *caps);
+gst_monoscope_srcconnect (GstPad * pad, const GstCaps * caps);
static GstElementClass *parent_class = NULL;
@@ -116,9 +116,9 @@ gst_monoscope_get_type (void)
if (!type) {
static const GTypeInfo info = {
- sizeof (GstMonoscopeClass),
- (GBaseInitFunc) gst_monoscope_base_init,
- NULL,
+ sizeof (GstMonoscopeClass),
+ (GBaseInitFunc) gst_monoscope_base_init,
+ NULL,
(GClassInitFunc) gst_monoscope_class_init,
NULL,
NULL,
@@ -132,37 +132,39 @@ gst_monoscope_get_type (void)
}
static void
-gst_monoscope_base_init (GstMonoscopeClass *klass)
+gst_monoscope_base_init (GstMonoscopeClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&src_template));
+ gst_static_pad_template_get (&src_template));
gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&sink_template));
+ gst_static_pad_template_get (&sink_template));
gst_element_class_set_details (element_class, &gst_monoscope_details);
}
static void
-gst_monoscope_class_init(GstMonoscopeClass *klass)
+gst_monoscope_class_init (GstMonoscopeClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
- gobject_class = (GObjectClass*) klass;
- gstelement_class = (GstElementClass*) klass;
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
}
static void
-gst_monoscope_init (GstMonoscope *monoscope)
+gst_monoscope_init (GstMonoscope * monoscope)
{
/* create the sink and src pads */
- monoscope->sinkpad = gst_pad_new_from_template (
- gst_static_pad_template_get (&sink_template ), "sink");
- monoscope->srcpad = gst_pad_new_from_template (
- gst_static_pad_template_get (&src_template ), "src");
+ monoscope->sinkpad =
+ gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
+ "sink");
+ monoscope->srcpad =
+ gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
+ "src");
gst_element_add_pad (GST_ELEMENT (monoscope), monoscope->sinkpad);
gst_element_add_pad (GST_ELEMENT (monoscope), monoscope->srcpad);
@@ -175,11 +177,11 @@ gst_monoscope_init (GstMonoscope *monoscope)
monoscope->first_buffer = TRUE;
monoscope->width = 256;
monoscope->height = 128;
- monoscope->fps = 25.; /* desired frame rate */
+ monoscope->fps = 25.; /* desired frame rate */
}
static GstPadLinkReturn
-gst_monoscope_srcconnect (GstPad *pad, const GstCaps *caps)
+gst_monoscope_srcconnect (GstPad * pad, const GstCaps * caps)
{
GstMonoscope *monoscope = GST_MONOSCOPE (gst_pad_get_parent (pad));
GstStructure *structure;
@@ -194,7 +196,7 @@ gst_monoscope_srcconnect (GstPad *pad, const GstCaps *caps)
}
static void
-gst_monoscope_chain (GstPad *pad, GstData *_data)
+gst_monoscope_chain (GstPad * pad, GstData * _data)
{
GstBuffer *bufin = GST_BUFFER (_data);
GstMonoscope *monoscope;
@@ -213,25 +215,26 @@ gst_monoscope_chain (GstPad *pad, GstData *_data)
/* FIXME: should really select the first 1024 samples after the timestamp. */
if (GST_BUFFER_TIMESTAMP (bufin) < monoscope->next_time || samples_in < 1024) {
- GST_DEBUG ("timestamp is %" G_GUINT64_FORMAT ": want >= %" G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (bufin), monoscope->next_time);
+ GST_DEBUG ("timestamp is %" G_GUINT64_FORMAT ": want >= %" G_GUINT64_FORMAT,
+ GST_BUFFER_TIMESTAMP (bufin), monoscope->next_time);
gst_buffer_unref (bufin);
return;
}
data = (gint16 *) GST_BUFFER_DATA (bufin);
/* FIXME: Select samples in a better way. */
- for (i=0; i < 512; i++) {
+ for (i = 0; i < 512; i++) {
monoscope->datain[i] = *data++;
}
if (monoscope->first_buffer) {
monoscope->visstate = monoscope_init (monoscope->width, monoscope->height);
- g_assert(monoscope->visstate != 0);
+ g_assert (monoscope->visstate != 0);
GST_DEBUG ("making new pad");
if (!gst_pad_is_negotiated (monoscope->srcpad)) {
if (gst_pad_renegotiate (monoscope->srcpad) <= 0) {
- GST_ELEMENT_ERROR (monoscope, CORE, NEGOTIATION, (NULL), (NULL));
- return;
+ GST_ELEMENT_ERROR (monoscope, CORE, NEGOTIATION, (NULL), (NULL));
+ return;
}
}
monoscope->first_buffer = FALSE;
@@ -239,7 +242,8 @@ gst_monoscope_chain (GstPad *pad, GstData *_data)
bufout = gst_buffer_new ();
GST_BUFFER_SIZE (bufout) = monoscope->width * monoscope->height * 4;
- GST_BUFFER_DATA (bufout) = (guchar *) monoscope_update (monoscope->visstate, monoscope->datain);
+ GST_BUFFER_DATA (bufout) =
+ (guchar *) monoscope_update (monoscope->visstate, monoscope->datain);
GST_BUFFER_TIMESTAMP (bufout) = monoscope->next_time;
GST_BUFFER_FLAG_SET (bufout, GST_BUFFER_DONTFREE);
@@ -254,20 +258,14 @@ gst_monoscope_chain (GstPad *pad, GstData *_data)
}
static gboolean
-plugin_init (GstPlugin *plugin)
+plugin_init (GstPlugin * plugin)
{
- return gst_element_register(plugin, "monoscope",
- GST_RANK_NONE, GST_TYPE_MONOSCOPE);
+ return gst_element_register (plugin, "monoscope",
+ GST_RANK_NONE, GST_TYPE_MONOSCOPE);
}
-GST_PLUGIN_DEFINE (
- GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "monoscope",
- "Monoscope visualization",
- plugin_init,
- VERSION,
- "LGPL",
- GST_PACKAGE,
- GST_ORIGIN
-)
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "monoscope",
+ "Monoscope visualization",
+ plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
diff --git a/gst/monoscope/monoscope.c b/gst/monoscope/monoscope.c
index eb0e728a..20a68099 100644
--- a/gst/monoscope/monoscope.c
+++ b/gst/monoscope/monoscope.c
@@ -29,110 +29,114 @@
#include <string.h>
#include <stdlib.h>
-static void colors_init(guint32 * colors)
+static void
+colors_init (guint32 * colors)
{
- int i;
- for (i = 0; i < 32; i++) {
- colors[i] = (i*8 << 16) + (255 << 8);
- colors[i+31] = (255 << 16) + (((31 - i) * 8) << 8);
- }
- colors[63] = (40 << 16) + (75 << 8);
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ colors[i] = (i * 8 << 16) + (255 << 8);
+ colors[i + 31] = (255 << 16) + (((31 - i) * 8) << 8);
+ }
+ colors[63] = (40 << 16) + (75 << 8);
}
-struct monoscope_state * monoscope_init (guint32 resx, guint32 resy)
+struct monoscope_state *
+monoscope_init (guint32 resx, guint32 resy)
{
- struct monoscope_state * stateptr;
- stateptr = calloc(1, sizeof(struct monoscope_state));
- if (stateptr == 0) return 0;
- stateptr->cstate = convolve_init();
- colors_init(stateptr->colors);
- return stateptr;
+ struct monoscope_state *stateptr;
+ stateptr = calloc (1, sizeof (struct monoscope_state));
+ if (stateptr == 0)
+ return 0;
+ stateptr->cstate = convolve_init ();
+ colors_init (stateptr->colors);
+ return stateptr;
}
-guint32 * monoscope_update (struct monoscope_state * stateptr,
- gint16 data [512])
+guint32 *
+monoscope_update (struct monoscope_state * stateptr, gint16 data[512])
{
- /* Note that CONVOLVE_BIG must == data size here, ie 512. */
- /* Really, we want samples evenly spread over the available data.
- * Just taking a continuous chunk will do for now, though. */
- int i;
- int foo;
- int bar;
- int h;
- guint32 *loc;
+ /* Note that CONVOLVE_BIG must == data size here, ie 512. */
+ /* Really, we want samples evenly spread over the available data.
+ * Just taking a continuous chunk will do for now, though. */
+ int i;
+ int foo;
+ int bar;
+ int h;
+ guint32 *loc;
- int factor;
- int val;
- int max = 1;
- short * thisEq;
+ int factor;
+ int val;
+ int max = 1;
+ short *thisEq;
- memcpy (stateptr->copyEq, data, sizeof (short) * CONVOLVE_BIG);
- thisEq = stateptr->copyEq;
-#if 1
- val = convolve_match (stateptr->avgEq, stateptr->copyEq, stateptr->cstate);
- thisEq += val;
-#endif
- memset(stateptr->display, 0, 256 * 128 * sizeof(guint32));
- for (i=0; i < 256; i++) {
- foo = thisEq[i] + (stateptr->avgEq[i] >> 1);
- stateptr->avgEq[i] = foo;
- if (foo < 0)
- foo = -foo;
- if (foo > max)
- max = foo;
+ memcpy (stateptr->copyEq, data, sizeof (short) * CONVOLVE_BIG);
+ thisEq = stateptr->copyEq;
+#if 1
+ val = convolve_match (stateptr->avgEq, stateptr->copyEq, stateptr->cstate);
+ thisEq += val;
+#endif
+ memset (stateptr->display, 0, 256 * 128 * sizeof (guint32));
+ for (i = 0; i < 256; i++) {
+ foo = thisEq[i] + (stateptr->avgEq[i] >> 1);
+ stateptr->avgEq[i] = foo;
+ if (foo < 0)
+ foo = -foo;
+ if (foo > max)
+ max = foo;
+ }
+ stateptr->avgMax += max - (stateptr->avgMax >> 8);
+ if (stateptr->avgMax < max)
+ stateptr->avgMax = max; /* Avoid overflow */
+ factor = 0x7fffffff / stateptr->avgMax;
+ /* Keep the scaling sensible. */
+ if (factor > (1 << 18))
+ factor = 1 << 18;
+ if (factor < (1 << 8))
+ factor = 1 << 8;
+ for (i = 0; i < 256; i++) {
+ foo = stateptr->avgEq[i] * factor;
+ foo >>= 18;
+ if (foo > 63)
+ foo = 63;
+ if (foo < -64)
+ foo = -64;
+ val = (i + ((foo + 64) << 8));
+ bar = val;
+ if ((bar > 0) && (bar < (256 * 128))) {
+ loc = stateptr->display + bar;
+ if (foo < 0) {
+ for (h = 0; h <= (-foo); h++) {
+ *loc = stateptr->colors[h];
+ loc += 256;
}
- stateptr->avgMax += max - (stateptr->avgMax >> 8);
- if (stateptr->avgMax < max)
- stateptr->avgMax = max; /* Avoid overflow */
- factor = 0x7fffffff / stateptr->avgMax;
- /* Keep the scaling sensible. */
- if (factor > (1 << 18))
- factor = 1 << 18;
- if (factor < (1 << 8))
- factor = 1 << 8;
- for (i=0; i < 256; i++) {
- foo = stateptr->avgEq[i] * factor;
- foo >>= 18;
- if (foo > 63)
- foo = 63;
- if (foo < -64)
- foo = -64;
- val = (i + ((foo+64) << 8));
- bar = val;
- if ((bar > 0) && (bar < (256 * 128))) {
- loc = stateptr->display + bar;
- if (foo < 0) {
- for (h = 0; h <= (-foo); h++) {
- *loc = stateptr->colors[h];
- loc+=256;
- }
- } else {
- for (h = 0; h <= foo; h++) {
- *loc = stateptr->colors[h];
- loc-=256;
- }
- }
- }
+ } else {
+ for (h = 0; h <= foo; h++) {
+ *loc = stateptr->colors[h];
+ loc -= 256;
}
+ }
+ }
+ }
- /* Draw grid. */
- for (i=16;i < 128; i+=16) {
- for (h = 0; h < 256; h+=2) {
- stateptr->display[(i << 8) + h] = stateptr->colors[63];
- if (i == 64)
- stateptr->display[(i << 8) + h + 1] = stateptr->colors[63];
- }
- }
- for (i = 16; i < 256; i+=16) {
- for (h = 0; h < 128; h+=2) {
- stateptr->display[i + (h << 8)] = stateptr->colors[63];
- }
- }
+ /* Draw grid. */
+ for (i = 16; i < 128; i += 16) {
+ for (h = 0; h < 256; h += 2) {
+ stateptr->display[(i << 8) + h] = stateptr->colors[63];
+ if (i == 64)
+ stateptr->display[(i << 8) + h + 1] = stateptr->colors[63];
+ }
+ }
+ for (i = 16; i < 256; i += 16) {
+ for (h = 0; h < 128; h += 2) {
+ stateptr->display[i + (h << 8)] = stateptr->colors[63];
+ }
+ }
- return stateptr->display;
+ return stateptr->display;
}
-void monoscope_close (struct monoscope_state * stateptr)
+void
+monoscope_close (struct monoscope_state *stateptr)
{
}
-
diff --git a/gst/monoscope/monoscope.h b/gst/monoscope/monoscope.h
index 8e7d7591..37be6fff 100644
--- a/gst/monoscope/monoscope.h
+++ b/gst/monoscope/monoscope.h
@@ -7,18 +7,19 @@
#define scope_width 256
#define scope_height 128
-struct monoscope_state {
- gint16 copyEq[CONVOLVE_BIG];
- int avgEq[CONVOLVE_SMALL]; /* a running average of the last few. */
- int avgMax; /* running average of max sample. */
- guint32 display[(scope_width + 1) * (scope_height + 1)];
+struct monoscope_state
+{
+ gint16 copyEq[CONVOLVE_BIG];
+ int avgEq[CONVOLVE_SMALL]; /* a running average of the last few. */
+ int avgMax; /* running average of max sample. */
+ guint32 display[(scope_width + 1) * (scope_height + 1)];
- convolve_state *cstate;
- guint32 colors[64];
+ convolve_state *cstate;
+ guint32 colors[64];
};
-struct monoscope_state * monoscope_init (guint32 resx, guint32 resy);
-guint32 * monoscope_update (struct monoscope_state * stateptr, gint16 data [512]);
-void monoscope_close (struct monoscope_state * stateptr);
+struct monoscope_state *monoscope_init (guint32 resx, guint32 resy);
+guint32 *monoscope_update (struct monoscope_state *stateptr, gint16 data[512]);
+void monoscope_close (struct monoscope_state *stateptr);
#endif