2 * Copyright (C) 2002 Richard Boulton <richard@tartarus.org>
3 * Copyright (C) 1998-2001 Andy Lo A Foe <andy@alsaplayer.org>
4 * Original code by Tinic Uro
6 * This code is copied from Alsaplayer.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "monoscope.h"
33 colors_init (guint32 * colors)
37 for (i = 0; i < 32; i++) {
38 colors[i] = (i * 8 << 16) + (255 << 8);
39 colors[i + 31] = (255 << 16) + (((31 - i) * 8) << 8);
41 colors[63] = (40 << 16) + (75 << 8);
44 struct monoscope_state *
45 monoscope_init (guint32 resx, guint32 resy)
47 struct monoscope_state *stateptr;
48 stateptr = calloc (1, sizeof (struct monoscope_state));
51 stateptr->cstate = convolve_init ();
52 colors_init (stateptr->colors);
57 monoscope_update (struct monoscope_state * stateptr, gint16 data[512])
59 /* Note that CONVOLVE_BIG must == data size here, ie 512. */
60 /* Really, we want samples evenly spread over the available data.
61 * Just taking a continuous chunk will do for now, though. */
73 memcpy (stateptr->copyEq, data, sizeof (short) * CONVOLVE_BIG);
74 thisEq = stateptr->copyEq;
76 val = convolve_match (stateptr->avgEq, stateptr->copyEq, stateptr->cstate);
79 memset (stateptr->display, 0, 256 * 128 * sizeof (guint32));
80 for (i = 0; i < 256; i++) {
81 foo = thisEq[i] + (stateptr->avgEq[i] >> 1);
82 stateptr->avgEq[i] = foo;
88 stateptr->avgMax += max - (stateptr->avgMax >> 8);
89 if (stateptr->avgMax < max)
90 stateptr->avgMax = max; /* Avoid overflow */
91 factor = 0x7fffffff / stateptr->avgMax;
92 /* Keep the scaling sensible. */
93 if (factor > (1 << 18))
95 if (factor < (1 << 8))
97 for (i = 0; i < 256; i++) {
98 foo = stateptr->avgEq[i] * factor;
104 val = (i + ((foo + 64) << 8));
106 if ((bar > 0) && (bar < (256 * 128))) {
107 loc = stateptr->display + bar;
109 for (h = 0; h <= (-foo); h++) {
110 *loc = stateptr->colors[h];
114 for (h = 0; h <= foo; h++) {
115 *loc = stateptr->colors[h];
123 for (i = 16; i < 128; i += 16) {
124 for (h = 0; h < 256; h += 2) {
125 stateptr->display[(i << 8) + h] = stateptr->colors[63];
127 stateptr->display[(i << 8) + h + 1] = stateptr->colors[63];
130 for (i = 16; i < 256; i += 16) {
131 for (h = 0; h < 128; h += 2) {
132 stateptr->display[i + (h << 8)] = stateptr->colors[63];
136 return stateptr->display;
140 monoscope_close (struct monoscope_state *stateptr)