diff options
Diffstat (limited to 'gst/monoscope/monoscope.c')
-rw-r--r-- | gst/monoscope/monoscope.c | 184 |
1 files changed, 94 insertions, 90 deletions
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) { } - |