chd 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +30 -0
- data/chd.gemspec +29 -0
- data/ext/chd.c +1008 -0
- data/ext/extconf.rb +60 -0
- data/lib/chd/cd.rb +272 -0
- data/lib/chd/metadata.rb +196 -0
- data/lib/chd/version.rb +4 -0
- data/lib/chd.rb +21 -0
- data/libchdr/CMakeLists.txt +104 -0
- data/libchdr/LICENSE.txt +24 -0
- data/libchdr/README.md +7 -0
- data/libchdr/deps/lzma-19.00/CMakeLists.txt +33 -0
- data/libchdr/deps/lzma-19.00/LICENSE +3 -0
- data/libchdr/deps/lzma-19.00/include/7zTypes.h +375 -0
- data/libchdr/deps/lzma-19.00/include/Alloc.h +51 -0
- data/libchdr/deps/lzma-19.00/include/Bra.h +64 -0
- data/libchdr/deps/lzma-19.00/include/Compiler.h +33 -0
- data/libchdr/deps/lzma-19.00/include/CpuArch.h +336 -0
- data/libchdr/deps/lzma-19.00/include/Delta.h +19 -0
- data/libchdr/deps/lzma-19.00/include/LzFind.h +121 -0
- data/libchdr/deps/lzma-19.00/include/LzHash.h +57 -0
- data/libchdr/deps/lzma-19.00/include/Lzma86.h +111 -0
- data/libchdr/deps/lzma-19.00/include/LzmaDec.h +234 -0
- data/libchdr/deps/lzma-19.00/include/LzmaEnc.h +76 -0
- data/libchdr/deps/lzma-19.00/include/LzmaLib.h +131 -0
- data/libchdr/deps/lzma-19.00/include/Precomp.h +10 -0
- data/libchdr/deps/lzma-19.00/include/Sort.h +18 -0
- data/libchdr/deps/lzma-19.00/lzma-history.txt +446 -0
- data/libchdr/deps/lzma-19.00/lzma.txt +328 -0
- data/libchdr/deps/lzma-19.00/lzma.vcxproj +543 -0
- data/libchdr/deps/lzma-19.00/lzma.vcxproj.filters +17 -0
- data/libchdr/deps/lzma-19.00/src/Alloc.c +455 -0
- data/libchdr/deps/lzma-19.00/src/Bra86.c +82 -0
- data/libchdr/deps/lzma-19.00/src/BraIA64.c +53 -0
- data/libchdr/deps/lzma-19.00/src/CpuArch.c +218 -0
- data/libchdr/deps/lzma-19.00/src/Delta.c +64 -0
- data/libchdr/deps/lzma-19.00/src/LzFind.c +1127 -0
- data/libchdr/deps/lzma-19.00/src/Lzma86Dec.c +54 -0
- data/libchdr/deps/lzma-19.00/src/LzmaDec.c +1185 -0
- data/libchdr/deps/lzma-19.00/src/LzmaEnc.c +1330 -0
- data/libchdr/deps/lzma-19.00/src/Sort.c +141 -0
- data/libchdr/deps/zlib-1.2.11/CMakeLists.txt +29 -0
- data/libchdr/deps/zlib-1.2.11/ChangeLog +1515 -0
- data/libchdr/deps/zlib-1.2.11/FAQ +368 -0
- data/libchdr/deps/zlib-1.2.11/INDEX +68 -0
- data/libchdr/deps/zlib-1.2.11/Makefile +5 -0
- data/libchdr/deps/zlib-1.2.11/Makefile.in +410 -0
- data/libchdr/deps/zlib-1.2.11/README +115 -0
- data/libchdr/deps/zlib-1.2.11/adler32.c +186 -0
- data/libchdr/deps/zlib-1.2.11/compress.c +86 -0
- data/libchdr/deps/zlib-1.2.11/configure +921 -0
- data/libchdr/deps/zlib-1.2.11/crc32.c +442 -0
- data/libchdr/deps/zlib-1.2.11/crc32.h +441 -0
- data/libchdr/deps/zlib-1.2.11/deflate.c +2163 -0
- data/libchdr/deps/zlib-1.2.11/deflate.h +349 -0
- data/libchdr/deps/zlib-1.2.11/doc/algorithm.txt +209 -0
- data/libchdr/deps/zlib-1.2.11/doc/rfc1950.txt +619 -0
- data/libchdr/deps/zlib-1.2.11/doc/rfc1951.txt +955 -0
- data/libchdr/deps/zlib-1.2.11/doc/rfc1952.txt +675 -0
- data/libchdr/deps/zlib-1.2.11/doc/txtvsbin.txt +107 -0
- data/libchdr/deps/zlib-1.2.11/gzclose.c +25 -0
- data/libchdr/deps/zlib-1.2.11/gzguts.h +218 -0
- data/libchdr/deps/zlib-1.2.11/gzlib.c +637 -0
- data/libchdr/deps/zlib-1.2.11/gzread.c +654 -0
- data/libchdr/deps/zlib-1.2.11/gzwrite.c +665 -0
- data/libchdr/deps/zlib-1.2.11/infback.c +640 -0
- data/libchdr/deps/zlib-1.2.11/inffast.c +323 -0
- data/libchdr/deps/zlib-1.2.11/inffast.h +11 -0
- data/libchdr/deps/zlib-1.2.11/inffixed.h +94 -0
- data/libchdr/deps/zlib-1.2.11/inflate.c +1561 -0
- data/libchdr/deps/zlib-1.2.11/inflate.h +125 -0
- data/libchdr/deps/zlib-1.2.11/inftrees.c +304 -0
- data/libchdr/deps/zlib-1.2.11/inftrees.h +62 -0
- data/libchdr/deps/zlib-1.2.11/make_vms.com +867 -0
- data/libchdr/deps/zlib-1.2.11/treebuild.xml +116 -0
- data/libchdr/deps/zlib-1.2.11/trees.c +1203 -0
- data/libchdr/deps/zlib-1.2.11/trees.h +128 -0
- data/libchdr/deps/zlib-1.2.11/uncompr.c +93 -0
- data/libchdr/deps/zlib-1.2.11/zconf.h +534 -0
- data/libchdr/deps/zlib-1.2.11/zconf.h.cmakein +536 -0
- data/libchdr/deps/zlib-1.2.11/zconf.h.in +534 -0
- data/libchdr/deps/zlib-1.2.11/zlib.3 +149 -0
- data/libchdr/deps/zlib-1.2.11/zlib.3.pdf +0 -0
- data/libchdr/deps/zlib-1.2.11/zlib.h +1912 -0
- data/libchdr/deps/zlib-1.2.11/zlib.map +94 -0
- data/libchdr/deps/zlib-1.2.11/zlib.pc.cmakein +13 -0
- data/libchdr/deps/zlib-1.2.11/zlib.pc.in +13 -0
- data/libchdr/deps/zlib-1.2.11/zlib2ansi +152 -0
- data/libchdr/deps/zlib-1.2.11/zutil.c +325 -0
- data/libchdr/deps/zlib-1.2.11/zutil.h +271 -0
- data/libchdr/include/dr_libs/dr_flac.h +12280 -0
- data/libchdr/include/libchdr/bitstream.h +43 -0
- data/libchdr/include/libchdr/cdrom.h +110 -0
- data/libchdr/include/libchdr/chd.h +427 -0
- data/libchdr/include/libchdr/chdconfig.h +10 -0
- data/libchdr/include/libchdr/coretypes.h +60 -0
- data/libchdr/include/libchdr/flac.h +50 -0
- data/libchdr/include/libchdr/huffman.h +90 -0
- data/libchdr/pkg-config.pc.in +10 -0
- data/libchdr/src/libchdr_bitstream.c +125 -0
- data/libchdr/src/libchdr_cdrom.c +415 -0
- data/libchdr/src/libchdr_chd.c +2744 -0
- data/libchdr/src/libchdr_flac.c +302 -0
- data/libchdr/src/libchdr_huffman.c +545 -0
- data/libchdr/src/link.T +5 -0
- data/libchdr/tests/CMakeLists.txt +2 -0
- data/libchdr/tests/benchmark.c +52 -0
- metadata +183 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
/* license:BSD-3-Clause
|
2
|
+
* copyright-holders:Aaron Giles
|
3
|
+
***************************************************************************
|
4
|
+
|
5
|
+
flac.h
|
6
|
+
|
7
|
+
FLAC compression wrappers
|
8
|
+
|
9
|
+
***************************************************************************/
|
10
|
+
|
11
|
+
#pragma once
|
12
|
+
|
13
|
+
#ifndef __FLAC_H__
|
14
|
+
#define __FLAC_H__
|
15
|
+
|
16
|
+
#include <stdint.h>
|
17
|
+
|
18
|
+
/***************************************************************************
|
19
|
+
* TYPE DEFINITIONS
|
20
|
+
***************************************************************************
|
21
|
+
*/
|
22
|
+
|
23
|
+
typedef struct _flac_decoder flac_decoder;
|
24
|
+
struct _flac_decoder {
|
25
|
+
/* output state */
|
26
|
+
void * decoder; /* actual encoder */
|
27
|
+
uint32_t sample_rate; /* decoded sample rate */
|
28
|
+
uint8_t channels; /* decoded number of channels */
|
29
|
+
uint8_t bits_per_sample; /* decoded bits per sample */
|
30
|
+
uint32_t compressed_offset; /* current offset in compressed data */
|
31
|
+
const uint8_t * compressed_start; /* start of compressed data */
|
32
|
+
uint32_t compressed_length; /* length of compressed data */
|
33
|
+
const uint8_t * compressed2_start; /* start of compressed data */
|
34
|
+
uint32_t compressed2_length; /* length of compressed data */
|
35
|
+
int16_t * uncompressed_start[8]; /* pointer to start of uncompressed data (up to 8 streams) */
|
36
|
+
uint32_t uncompressed_offset; /* current position in uncompressed data */
|
37
|
+
uint32_t uncompressed_length; /* length of uncompressed data */
|
38
|
+
int uncompressed_swap; /* swap uncompressed sample data */
|
39
|
+
uint8_t custom_header[0x2a]; /* custom header */
|
40
|
+
};
|
41
|
+
|
42
|
+
/* ======================> flac_decoder */
|
43
|
+
|
44
|
+
int flac_decoder_init(flac_decoder* decoder);
|
45
|
+
void flac_decoder_free(flac_decoder* decoder);
|
46
|
+
int flac_decoder_reset(flac_decoder* decoder, uint32_t sample_rate, uint8_t num_channels, uint32_t block_size, const void *buffer, uint32_t length);
|
47
|
+
int flac_decoder_decode_interleaved(flac_decoder* decoder, int16_t *samples, uint32_t num_samples, int swap_endian);
|
48
|
+
uint32_t flac_decoder_finish(flac_decoder* decoder);
|
49
|
+
|
50
|
+
#endif /* __FLAC_H__ */
|
@@ -0,0 +1,90 @@
|
|
1
|
+
/* license:BSD-3-Clause
|
2
|
+
* copyright-holders:Aaron Giles
|
3
|
+
***************************************************************************
|
4
|
+
|
5
|
+
huffman.h
|
6
|
+
|
7
|
+
Static Huffman compression and decompression helpers.
|
8
|
+
|
9
|
+
***************************************************************************/
|
10
|
+
|
11
|
+
#pragma once
|
12
|
+
|
13
|
+
#ifndef __HUFFMAN_H__
|
14
|
+
#define __HUFFMAN_H__
|
15
|
+
|
16
|
+
#include <libchdr/bitstream.h>
|
17
|
+
|
18
|
+
|
19
|
+
/***************************************************************************
|
20
|
+
* CONSTANTS
|
21
|
+
***************************************************************************
|
22
|
+
*/
|
23
|
+
|
24
|
+
enum huffman_error
|
25
|
+
{
|
26
|
+
HUFFERR_NONE = 0,
|
27
|
+
HUFFERR_TOO_MANY_BITS,
|
28
|
+
HUFFERR_INVALID_DATA,
|
29
|
+
HUFFERR_INPUT_BUFFER_TOO_SMALL,
|
30
|
+
HUFFERR_OUTPUT_BUFFER_TOO_SMALL,
|
31
|
+
HUFFERR_INTERNAL_INCONSISTENCY,
|
32
|
+
HUFFERR_TOO_MANY_CONTEXTS
|
33
|
+
};
|
34
|
+
|
35
|
+
/***************************************************************************
|
36
|
+
* TYPE DEFINITIONS
|
37
|
+
***************************************************************************
|
38
|
+
*/
|
39
|
+
|
40
|
+
typedef uint16_t lookup_value;
|
41
|
+
|
42
|
+
/* a node in the huffman tree */
|
43
|
+
struct node_t
|
44
|
+
{
|
45
|
+
struct node_t* parent; /* pointer to parent node */
|
46
|
+
uint32_t count; /* number of hits on this node */
|
47
|
+
uint32_t weight; /* assigned weight of this node */
|
48
|
+
uint32_t bits; /* bits used to encode the node */
|
49
|
+
uint8_t numbits; /* number of bits needed for this node */
|
50
|
+
};
|
51
|
+
|
52
|
+
/* ======================> huffman_context_base */
|
53
|
+
|
54
|
+
/* context class for decoding */
|
55
|
+
struct huffman_decoder
|
56
|
+
{
|
57
|
+
/* internal state */
|
58
|
+
uint32_t numcodes; /* number of total codes being processed */
|
59
|
+
uint8_t maxbits; /* maximum bits per code */
|
60
|
+
uint8_t prevdata; /* value of the previous data (for delta-RLE encoding) */
|
61
|
+
int rleremaining; /* number of RLE bytes remaining (for delta-RLE encoding) */
|
62
|
+
lookup_value * lookup; /* pointer to the lookup table */
|
63
|
+
struct node_t * huffnode; /* array of nodes */
|
64
|
+
uint32_t * datahisto; /* histogram of data values */
|
65
|
+
|
66
|
+
/* array versions of the info we need */
|
67
|
+
#if 0
|
68
|
+
node_t* huffnode_array; /* [_NumCodes]; */
|
69
|
+
lookup_value* lookup_array; /* [1 << _MaxBits]; */
|
70
|
+
#endif
|
71
|
+
};
|
72
|
+
|
73
|
+
/* ======================> huffman_decoder */
|
74
|
+
|
75
|
+
struct huffman_decoder* create_huffman_decoder(int numcodes, int maxbits);
|
76
|
+
void delete_huffman_decoder(struct huffman_decoder* decoder);
|
77
|
+
|
78
|
+
/* single item operations */
|
79
|
+
uint32_t huffman_decode_one(struct huffman_decoder* decoder, struct bitstream* bitbuf);
|
80
|
+
|
81
|
+
enum huffman_error huffman_import_tree_rle(struct huffman_decoder* decoder, struct bitstream* bitbuf);
|
82
|
+
enum huffman_error huffman_import_tree_huffman(struct huffman_decoder* decoder, struct bitstream* bitbuf);
|
83
|
+
|
84
|
+
int huffman_build_tree(struct huffman_decoder* decoder, uint32_t totaldata, uint32_t totalweight);
|
85
|
+
enum huffman_error huffman_assign_canonical_codes(struct huffman_decoder* decoder);
|
86
|
+
enum huffman_error huffman_compute_tree_from_histo(struct huffman_decoder* decoder);
|
87
|
+
|
88
|
+
void huffman_build_lookup_table(struct huffman_decoder* decoder);
|
89
|
+
|
90
|
+
#endif
|
@@ -0,0 +1,10 @@
|
|
1
|
+
prefix=@CMAKE_INSTALL_PREFIX@
|
2
|
+
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
3
|
+
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/libchdr
|
4
|
+
|
5
|
+
Name: libchdr
|
6
|
+
Description: Standalone library for reading MAME's CHDv1-v5 formats
|
7
|
+
Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@
|
8
|
+
Libs: -L${libdir} -lchdr @LIBS@
|
9
|
+
Cflags: -I${includedir}
|
10
|
+
|
@@ -0,0 +1,125 @@
|
|
1
|
+
/* license:BSD-3-Clause
|
2
|
+
* copyright-holders:Aaron Giles
|
3
|
+
***************************************************************************
|
4
|
+
|
5
|
+
bitstream.c
|
6
|
+
|
7
|
+
Helper classes for reading/writing at the bit level.
|
8
|
+
|
9
|
+
***************************************************************************/
|
10
|
+
|
11
|
+
#include <stdlib.h>
|
12
|
+
#include <libchdr/bitstream.h>
|
13
|
+
|
14
|
+
/***************************************************************************
|
15
|
+
* INLINE FUNCTIONS
|
16
|
+
***************************************************************************
|
17
|
+
*/
|
18
|
+
|
19
|
+
int bitstream_overflow(struct bitstream* bitstream) { return ((bitstream->doffset - bitstream->bits / 8) > bitstream->dlength); }
|
20
|
+
|
21
|
+
/*-------------------------------------------------
|
22
|
+
* create_bitstream - constructor
|
23
|
+
*-------------------------------------------------
|
24
|
+
*/
|
25
|
+
|
26
|
+
struct bitstream* create_bitstream(const void *src, uint32_t srclength)
|
27
|
+
{
|
28
|
+
struct bitstream* bitstream = (struct bitstream*)malloc(sizeof(struct bitstream));
|
29
|
+
bitstream->buffer = 0;
|
30
|
+
bitstream->bits = 0;
|
31
|
+
bitstream->read = (const uint8_t*)src;
|
32
|
+
bitstream->doffset = 0;
|
33
|
+
bitstream->dlength = srclength;
|
34
|
+
return bitstream;
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
/*-----------------------------------------------------
|
39
|
+
* bitstream_peek - fetch the requested number of bits
|
40
|
+
* but don't advance the input pointer
|
41
|
+
*-----------------------------------------------------
|
42
|
+
*/
|
43
|
+
|
44
|
+
uint32_t bitstream_peek(struct bitstream* bitstream, int numbits)
|
45
|
+
{
|
46
|
+
if (numbits == 0)
|
47
|
+
return 0;
|
48
|
+
|
49
|
+
/* fetch data if we need more */
|
50
|
+
if (numbits > bitstream->bits)
|
51
|
+
{
|
52
|
+
while (bitstream->bits <= 24)
|
53
|
+
{
|
54
|
+
if (bitstream->doffset < bitstream->dlength)
|
55
|
+
bitstream->buffer |= bitstream->read[bitstream->doffset] << (24 - bitstream->bits);
|
56
|
+
bitstream->doffset++;
|
57
|
+
bitstream->bits += 8;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
/* return the data */
|
62
|
+
return bitstream->buffer >> (32 - numbits);
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
/*-----------------------------------------------------
|
67
|
+
* bitstream_remove - advance the input pointer by the
|
68
|
+
* specified number of bits
|
69
|
+
*-----------------------------------------------------
|
70
|
+
*/
|
71
|
+
|
72
|
+
void bitstream_remove(struct bitstream* bitstream, int numbits)
|
73
|
+
{
|
74
|
+
bitstream->buffer <<= numbits;
|
75
|
+
bitstream->bits -= numbits;
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
/*-----------------------------------------------------
|
80
|
+
* bitstream_read - fetch the requested number of bits
|
81
|
+
*-----------------------------------------------------
|
82
|
+
*/
|
83
|
+
|
84
|
+
uint32_t bitstream_read(struct bitstream* bitstream, int numbits)
|
85
|
+
{
|
86
|
+
uint32_t result = bitstream_peek(bitstream, numbits);
|
87
|
+
bitstream_remove(bitstream, numbits);
|
88
|
+
return result;
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
/*-------------------------------------------------
|
93
|
+
* read_offset - return the current read offset
|
94
|
+
*-------------------------------------------------
|
95
|
+
*/
|
96
|
+
|
97
|
+
uint32_t bitstream_read_offset(struct bitstream* bitstream)
|
98
|
+
{
|
99
|
+
uint32_t result = bitstream->doffset;
|
100
|
+
int bits = bitstream->bits;
|
101
|
+
while (bits >= 8)
|
102
|
+
{
|
103
|
+
result--;
|
104
|
+
bits -= 8;
|
105
|
+
}
|
106
|
+
return result;
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
/*-------------------------------------------------
|
111
|
+
* flush - flush to the nearest byte
|
112
|
+
*-------------------------------------------------
|
113
|
+
*/
|
114
|
+
|
115
|
+
uint32_t bitstream_flush(struct bitstream* bitstream)
|
116
|
+
{
|
117
|
+
while (bitstream->bits >= 8)
|
118
|
+
{
|
119
|
+
bitstream->doffset--;
|
120
|
+
bitstream->bits -= 8;
|
121
|
+
}
|
122
|
+
bitstream->bits = bitstream->buffer = 0;
|
123
|
+
return bitstream->doffset;
|
124
|
+
}
|
125
|
+
|