diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libmusepack/crc32.c | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libmusepack/crc32.c')
-rw-r--r-- | lib/rbcodec/codecs/libmusepack/crc32.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libmusepack/crc32.c b/lib/rbcodec/codecs/libmusepack/crc32.c new file mode 100644 index 0000000000..7613f1c2c8 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/crc32.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * C Implementation: crc32 | ||
3 | * | ||
4 | * code from http://www.w3.org/TR/PNG/#D-CRCAppendix | ||
5 | * | ||
6 | */ | ||
7 | #include "internal.h" | ||
8 | |||
9 | /* Table of CRCs of all 8-bit messages. */ | ||
10 | static unsigned long crc_table[256]; | ||
11 | |||
12 | /* Flag: has the table been computed? Initially false. */ | ||
13 | static int crc_table_computed = 0; | ||
14 | |||
15 | /* Make the table for a fast CRC. */ | ||
16 | static void make_crc_table(void) | ||
17 | { | ||
18 | unsigned long c; | ||
19 | int n, k; | ||
20 | |||
21 | for (n = 0; n < 256; n++) { | ||
22 | c = (unsigned long) n; | ||
23 | for (k = 0; k < 8; k++) { | ||
24 | if (c & 1) | ||
25 | c = 0xedb88320L ^ (c >> 1); | ||
26 | else | ||
27 | c = c >> 1; | ||
28 | } | ||
29 | crc_table[n] = c; | ||
30 | } | ||
31 | crc_table_computed = 1; | ||
32 | } | ||
33 | |||
34 | |||
35 | /* Update a running CRC with the bytes buf[0..len-1]--the CRC | ||
36 | should be initialized to all 1's, and the transmitted value | ||
37 | is the 1's complement of the final running CRC (see the | ||
38 | crc() routine below). */ | ||
39 | |||
40 | static unsigned long update_crc(unsigned long crc, unsigned char *buf, int len) | ||
41 | { | ||
42 | unsigned long c = crc; | ||
43 | int n; | ||
44 | |||
45 | if (!crc_table_computed) | ||
46 | make_crc_table(); | ||
47 | for (n = 0; n < len; n++) { | ||
48 | c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); | ||
49 | } | ||
50 | return c; | ||
51 | } | ||
52 | |||
53 | /* Return the CRC of the bytes buf[0..len-1]. */ | ||
54 | unsigned long mpc_crc32(unsigned char *buf, int len) | ||
55 | { | ||
56 | return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL; | ||
57 | } | ||