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 #include "ProcTools.h" |
|
22 #include "AudPanic.h" |
|
23 |
|
24 #include "mime_io.h" |
|
25 |
|
26 |
|
27 TBool ProcTools::Dec2Bin(TUint8 aDec, TBuf8<8>& aBinary) |
|
28 { |
|
29 |
|
30 // clear aBinary just in case |
|
31 aBinary.Delete(0, aBinary.Length()); |
|
32 |
|
33 aBinary.AppendNum(aDec, EBinary); |
|
34 |
|
35 TInt zerosNeeded = 0; |
|
36 if (aBinary.Length() == 8) |
|
37 { |
|
38 // the MSB is one -> no padding needed |
|
39 } |
|
40 else |
|
41 { |
|
42 |
|
43 zerosNeeded = 8 - aBinary.Length(); |
|
44 for(TInt as = 0 ; as < zerosNeeded ; as++) |
|
45 { |
|
46 aBinary.AppendNum(0); |
|
47 } |
|
48 |
|
49 for (TInt tr = 8 - 1 ; tr >= 0 ; tr--) |
|
50 { |
|
51 |
|
52 if (tr >= zerosNeeded) |
|
53 { |
|
54 aBinary[tr] = aBinary[tr-zerosNeeded]; |
|
55 } |
|
56 else |
|
57 { |
|
58 aBinary[tr] = '0'; |
|
59 } |
|
60 |
|
61 } |
|
62 } |
|
63 |
|
64 |
|
65 return ETrue; |
|
66 } |
|
67 |
|
68 TBool ProcTools::Dec2BinL(TUint32 aDec, HBufC8*& aBin) |
|
69 { |
|
70 |
|
71 // 32 bits, the leftmost is one |
|
72 TUint32 bitMask = 0x80000000; |
|
73 |
|
74 TBool onlyZeros = ETrue; |
|
75 for (TInt a = 32 ; a > 0 ; a--) |
|
76 { |
|
77 TUint32 res = bitMask & aDec; |
|
78 |
|
79 if (res > 0 && onlyZeros) |
|
80 { |
|
81 // the first one from left found |
|
82 onlyZeros = EFalse; |
|
83 aBin = HBufC8::NewL(a); |
|
84 aBin->Des().Append('1'); |
|
85 } |
|
86 else if (res > 0 && !onlyZeros) |
|
87 { |
|
88 aBin->Des().Append('1'); |
|
89 } |
|
90 else if (res == 0 && !onlyZeros) |
|
91 { |
|
92 aBin->Des().Append('0'); |
|
93 |
|
94 } |
|
95 bitMask >>= 1; |
|
96 } |
|
97 |
|
98 return ETrue; |
|
99 |
|
100 } |
|
101 |
|
102 TBool ProcTools::Bin2Dec(const TDesC8& aBin, TUint& aDec) |
|
103 { |
|
104 |
|
105 TLex8 leks(aBin); |
|
106 |
|
107 if (leks.Val(aDec, EBinary) != KErrNone) |
|
108 { |
|
109 return EFalse; |
|
110 } |
|
111 return ETrue; |
|
112 |
|
113 } |
|
114 |
|
115 TBool ProcTools::Des2Dec(TDesC8& aDes, TUint& aDec) |
|
116 { |
|
117 |
|
118 TLex8 leks(aDes); |
|
119 |
|
120 if (leks.Val(aDec, EDecimal) != KErrNone) |
|
121 { |
|
122 return EFalse; |
|
123 } |
|
124 return ETrue; |
|
125 |
|
126 |
|
127 } |
|
128 |
|
129 TBool ProcTools::Des2BinL(const TDesC8& aDes, HBufC8*& aBin) |
|
130 { |
|
131 |
|
132 aBin = HBufC8::NewL(aDes.Length()*8); |
|
133 // clear aBinary just in case |
|
134 |
|
135 for (TInt a = 0 ; a < aDes.Length() ; a++) |
|
136 { |
|
137 |
|
138 TUint8 chDec = aDes[a]; |
|
139 |
|
140 aBin->Des().AppendNum(chDec, EBinary); |
|
141 |
|
142 TInt zerosNeeded = 0; |
|
143 if (aBin->Des().Length() == (a+1)*8) |
|
144 { |
|
145 // the MSB is one -> no padding needed |
|
146 } |
|
147 else |
|
148 { |
|
149 |
|
150 zerosNeeded = (a+1)*8 - aBin->Des().Length(); |
|
151 for(TInt as = 0 ; as < zerosNeeded ; as++) |
|
152 { |
|
153 aBin->Des().Insert(a*8, _L8("0")); |
|
154 //AppendNum(0); |
|
155 } |
|
156 |
|
157 } |
|
158 } |
|
159 |
|
160 |
|
161 return ETrue; |
|
162 |
|
163 } |
|
164 |
|
165 TInt ProcTools::MilliSeconds(TTimeIntervalMicroSeconds aMicroSeconds) |
|
166 { |
|
167 |
|
168 #ifndef EKA2 |
|
169 return (aMicroSeconds.Int64()/1000).GetTInt(); |
|
170 #else |
|
171 return (aMicroSeconds.Int64()/1000); |
|
172 #endif |
|
173 |
|
174 } |
|
175 |
|
176 TTimeIntervalMicroSeconds ProcTools::MicroSeconds(TInt aMilliSeconds) |
|
177 { |
|
178 |
|
179 TTimeIntervalMicroSeconds mic(aMilliSeconds*1000); |
|
180 return mic; |
|
181 } |
|
182 |
|
183 TInt ProcTools::GetTInt(TInt64 aTInt64) |
|
184 { |
|
185 |
|
186 #ifndef EKA2 |
|
187 return aTInt64.GetTInt(); |
|
188 #else |
|
189 return aTInt64; |
|
190 #endif |
|
191 |
|
192 } |
|
193 |
|
194 TInt ProcTools::GetValueFromShuffledFrame(const HBufC8* aFrame, |
|
195 const TUint8 aBitPositions[], |
|
196 const TInt aSize) |
|
197 { |
|
198 |
|
199 HBufC8* inBytes = 0; |
|
200 TRAPD(err, inBytes = HBufC8::NewL(aSize)); |
|
201 if (err != KErrNone) |
|
202 { |
|
203 inBytes = 0; |
|
204 return -1; |
|
205 } |
|
206 |
|
207 |
|
208 _LIT8(KZero, "0"); |
|
209 _LIT8(KOne, "1"); |
|
210 |
|
211 |
|
212 for (TInt a = 0 ; a < aSize ; a++) |
|
213 { |
|
214 |
|
215 TUint8 mask = 0x80; // 1000 0000b |
|
216 TUint byteNumber = aBitPositions[a]/8; |
|
217 TUint bitNumber = aBitPositions[a]%8; |
|
218 |
|
219 const TUint8 byteNow = (*aFrame)[byteNumber]; |
|
220 |
|
221 mask >>= bitNumber; |
|
222 |
|
223 //TUint8 masked = byteNow & mask; |
|
224 // why casting is needed, dunno? |
|
225 |
|
226 TUint8 masked = static_cast<TUint8>(byteNow & mask); |
|
227 |
|
228 if (masked == 0) |
|
229 { |
|
230 inBytes->Des().Append(KZero); |
|
231 } |
|
232 else |
|
233 { |
|
234 inBytes->Des().Append(KOne); |
|
235 } |
|
236 } |
|
237 TUint dec = 0; |
|
238 Bin2Dec(inBytes->Des(), dec); |
|
239 delete inBytes; |
|
240 inBytes = 0; |
|
241 return dec; |
|
242 |
|
243 |
|
244 } |
|
245 |
|
246 |
|
247 |
|
248 TInt ProcTools::GetValueFromShuffledAWBFrameL(const HBufC8* aFrame, TInt aBitRate, TInt aBitPosition, TInt aLength) |
|
249 { |
|
250 |
|
251 HBufC8* inBytes = HBufC8::NewLC(aLength); |
|
252 |
|
253 |
|
254 _LIT8(KZero, "0"); |
|
255 _LIT8(KOne, "1"); |
|
256 |
|
257 const TInt* table = 0; |
|
258 TInt tableSize = 0; |
|
259 |
|
260 switch(aBitRate) |
|
261 { |
|
262 case(23850): |
|
263 { |
|
264 table = sort_2385; |
|
265 tableSize = 477; |
|
266 break; |
|
267 } |
|
268 case(23050): |
|
269 { |
|
270 table = sort_2305; |
|
271 tableSize = 461; |
|
272 break; |
|
273 } |
|
274 case(19850): |
|
275 { |
|
276 table = sort_1985; |
|
277 tableSize = 397; |
|
278 break; |
|
279 } |
|
280 case(18250): |
|
281 { |
|
282 table = sort_1825; |
|
283 tableSize = 365; |
|
284 break; |
|
285 } |
|
286 case(15850): |
|
287 { |
|
288 table = sort_1585; |
|
289 tableSize = 317; |
|
290 break; |
|
291 } |
|
292 case(14250): |
|
293 { |
|
294 table = sort_1425; |
|
295 tableSize = 285; |
|
296 break; |
|
297 } |
|
298 case(12650): |
|
299 { |
|
300 table = sort_1265; |
|
301 tableSize = 253; |
|
302 break; |
|
303 } |
|
304 case(8850): |
|
305 { |
|
306 table = sort_885; |
|
307 tableSize = 177; |
|
308 break; |
|
309 } |
|
310 case(6600): |
|
311 { |
|
312 table = sort_660; |
|
313 tableSize = 132; |
|
314 break; |
|
315 } |
|
316 default: |
|
317 { |
|
318 // illegal bitrate |
|
319 CleanupStack::PopAndDestroy(inBytes); |
|
320 return -1; |
|
321 } |
|
322 |
|
323 } |
|
324 |
|
325 |
|
326 for (TInt a = 0 ; a < aLength ; a++) |
|
327 { |
|
328 TInt bitIndex = FindIndex(aBitPosition+a, table, tableSize)+8; |
|
329 |
|
330 TUint8 mask = 0x80; // 1000 0000b |
|
331 TUint byteNumber = bitIndex/8; |
|
332 TUint bitNumber = bitIndex%8; |
|
333 |
|
334 const TUint8 byteNow = (*aFrame)[byteNumber]; |
|
335 |
|
336 mask >>= bitNumber; |
|
337 |
|
338 //TUint8 masked = byteNow & mask; |
|
339 // why casting is needed, dunno? |
|
340 |
|
341 TUint8 masked = static_cast<TUint8>(byteNow & mask); |
|
342 |
|
343 if (masked == 0) |
|
344 { |
|
345 inBytes->Des().Append(KZero); |
|
346 } |
|
347 else |
|
348 { |
|
349 inBytes->Des().Append(KOne); |
|
350 } |
|
351 } |
|
352 |
|
353 TUint dec = 0; |
|
354 Bin2Dec(inBytes->Des(), dec); |
|
355 CleanupStack::PopAndDestroy(inBytes); |
|
356 |
|
357 inBytes = 0; |
|
358 return dec; |
|
359 |
|
360 } |
|
361 |
|
362 |
|
363 TBool ProcTools::SetValueToShuffledAWBFrame(TUint8 aNewValue, HBufC8* aFrame, |
|
364 TInt aBitRate, TInt aBitPosition, TInt aLength) |
|
365 { |
|
366 |
|
367 const TInt* table = 0; |
|
368 TInt tableSize = 0; |
|
369 |
|
370 switch(aBitRate) |
|
371 { |
|
372 case(23850): |
|
373 { |
|
374 table = sort_2385; |
|
375 tableSize = 477; |
|
376 |
|
377 break; |
|
378 } |
|
379 case(23050): |
|
380 { |
|
381 table = sort_2305; |
|
382 tableSize = 461; |
|
383 |
|
384 break; |
|
385 } |
|
386 case(19850): |
|
387 { |
|
388 table = sort_1985; |
|
389 tableSize = 397; |
|
390 |
|
391 break; |
|
392 } |
|
393 case(18250): |
|
394 { |
|
395 table = sort_1825; |
|
396 tableSize = 365; |
|
397 |
|
398 break; |
|
399 } |
|
400 case(15850): |
|
401 { |
|
402 table = sort_1585; |
|
403 tableSize = 317; |
|
404 |
|
405 break; |
|
406 } |
|
407 case(14250): |
|
408 { |
|
409 table = sort_1425; |
|
410 tableSize = 285; |
|
411 |
|
412 break; |
|
413 } |
|
414 case(12650): |
|
415 { |
|
416 table = sort_1265; |
|
417 tableSize = 253; |
|
418 |
|
419 break; |
|
420 } |
|
421 case(8850): |
|
422 { |
|
423 table = sort_885; |
|
424 tableSize = 177; |
|
425 |
|
426 break; |
|
427 } |
|
428 case(6600): |
|
429 { |
|
430 table = sort_660; |
|
431 tableSize = 132; |
|
432 |
|
433 break; |
|
434 } |
|
435 default: |
|
436 { |
|
437 // illegal bitrate |
|
438 return -1; |
|
439 } |
|
440 |
|
441 } |
|
442 |
|
443 |
|
444 _LIT8(KZero, "0"); |
|
445 |
|
446 TBuf8<8> newValueBin; |
|
447 Dec2Bin(aNewValue, newValueBin); |
|
448 // remove leading zeros |
|
449 newValueBin.Delete(0, 8-aLength); |
|
450 |
|
451 |
|
452 |
|
453 TPtr8 framePtr(aFrame->Des()); |
|
454 |
|
455 for (TInt a = 0 ; a < newValueBin.Size() ; a++) |
|
456 { |
|
457 |
|
458 TInt bitIndex = FindIndex(aBitPosition+a, table, tableSize)+8; |
|
459 |
|
460 TUint8 bitPositionInByte = static_cast<TUint8>(bitIndex%8); |
|
461 TUint byteNumber = bitIndex/8; |
|
462 |
|
463 if (newValueBin.Mid(a,1).Compare(KZero) == 0) |
|
464 { |
|
465 |
|
466 TUint8 mask = 0x80; // 0111 1111b |
|
467 mask >>= bitPositionInByte; |
|
468 mask = static_cast<TUint8>(~mask); |
|
469 |
|
470 //---> |
|
471 // TUint8 oldByte = framePtr[byteNumber]; |
|
472 // TUint8 newByte = oldByte & mask; |
|
473 //<-- |
|
474 |
|
475 framePtr[byteNumber] = static_cast<TUint8>(framePtr[byteNumber] & mask); |
|
476 |
|
477 } |
|
478 else |
|
479 { |
|
480 |
|
481 TUint8 mask = 0x80; // 1000 0000b |
|
482 mask >>= bitPositionInByte; |
|
483 |
|
484 //---> |
|
485 // TUint8 oldByte = framePtr[byteNumber]; |
|
486 // TUint8 newByte = oldByte & mask; |
|
487 //<-- |
|
488 framePtr[byteNumber] = static_cast<TUint8>(framePtr[byteNumber] | mask); |
|
489 |
|
490 } |
|
491 |
|
492 } |
|
493 |
|
494 return EFalse; |
|
495 } |
|
496 |
|
497 TBool ProcTools::SetValueToShuffledFrame(HBufC8* aFrame, TUint8 aNewValue, |
|
498 const TUint8 aBitPositions[], |
|
499 TInt aSize) |
|
500 { |
|
501 |
|
502 |
|
503 _LIT8(KZero, "0"); |
|
504 |
|
505 TBuf8<8> newValueBin; |
|
506 Dec2Bin(aNewValue, newValueBin); |
|
507 newValueBin.Delete(0, 8-aSize); |
|
508 |
|
509 TPtr8 framePtr(aFrame->Des()); |
|
510 |
|
511 for (TInt a = 0 ; a < aSize ; a++) |
|
512 { |
|
513 |
|
514 TUint8 bitPosition = static_cast<TUint8>(aBitPositions[a]%8); |
|
515 TUint byteNumber = aBitPositions[a]/8; |
|
516 |
|
517 if (newValueBin.Mid(a,1).Compare(KZero) == 0) |
|
518 { |
|
519 |
|
520 TUint8 mask = 0x80; // 0111 1111b |
|
521 mask >>= bitPosition; |
|
522 mask = static_cast<TUint8>(~mask); |
|
523 |
|
524 //---> |
|
525 // TUint8 oldByte = framePtr[byteNumber]; |
|
526 // TUint8 newByte = oldByte & mask; |
|
527 //<-- |
|
528 |
|
529 framePtr[byteNumber] = static_cast<TUint8>(framePtr[byteNumber] & mask); |
|
530 |
|
531 } |
|
532 else |
|
533 { |
|
534 |
|
535 TUint8 mask = 0x80; // 1000 0000b |
|
536 mask >>= bitPosition; |
|
537 |
|
538 //---> |
|
539 // TUint8 oldByte = framePtr[byteNumber]; |
|
540 // TUint8 newByte = oldByte & mask; |
|
541 //<-- |
|
542 framePtr[byteNumber] = static_cast<TUint8>(framePtr[byteNumber] | mask); |
|
543 |
|
544 } |
|
545 |
|
546 |
|
547 |
|
548 } |
|
549 |
|
550 return ETrue; |
|
551 |
|
552 } |
|
553 |
|
554 |
|
555 |
|
556 TBool ProcTools::WriteValuesToFileL(const RArray<TInt>& aArray, const TDesC& aFilename) |
|
557 { |
|
558 |
|
559 RFs fs; |
|
560 User::LeaveIfError(fs.Connect()); |
|
561 |
|
562 RFile file; |
|
563 TInt err=file.Open(fs, aFilename, EFileWrite); |
|
564 |
|
565 if (err==KErrNotFound) |
|
566 { |
|
567 err=file.Create(fs, aFilename, EFileWrite); |
|
568 } |
|
569 TInt nolla = 0; |
|
570 file.Seek(ESeekEnd, nolla); |
|
571 for (TInt a = 0; a < aArray.Count() ; a++) |
|
572 { |
|
573 TBuf8<8> num; |
|
574 num.AppendNum(aArray[a]); |
|
575 file.Write(num); |
|
576 file.Write(_L8("\n")); |
|
577 |
|
578 |
|
579 } |
|
580 |
|
581 file.Close(); |
|
582 fs.Close(); |
|
583 |
|
584 return ETrue; |
|
585 } |
|
586 |
|
587 |
|
588 TUint8 ProcTools::FindNewIndexSQ(TInt aNewGain, const TInt aGainTable[], TInt aTableSize) |
|
589 { |
|
590 |
|
591 if (aTableSize > 256) |
|
592 { |
|
593 TAudPanic::Panic(TAudPanic::EInternal); |
|
594 } |
|
595 |
|
596 TUint8 tableSize = static_cast<TUint8>(aTableSize-1); |
|
597 |
|
598 TInt minimum = 0xFFFF; |
|
599 TUint8 indexFound = 0; |
|
600 |
|
601 for (TUint a = 0 ; a <= tableSize ; a++) |
|
602 { |
|
603 |
|
604 if (Abs(aGainTable[a]-aNewGain) < minimum) |
|
605 { |
|
606 minimum = Abs(aGainTable[a]-aNewGain); |
|
607 indexFound = static_cast<TUint8>(a); |
|
608 } |
|
609 } |
|
610 |
|
611 return indexFound; |
|
612 |
|
613 } |
|
614 |
|
615 TUint8 ProcTools::FindNewIndexVQ(TInt aNewGain, TInt aOldPitch, const TInt aGainTable[], TInt aTableSize) |
|
616 { |
|
617 |
|
618 if (aTableSize > 256) |
|
619 { |
|
620 TAudPanic::Panic(TAudPanic::EInternal); |
|
621 } |
|
622 |
|
623 TUint8 tableSize = static_cast<TUint8>(aTableSize-1); |
|
624 |
|
625 |
|
626 |
|
627 TInt minimum = KMaxTInt; |
|
628 TUint8 indexFound = 0; |
|
629 |
|
630 for (TUint a = 0 ; a <= tableSize ; a+=2) |
|
631 { |
|
632 |
|
633 // gpitch: Q14 , 2^14 = 16384 |
|
634 TInt distance_pitch = (100*(Abs(aGainTable[a]-aOldPitch)))/16384; |
|
635 |
|
636 // g_fac: Q12 , 2^12 = 4096 |
|
637 TInt distance_fc = (100*Abs(aGainTable[a+1]-aNewGain))/4096; |
|
638 |
|
639 |
|
640 TInt distance = distance_pitch*distance_pitch + distance_fc*distance_fc; |
|
641 |
|
642 if (distance < minimum) |
|
643 { |
|
644 minimum = distance; |
|
645 indexFound = static_cast<TUint8>(a); |
|
646 } |
|
647 } |
|
648 |
|
649 return static_cast<TUint8>(indexFound/2); |
|
650 |
|
651 } |
|
652 |
|
653 TUint8 ProcTools::FindNewIndexVQ2(TInt aNewGain, TInt aOldPitch, const TInt aGainTable[], TInt aTableSize) |
|
654 { |
|
655 |
|
656 if (aTableSize > 256) |
|
657 { |
|
658 TAudPanic::Panic(TAudPanic::EInternal); |
|
659 } |
|
660 |
|
661 TUint8 tableSize = static_cast<TUint8>(aTableSize-1); |
|
662 |
|
663 TInt minimum = KMaxTInt; |
|
664 TUint8 indexFound = 0; |
|
665 |
|
666 for (TUint a = 0 ; a <= tableSize ; a+=2) |
|
667 { |
|
668 |
|
669 // gpitch: Q14 , 2^14 = 16384 |
|
670 TInt distance_pitch = (100*(Abs(aGainTable[a]-aOldPitch)))/16384; |
|
671 |
|
672 // g_fac: Q11 , 2^11 = 2048 |
|
673 TInt distance_fc = (100*Abs(aGainTable[a+1]-aNewGain))/2048; |
|
674 |
|
675 |
|
676 TInt distance = distance_pitch*distance_pitch + distance_fc*distance_fc; |
|
677 |
|
678 if (distance < minimum) |
|
679 { |
|
680 minimum = distance; |
|
681 indexFound = static_cast<TUint8>(a); |
|
682 } |
|
683 } |
|
684 |
|
685 return static_cast<TUint8>(indexFound/2); |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 } |
|
691 |
|
692 |
|
693 TUint8 ProcTools::FindNewIndex475VQ(TInt aNewGain0, TInt aOldPitch0, TInt aNewGain1, TInt aOldPitch1) |
|
694 { |
|
695 |
|
696 TInt minimum = KMaxTInt; |
|
697 TInt indexFound = -1; |
|
698 |
|
699 TInt tableSize = 256*4; |
|
700 |
|
701 |
|
702 for (TInt a = 0 ; a < tableSize-3 ; a+=4) |
|
703 { |
|
704 |
|
705 // gpitch: Q14 , 2^14 = 16384 |
|
706 TInt distance_pitch0 = (100*(Abs(KAmrGainTable475[a]-aOldPitch0)))/16384; |
|
707 TInt distance_pitch1 = (100*(Abs(KAmrGainTable475[a+2]-aOldPitch1)))/16384; |
|
708 |
|
709 // g_fac: Q12 , 2^12 = 4096 |
|
710 TInt distance_fc0 = (100*Abs(KAmrGainTable475[a+1]-aNewGain0))/4096; |
|
711 TInt distance_fc1 = (100*Abs(KAmrGainTable475[a+3]-aNewGain1))/4096; |
|
712 |
|
713 TInt distance = distance_pitch0*distance_pitch0 + distance_fc0*distance_fc0 + |
|
714 distance_pitch1*distance_pitch1 + distance_fc1*distance_fc1; |
|
715 |
|
716 if (distance < minimum) |
|
717 { |
|
718 minimum = distance; |
|
719 indexFound = a; |
|
720 } |
|
721 } |
|
722 |
|
723 return static_cast<TUint8>(indexFound/4); |
|
724 |
|
725 } |
|
726 |
|
727 TInt ProcTools::FindIndex(TInt aKey, const TInt aBitPositions[], TInt aTableLength) |
|
728 { |
|
729 |
|
730 for (TInt a = 0 ; a < aTableLength ; a++) |
|
731 { |
|
732 if (aBitPositions[a] == aKey) return a; |
|
733 } |
|
734 |
|
735 return -1; |
|
736 |
|
737 } |
|
738 |
|
739 TBool ProcTools::GenerateADTSHeaderL(TBuf8<7>& aHeader, TInt aFrameLength, TAudFileProperties aProperties) |
|
740 { |
|
741 TUint8 byte1 = 0xFF; |
|
742 |
|
743 TUint8 byte2 = 0x0; |
|
744 if (aProperties.iAudioType == EAudAAC_MPEG2) |
|
745 { |
|
746 byte2 = 0xF9; |
|
747 } |
|
748 else if (aProperties.iAudioType == EAudAAC_MPEG4) |
|
749 { |
|
750 byte2 = 0xF1; |
|
751 } |
|
752 else return EFalse; |
|
753 TBuf8<8> byte3b(8); |
|
754 TBuf8<8> byte4b(8); |
|
755 TBuf8<8> byte5b(8); |
|
756 TBuf8<8> byte6b(8); |
|
757 TBuf8<8> byte7b(8); |
|
758 |
|
759 byte3b.Fill('0'); |
|
760 byte4b.Fill('0'); |
|
761 byte5b.Fill('0'); |
|
762 byte6b.Fill('0'); |
|
763 byte7b.Fill('0'); |
|
764 |
|
765 |
|
766 const TInt KAAC_SAMPLING_RATES[16] = {96000,88200,64000,48000,44100,32000,24000, |
|
767 22050,16000,12000,11025,8000,0,0,0,0}; |
|
768 |
|
769 TBool srFound = EFalse; |
|
770 TUint8 srIndex = 0; |
|
771 for (srIndex = 0 ; srIndex < 14 ; srIndex++) |
|
772 { |
|
773 if (KAAC_SAMPLING_RATES[srIndex] == aProperties.iSamplingRate) |
|
774 { |
|
775 srFound = ETrue; |
|
776 break; |
|
777 } |
|
778 } |
|
779 |
|
780 if (srFound) |
|
781 { |
|
782 TBuf8<8> srB; |
|
783 ProcTools::Dec2Bin(srIndex, srB); |
|
784 |
|
785 // Sampling rate |
|
786 byte3b[2] = srB[4]; |
|
787 byte3b[3] = srB[5]; |
|
788 byte3b[4] = srB[6]; |
|
789 byte3b[5] = srB[7]; |
|
790 |
|
791 } |
|
792 |
|
793 |
|
794 |
|
795 // private bit |
|
796 byte3b[6] = '0'; |
|
797 |
|
798 // channel configuration |
|
799 byte3b[7] = '0'; |
|
800 if (aProperties.iChannelMode == EAudStereo) |
|
801 { |
|
802 byte4b[0] = '1'; |
|
803 byte4b[1] = '0'; |
|
804 |
|
805 } |
|
806 else if(aProperties.iChannelMode == EAudSingleChannel) |
|
807 { |
|
808 byte4b[0] = '0'; |
|
809 byte4b[1] = '1'; |
|
810 |
|
811 } |
|
812 else |
|
813 { |
|
814 return EFalse; |
|
815 } |
|
816 |
|
817 //original/copy & home |
|
818 byte4b[2] = '0'; |
|
819 byte4b[3] = '0'; |
|
820 // copyright identification & start |
|
821 byte4b[4] = '0'; |
|
822 byte4b[5] = '0'; |
|
823 |
|
824 HBufC8* lenBin = 0; |
|
825 if (ProcTools::Dec2BinL(aFrameLength+7, lenBin)) |
|
826 { |
|
827 |
|
828 TInt fromRight = 0; |
|
829 for(TInt i = lenBin->Size()-1 ; i >= 0 ; i--) |
|
830 { |
|
831 if (fromRight < 3) |
|
832 { |
|
833 // byte7 |
|
834 byte6b[2-fromRight] = lenBin->Des()[i]; |
|
835 } |
|
836 else if (fromRight < 11) |
|
837 { |
|
838 // byte6 |
|
839 byte5b[10-fromRight] = lenBin->Des()[i]; |
|
840 |
|
841 } |
|
842 else if (fromRight < 13) |
|
843 { |
|
844 // byte5 |
|
845 byte4b[18-fromRight] = lenBin->Des()[i]; |
|
846 } |
|
847 |
|
848 fromRight++; |
|
849 } |
|
850 |
|
851 delete lenBin; |
|
852 } |
|
853 |
|
854 TInt bitInd = 0; |
|
855 for (bitInd = 3 ; bitInd < 8 ; bitInd++) |
|
856 { |
|
857 byte6b[bitInd] = '1'; |
|
858 } |
|
859 for (bitInd = 0 ; bitInd < 6 ; bitInd++) |
|
860 { |
|
861 byte7b[bitInd] = '1'; |
|
862 } |
|
863 |
|
864 |
|
865 aHeader.Append(byte1); |
|
866 aHeader.Append(byte2); |
|
867 |
|
868 TUint tmpByte = 0; |
|
869 ProcTools::Bin2Dec(byte3b, tmpByte); |
|
870 |
|
871 // profile |
|
872 TUint8 bitMask = aProperties.iAACObjectType; |
|
873 bitMask <<= 6; |
|
874 tmpByte = tmpByte | bitMask; |
|
875 |
|
876 aHeader.Append(static_cast<TUint8>(tmpByte)); |
|
877 |
|
878 ProcTools::Bin2Dec(byte4b, tmpByte); |
|
879 aHeader.Append(static_cast<TUint8>(tmpByte)); |
|
880 |
|
881 ProcTools::Bin2Dec(byte5b, tmpByte); |
|
882 aHeader.Append(static_cast<TUint8>(tmpByte)); |
|
883 |
|
884 ProcTools::Bin2Dec(byte6b, tmpByte); |
|
885 aHeader.Append(static_cast<TUint8>(tmpByte)); |
|
886 |
|
887 ProcTools::Bin2Dec(byte7b, tmpByte); |
|
888 aHeader.Append(static_cast<TUint8>(tmpByte)); |
|
889 |
|
890 return ETrue; |
|
891 |
|
892 } |
|
893 |
|
894 TInt ProcTools::GetNextAMRFrameLength(const HBufC8* aFrame, TInt aPosNow) |
|
895 { |
|
896 |
|
897 |
|
898 if (aPosNow >= aFrame->Size()) return -1; |
|
899 |
|
900 |
|
901 const TUint8 ch = (*aFrame)[aPosNow]; |
|
902 |
|
903 TUint dec_mode = (enum Mode)((ch & 0x0078) >> 3); |
|
904 |
|
905 switch (dec_mode) |
|
906 { |
|
907 case 0: |
|
908 { |
|
909 return 12+1; |
|
910 } |
|
911 |
|
912 case 1: |
|
913 { |
|
914 return 13+1; |
|
915 } |
|
916 |
|
917 case 2: |
|
918 { |
|
919 return 15+1; |
|
920 } |
|
921 |
|
922 case 3: |
|
923 { |
|
924 return 17+1; |
|
925 } |
|
926 |
|
927 case 4: |
|
928 { |
|
929 return 19+1; |
|
930 } |
|
931 |
|
932 case 5: |
|
933 { |
|
934 return 20+1; |
|
935 } |
|
936 |
|
937 case 6: |
|
938 { |
|
939 return 26+1; |
|
940 } |
|
941 |
|
942 case 7: |
|
943 { |
|
944 return 31+1; |
|
945 } |
|
946 |
|
947 case 8: |
|
948 { |
|
949 return 5+1; |
|
950 } |
|
951 |
|
952 case 15: |
|
953 { |
|
954 return 0+1; |
|
955 } |
|
956 |
|
957 default: |
|
958 return 0+1; |
|
959 |
|
960 }; |
|
961 |
|
962 |
|
963 } |
|
964 |
|
965 |
|
966 CProcessingEvent* CProcessingEvent::NewL() |
|
967 { |
|
968 CProcessingEvent* self = new (ELeave) CProcessingEvent(); |
|
969 CleanupStack::PushL(self); |
|
970 self->ConstructL(); |
|
971 CleanupStack::Pop(self); |
|
972 return self; |
|
973 |
|
974 } |
|
975 |
|
976 void CProcessingEvent::ConstructL() |
|
977 { |
|
978 } |
|
979 |
|
980 CProcessingEvent::~CProcessingEvent() |
|
981 { |
|
982 iAllIndexes.Close(); |
|
983 } |
|
984 |
|
985 |
|
986 CProcessingEvent::CProcessingEvent() |
|
987 { |
|
988 } |
|
989 |
|
990 void CProcessingEvent::InsertIndex(TInt aIndex) |
|
991 { |
|
992 iAllIndexes.Append(aIndex); |
|
993 } |
|
994 |
|
995 TInt CProcessingEvent::GetIndex(TInt aProcessingEventIndex) |
|
996 { |
|
997 return iAllIndexes[aProcessingEventIndex]; |
|
998 } |
|
999 |
|
1000 TBool CProcessingEvent::GetAllIndexes(RArray<TInt>& aAllIndexes) |
|
1001 { |
|
1002 for (TInt a = 0 ; a < iAllIndexes.Count() ; a++) |
|
1003 { |
|
1004 aAllIndexes.Append(iAllIndexes[a]); |
|
1005 |
|
1006 } |
|
1007 return ETrue; |
|
1008 } |
|
1009 |
|
1010 TInt CProcessingEvent::IndexCount() |
|
1011 { |
|
1012 return iAllIndexes.Count(); |
|
1013 } |
|
1014 |
|
1015 TInt CProcessingEvent::FindIndex(TInt aClipIndex) |
|
1016 { |
|
1017 return iAllIndexes.Find(aClipIndex); |
|
1018 } |
|
1019 |
|
1020 void CProcessingEvent::RemoveIndex(TInt aProcessingEventIndex) |
|
1021 { |
|
1022 iAllIndexes.Remove(aProcessingEventIndex); |
|
1023 } |
|
1024 |
|
1025 |
|
1026 TInt CProcessingEvent::Compare(const CProcessingEvent& c1, const CProcessingEvent& c2) |
|
1027 { |
|
1028 |
|
1029 if (c1.iPosition > c2.iPosition) |
|
1030 { |
|
1031 return 1; |
|
1032 } |
|
1033 else if (c1.iPosition < c2.iPosition) |
|
1034 { |
|
1035 return -1; |
|
1036 } |
|
1037 else |
|
1038 { |
|
1039 return 0; |
|
1040 } |
|
1041 } |
|
1042 |
|
1043 |
|