blob: ab81a300b20d1941c00be747f3f2393d7084e988 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/***************************************************************************
2**
3** ITU-T G.722.1 (2005-05) - Fixed point implementation for main body and Annex C
4** > Software Release 2.1 (2008-06)
5** (Simple repackaging; no change from 2005-05 Release 2.0 code)
6**
7** © 2004 Polycom, Inc.
8**
9** All rights reserved.
10**
11***************************************************************************/
12
13/***************************************************************************
14 Filename: decoder.c
15
16 Purpose: Contains files used to implement the G.722.1 Annex C decoder
17
18 Design Notes:
19
20***************************************************************************/
21
22/***************************************************************************
23 Include files
24***************************************************************************/
25#include "defs.h"
26#include "tables.h"
27#include "huff_def.h"
28#include "count.h"
29
30
31/***************************************************************************
32 Function: decoder
33
34 Syntax: void decoder(Bit_Obj *bitobj,
35 Rand_Obj *randobj,
36 Word16 number_of_regions,
37 Word16 *decoder_mlt_coefs,
38 Word16 *p_mag_shift,
39 Word16 *p_old_mag_shift,
40 Word16 *old_decoder_mlt_coefs,
41 Word16 frame_error_flag)
42
43 inputs: Bit_Obj *bitobj
44 Rand_Obj *randobj
45 Word16 number_of_regions
46 Word16 *p_old_mag_shift
47 Word16 *old_decoder_mlt_coefs
48 Word16 frame_error_flag
49
50 outputs: Word16 *decoder_mlt_coefs,
51 Word16 *p_mag_shift,
52
53
54
55 Description: Decodes the out_words into mlt coefs using G.722.1 Annex C
56
57 Design Notes:
58
59 WMOPS: 7kHz | 24kbit | 32kbit
60 -------|-------------|----------------
61 AVG | 0.84 | 0.94
62 -------|-------------|----------------
63 MAX | 0.90 | 1.00
64 -------|-------------|----------------
65
66 14kHz | 24kbit | 32kbit | 48kbit
67 -------|-------------|----------------|----------------
68 AVG | 1.31 | 1.56 | 1.88
69 -------|-------------|----------------|----------------
70 MAX | 1.59 | 1.80 | 1.98
71 -------|-------------|----------------|----------------
72
73***************************************************************************/
74void decoder(Bit_Obj *bitobj,
75 Rand_Obj *randobj,
76 Word16 number_of_regions,
77 Word16 *decoder_mlt_coefs,
78 Word16 *p_mag_shift,
79 Word16 *p_old_mag_shift,
80 Word16 *old_decoder_mlt_coefs,
81 Word16 frame_error_flag)
82{
83
84
85 Word16 absolute_region_power_index[MAX_NUMBER_OF_REGIONS];
86 Word16 decoder_power_categories[MAX_NUMBER_OF_REGIONS];
87 Word16 decoder_category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES-1];
88 UWord16 categorization_control;
89 Word16 decoder_region_standard_deviation[MAX_NUMBER_OF_REGIONS];
90 Word16 i;
91
92 Word16 num_categorization_control_bits;
93 Word16 num_categorization_control_possibilities;
94 Word16 number_of_coefs;
95 Word16 number_of_valid_coefs;
96
97
98 test();
99 if (number_of_regions==NUMBER_OF_REGIONS)
100 {
101 num_categorization_control_bits = NUM_CATEGORIZATION_CONTROL_BITS;
102 move16();
103 num_categorization_control_possibilities = NUM_CATEGORIZATION_CONTROL_POSSIBILITIES;
104 move16();
105 number_of_coefs = DCT_LENGTH;
106 move16();
107 number_of_valid_coefs = NUMBER_OF_VALID_COEFS;
108 move16();
109 }
110 else
111 {
112 num_categorization_control_bits = MAX_NUM_CATEGORIZATION_CONTROL_BITS;
113 move16();
114 num_categorization_control_possibilities = MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES;
115 move16();
116 number_of_coefs = MAX_DCT_LENGTH;
117 move16();
118 number_of_valid_coefs = MAX_NUMBER_OF_VALID_COEFS;
119 move16();
120 }
121
122 test();
123 if (frame_error_flag == 0)
124 {
125
126 /* convert the bits to absolute region power index and decoder_region_standard_deviation */
127
128 decode_envelope(bitobj,
129 number_of_regions,
130 decoder_region_standard_deviation,
131 absolute_region_power_index,
132 p_mag_shift);
133
134 /* fill the categorization_control with NUM_CATEGORIZATION_CONTROL_BITS */
135 categorization_control = 0;
136 for (i=0; i<num_categorization_control_bits; i++)
137 {
138 get_next_bit(bitobj);
139 categorization_control = shl_nocheck(categorization_control,1);
140 categorization_control = add(categorization_control,bitobj->next_bit);
141 }
142
143 bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,num_categorization_control_bits);
144
145 /* obtain decoder power categories and category balances */
146 /* based on the absolute region power index */
147 categorize(bitobj->number_of_bits_left,
148 number_of_regions,
149 num_categorization_control_possibilities,
150 absolute_region_power_index,
151 decoder_power_categories,
152 decoder_category_balances);
153
154 /* perform adjustmaents to the power categories and category balances based on the cat control */
155 rate_adjust_categories(categorization_control,
156 decoder_power_categories,
157 decoder_category_balances);
158
159 /* decode the quantized bits into mlt coefs */
160 decode_vector_quantized_mlt_indices(bitobj,
161 randobj,
162 number_of_regions,
163 decoder_region_standard_deviation,
164 decoder_power_categories,
165 decoder_mlt_coefs);
166
167 /* test for frame errors */
168 test_4_frame_errors(bitobj,
169 number_of_regions,
170 num_categorization_control_possibilities,
171 &frame_error_flag,
172 categorization_control,
173 absolute_region_power_index);
174 }
175
176 /* perform error handling operations */
177 error_handling(number_of_coefs,
178 number_of_valid_coefs,
179 &frame_error_flag,
180 decoder_mlt_coefs,
181 old_decoder_mlt_coefs,
182 p_mag_shift,
183 p_old_mag_shift);
184
185}
186
187/***************************************************************************
188 Function: decode_envelope
189
190 Syntax: void decode_envelope(Bit_Obj *bitobj,
191 Word16 number_of_regions,
192 Word16 *decoder_region_standard_deviation,
193 Word16 *absolute_region_power_index,
194 Word16 *p_mag_shift)
195
196 inputs: Bit_Obj *bitobj
197 Word16 number_of_regions
198
199
200 outputs: Word16 *decoder_region_standard_deviation
201 Word16 *absolute_region_power_index
202 Word16 *p_mag_shift
203
204
205 Description: Recover differential_region_power_index from code bits
206
207 Design Notes:
208
209 WMOPS: 7kHz | 24kbit | 32kbit
210 -------|--------------|----------------
211 AVG | 0.04 | 0.04
212 -------|--------------|----------------
213 MAX | 0.05 | 0.05
214 -------|--------------|----------------
215
216 14kHz | 24kbit | 32kbit | 48kbit
217 -------|--------------|----------------|----------------
218 AVG | 0.08 | 0.08 | 0.08
219 -------|--------------|----------------|----------------
220 MAX | 0.10 | 0.10 | 0.10
221 -------|--------------|----------------|----------------
222
223***************************************************************************/
224void decode_envelope(Bit_Obj *bitobj,
225 Word16 number_of_regions,
226 Word16 *decoder_region_standard_deviation,
227 Word16 *absolute_region_power_index,
228 Word16 *p_mag_shift)
229
230{
231 Word16 region;
232 Word16 i;
233 Word16 index;
234 Word16 differential_region_power_index[MAX_NUMBER_OF_REGIONS];
235 Word16 max_index;
236
237 Word16 temp;
238 Word16 temp1;
239 Word16 temp2;
240 Word32 acca;
241
242 index = 0;
243 move16();
244
245 /* get 5 bits from the current code word */
246 for (i=0; i<5; i++)
247 {
248 get_next_bit(bitobj);
249 index = shl_nocheck(index,1);
250 index = add(index,bitobj->next_bit);
251 }
252 bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,5);
253
254 /* ESF_ADJUSTMENT_TO_RMS_INDEX compensates for the current (9/30/96)
255 IMLT being scaled to high by the ninth power of sqrt(2). */
256 differential_region_power_index[0] = sub(index,ESF_ADJUSTMENT_TO_RMS_INDEX);
257 move16();
258
259 /* obtain differential_region_power_index */
260 for (region=1; region<number_of_regions; region++)
261 {
262 index = 0;
263 move16();
264 do
265 {
266 get_next_bit(bitobj);
267 test();
268 if (bitobj->next_bit == 0)
269 {
270 index = differential_region_power_decoder_tree[region][index][0];
271 move16();
272 }
273 else
274 {
275 index = differential_region_power_decoder_tree[region][index][1];
276 move16();
277 }
278 bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
279 test();
280 } while (index > 0);
281
282 differential_region_power_index[region] = negate(index);
283 move16();
284 }
285
286 /* Reconstruct absolute_region_power_index[] from differential_region_power_index[]. */
287 absolute_region_power_index[0] = differential_region_power_index[0];
288 move16();
289 for (region=1; region<number_of_regions; region++)
290 {
291 acca = L_add(absolute_region_power_index[region-1],differential_region_power_index[region]);
292 acca = L_add(acca,DRP_DIFF_MIN);
293 absolute_region_power_index[region] = extract_l(acca);
294 }
295
296 /* Reconstruct decoder_region_standard_deviation[] from absolute_region_power_index[]. */
297 /* DEBUG!!!! - This integer method jointly computes the mag_shift
298 and the standard deviations already mag_shift compensated. It
299 relies on REGION_POWER_STEPSIZE_DB being exactly 3.010299957 db
300 or a square root of 2 chnage in standard deviation. If
301 REGION_POWER_STEPSIZE_DB changes, this software must be
302 reworked. */
303
304 temp = 0;
305 move16();
306 max_index = 0;
307 move16();
308 for (region=0; region<number_of_regions; region++)
309 {
310 acca = L_add(absolute_region_power_index[region],REGION_POWER_TABLE_NUM_NEGATIVES);
311 i = extract_l(acca);
312
313 temp1 = sub(i,max_index);
314 test();
315 if (temp1 > 0)
316 {
317 max_index = i;
318 move16();
319 }
320 temp = add(temp,int_region_standard_deviation_table[i]);
321 }
322 i = 9;
323 move16();
324
325 temp1 = sub(temp,8);
326 temp2 = sub(max_index,28);
327 test();
328 test();
329 logic16();
330 test();
331 logic16();
332 while ((i >= 0) && ((temp1 >= 0) || (temp2 > 0)))
333 {
334 i = sub(i,1);
335 temp = shr_nocheck(temp,1);
336 max_index = sub(max_index,2);
337 temp1 = sub(temp,8);
338 temp2 = sub(max_index,28);
339 test();
340 test();
341 logic16();
342 test();
343 logic16();
344 }
345
346 *p_mag_shift = i;
347 move16();
348
349 /* pointer arithmetic */
350 temp = (Word16 )(REGION_POWER_TABLE_NUM_NEGATIVES + (*p_mag_shift * 2));
351
352 for (region=0; region<number_of_regions; region++)
353 {
354 acca = L_add(absolute_region_power_index[region],temp);
355 i = extract_l(acca);
356 decoder_region_standard_deviation[region] = int_region_standard_deviation_table[i];
357 move16();
358 }
359
360}
361
362/***************************************************************************
363 Function: rate_adjust_categories
364
365 Syntax: void rate_adjust_categories(Word16 categorization_control,
366 Word16 *decoder_power_categories,
367 Word16 *decoder_category_balances)
368
369 inputs: Word16 categorization_control,
370 Word16 *decoder_power_categories,
371 Word16 *decoder_category_balances
372
373 outputs: Word16 categorization_control,
374 Word16 *decoder_power_categories,
375
376 Description: Adjust the power categories based on the categorization control
377
378 Design Notes:
379
380 WMOPS: 7kHz | 24kbit | 32kbit
381 -------|--------------|----------------
382 AVG | 0.00 | 0.00
383 -------|--------------|----------------
384 MAX | 0.00 | 0.00
385 -------|--------------|----------------
386
387 14kHz | 24kbit | 32kbit | 48kbit
388 -------|--------------|----------------|----------------
389 AVG | 0.00 | 0.00 | 0.00
390 -------|--------------|----------------|----------------
391 MAX | 0.01 | 0.01 | 0.01
392 -------|--------------|----------------|----------------
393
394***************************************************************************/
395void rate_adjust_categories(Word16 categorization_control,
396 Word16 *decoder_power_categories,
397 Word16 *decoder_category_balances)
398{
399 Word16 i;
400 Word16 region;
401
402 i = 0;
403 move16();
404
405 test();
406 while (categorization_control > 0)
407 {
408 region = decoder_category_balances[i++];
409 move16();
410 decoder_power_categories[region] = add(decoder_power_categories[region],1);
411 move16();
412 categorization_control = sub(categorization_control,1);
413 }
414
415}
416
417/***************************************************************************
418 Function: decode_vector_quantized_mlt_indices
419
420 Syntax: void decode_vector_quantized_mlt_indices(Bit_Obj *bitobj,
421 Rand_Obj *randobj,
422 Word16 number_of_regions,
423 Word16 *decoder_region_standard_deviation,
424 Word16 *decoder_power_categories,
425 Word16 *decoder_mlt_coefs)
426 inputs: Bit_Obj *bitobj
427 Rand_Obj *randobj
428 Word16 number_of_regions
429 Word16 *decoder_region_standard_deviation
430 Word16 *decoder_power_categories
431
432
433 outputs: Word16 *decoder_mlt_coefs
434
435
436 Description: Decode MLT coefficients
437
438 Design Notes:
439
440 WMOPS: 7kHz | 24kbit | 32kbit
441 -------|--------------|----------------
442 AVG | 0.60 | 0.72
443 -------|--------------|----------------
444 MAX | 0.67 | 0.76
445 -------|--------------|----------------
446
447 14kHz | 24kbit | 32kbit | 48kbit
448 -------|--------------|----------------|----------------
449 AVG | 0.77 | 0.98 | 1.28
450 -------|--------------|----------------|----------------
451 MAX | 1.05 | 1.18 | 1.36
452 -------|--------------|----------------|----------------
453
454***************************************************************************/
455void decode_vector_quantized_mlt_indices(Bit_Obj *bitobj,
456 Rand_Obj *randobj,
457 Word16 number_of_regions,
458 Word16 *decoder_region_standard_deviation,
459 Word16 *decoder_power_categories,
460 Word16 *decoder_mlt_coefs)
461{
462 Word16 standard_deviation;
463 Word16 *decoder_mlt_ptr;
464 Word16 decoder_mlt_value;
465 Word16 noifillpos;
466 Word16 noifillneg;
467 Word16 noise_fill_factor[3] = {5793,8192,23170};
468 Word16 region;
469 Word16 category;
470 Word16 j,n;
471 Word16 k[MAX_VECTOR_DIMENSION];
472 Word16 vec_dim;
473 Word16 num_vecs;
474 Word16 index;
475 Word16 bit=0;
476 Word16 signs_index=0;
477 Word16 num_sign_bits;
478 Word16 ran_out_of_bits_flag;
479 Word16 *decoder_table_ptr;
480 Word16 random_word;
481
482 Word16 temp1;
483 Word16 temp;
484 Word32 acca;
485
486 ran_out_of_bits_flag = 0;
487 move16();
488
489 for (region=0; region<number_of_regions; region++)
490 {
491 category = (Word16)decoder_power_categories[region];
492 move16();
493 acca = L_mult0(region,REGION_SIZE);
494 index = extract_l(acca);
495 decoder_mlt_ptr = &decoder_mlt_coefs[index];
496 move16();
497 standard_deviation = decoder_region_standard_deviation[region];
498 move16();
499
500 temp = sub(category,7);
501 test();
502 if (temp < 0)
503 {
504 /* Get the proper table of decoder tables, vec_dim, and num_vecs for the cat */
505 decoder_table_ptr = (Word16 *) table_of_decoder_tables[category];
506 move16();
507 vec_dim = vector_dimension[category];
508 move16();
509 num_vecs = number_of_vectors[category];
510 move16();
511
512 for (n=0; n<num_vecs; n++)
513 {
514 index = 0;
515 move16();
516
517 /* get index */
518 do
519 {
520 test();
521 if (bitobj->number_of_bits_left <= 0)
522 {
523 ran_out_of_bits_flag = 1;
524 move16();
525 break;
526 }
527
528 get_next_bit(bitobj);
529
530 test();
531 if (bitobj->next_bit == 0)
532 {
533 temp = shl_nocheck(index,1);
534 index = (Word16)*(decoder_table_ptr + temp);
535 move16();
536 }
537 else
538 {
539 temp = shl_nocheck(index,1);
540 index = (Word16)*(decoder_table_ptr + temp + 1);
541 move16();
542 }
543 bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
544 test();
545
546 } while (index > 0);
547
548 test();
549 if (ran_out_of_bits_flag != 0)
550 break;
551
552 index = negate(index);
553
554 /* convert index into array used to access the centroid table */
555 /* get the number of sign bits in the index */
556 num_sign_bits = index_to_array(index,k,category);
557
558 temp = sub(bitobj->number_of_bits_left,num_sign_bits);
559 test();
560 if (temp >= 0)
561 {
562
563 test();
564 if (num_sign_bits != 0)
565 {
566 signs_index = 0;
567 move16();
568 for (j=0; j<num_sign_bits; j++)
569 {
570 get_next_bit(bitobj);
571 signs_index = shl_nocheck(signs_index,1);
572 signs_index = add(signs_index,bitobj->next_bit);
573 bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
574 }
575 temp = sub(num_sign_bits,1);
576 bit = shl_nocheck(1,(temp));
577 }
578
579 for (j=0; j<vec_dim; j++)
580 {
581 acca = L_mult0(standard_deviation,mlt_quant_centroid[category][k[j]]);
582 acca = L_shr_nocheck(acca,12);
583 decoder_mlt_value = extract_l(acca);
584
585 test();
586 if (decoder_mlt_value != 0)
587 {
588 test();
589 if ((signs_index & bit) == 0)
590 decoder_mlt_value = negate(decoder_mlt_value);
591 bit = shr_nocheck(bit,1);
592 }
593 *decoder_mlt_ptr++ = decoder_mlt_value;
594 move16();
595 }
596 }
597 else
598 {
599 ran_out_of_bits_flag = 1;
600 move16();
601 break;
602 }
603 }
604 /* If ran out of bits during decoding do noise fill for remaining regions. */
605 /* DEBUG!! - For now also redo all of last region with all noise fill. */
606 test();
607 if (ran_out_of_bits_flag != 0)
608 {
609 temp = add(region,1);
610 for (j=temp; j<number_of_regions; j++)
611 {
612 decoder_power_categories[j] = 7;
613 move16();
614 }
615 category = 7;
616 move16();
617 decoder_mlt_ptr = &decoder_mlt_coefs[region*REGION_SIZE];
618 move16();
619 }
620 }
621
622 temp = sub(category,5);
623 temp1 = sub(category,6);
624 test();
625 test();
626 logic16();
627 if ((temp == 0) || (temp1 == 0))
628 {
629
630 decoder_mlt_ptr = &decoder_mlt_coefs[region*REGION_SIZE];
631 move16();
632 noifillpos = mult(standard_deviation,noise_fill_factor[category - 5]);
633 noifillneg = negate(noifillpos);
634
635 random_word = get_rand(randobj);
636
637 for (j=0; j<10; j++)
638 {
639 test();
640 if (*decoder_mlt_ptr == 0)
641 {
642 logic16();
643 test();
644 if ((random_word & 1) == 0)
645 {
646 temp1 = noifillneg;
647 move16();
648 }
649 else
650 {
651 temp1 = noifillpos;
652 move16();
653 }
654 *decoder_mlt_ptr = temp1;
655 move16();
656 random_word = shr_nocheck(random_word,1);
657 }
658 /* pointer arithmetic */
659 decoder_mlt_ptr++;
660 }
661 random_word = get_rand(randobj);
662 for (j=0; j<10; j++)
663 {
664 test();
665 if (*decoder_mlt_ptr == 0)
666 {
667 logic16();
668 test();
669 if ((random_word & 1) == 0)
670 {
671 temp1 = noifillneg;
672 move16();
673 }
674 else
675 {
676 temp1 = noifillpos;
677 move16();
678 }
679 *decoder_mlt_ptr = temp1;
680 move16();
681 random_word = shr_nocheck(random_word,1);
682 }
683 /* pointer arithmetic */
684 decoder_mlt_ptr++;
685 }
686 }
687
688 /* if (category == 7) */
689 temp1 = sub(category,7);
690 test();
691 if (temp1 == 0)
692 {
693 index = sub(category,5);
694 noifillpos = mult(standard_deviation,noise_fill_factor[index]);
695 noifillneg = negate(noifillpos);
696
697 random_word = get_rand(randobj);
698 for (j=0; j<10; j++)
699 {
700 logic16();
701 test();
702 if ((random_word & 1) == 0)
703 {
704 temp1 = noifillneg;
705 move16();
706 }
707 else
708 {
709 temp1 = noifillpos;
710 move16();
711 }
712 *decoder_mlt_ptr++ = temp1;
713 move16();
714 random_word = shr_nocheck(random_word,1);
715 }
716 random_word = get_rand(randobj);
717 for (j=0; j<10; j++)
718 {
719 logic16();
720 test();
721 if ((random_word & 1) == 0)
722 {
723 temp1 = noifillneg;
724 move16();
725 }
726 else
727 {
728 temp1 = noifillpos;
729 move16();
730 }
731
732 *decoder_mlt_ptr++ = temp1;
733 move16();
734 random_word = shr_nocheck(random_word,1);
735 }
736 }
737 }
738
739 test();
740 if (ran_out_of_bits_flag)
741 bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
742}
743/****************************************************************************************
744 Function: index_to_array
745
746 Syntax: number_of_non_zero = index_to_array(Word16 index,
747 Word16 array[MAX_VECTOR_DIMENSION],
748 Word16 category)
749
750 inputs: Word16 index
751 Word16 category
752
753 outputs: Word16 array[MAX_VECTOR_DIMENSION] - used in decoder to access
754 mlt_quant_centroid table
755
756 Word16 number_of_non_zero - number of non zero elements
757 in the array
758
759 Description: Computes an array of sign bits with the length of the category vector
760 Returns the number of sign bits and the array
761
762 WMOPS: 7kHz | 24kbit | 32kbit
763 -------|--------------|----------------
764 AVG | 0.00 | 0.00
765 -------|--------------|----------------
766 MAX | 0.00 | 0.00
767 -------|--------------|----------------
768
769 14kHz | 24kbit | 32kbit | 48kbit
770 -------|--------------|----------------|----------------
771 AVG | 0.00 | 0.00 | 0.00
772 -------|--------------|----------------|----------------
773 MAX | 0.00 | 0.00 | 0.00
774 -------|--------------|----------------|----------------
775
776****************************************************************************************/
777Word16 index_to_array(Word16 index,Word16 *array,Word16 category)
778{
779 Word16 j,q,p;
780 Word16 number_of_non_zero;
781 Word16 max_bin_plus_one;
782 Word16 inverse_of_max_bin_plus_one;
783 Word16 temp;
784
785 number_of_non_zero = 0;
786 move16();
787
788 p = index;
789 move16();
790
791 max_bin_plus_one = add(max_bin[category],1);
792 inverse_of_max_bin_plus_one = max_bin_plus_one_inverse[category];
793 move16();
794
795 temp = sub(vector_dimension[category],1);
796 for (j=temp; j>=0; j--)
797 {
798 q = mult(p,inverse_of_max_bin_plus_one);
799 temp = extract_l(L_mult0(q,max_bin_plus_one));
800 array[j] = sub(p,temp);
801 move16();
802
803 p = q;
804 move16();
805
806 temp = array[j];
807 move16();
808 test();
809 if (temp != 0)
810 number_of_non_zero = add(number_of_non_zero,1);
811 }
812 return(number_of_non_zero);
813}
814/***************************************************************************
815 Function: test_4_frame_errors
816
817 Syntax: void test_4_frame_errors(Bit_Obj *bitobj,
818 Word16 number_of_regions,
819 Word16 num_categorization_control_possibilities,
820 Word16 *frame_error_flag,
821 Word16 categorization_control,
822 Word16 *absolute_region_power_index)
823
824 inputs: bit_obj
825 number_of_regions
826 num_categorization_control_possibilities
827 frame_error_flag
828 categorization_control
829 absolute_region_power_index
830
831
832 outputs: frame_error_flag
833
834
835
836
837 Description: Tests for error conditions and sets the frame_error_flag accordingly
838
839 Design Notes:
840
841 WMOPS: 7kHz | 24kbit | 32kbit
842 -------|--------------|----------------
843 AVG | 0.01 | 0.01
844 -------|--------------|----------------
845 MAX | 0.04 | 0.08
846 -------|--------------|----------------
847
848 14kHz | 24kbit | 32kbit | 48kbit
849 -------|--------------|----------------|----------------
850 AVG | 0.01 | 0.01 | 0.01
851 -------|--------------|----------------|----------------
852 MAX | 0.02 | 0.06 | 0.08
853 -------|--------------|----------------|----------------
854
855***************************************************************************/
856void test_4_frame_errors(Bit_Obj *bitobj,
857 Word16 number_of_regions,
858 Word16 num_categorization_control_possibilities,
859 Word16 *frame_error_flag,
860 Word16 categorization_control,
861 Word16 *absolute_region_power_index)
862{
863 Word16 region;
864 Word16 i;
865 Word16 temp;
866 Word32 acca;
867 Word32 accb;
868
869 /* Test for bit stream errors. */
870
871 test();
872 if (bitobj->number_of_bits_left > 0)
873 {
874 for (i=0; i<bitobj->number_of_bits_left; i++)
875 {
876 get_next_bit(bitobj);
877 test();
878 if (bitobj->next_bit == 0)
879 {
880 *frame_error_flag = 1;
881 move16();
882 }
883 }
884 }
885 else
886 {
887 temp = sub(categorization_control,sub(num_categorization_control_possibilities,1));
888 test();
889 if (temp < 0)
890 {
891 test();
892 if (bitobj->number_of_bits_left < 0)
893 {
894 *frame_error_flag |= 2;
895 logic16();
896 }
897 }
898 }
899
900 /* checks to ensure that abs_region_power_index is within range */
901 /* the error flag is set if it is out of range */
902 for (region=0; region<number_of_regions; region++)
903 {
904 /* the next two lines of comments were modified in release 1.2
905 * to correct the description of the range of
906 * absolute_region_power_index[] to be tested in the next
907 * 9 lines of code.
908 */
909 /* if ((absolute_region_power_index[region] > 31) ||
910 (absolute_region_power_index[region] < -8) */
911
912 acca = L_add(absolute_region_power_index[region],ESF_ADJUSTMENT_TO_RMS_INDEX);
913 accb = L_sub(acca,31);
914 acca = L_add(acca,8);
915 test();
916
917 /* the next line was modifed in release 1.2 to
918 * correct miss typed code and error checking.
919 */
920 if ((accb > 0) || (acca < 0))
921 {
922 *frame_error_flag |= 4;
923 logic16();
924 }
925 }
926
927}
928/***************************************************************************
929 Function: error_handling
930
931 Syntax: void error_handling(Word16 number_of_coefs,
932 Word16 number_of_valid_coefs,
933 Word16 *frame_error_flag,
934 Word16 *decoder_mlt_coefs,
935 Word16 *old_decoder_mlt_coefs,
936 Word16 *p_mag_shift,
937 Word16 *p_old_mag_shift)
938
939 inputs: number_of_coefs
940 number_of_valid_coefs
941 frame_error_flag
942 old_decoder_mlt_coefs
943 p_old_mag_shift
944
945
946 outputs: decoder_mlt_coefs
947 old_decoder_mlt_coefs
948 p_mag_shift
949 p_old_mag_shift
950
951
952
953 Description: If both the current and previous frames are errored,
954 set the mlt coefficients to 0. If only the current frame
955 is errored, then repeat the previous frame's mlt coefficients.
956
957 Design Notes:
958
959 WMOPS: 7kHz | 24kbit | 32kbit
960 -------|--------------|----------------
961 AVG | 0.02 | 0.02
962 -------|--------------|----------------
963 MAX | 0.03 | 0.03
964 -------|--------------|----------------
965
966 14kHz | 24kbit | 32kbit | 48kbit
967 -------|--------------|----------------|----------------
968 AVG | 0.03 | 0.03 | 0.03
969 -------|--------------|----------------|----------------
970 MAX | 0.03 | 0.03 | 0.06
971 -------|--------------|----------------|----------------
972
973***************************************************************************/
974void error_handling(Word16 number_of_coefs,
975 Word16 number_of_valid_coefs,
976 Word16 *frame_error_flag,
977 Word16 *decoder_mlt_coefs,
978 Word16 *old_decoder_mlt_coefs,
979 Word16 *p_mag_shift,
980 Word16 *p_old_mag_shift)
981{
982 Word16 i;
983
984 test();
985 if (*frame_error_flag != 0)
986 {
987
988 for (i = 0; i < number_of_valid_coefs; i++)
989 {
990 decoder_mlt_coefs[i] = old_decoder_mlt_coefs[i];
991 move16();
992 }
993
994 for (i = 0; i < number_of_valid_coefs; i++)
995 {
996 old_decoder_mlt_coefs[i] = 0;
997 move16();
998 }
999
1000 *p_mag_shift = *p_old_mag_shift;
1001 move16();
1002
1003 *p_old_mag_shift = 0;
1004 move16();
1005 }
1006 else
1007 {
1008 /* Store in case next frame is errored. */
1009 for (i = 0; i < number_of_valid_coefs; i++)
1010 {
1011 old_decoder_mlt_coefs[i] = decoder_mlt_coefs[i];
1012 move16();
1013 }
1014
1015 *p_old_mag_shift = *p_mag_shift;
1016 move16();
1017 }
1018
1019
1020 /* Zero out the upper 1/8 of the spectrum. */
1021 for (i = number_of_valid_coefs; i < number_of_coefs; i++)
1022 {
1023 decoder_mlt_coefs[i] = 0;
1024 move16();
1025 }
1026
1027}
1028/****************************************************************************************
1029 Function: get_next_bit
1030
1031 Syntax: void get_next_bit(Bit_Obj *bitobj)
1032
1033 Description: Returns the next bit in the current word inside the bit object
1034
1035 WMOPS: 7kHz | 24kbit | 32kbit
1036 -------|--------------|----------------
1037 AVG | 0.00 | 0.00
1038 -------|--------------|----------------
1039 MAX | 0.00 | 0.00
1040 -------|--------------|----------------
1041
1042 14kHz | 24kbit | 32kbit | 48kbit
1043 -------|--------------|----------------|----------------
1044 AVG | 0.00 | 0.00 | 0.00
1045 -------|--------------|----------------|----------------
1046 MAX | 0.00 | 0.00 | 0.00
1047 -------|--------------|----------------|----------------
1048
1049****************************************************************************************/
1050void get_next_bit(Bit_Obj *bitobj)
1051{
1052 Word16 temp;
1053
1054 test();
1055 if (bitobj->code_bit_count == 0)
1056 {
1057 bitobj->current_word = *bitobj->code_word_ptr++;
1058 move16();
1059 bitobj->code_bit_count = 16;
1060 move16();
1061 }
1062 bitobj->code_bit_count = sub(bitobj->code_bit_count,1);
1063 temp = shr_nocheck(bitobj->current_word,bitobj->code_bit_count);
1064 logic16();
1065 bitobj->next_bit = (Word16 )(temp & 1);
1066
1067}
1068/****************************************************************************************
1069 Function: get_rand
1070
1071 Syntax: Word16 get_rand(Rand_Obj *randobj)
1072
1073 Description: Returns a random Word16 based on the seeds inside the rand object
1074
1075 WMOPS: 7kHz | 24kbit | 32kbit
1076 -------|--------------|----------------
1077 AVG | 0.00 | 0.00
1078 -------|--------------|----------------
1079 MAX | 0.00 | 0.00
1080 -------|--------------|----------------
1081
1082 14kHz | 24kbit | 32kbit | 48kbit
1083 -------|--------------|----------------|----------------
1084 AVG | 0.00 | 0.00 | 0.00
1085 -------|--------------|----------------|----------------
1086 MAX | 0.00 | 0.00 | 0.00
1087 -------|--------------|----------------|----------------
1088
1089****************************************************************************************/
1090Word16 get_rand(Rand_Obj *randobj)
1091{
1092 Word16 random_word;
1093 Word32 acca;
1094
1095 acca = L_add(randobj->seed0,randobj->seed3);
1096 random_word = extract_l(acca);
1097
1098 logic16();
1099 test();
1100 if ((random_word & 32768L) != 0)
1101 random_word = add(random_word,1);
1102
1103 randobj->seed3 = randobj->seed2;
1104 move16();
1105 randobj->seed2 = randobj->seed1;
1106 move16();
1107 randobj->seed1 = randobj->seed0;
1108 move16();
1109 randobj->seed0 = random_word;
1110 move16();
1111
1112 return(random_word);
1113}