monoscope: code cleanup
Use constants more often. Cleanup comments and add more to explain how things work.
This commit is contained in:
parent
3738ce8ba1
commit
daea0540fd
@ -17,10 +17,10 @@
|
|||||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Note: 7th December 2004: This file used to be licensed under the GPL,
|
* Note: 7th December 2004: This file used to be licensed under the GPL,
|
||||||
* but we got permission from Ralp Loader to relicense it to LGPL.
|
* but we got permission from Ralp Loader to relicense it to LGPL.
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -248,18 +248,25 @@ convolve_run (stack_entry * top, unsigned size, double *scratch)
|
|||||||
} while (top->b.main != NULL);
|
} while (top->b.main != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/*
|
||||||
convolve_match (const int *lastchoice,
|
* convolve_match:
|
||||||
const short *input, convolve_state * state)
|
* @lastchoice: an array of size SMALL.
|
||||||
/* lastchoice is a 256 sized array. input is a 512 array. We find the
|
* @input: an array of siue BIG (2*SMALL)
|
||||||
* contiguous length 256 sub-array of input that best matches lastchoice.
|
* @state: a (non-NULL) pointer returned by convolve_init.
|
||||||
* A measure of how good a sub-array is compared with the lastchoice is
|
*
|
||||||
* given by the sum of the products of each pair of entries. We maximise
|
* We find the contiguous SMALL-size sub-array of input that best matches
|
||||||
|
* lastchoice. A measure of how good a sub-array is compared with the lastchoice
|
||||||
|
* is given by the sum of the products of each pair of entries. We maximise
|
||||||
* that, by taking an appropriate convolution, and then finding the maximum
|
* that, by taking an appropriate convolution, and then finding the maximum
|
||||||
* entry in the convolutions. state is a (non-NULL) pointer returned by
|
* entry in the convolutions.
|
||||||
* convolve_init. */
|
*
|
||||||
|
* Return: the position of the best match
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
convolve_match (const int *lastchoice, const short *input,
|
||||||
|
convolve_state * state)
|
||||||
{
|
{
|
||||||
double avg;
|
double avg = 0;
|
||||||
double best;
|
double best;
|
||||||
int p = 0;
|
int p = 0;
|
||||||
int i;
|
int i;
|
||||||
@ -268,47 +275,45 @@ convolve_match (const int *lastchoice,
|
|||||||
double *scratch = state->scratch;
|
double *scratch = state->scratch;
|
||||||
stack_entry *top = state->stack + (STACK_SIZE - 1);
|
stack_entry *top = state->stack + (STACK_SIZE - 1);
|
||||||
|
|
||||||
#if 1
|
for (i = 0; i < CONVOLVE_BIG; i++)
|
||||||
for (i = 0; i < 512; i++)
|
|
||||||
left[i] = input[i];
|
left[i] = input[i];
|
||||||
|
|
||||||
avg = 0;
|
for (i = 0; i < CONVOLVE_SMALL; i++) {
|
||||||
for (i = 0; i < 256; i++) {
|
double a = lastchoice[(CONVOLVE_SMALL - 1) - i];
|
||||||
double a = lastchoice[255 - i];
|
|
||||||
|
|
||||||
right[i] = a;
|
right[i] = a;
|
||||||
avg += a;
|
avg += a;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/* We adjust the smaller of the two input arrays to have average
|
/* We adjust the smaller of the two input arrays to have average
|
||||||
* value 0. This makes the eventual result insensitive to both
|
* value 0. This makes the eventual result insensitive to both
|
||||||
* constant offsets and positive multipliers of the inputs. */
|
* constant offsets and positive multipliers of the inputs. */
|
||||||
avg /= 256;
|
avg /= CONVOLVE_SMALL;
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < CONVOLVE_SMALL; i++)
|
||||||
right[i] -= avg;
|
right[i] -= avg;
|
||||||
/* End-of-stack marker. */
|
/* End-of-stack marker. */
|
||||||
top[1].b.null = scratch;
|
top[1].b.null = scratch;
|
||||||
top[1].b.main = NULL;
|
top[1].b.main = NULL;
|
||||||
/* The low 256x256, of which we want the high 256 outputs. */
|
/* The low SMALLxSMALL, of which we want the high outputs. */
|
||||||
top->v.left = left;
|
top->v.left = left;
|
||||||
top->v.right = right;
|
top->v.right = right;
|
||||||
top->v.out = right + 256;
|
top->v.out = right + CONVOLVE_SMALL;
|
||||||
convolve_run (top, 256, scratch);
|
convolve_run (top, CONVOLVE_SMALL, scratch);
|
||||||
|
|
||||||
/* The high 256x256, of which we want the low 256 outputs. */
|
/* The high SMALLxSMALL, of which we want the low outputs. */
|
||||||
top->v.left = left + 256;
|
top->v.left = left + CONVOLVE_SMALL;
|
||||||
top->v.right = right;
|
top->v.right = right;
|
||||||
top->v.out = right;
|
top->v.out = right;
|
||||||
convolve_run (top, 256, scratch);
|
convolve_run (top, CONVOLVE_SMALL, scratch);
|
||||||
|
|
||||||
/* Now find the best position amoungs this. Apart from the first
|
/* Now find the best position amoungs this. Apart from the first
|
||||||
* and last, the required convolution outputs are formed by adding
|
* and last, the required convolution outputs are formed by adding
|
||||||
* outputs from the two convolutions above. */
|
* outputs from the two convolutions above. */
|
||||||
best = right[511];
|
best = right[CONVOLVE_BIG - 1];
|
||||||
right[767] = 0;
|
right[CONVOLVE_BIG + CONVOLVE_SMALL + 1] = 0;
|
||||||
p = -1;
|
p = -1;
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < CONVOLVE_SMALL; i++) {
|
||||||
double a = right[i] + right[i + 512];
|
double a = right[i] + right[i + CONVOLVE_BIG];
|
||||||
|
|
||||||
if (a > best) {
|
if (a > best) {
|
||||||
best = a;
|
best = a;
|
||||||
@ -320,21 +325,19 @@ convolve_match (const int *lastchoice,
|
|||||||
#if 0
|
#if 0
|
||||||
{
|
{
|
||||||
/* This is some debugging code... */
|
/* This is some debugging code... */
|
||||||
int bad = 0;
|
|
||||||
|
|
||||||
best = 0;
|
best = 0;
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < CONVOLVE_SMALL; i++)
|
||||||
best += ((double) input[i + p]) * ((double) lastchoice[i] - avg);
|
best += ((double) input[i + p]) * ((double) lastchoice[i] - avg);
|
||||||
|
|
||||||
for (i = 0; i < 257; i++) {
|
for (i = 0; i <= CONVOLVE_SMALL; i++) {
|
||||||
double tot = 0;
|
double tot = 0;
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
|
|
||||||
for (j = 0; j < 256; j++)
|
for (j = 0; j < CONVOLVE_SMALL; j++)
|
||||||
tot += ((double) input[i + j]) * ((double) lastchoice[j] - avg);
|
tot += ((double) input[i + j]) * ((double) lastchoice[j] - avg);
|
||||||
if (tot > best)
|
if (tot > best)
|
||||||
printf ("(%i)", i);
|
printf ("(%i)", i);
|
||||||
if (tot != left[i + 255])
|
if (tot != left[i + (CONVOLVE_SMALL - 1)])
|
||||||
printf ("!");
|
printf ("!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
* the BSD license without a advertisig clause. Andy Lo A Foe then relicensed the
|
* the BSD license without a advertisig clause. Andy Lo A Foe then relicensed the
|
||||||
* code when he used it for Alsaplayer to GPL with Tinic's permission. Richard Boulton
|
* code when he used it for Alsaplayer to GPL with Tinic's permission. Richard Boulton
|
||||||
* then took this code and made a GPL plugin out of it.
|
* then took this code and made a GPL plugin out of it.
|
||||||
*
|
*
|
||||||
* 7th December 2004 Christian Schaller: Richard Boulton and Andy Lo A Foe gave
|
* 7th December 2004 Christian Schaller: Richard Boulton and Andy Lo A Foe gave
|
||||||
* permission to relicense their changes under BSD license so we where able to restore the
|
* permission to relicense their changes under BSD license so we where able to restore the
|
||||||
* code to Tinic's original BSD license.
|
* code to Tinic's original BSD license.
|
||||||
*
|
*
|
||||||
* This file is under what is known as the BSD license:
|
* This file is under what is known as the BSD license:
|
||||||
@ -17,21 +17,21 @@
|
|||||||
* Redistribution and use in source and binary forms, with or without modification, i
|
* Redistribution and use in source and binary forms, with or without modification, i
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
* 3. The name of the author may not be used to endorse or promote products derived from
|
* 3. The name of the author may not be used to endorse or promote products derived from
|
||||||
* this software without specific prior written permission.
|
* this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -95,14 +95,12 @@ monoscope_update (struct monoscope_state *stateptr, gint16 data[512])
|
|||||||
int factor;
|
int factor;
|
||||||
int val;
|
int val;
|
||||||
int max = 1;
|
int max = 1;
|
||||||
short *thisEq;
|
short *thisEq = stateptr->copyEq;
|
||||||
|
|
||||||
memcpy (stateptr->copyEq, data, sizeof (short) * CONVOLVE_BIG);
|
memcpy (thisEq, data, sizeof (short) * CONVOLVE_BIG);
|
||||||
thisEq = stateptr->copyEq;
|
|
||||||
#if 1
|
|
||||||
val = convolve_match (stateptr->avgEq, stateptr->copyEq, stateptr->cstate);
|
val = convolve_match (stateptr->avgEq, stateptr->copyEq, stateptr->cstate);
|
||||||
thisEq += val;
|
thisEq += val;
|
||||||
#endif
|
|
||||||
memset (stateptr->display, 0, 256 * 128 * sizeof (guint32));
|
memset (stateptr->display, 0, 256 * 128 * sizeof (guint32));
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
foo = thisEq[i] + (stateptr->avgEq[i] >> 1);
|
foo = thisEq[i] + (stateptr->avgEq[i] >> 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user