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"
32 static void colors_init(guint32 * colors)
35 for (i = 0; i < 32; i++) {
36 colors[i] = (i*8 << 16) + (255 << 8);
37 colors[i+31] = (255 << 16) + (((31 - i) * 8) << 8);
39 colors[63] = (40 << 16) + (75 << 8);
42 struct monoscope_state * monoscope_init (guint32 resx, guint32 resy)
44 struct monoscope_state * stateptr;
45 stateptr = calloc(1, sizeof(struct monoscope_state));
46 if (stateptr == 0) return 0;
47 stateptr->cstate = convolve_init();
48 colors_init(stateptr->colors);
52 guint32 * monoscope_update (struct monoscope_state * stateptr,
55 /* Note that CONVOLVE_BIG must == data size here, ie 512. */
56 /* Really, we want samples evenly spread over the available data.
57 * Just taking a continuous chunk will do for now, though. */
69 memcpy (stateptr->copyEq, data, sizeof (short) * CONVOLVE_BIG);
70 thisEq = stateptr->copyEq;
72 val = convolve_match (stateptr->avgEq, stateptr->copyEq, stateptr->cstate);
75 memset(stateptr->display, 0, 256 * 128 * sizeof(guint32));
76 for (i=0; i < 256; i++) {
77 foo = thisEq[i] + (stateptr->avgEq[i] >> 1);
78 stateptr->avgEq[i] = foo;
84 stateptr->avgMax += max - (stateptr->avgMax >> 8);
85 if (stateptr->avgMax < max)
86 stateptr->avgMax = max; /* Avoid overflow */
87 factor = 0x7fffffff / stateptr->avgMax;
88 /* Keep the scaling sensible. */
89 if (factor > (1 << 18))
91 if (factor < (1 << 8))
93 for (i=0; i < 256; i++) {
94 foo = stateptr->avgEq[i] * factor;
100 val = (i + ((foo+64) << 8));
102 if ((bar > 0) && (bar < (256 * 128))) {
103 loc = stateptr->display + bar;
105 for (h = 0; h <= (-foo); h++) {
106 *loc = stateptr->colors[h];
110 for (h = 0; h <= foo; h++) {
111 *loc = stateptr->colors[h];
119 for (i=16;i < 128; i+=16) {
120 for (h = 0; h < 256; h+=2) {
121 stateptr->display[(i << 8) + h] = stateptr->colors[63];
123 stateptr->display[(i << 8) + h + 1] = stateptr->colors[63];
126 for (i = 16; i < 256; i+=16) {
127 for (h = 0; h < 128; h+=2) {
128 stateptr->display[i + (h << 8)] = stateptr->colors[63];
132 return stateptr->display;
135 void monoscope_close (struct monoscope_state * stateptr)