Debian Codegraph @

libtwolame/dab.c

raw
1 /*
2 * TwoLAME: an optimized MPEG Audio Layer Two encoder
3 *
4 * Copyright (C) 2001-2004 Michael Cheng
5 * Copyright (C) 2004-2018 The TwoLAME Project
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23
24 #include <stdio.h>
25 #include <string.h>
26
27 #include "twolame.h"
28 #include "common.h"
29 #include "dab.h"
30
31
32 void
33 twolame_dab_crc_calc(twolame_options * glopts,
34 unsigned int bit_alloc[2][SBLIMIT],
35 unsigned int scfsi[2][SBLIMIT],
36 unsigned int scalar[2][3][SBLIMIT], unsigned int *crc, int packed)
37 {
38 int i, j, k;
39 int nch = glopts->num_channels_out;
40 int nb_scalar;
41 int f[5] = { 0, 4, 8, 16, 30 };
42 int first, last;
43
44 first = f[packed];
45 last = f[packed + 1];
46 if (last > glopts->sblimit)
47 last = glopts->sblimit;
48
49 nb_scalar = 0;
50 *crc = 0x0;
51 for (i = first; i < last; i++)
52 for (k = 0; k < nch; k++)
53 if (bit_alloc[k][i]) /* above jsbound, bit_alloc[0][i] == ba[1][i] */
54 switch (scfsi[k][i]) {
55 case 0:
56 for (j = 0; j < 3; j++) {
57 nb_scalar++;
58 twolame_dab_crc_update(scalar[k][j][i] >> 3, 3, crc);
59 }
60 break;
61 case 1:
62 case 3:
63 nb_scalar += 2;
64 twolame_dab_crc_update(scalar[k][0][i] >> 3, 3, crc);
65 twolame_dab_crc_update(scalar[k][2][i] >> 3, 3, crc);
66 break;
67 case 2:
68 nb_scalar++;
69 twolame_dab_crc_update(scalar[k][0][i] >> 3, 3, crc);
70 }
71 }
72
73 void twolame_dab_crc_update(unsigned int data, unsigned int length, unsigned int *crc)
74 {
75 unsigned int masking, carry;
76
77 masking = 1 << length;
78
79 while ((masking >>= 1)) {
80 carry = *crc & 0x80;
81 *crc <<= 1;
82 if (!carry ^ !(data & masking))
83 *crc ^= CRC8_POLYNOMIAL;
84 }
85 *crc &= 0xff;
86 }
87
88 // vim:ts=4:sw=4:nowrap: