1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "ProcAWBFrameHandler.h" |
|
23 #include "ProcFrameHandler.h" |
|
24 #include "ProcTools.h" |
|
25 #include "q_gain2.h" |
|
26 #include "AWBConstants.h" |
|
27 |
|
28 #include <f32file.h> |
|
29 #include <e32math.h> |
|
30 |
|
31 |
|
32 TBool CProcAWBFrameHandler::ManipulateGainL(const HBufC8* aFrameIn, HBufC8*& aFrameOut, TInt8 aGain) |
|
33 { |
|
34 |
|
35 aFrameOut = HBufC8::NewLC(aFrameIn->Size()); |
|
36 aFrameOut->Des().Copy(aFrameIn->Ptr(), aFrameIn->Size()); |
|
37 |
|
38 aGain = static_cast<TInt8>(aGain/2); |
|
39 |
|
40 const TUint8 modeByte = (*aFrameOut)[0]; |
|
41 |
|
42 TUint8 toc = modeByte; |
|
43 TUint8 mode = static_cast<TUint8>((toc >> 3) & 0x0F); |
|
44 |
|
45 TInt bitrate = KAWBBitRates[mode]; |
|
46 |
|
47 RArray<TInt> gains; |
|
48 CleanupClosePushL(gains); |
|
49 TInt maxGain = 0; |
|
50 GetAWBGainsL(aFrameOut, gains, maxGain); |
|
51 |
|
52 TInt gamma10000 = KAwbGain_dB2Gamma[aGain+127]; |
|
53 |
|
54 TInt a = 0; |
|
55 TInt old_gain = 0; |
|
56 TInt old_pitch = 0; |
|
57 TInt new_gain = 0; |
|
58 TInt8 new_index = 0; |
|
59 TInt bitRateIndex = -1; |
|
60 |
|
61 switch (bitrate) |
|
62 { |
|
63 |
|
64 case 23850: |
|
65 case 23050: |
|
66 case 19850: |
|
67 case 18250: |
|
68 case 15850: |
|
69 case 14250: |
|
70 case 12650: |
|
71 { |
|
72 |
|
73 for (a = 0; a < gains.Count()-1 ; a+=2) |
|
74 { |
|
75 |
|
76 old_gain = gains[a+1]; |
|
77 new_gain = static_cast<TInt>((gamma10000*old_gain)/10000); |
|
78 old_pitch = gains[a]; |
|
79 |
|
80 new_index = ProcTools::FindNewIndexVQ2(new_gain, old_pitch, |
|
81 t_qua_gain7b, |
|
82 2*128); |
|
83 |
|
84 |
|
85 bitRateIndex = ProcTools::FindIndex(bitrate, KAWBBitRates, 9); |
|
86 |
|
87 |
|
88 if (a == 0) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
89 aFrameOut, |
|
90 bitrate, |
|
91 KGainPositions[bitRateIndex*4], 7); |
|
92 else if (a == 2) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
93 aFrameOut, |
|
94 bitrate, |
|
95 KGainPositions[bitRateIndex*4+1], 7); |
|
96 else if (a == 4) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
97 aFrameOut, |
|
98 bitrate, |
|
99 KGainPositions[bitRateIndex*4+2], 7); |
|
100 else if (a == 6) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
101 aFrameOut, |
|
102 bitrate, |
|
103 KGainPositions[bitRateIndex*4+3], 7); |
|
104 |
|
105 } |
|
106 |
|
107 |
|
108 |
|
109 break; |
|
110 } |
|
111 |
|
112 case 8850: |
|
113 case 6600: |
|
114 { |
|
115 for (a = 0; a < gains.Count()-1 ; a+=2) |
|
116 { |
|
117 |
|
118 old_gain = gains[a+1]; |
|
119 new_gain = static_cast<TInt>((gamma10000*old_gain)/10000); |
|
120 old_pitch = gains[a]; |
|
121 |
|
122 new_index = ProcTools::FindNewIndexVQ2(new_gain, old_pitch, |
|
123 t_qua_gain6b, |
|
124 2*64); |
|
125 |
|
126 bitRateIndex = ProcTools::FindIndex(bitrate, KAWBBitRates, 9); |
|
127 |
|
128 |
|
129 if (a == 0) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
130 aFrameOut, |
|
131 bitrate, |
|
132 KGainPositions[bitRateIndex*4], 6); |
|
133 else if (a == 2) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
134 aFrameOut, |
|
135 bitrate, |
|
136 KGainPositions[bitRateIndex*4+1], 6); |
|
137 else if (a == 4) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
138 aFrameOut, |
|
139 bitrate, |
|
140 KGainPositions[bitRateIndex*4+2], 6); |
|
141 else if (a == 6) ProcTools::SetValueToShuffledAWBFrame(new_index, |
|
142 aFrameOut, |
|
143 bitrate, |
|
144 KGainPositions[bitRateIndex*4+3], 6); |
|
145 } |
|
146 |
|
147 break; |
|
148 } |
|
149 } |
|
150 |
|
151 CleanupStack::PopAndDestroy(&gains); |
|
152 CleanupStack::Pop(); // aFrameOut |
|
153 return ETrue; |
|
154 } |
|
155 |
|
156 TBool CProcAWBFrameHandler::GetGainL(const HBufC8* aFrame, RArray<TInt>& aGains, TInt& aMaxGain) const |
|
157 { |
|
158 |
|
159 RArray<TInt> AWBGains; |
|
160 CleanupClosePushL(AWBGains); |
|
161 GetAWBGainsL(aFrame, AWBGains, aMaxGain); |
|
162 |
|
163 for (TInt a = 0; a < AWBGains.Count() ; a++) |
|
164 { |
|
165 if (a%2 == 1) |
|
166 { |
|
167 aGains.Append(AWBGains[a]); |
|
168 } |
|
169 |
|
170 } |
|
171 |
|
172 CleanupStack::PopAndDestroy(&AWBGains); |
|
173 |
|
174 return ETrue; |
|
175 } |
|
176 |
|
177 |
|
178 TBool CProcAWBFrameHandler::GetNormalizingMargin(const HBufC8* aFrame, TInt8& aMargin) const |
|
179 |
|
180 { |
|
181 |
|
182 RArray<TInt> gains; |
|
183 |
|
184 TInt error = KErrNone; |
|
185 TRAP( error, CleanupClosePushL(gains) ); |
|
186 |
|
187 if (error != KErrNone) |
|
188 return EFalse; |
|
189 |
|
190 TInt maxGain; |
|
191 |
|
192 TRAPD(err, GetAWBGainsL(aFrame, gains, maxGain)); |
|
193 |
|
194 if (err != KErrNone) |
|
195 { |
|
196 return EFalse; |
|
197 } |
|
198 |
|
199 TInt largestGain = 1; |
|
200 |
|
201 for (TInt a = 1 ; a < gains.Count() ; a+=2) |
|
202 { |
|
203 if (gains[a] > largestGain) |
|
204 { |
|
205 largestGain = gains[a]; |
|
206 } |
|
207 |
|
208 } |
|
209 TInt gamma10000 = (32767*10000)/largestGain; |
|
210 |
|
211 |
|
212 CleanupStack::PopAndDestroy(&gains); |
|
213 |
|
214 TUint8 newIndex = ProcTools::FindNewIndexSQ(gamma10000, KAwbGain_dB2Gamma, 256); |
|
215 |
|
216 TInt8 newGain = static_cast<TInt8>(newIndex-127); |
|
217 |
|
218 if (newGain > 63) |
|
219 { |
|
220 newGain = 63; |
|
221 } |
|
222 else if (newGain < -63) |
|
223 { |
|
224 newGain = -63; |
|
225 } |
|
226 |
|
227 aMargin = static_cast<TInt8>(newGain*2); |
|
228 // aMargin is now in dB/2:s |
|
229 return ETrue; |
|
230 |
|
231 } |
|
232 |
|
233 CProcAWBFrameHandler::~CProcAWBFrameHandler() |
|
234 { |
|
235 |
|
236 } |
|
237 |
|
238 CProcAWBFrameHandler* CProcAWBFrameHandler::NewL() |
|
239 { |
|
240 |
|
241 |
|
242 CProcAWBFrameHandler* self = NewLC(); |
|
243 CleanupStack::Pop(self); |
|
244 return self; |
|
245 |
|
246 } |
|
247 CProcAWBFrameHandler* CProcAWBFrameHandler::NewLC() |
|
248 { |
|
249 |
|
250 CProcAWBFrameHandler* self = new (ELeave) CProcAWBFrameHandler(); |
|
251 CleanupStack::PushL(self); |
|
252 self->ConstructL(); |
|
253 return self; |
|
254 |
|
255 } |
|
256 |
|
257 void CProcAWBFrameHandler::ConstructL() |
|
258 { |
|
259 |
|
260 } |
|
261 |
|
262 CProcAWBFrameHandler::CProcAWBFrameHandler() |
|
263 { |
|
264 |
|
265 } |
|
266 |
|
267 TBool CProcAWBFrameHandler::GetAWBGainsL(const HBufC8* aFrame, |
|
268 RArray<TInt>& aGains, |
|
269 TInt& aMaxGain) const |
|
270 |
|
271 { |
|
272 |
|
273 const TUint8 modeByte = (*aFrame)[0]; |
|
274 |
|
275 TUint8 toc = modeByte; |
|
276 TUint8 mode = static_cast<TUint8>((toc >> 3) & 0x0F); |
|
277 |
|
278 TInt bitrate = KAWBBitRates[mode]; |
|
279 TInt cbIndex = -1; |
|
280 TInt a = 0; |
|
281 |
|
282 switch (bitrate) |
|
283 { |
|
284 |
|
285 case 23850: |
|
286 { |
|
287 |
|
288 for (a = 0 ; a < 4 ; a++) |
|
289 { |
|
290 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
291 KGainPositions[TAWBBitRate23850*4+a], 7); |
|
292 TInt pitch = t_qua_gain7b[cbIndex*2]; |
|
293 TInt gain = t_qua_gain7b[cbIndex*2+1]; |
|
294 aGains.Append(pitch); |
|
295 aGains.Append(gain); |
|
296 } |
|
297 |
|
298 break; |
|
299 } |
|
300 |
|
301 case 23050: |
|
302 { |
|
303 for (a = 0 ; a < 4 ; a++) |
|
304 { |
|
305 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
306 KGainPositions[TAWBBitRate23050*4+a], 7); |
|
307 TInt pitch = t_qua_gain7b[cbIndex*2]; |
|
308 TInt gain = t_qua_gain7b[cbIndex*2+1]; |
|
309 aGains.Append(pitch); |
|
310 aGains.Append(gain); |
|
311 } |
|
312 break; |
|
313 } |
|
314 case 19850: |
|
315 { |
|
316 for (a = 0 ; a < 4 ; a++) |
|
317 { |
|
318 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
319 KGainPositions[TAWBBitRate19850*4+a], 7); |
|
320 TInt pitch = t_qua_gain7b[cbIndex*2]; |
|
321 TInt gain = t_qua_gain7b[cbIndex*2+1]; |
|
322 aGains.Append(pitch); |
|
323 aGains.Append(gain); |
|
324 } |
|
325 break; |
|
326 } |
|
327 case 18250: |
|
328 { |
|
329 for (a = 0 ; a < 4 ; a++) |
|
330 { |
|
331 |
|
332 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
333 KGainPositions[TAWBBitRate18250*4+a], 7); |
|
334 TInt pitch = t_qua_gain7b[cbIndex*2]; |
|
335 TInt gain = t_qua_gain7b[cbIndex*2+1]; |
|
336 aGains.Append(pitch); |
|
337 aGains.Append(gain); |
|
338 } |
|
339 break; |
|
340 } |
|
341 case 15850: |
|
342 { |
|
343 for (a = 0 ; a < 4 ; a++) |
|
344 { |
|
345 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
346 KGainPositions[TAWBBitRate15850*4+a], 7); |
|
347 TInt pitch = t_qua_gain7b[cbIndex*2]; |
|
348 TInt gain = t_qua_gain7b[cbIndex*2+1]; |
|
349 aGains.Append(pitch); |
|
350 aGains.Append(gain); |
|
351 } |
|
352 |
|
353 break; |
|
354 } |
|
355 case 14250: |
|
356 { |
|
357 for (a = 0 ; a < 4 ; a++) |
|
358 { |
|
359 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
360 KGainPositions[TAWBBitRate14250*4+a], 7); |
|
361 TInt pitch = t_qua_gain7b[cbIndex*2]; |
|
362 TInt gain = t_qua_gain7b[cbIndex*2+1]; |
|
363 aGains.Append(pitch); |
|
364 aGains.Append(gain); |
|
365 } |
|
366 |
|
367 break; |
|
368 } |
|
369 case 12650: |
|
370 { |
|
371 for (a = 0 ; a < 4 ; a++) |
|
372 { |
|
373 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
374 KGainPositions[TAWBBitRate12650*4+a], 7); |
|
375 TInt pitch = t_qua_gain7b[cbIndex*2]; |
|
376 TInt gain = t_qua_gain7b[cbIndex*2+1]; |
|
377 aGains.Append(pitch); |
|
378 aGains.Append(gain); |
|
379 } |
|
380 |
|
381 break; |
|
382 } |
|
383 case 8850: |
|
384 { |
|
385 for (a = 0 ; a < 4 ; a++) |
|
386 { |
|
387 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
388 KGainPositions[TAWBBitRate8850*4+a], 6); |
|
389 TInt pitch = t_qua_gain6b[cbIndex*2]; |
|
390 TInt gain = t_qua_gain6b[cbIndex*2+1]; |
|
391 aGains.Append(pitch); |
|
392 aGains.Append(gain); |
|
393 } |
|
394 |
|
395 break; |
|
396 } |
|
397 case 6600: |
|
398 { |
|
399 for (a = 0 ; a < 4 ; a++) |
|
400 { |
|
401 cbIndex = ProcTools::GetValueFromShuffledAWBFrameL(aFrame, bitrate, |
|
402 KGainPositions[TAWBBitRate6600*4+a], 6); |
|
403 TInt pitch = t_qua_gain6b[cbIndex*2]; |
|
404 TInt gain = t_qua_gain6b[cbIndex*2+1]; |
|
405 aGains.Append(pitch); |
|
406 aGains.Append(gain); |
|
407 } |
|
408 |
|
409 break; |
|
410 } |
|
411 |
|
412 } |
|
413 aMaxGain = 32767; |
|
414 |
|
415 return ETrue; |
|
416 |
|
417 |
|
418 } |
|
419 |
|