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 newEq[CONVOLVE_BIG]; // latest block of 512 samples.
29 static gint16 copyEq[CONVOLVE_BIG];
30 static int avgEq[CONVOLVE_SMALL]; // a running average of the last few.
31 static int avgMax; // running average of max sample.
32 static guint32 display[(scope_width + 1) * (scope_height + 1)];
34 static convolve_state *state = NULL;
35 static guint32 colors[64];
37 static void colors_init(guint32 * colors)
40 for (i = 0; i < 32; i++) {
41 colors[i] = (i*8 << 16) + (255 << 8);
42 colors[i+31] = (255 << 16) + (((31 - i) * 8) << 8);
44 colors[63] = (40 << 16) + (75 << 8);
47 void monoscope_init (guint32 resx, guint32 resy)
49 state = convolve_init();
53 guint32 * monoscope_update (gint16 data [2][512])
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. */
59 for (i = 0; i < CONVOLVE_BIG; i++) {
60 /* Average the two channels. */
61 newEq[i] = (((int) data[0][i]) + (int) data[1][i]) >> 1;
67 guchar bits[ 257 * 129];
74 memcpy (copyEq, newEq, sizeof (short) * CONVOLVE_BIG);
77 val = convolve_match (avgEq, copyEq, state);
80 memset(display, 0, 256 * 128 * sizeof(guint32));
81 for (i=0; i < 256; i++) {
82 foo = thisEq[i] + (avgEq[i] >> 1);
89 avgMax += max - (avgMax >> 8);
91 avgMax = max; /* Avoid overflow */
92 factor = 0x7fffffff / avgMax;
93 /* Keep the scaling sensible. */
94 if (factor > (1 << 18))
96 if (factor < (1 << 8))
98 for (i=0; i < 256; i++) {
99 foo = avgEq[i] * factor;
105 val = (i + ((foo+64) << 8));
107 if ((bar > 0) && (bar < (256 * 128))) {
110 for (h = 0; h <= (-foo); h++) {
115 for (h = 0; h <= foo; h++) {
124 for (i=16;i < 128; i+=16) {
125 for (h = 0; h < 256; h+=2) {
126 display[(i << 8) + h] = colors[63];
128 display[(i << 8) + h + 1] = colors[63];
131 for (i = 16; i < 256; i+=16) {
132 for (h = 0; h < 128; h+=2) {
133 display[i + (h << 8)] = colors[63];
140 void monoscope_close ()