/
mp3dec.h
executable file
·207 lines (188 loc) · 6.27 KB
/
mp3dec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file, are
* subject to the current version of the RealNetworks Public Source License
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
* in which case the RCSL will apply. You may also obtain the license terms
* directly from RealNetworks. You may not use this file except in
* compliance with the RPSL or, if you have a valid RCSL with RealNetworks
* applicable to this file, the RCSL. Please see the applicable RPSL or
* RCSL for the rights, obligations and limitations governing use of the
* contents of the file.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the portions
* it created.
*
* This file, and the files included with this file, is distributed and made
* available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
/**************************************************************************************
* Fixed-point MP3 decoder
* Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com)
* June 2003
*
* mp3dec.h - public C API for MP3 decoder
**************************************************************************************/
#ifndef _MP3DEC_H
#define _MP3DEC_H
#if defined(_WIN32) && !defined(_WIN32_WCE)
#
#elif defined(_WIN32) && defined(_WIN32_WCE) && defined(ARM)
#
#elif defined(_WIN32) && defined(WINCE_EMULATOR)
#
#elif defined(ARM_ADS)
#
#elif defined(_SYMBIAN) && defined(__WINS__) /* Symbian emulator for Ix86 */
#
#elif defined(__GNUC__) && defined(ARM)
#
#elif defined(__GNUC__) && defined(MIPS)
#
#elif defined(__GNUC__) && defined(__i386__)
#
#elif defined(_OPENWAVE_SIMULATOR) || defined(_OPENWAVE_ARMULATOR)
#
#elif defined(__GNUC__)
#else
#error No platform defined. See valid options in mp3dec.h
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* determining MAINBUF_SIZE:
* max mainDataBegin = (2^9 - 1) bytes (since 9-bit offset) = 511
* max nSlots (concatenated with mainDataBegin bytes from before) = 1440 - 9 - 4 + 1 = 1428
* 511 + 1428 = 1939, round up to 1940 (4-byte align)
*/
#define MAINBUF_SIZE 1940
#define MAX_NGRAN 2 /* max granules */
#define MAX_NCHAN 2 /* max channels */
#define MAX_NSAMP 576 /* max samples per channel, per granule */
/* map to 0,1,2 to make table indexing easier */
typedef enum {
MPEG1 = 0,
MPEG2 = 1,
MPEG25 = 2
} MPEGVersion;
typedef void *HMP3Decoder;
typedef enum {
ERR_MP3_NONE = 0,
ERR_MP3_INDATA_UNDERFLOW = -1,
ERR_MP3_MAINDATA_UNDERFLOW = -2,
ERR_MP3_FREE_BITRATE_SYNC = -3,
ERR_MP3_OUT_OF_MEMORY = -4,
ERR_MP3_NULL_POINTER = -5,
ERR_MP3_INVALID_FRAMEHEADER = -6,
ERR_MP3_INVALID_SIDEINFO = -7,
ERR_MP3_INVALID_SCALEFACT = -8,
ERR_MP3_INVALID_HUFFCODES = -9,
ERR_MP3_INVALID_DEQUANTIZE = -10,
ERR_MP3_INVALID_IMDCT = -11,
ERR_MP3_INVALID_SUBBAND = -12,
ERR_UNKNOWN = -9999
} err_mp3_t;
typedef struct _MP3FrameInfo {
int bitrate;
int nChans;
int samprate;
int bitsPerSample;
int outputSamps;
int layer;
int version;
} MP3FrameInfo;
/* public API */
/**
* @brief Init the decoder of MP3
*
* This API init the mp3 decoder module:
* - allocate memory for platform-specific data
* - clear all the user-accessible fields
*
* @param None
*
* @return None
*
*/
HMP3Decoder MP3InitDecoder(void);
/**
* @brief Free the decoder of MP3
*
* This API free the mp3 decoder module:
* - free platform-specific data allocated by InitMP3Decoder
* - zero out the contents of MP3DecInfo struct
*
* @param HMP3Decoder valid MP3 decoder instance pointer
*
* @return None
*
*/
void MP3FreeDecoder(HMP3Decoder hMP3Decoder);
/**
* @brief Decode one frame of MP3 data
*
* @param hMP3Decoder valid MP3 decoder instance pointer
* @param inbuf double pointer to buffer of MP3 data (containing headers + mainData)
* @param bytesLeft number of valid bytes remaining in inbuf
* @param outbuf pointer to outbuf, big enough to hold one frame of decoded PCM samples
* @param useSize flag indicating whether MP3 data is normal MPEG format (useSize = 0) or reformatted as "self-contained" frames (useSize = 1)
*
* @return error code, defined in mp3dec.h (0 means no error, < 0 means error)
*
*/
int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, short *outbuf, int useSize);
/**
* @brief Get info about last MP3 frame decoded
*
* This API get the info about last mp3 decoded:
* - number of sampled decoded, sample rate, bitrate, etc.
*
* @param hMP3Decoder valid MP3 decoder instance pointer
* @param mp3FrameInfo pointer to MP3FrameInfo struct
*
* @return None
*
*/
void MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo);
/**
* @brief Parse MP3 frame header
*
* @param hMP3Decoder valid MP3 decoder instance pointer
* @param mp3FrameInfo pointer to MP3FrameInfo struct
* @param buf pointer to buffer containing valid MP3 frame header
*
* @return error code, defined in mp3dec.h (0 means no error, < 0 means error)
*
*/
int MP3GetNextFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo, unsigned char *buf);
/**
* @brief locate the next byte-alinged sync word in the raw mp3 stream
*
* @param buf buffer to search for sync word
* @param nBytes max number of bytes to search in buffer
*
* @return
* - offset to first sync word (bytes from start of buf)
* - -1 if sync not found after searching nBytes
*/
int MP3FindSyncWord(unsigned char *buf, int nBytes);
#ifdef __cplusplus
}
#endif
#endif /* _MP3DEC_H */