1 /*
2  * ALAC (Apple Lossless Audio Codec) decoder
3  * Copyright (c) 2005 David Hammerton
4  * All rights reserved.
5  *
6  * This is the actual decoder.
7  *
8  * http://crazney.net/programs/itunes/alac.html
9  *
10  * Permission is hereby granted, free of charge, to any person
11  * obtaining a copy of this software and associated documentation
12  * files (the "Software"), to deal in the Software without
13  * restriction, including without limitation the rights to use,
14  * copy, modify, merge, publish, distribute, sublicense, and/or
15  * sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  *
30  */
31 
32 #ifndef __ALAC__DECOMP_H
33 #define __ALAC__DECOMP_H
34 
35 #include <stdint.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 
42 typedef struct alac_file alac_file;
43 
44 alac_file *create_alac(int samplesize, int numchannels);
45 void dispose_alac(alac_file* alac);
46 void decode_frame(alac_file *alac,
47                   unsigned char *inbuffer,
48                   void *outbuffer, int *outputsize);
49 void alac_set_info(alac_file *alac, char *inputbuffer);
50 
51 struct alac_file
52 {
53     unsigned char *input_buffer;
54     int input_buffer_bitaccumulator; /* used so we can do arbitary
55                                       bit reads */
56 
57     int samplesize;
58     int numchannels;
59     int bytespersample;
60 
61     /* buffers */
62     int32_t *predicterror_buffer_a;
63     int32_t *predicterror_buffer_b;
64 
65     int32_t *outputsamples_buffer_a;
66     int32_t *outputsamples_buffer_b;
67 
68 	  int32_t *uncompressed_bytes_buffer_a;
69 	  int32_t *uncompressed_bytes_buffer_b;
70 
71     /* stuff from setinfo */
72     uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */    /* max samples per frame? */
73     uint8_t setinfo_7a; /* 0x00 */
74     uint8_t setinfo_sample_size; /* 0x10 */
75     uint8_t setinfo_rice_historymult; /* 0x28 */
76     uint8_t setinfo_rice_initialhistory; /* 0x0a */
77     uint8_t setinfo_rice_kmodifier; /* 0x0e */
78     uint8_t setinfo_7f; /* 0x02 */
79     uint16_t setinfo_80; /* 0x00ff */
80     uint32_t setinfo_82; /* 0x000020e7 */ /* max sample size?? */
81     uint32_t setinfo_86; /* 0x00069fe4 */ /* bit rate (avarge)?? */
82     uint32_t setinfo_8a_rate; /* 0x0000ac44 */
83     /* end setinfo stuff */
84 
85 };
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif /* __ALAC__DECOMP_H */
92 
93