1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007  Josh Coalson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * - Neither the name of the Xiph.org Foundation nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Alexandru Munteanu's note : copied from libflac and modified
32  * File part of the libmp3splt flac plugin.
33  *
34  * Copyright (c) 2014 Alexandru Munteanu - <m@ioalex.net>
35  *
36  * http://mp3splt.sourceforge.net
37  */
38 
39 /**********************************************************
40  *
41  * Libmp3splt license:
42  *
43  * This program is free software; you can redistribute it and/or
44  * modify it under the terms of the GNU General Public License
45  * as published by the Free Software Foundation; either version 2
46  * of the License, or (at your option) any later version.
47  *
48  * This program is distributed in the hope that it will be useful,
49  * but WITHOUT ANY WARRANTY; without even the implied warranty of
50  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51  * GNU General Public License for more details.
52  *
53  * You should have received a copy of the GNU General Public License
54  * along with this program; if not, write to the Free Software
55  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
56  * USA.
57  *
58  *********************************************************/
59 
60 #ifndef MP3SPLT_FROM_FLAC_LIBRARY_H
61 
62 #define SPLT_FLAC_STREAMINFO_LENGTH 34
63 
64 extern unsigned splt_flac_l_crc16_table[256];
65 extern unsigned char const splt_flac_l_crc8_table[256];
66 
67 #define SPLT_FLAC_UPDATE_CRC16(crc16, data) crc16 = ((crc16<<8) ^ splt_flac_l_crc16_table[(crc16>>8) ^ data]) & 0xffff
68 #define SPLT_FLAC_UPDATE_CRC8(crc8, data) crc8 = splt_flac_l_crc8_table[crc8 ^ data]
69 
70 uint32_t splt_flac_l_read_utf8_uint32(void *flac_frame_reader, splt_code *error,
71     unsigned char *number_of_bytes);
72 uint64_t splt_flac_l_read_utf8_uint64(void *flac_frame_reader, splt_code *error,
73     unsigned char *number_of_bytes);
74 
75 void splt_flac_l_convert_to_streaminfo(FLAC__StreamMetadata_StreamInfo *block, unsigned char *bytes);
76 unsigned char *splt_flac_l_convert_from_streaminfo(FLAC__StreamMetadata_StreamInfo *block);
77 FLAC__uint32 splt_flac_l_unpack_uint32(FLAC__byte *b, unsigned bytes);
78 void splt_flac_l_pack_uint32(FLAC__uint32 val, FLAC__byte *b, unsigned bytes);
79 FLAC__uint32 splt_flac_l_unpack_uint32_little_endian(FLAC__byte *b, unsigned bytes);
80 void splt_flac_l_pack_uint32_little_endian(FLAC__uint32 val, FLAC__byte *b, unsigned bytes);
81 
82 unsigned char *splt_flac_l_convert_to_utf8(FLAC__uint64 val, unsigned char *utf8_used_bytes);
83 
84 static const unsigned char splt_flac_l_byte_to_unary_table[] = {
85   8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
86   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
87   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
88   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
89   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
90   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
91   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
92   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
93   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
101 };
102 
103 #define MP3SPLT_FROM_FLAC_LIBRARY_H
104 
105 #endif
106 
107