~ubuntu-branches/ubuntu/karmic/asterisk/karmic

« back to all changes in this revision

Viewing changes to codecs/lpc10/ham84.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2002-04-27 21:19:32 UTC
  • Revision ID: james.westby@ubuntu.com-20020427211932-kqaertc4bg7ss5mc
Tags: upstream-0.1.11
ImportĀ upstreamĀ versionĀ 0.1.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
$Log: ham84.c,v $
 
4
Revision 1.2  2000/01/05 08:20:39  markster
 
5
Some OSS fixes and a few lpc changes to make it actually work
 
6
 
 
7
 * Revision 1.1  1996/08/19  22:32:07  jaf
 
8
 * Initial revision
 
9
 *
 
10
 
 
11
*/
 
12
 
 
13
#ifdef P_R_O_T_O_T_Y_P_E_S
 
14
extern int ham84_(integer *input, integer *output, integer *errcnt);
 
15
#endif
 
16
 
 
17
/*  -- translated by f2c (version 19951025).
 
18
   You must link the resulting object file with the libraries:
 
19
        -lf2c -lm   (in that order)
 
20
*/
 
21
 
 
22
#include "f2c.h"
 
23
 
 
24
/* ***************************************************************** */
 
25
 
 
26
/*      HAM84 Version 45G */
 
27
 
 
28
/* $Log: ham84.c,v $
 
29
/* Revision 1.2  2000/01/05 08:20:39  markster
 
30
/* Some OSS fixes and a few lpc changes to make it actually work
 
31
/*
 
32
 * Revision 1.1  1996/08/19  22:32:07  jaf
 
33
 * Initial revision
 
34
 * */
 
35
/* Revision 1.3  1996/03/21  15:26:00  jaf */
 
36
/* Put comment header in standard form. */
 
37
 
 
38
/* Revision 1.2  1996/03/13  22:00:13  jaf */
 
39
/* Comments added explaining that none of the local variables of this */
 
40
/* subroutine need to be saved from one invocation to the next. */
 
41
 
 
42
/* Revision 1.1  1996/02/07 14:47:04  jaf */
 
43
/* Initial revision */
 
44
 
 
45
 
 
46
/* ***************************************************************** */
 
47
 
 
48
/*  Hamming 8,4 Decoder - can correct 1 out of seven bits */
 
49
/*   and can detect up to two errors. */
 
50
 
 
51
/* Input: */
 
52
/*  INPUT  - Seven bit data word, 4 bits parameter and */
 
53
/*           4 bits parity information */
 
54
/* Input/Output: */
 
55
/*  ERRCNT - Sums errors detected by Hamming code */
 
56
/* Output: */
 
57
/*  OUTPUT - 4 corrected parameter bits */
 
58
 
 
59
/* This subroutine is entered with an eight bit word in INPUT.  The 8th */
 
60
/* bit is parity and is stripped off.  The remaining 7 bits address the */
 
61
/* hamming 8,4 table and the output OUTPUT from the table gives the 4 */
 
62
/* bits of corrected data.  If bit 4 is set, no error was detected. */
 
63
/* ERRCNT is the number of errors counted. */
 
64
 
 
65
/* This subroutine has no local state. */
 
66
 
 
67
/* Subroutine */ int ham84_(integer *input, integer *output, integer *errcnt)
 
68
{
 
69
    /* Initialized data */
 
70
 
 
71
    static integer dactab[128] = { 16,0,0,3,0,5,14,7,0,9,14,11,14,13,30,14,0,
 
72
            9,2,7,4,7,7,23,9,25,10,9,12,9,14,7,0,5,2,11,5,21,6,5,8,11,11,27,
 
73
            12,5,14,11,2,1,18,2,12,5,2,7,12,9,2,11,28,12,12,15,0,3,3,19,4,13,
 
74
            6,3,8,13,10,3,13,29,14,13,4,1,10,3,20,4,4,7,10,9,26,10,4,13,10,15,
 
75
            8,1,6,3,6,5,22,6,24,8,8,11,8,13,6,15,1,17,2,1,4,1,6,15,8,1,10,15,
 
76
            12,15,15,31 };
 
77
 
 
78
    integer i__, j, parity;
 
79
 
 
80
/*       Arguments */
 
81
/*       Parameters/constants */
 
82
/*       Local variables that need not be saved */
 
83
/*  Determine parity of input word */
 
84
    parity = *input & 255;
 
85
    parity ^= parity / 16;
 
86
    parity ^= parity / 4;
 
87
    parity ^= parity / 2;
 
88
    parity &= 1;
 
89
    i__ = dactab[*input & 127];
 
90
    *output = i__ & 15;
 
91
    j = i__ & 16;
 
92
    if (j != 0) {
 
93
/*          No errors detected in seven bits */
 
94
        if (parity != 0) {
 
95
            ++(*errcnt);
 
96
        }
 
97
    } else {
 
98
/*          One or two errors detected */
 
99
        ++(*errcnt);
 
100
        if (parity == 0) {
 
101
/*             Two errors detected */
 
102
            ++(*errcnt);
 
103
            *output = -1;
 
104
        }
 
105
    }
 
106
    return 0;
 
107
} /* ham84_ */
 
108