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.
22 #include "monoscope.h"
27 static void colors_init(guint32 * colors)
30 for (i = 0; i < 32; i++) {
31 colors[i] = (i*8 << 16) + (255 << 8);
32 colors[i+31] = (255 << 16) + (((31 - i) * 8) << 8);
34 colors[63] = (40 << 16) + (75 << 8);
37 struct monoscope_state * monoscope_init (guint32 resx, guint32 resy)
39 struct monoscope_state * stateptr;
40 stateptr = calloc(1, sizeof(struct monoscope_state));
41 if (stateptr == 0) return 0;
42 stateptr->cstate = convolve_init();
43 colors_init(stateptr->colors);
47 guint32 * monoscope_update (struct monoscope_state * stateptr,
50 /* Note that CONVOLVE_BIG must == data size here, ie 512. */
51 /* Really, we want samples evenly spread over the available data.
52 * Just taking a continuous chunk will do for now, though. */
64 memcpy (stateptr->copyEq, data, sizeof (short) * CONVOLVE_BIG);
65 thisEq = stateptr->copyEq;
67 val = convolve_match (stateptr->avgEq, stateptr->copyEq, stateptr->cstate);
70 memset(stateptr->display, 0, 256 * 128 * sizeof(guint32));
71 for (i=0; i < 256; i++) {
72 foo = thisEq[i] + (stateptr->avgEq[i] >> 1);
73 stateptr->avgEq[i] = foo;
79 stateptr->avgMax += max - (stateptr->avgMax >> 8);
80 if (stateptr->avgMax < max)
81 stateptr->avgMax = max; /* Avoid overflow */
82 factor = 0x7fffffff / stateptr->avgMax;
83 /* Keep the scaling sensible. */
84 if (factor > (1 << 18))
86 if (factor < (1 << 8))
88 for (i=0; i < 256; i++) {
89 foo = stateptr->avgEq[i] * factor;
95 val = (i + ((foo+64) << 8));
97 if ((bar > 0) && (bar < (256 * 128))) {
98 loc = stateptr->display + bar;
100 for (h = 0; h <= (-foo); h++) {
101 *loc = stateptr->colors[h];
105 for (h = 0; h <= foo; h++) {
106 *loc = stateptr->colors[h];
114 for (i=16;i < 128; i+=16) {
115 for (h = 0; h < 256; h+=2) {
116 stateptr->display[(i << 8) + h] = stateptr->colors[63];
118 stateptr->display[(i << 8) + h + 1] = stateptr->colors[63];
121 for (i = 16; i < 256; i+=16) {
122 for (h = 0; h < 128; h+=2) {
123 stateptr->display[i + (h << 8)] = stateptr->colors[63];
127 return stateptr->display;
130 void monoscope_close (struct monoscope_state * stateptr)