|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Telephony Multimedia Service |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __AMRCODEC_H__ |
|
20 #define __AMRCODEC_H__ |
|
21 |
|
22 // INCLUDES |
|
23 |
|
24 #include <E32Base.h> |
|
25 |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 |
|
29 class CAmrToPcmDecoderImpl; |
|
30 class CPcmToAmrEncoderImpl; |
|
31 |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 /** |
|
36 * TAmrDecParams |
|
37 * AMR decoding parameters. |
|
38 */ |
|
39 class TAmrDecParams |
|
40 { |
|
41 public: |
|
42 /** |
|
43 * Default constructor. |
|
44 */ |
|
45 inline TAmrDecParams(); |
|
46 public: |
|
47 // error concealment level (0 none, 1 default) |
|
48 TInt iConcealment; |
|
49 }; |
|
50 |
|
51 TAmrDecParams::TAmrDecParams() : |
|
52 iConcealment(1) {} |
|
53 |
|
54 /** |
|
55 * TAmrEncParams |
|
56 * AMR encoding parameters. |
|
57 */ |
|
58 class TAmrEncParams |
|
59 { |
|
60 public: |
|
61 /** |
|
62 * Default constructor. |
|
63 */ |
|
64 inline TAmrEncParams(); |
|
65 public: |
|
66 // encoding mode 0-7 (0=MR475,1=MR515,...,7=MR122, default 7) |
|
67 TInt iMode; |
|
68 // DTX flag (TRUE or default FALSE) |
|
69 TInt iDTX; |
|
70 }; |
|
71 |
|
72 TAmrEncParams::TAmrEncParams() : |
|
73 iMode(7), iDTX(0) {} |
|
74 |
|
75 |
|
76 // CLASS DEFINITIONS |
|
77 |
|
78 /** |
|
79 * TAmrFrameInfo |
|
80 * AMR frame info struct. |
|
81 */ |
|
82 class TAmrFrameInfo |
|
83 { |
|
84 public: |
|
85 /** |
|
86 * Default constructor. |
|
87 */ |
|
88 TAmrFrameInfo() {}; |
|
89 public: |
|
90 /** |
|
91 * Returns the size of smallest AMR audio frame, i.e., the size of one DTX |
|
92 * frame. NO DATA frames (size 1 byte) are not taken into account here. |
|
93 * |
|
94 * @since ?Series60_version |
|
95 * @param none |
|
96 * @return TInt |
|
97 */ |
|
98 IMPORT_C static TInt MinFrameSize(); |
|
99 |
|
100 /** |
|
101 * Returns the size of biggest AMR audio frame, i.e., the size of one EFR |
|
102 * frame. |
|
103 * |
|
104 * @since ?Series60_version |
|
105 * @param none |
|
106 * @return TInt |
|
107 */ |
|
108 IMPORT_C static TInt MaxFrameSize(); |
|
109 |
|
110 /** |
|
111 * Returns the maximum number of samples per one audio channel in one |
|
112 * AMR audio frame. |
|
113 * |
|
114 * @since ?Series60_version |
|
115 * @param none |
|
116 * @return TInt |
|
117 */ |
|
118 IMPORT_C static TInt MaxFrameSamples(); |
|
119 |
|
120 /** |
|
121 * Returns the maximum number audio channels in one frame. |
|
122 * |
|
123 * @since ?Series60_version |
|
124 * @param none |
|
125 * @return TInt |
|
126 */ |
|
127 IMPORT_C static TInt MaxChannels(); |
|
128 |
|
129 /** |
|
130 * Returns the size of one AMR frame header. The header must include |
|
131 * all bits needed for determining the actual frame length. |
|
132 * |
|
133 * @since ?Series60_version |
|
134 * @param none |
|
135 * @return TInt Size of AMR frame header |
|
136 */ |
|
137 IMPORT_C static TInt FrameHeaderSize(); |
|
138 |
|
139 /** |
|
140 * Returns the size of frame described by given coding parameters. The only |
|
141 * parameter used in calculation is the coding mode (iMode). |
|
142 * |
|
143 * @since ?Series60_version |
|
144 * @param none |
|
145 * @return TInt AMR frame size |
|
146 */ |
|
147 IMPORT_C static TInt FrameSize(const TAmrFrameInfo& aInfo); |
|
148 public: |
|
149 TInt iMode; // encoding mode |
|
150 TInt iBitrate; // bitrate (kbit/s) |
|
151 TInt iSamplingRate; // sampling frequency (Hz) |
|
152 TInt iChannels; // number of channels |
|
153 TInt iFrameSize; // encoded size (bytes) |
|
154 TInt iFrameSamples; // decoded size (samples per channel) |
|
155 public: |
|
156 TInt iSamplingRateOut; // sampling frequency after conversion (Hz) |
|
157 TInt iChannelsOut; // number of audio channels after conversion (1 or 2) |
|
158 TInt iFrameSamplesOut; // decoded size after conversion (samples per channel) |
|
159 }; |
|
160 |
|
161 /** |
|
162 * CAmrToPcmDecoder |
|
163 * Low level AMR decoding API. |
|
164 */ |
|
165 class CAmrToPcmDecoder : public CBase |
|
166 { |
|
167 protected: |
|
168 /** |
|
169 * Default constructor. |
|
170 */ |
|
171 IMPORT_C CAmrToPcmDecoder(); |
|
172 |
|
173 /** |
|
174 * 2nd phase constructor. Constructs the decoder. |
|
175 */ |
|
176 IMPORT_C void ConstructL(); |
|
177 public: |
|
178 /** |
|
179 * Two-phased constructor. First allocates and constructs decoder |
|
180 * and then resets it according to the given configuration. |
|
181 * |
|
182 * @since ?Series60_version |
|
183 * @param aConf Decoder configuration params |
|
184 * @return CAmrToPcmDecoder* Pointer to constructed decoder |
|
185 */ |
|
186 IMPORT_C static CAmrToPcmDecoder* NewL(const TAmrDecParams& aConf); |
|
187 |
|
188 /** |
|
189 * Destructor |
|
190 */ |
|
191 IMPORT_C virtual ~CAmrToPcmDecoder(); |
|
192 |
|
193 /** |
|
194 * Initializes decoder and resets it into the default decoding state. |
|
195 * |
|
196 * @since ?Series60_version |
|
197 * @param none |
|
198 * @return void |
|
199 */ |
|
200 IMPORT_C void Reset(); |
|
201 |
|
202 /** |
|
203 * Initializes decoder and resets it according to the given configuration. |
|
204 * |
|
205 * @since ?Series60_version |
|
206 * @param aConf Decoder configuration params |
|
207 * @return void |
|
208 */ |
|
209 IMPORT_C void Reset(const TAmrDecParams& aConf); |
|
210 |
|
211 /** |
|
212 * Calculates the frame size and returns information about the frame which |
|
213 * starts from the beginning of aBuf. Returns 0, if the frame bit syntax is |
|
214 * incorrect or not enough bits are available for calculating the frame size |
|
215 * and the frame parameters (aBufLen < TAmrCodecParams::FrameHeaderSize). |
|
216 * |
|
217 * The frame parameters returned via aInfo are: mode, sampling frequency, |
|
218 * number of channels, frame size (same as return value) and number of |
|
219 * samples in this frame. See also TMdaRawAmrAudioCodec class. |
|
220 * |
|
221 * @since ?Series60_version |
|
222 * @param aBuf Pointer to frame buffer |
|
223 * @param aBufLen Length of frame buffer |
|
224 * @param aInfo Reference to frame parameters |
|
225 * @return TInt Length of frame in bytes |
|
226 */ |
|
227 IMPORT_C static TInt FrameInfo(const TUint8* aBuf, TInt aBufLen, TAmrFrameInfo& aInfo); |
|
228 |
|
229 /** |
|
230 * A variation of the FrameInfo above, which takes into account the |
|
231 * decoding switches in calculating iSampligRateOut, iChannelsOut |
|
232 * and iFrameSamplesOut.Initializes decoder and resets it according |
|
233 * to the given configuration. |
|
234 * |
|
235 * @since ?Series60_version |
|
236 * @param aBuf Pointer to frame buffer |
|
237 * @param aBufLen Length of frame buffer |
|
238 * @param aInfo Reference to fram parameters |
|
239 * @param aConf Reference to decoding switches |
|
240 * @return TInt Length of frame in bytes |
|
241 */ |
|
242 IMPORT_C static TInt FrameInfo(const TUint8* aBuf, TInt aBufLen, TAmrFrameInfo& aInfo, const TAmrDecParams& aConf); |
|
243 |
|
244 /** |
|
245 * This routine seeks the start position of the next frame and returns |
|
246 * the byte position of its header. Returns aBufLen, if no valid frame |
|
247 * can not be found (see FrameInfo). The seek progresses from the start |
|
248 * of aBuf (0) toward the end of aBuf(aBufLen - 1). |
|
249 * |
|
250 * The level of syntax check depends on the number of bits available. At |
|
251 * minimum the first frame header bits are checked only, but if more |
|
252 * bits are available, they can be used to make the sync seek more robust. |
|
253 * For succesful seek the whole frame does not need to exist in aBuf. |
|
254 * |
|
255 * @since ?Series60_version |
|
256 * @param aBuf Pointer to frame buffer |
|
257 * @param aBufLen Length of frame buffer |
|
258 * @return TInt Frame position or aBufLen |
|
259 */ |
|
260 IMPORT_C static TInt SeekSync(const TUint8* aBuf, TInt aBufLen); |
|
261 |
|
262 /** |
|
263 * Decodes one frame. |
|
264 * |
|
265 * @since ?Series60_version |
|
266 * @param aSrc Pointer to bit stream buffer |
|
267 * @param aSrcUsed Number of consumed bytes |
|
268 * @param aDst Pointer to PCM buffer |
|
269 * @param aDstLen Number of produced bytes |
|
270 * @param aMuteFlag If ETrue this frame is muted |
|
271 * @return TInt Non-zero if decoding failed |
|
272 */ |
|
273 IMPORT_C TInt Decode(TUint8* aSrc, TInt& aSrcUsed, TUint8* aDst, TInt& aDstLen, TBool aMuteFlag); |
|
274 |
|
275 /** |
|
276 * Decodes one frame from aSrc to aDst1 and aDst2. NOTE: aDst1 or |
|
277 * aDst2 can be NULL and in that case decoding to that buffer is not |
|
278 * requested. |
|
279 * |
|
280 * @since ?Series60_version |
|
281 * @param aSrc Pointer to bit stream buffer |
|
282 * @param aSrcUsed Number of consumed bytes |
|
283 * @param aDst1 Pointer to PCM sample buffer (time domain sample) |
|
284 * @param aDst2 Pointer to frequency sample buffer (frequency domain sample) |
|
285 * @param aDstLen1 Number of produced bytes in aDst1 |
|
286 * @param aDstLen2 Number of produced bytes in aDst2 |
|
287 * @param aMuteFlag If ETrue this frame is muted |
|
288 * @return TInt Non-zero if decoding failed |
|
289 */ |
|
290 IMPORT_C TInt Decode(TUint8* aSrc, TInt& aSrcUsed, TUint8* aDst1, TUint8* aDst2, TInt& aDstLen1, TInt& aDstLen2, TInt aMuteFlag); |
|
291 private: |
|
292 CAmrToPcmDecoderImpl* iState; |
|
293 }; |
|
294 |
|
295 /** |
|
296 * CPcmToAmrEncoder |
|
297 * Low level AMR encoding API. |
|
298 */ |
|
299 class CPcmToAmrEncoder : public CBase |
|
300 { |
|
301 protected: |
|
302 |
|
303 /** |
|
304 * Default constructor. |
|
305 */ |
|
306 IMPORT_C CPcmToAmrEncoder(); |
|
307 |
|
308 /** |
|
309 * 2nd phase constructor. Constructs the encoder. |
|
310 */ |
|
311 IMPORT_C void ConstructL(); |
|
312 public: |
|
313 |
|
314 /** |
|
315 * Two-phased constructor. First allocates and constructs encoder |
|
316 * and then resets it according to the given configuration. |
|
317 * |
|
318 * @since ?Series60_version |
|
319 * @param aConf Encoder configuration params |
|
320 * @return CPcmToAmrEncoder* Pointer to constructed encoder |
|
321 */ |
|
322 IMPORT_C static CPcmToAmrEncoder* NewL(const TAmrEncParams& aConf); |
|
323 |
|
324 /** |
|
325 * Destructor |
|
326 */ |
|
327 IMPORT_C virtual ~CPcmToAmrEncoder(); |
|
328 |
|
329 /** |
|
330 * Initializes encoder and resets encoder state. |
|
331 * |
|
332 * @since ?Series60_version |
|
333 * @param none |
|
334 * @return void |
|
335 */ |
|
336 IMPORT_C void Reset(); |
|
337 |
|
338 /** |
|
339 * Initializes encoder and resets it according to the given configuration. |
|
340 * |
|
341 * @since ?Series60_version |
|
342 * @param aConf Encoder configuration params |
|
343 * @return void |
|
344 */ |
|
345 IMPORT_C void Reset(const TAmrEncParams& aConf); |
|
346 |
|
347 /** |
|
348 * Encodes one frame. |
|
349 * |
|
350 * @since ?Series60_version |
|
351 * @param aSrc Pointer to PCM buffer |
|
352 * @param aSrcUsed Number of consumed bytes |
|
353 * @param aDst Pointer to bit stream buffer |
|
354 * @param aDstLen Length of resulting frame |
|
355 * @return TInt Non-zero if encoding failed |
|
356 */ |
|
357 IMPORT_C TInt Encode(TUint8* aSrc, TInt& aSrcUsed, TUint8* aDst, TInt& aDstLen); |
|
358 private: |
|
359 CPcmToAmrEncoderImpl* iState; |
|
360 }; |
|
361 |
|
362 #endif //__AMRCODEC_H__ |
|
363 |
|
364 // End of File |