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"
25 #define scope_width 256
26 #define scope_height 128
28 static gint16 copyEq[CONVOLVE_BIG];
29 static int avgEq[CONVOLVE_SMALL]; // a running average of the last few.
30 static int avgMax; // running average of max sample.
31 static guint32 display[(scope_width + 1) * (scope_height + 1)];
33 static convolve_state *state = NULL;
34 static guint32 colors[64];
36 static void colors_init(guint32 * colors)
39 for (i = 0; i < 32; i++) {
40 colors[i] = (i*8 << 16) + (255 << 8);
41 colors[i+31] = (255 << 16) + (((31 - i) * 8) << 8);
43 colors[63] = (40 << 16) + (75 << 8);
46 void monoscope_init (guint32 resx, guint32 resy)
48 state = convolve_init();
52 guint32 * monoscope_update (gint16 data [512])
54 /* Note that CONVOLVE_BIG must == data size here, ie 512. */
55 /* Really, we want samples evenly spread over the available data.
56 * Just taking a continuous chunk will do for now, though. */
68 memcpy (copyEq, data, sizeof (short) * CONVOLVE_BIG);
71 val = convolve_match (avgEq, copyEq, state);
74 memset(display, 0, 256 * 128 * sizeof(guint32));
75 for (i=0; i < 256; i++) {
76 foo = thisEq[i] + (avgEq[i] >> 1);
83 avgMax += max - (avgMax >> 8);
85 avgMax = max; /* Avoid overflow */
86 factor = 0x7fffffff / avgMax;
87 /* Keep the scaling sensible. */
88 if (factor > (1 << 18))
90 if (factor < (1 << 8))
92 for (i=0; i < 256; i++) {
93 foo = avgEq[i] * factor;
99 val = (i + ((foo+64) << 8));
101 if ((bar > 0) && (bar < (256 * 128))) {
104 for (h = 0; h <= (-foo); h++) {
109 for (h = 0; h <= foo; h++) {
118 for (i=16;i < 128; i+=16) {
119 for (h = 0; h < 256; h+=2) {
120 display[(i << 8) + h] = colors[63];
122 display[(i << 8) + h + 1] = colors[63];
125 for (i = 16; i < 256; i+=16) {
126 for (h = 0; h < 128; h+=2) {
127 display[i + (h << 8)] = colors[63];
134 void monoscope_close ()