1 /*
2 Copyright (c) 2005-2009, The Musepack Development Team
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the The Musepack Development Team nor the
18 names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior
20 written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 /// \file internal.h
35 /// Definitions and structures used only internally by the libmpcdec.
36 #ifndef _MPCDEC_INTERNAL_H_
37 #define _MPCDEC_INTERNAL_H_
38 #ifdef WIN32
39 #pragma once
40 #endif
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 #include <mpc/mpcdec.h>
46
47 /// Big/little endian 32 bit byte swapping routine.
48 static mpc_inline
mpc_swap32(mpc_uint32_t val)49 mpc_uint32_t mpc_swap32(mpc_uint32_t val) {
50 return (((val & 0xFF000000) >> 24) | ((val & 0x00FF0000) >> 8)
51 | ((val & 0x0000FF00) << 8) | ((val & 0x000000FF) << 24));
52 }
53
54 typedef struct mpc_block_t {
55 char key[2]; // block key
56 mpc_uint64_t size; // block size minus the block header size
57 } mpc_block;
58
59 #define MAX_FRAME_SIZE 4352
60 #define DEMUX_BUFFER_SIZE (65536 - MAX_FRAME_SIZE) // need some space as sand box
61
62 struct mpc_demux_t {
63 mpc_reader * r;
64 mpc_decoder * d;
65 mpc_streaminfo si;
66
67 // buffer
68 mpc_uint8_t buffer[DEMUX_BUFFER_SIZE + MAX_FRAME_SIZE];
69 mpc_size_t bytes_total;
70 mpc_bits_reader bits_reader;
71 mpc_int32_t block_bits; /// bits remaining in current audio block
72 mpc_uint_t block_frames; /// frames remaining in current audio block
73
74 // seeking
75 mpc_seek_t * seek_table;
76 mpc_uint_t seek_pwr; /// distance between 2 frames in seek_table = 2^seek_pwr
77 mpc_uint32_t seek_table_size; /// used size in seek_table
78
79 // chapters
80 mpc_seek_t chap_pos; /// supposed position of the first chapter block
81 mpc_int_t chap_nb; /// number of chapters (-1 if unknown, 0 if no chapter)
82 mpc_chap_info * chap; /// chapters position and tag
83
84 };
85
86 /**
87 * checks if a block key is valid
88 * @param key the two caracters key to check
89 * @return MPC_STATUS_FAIL if the key is invalid, MPC_STATUS_OK else
90 */
mpc_check_key(char * key)91 static mpc_inline mpc_status mpc_check_key(char * key)
92 {
93 if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90)
94 return MPC_STATUS_FAIL;
95 return MPC_STATUS_OK;
96 }
97
98 /// helper functions used by multiple files
99 mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c
100 void mpc_decoder_init_quant(mpc_decoder *d, double scale_factor);
101 void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData, mpc_int_t channels);
102
103 #define MPC_IS_FAILURE(X) ((int)(X) < (int)MPC_STATUS_OK)
104 #define MPC_AUTO_FAIL(X) { mpc_status s = (X); if (MPC_IS_FAILURE(s)) return s; }
105
106
107 #ifdef __cplusplus
108 }
109 #endif
110 #endif
111