123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- #include "gc_pred.h"
- const char gc_pred_id[] = "@(#)$Id $" gc_pred_h;
- #include <stdio.h>
- #include <stdlib.h>
- #include "typedef.h"
- #include "basic_op.h"
- #include "oper_32b.h"
- #include "cnst.h"
- #include "count.h"
- #include "log2.h"
- #include "copy.h"
- #define NPRED 4
- static const Word16 pred[NPRED] = {5571, 4751, 2785, 1556};
- #define MEAN_ENER_MR122 783741L
- static const Word16 pred_MR122[NPRED] = {44, 37, 22, 12};
- #define MIN_ENERGY -14336
- #define MIN_ENERGY_MR122 -2381
- int gc_pred_init (gc_predState **state)
- {
- gc_predState* s;
- if (state == (gc_predState **) NULL){
- wfprintf(stderr, "gc_pred_init: invalid parameter\n");
- return -1;
- }
- *state = NULL;
-
- if ((s= (gc_predState *) wmalloc(sizeof(gc_predState))) == NULL){
- wfprintf(stderr, "gc_pred_init: can not malloc state structure\n");
- return -1;
- }
- gc_pred_reset(s);
- *state = s;
- return 0;
- }
- int gc_pred_reset (gc_predState *state)
- {
- Word16 i;
- if (state == (gc_predState *) NULL){
- wfprintf(stderr, "gc_pred_reset: invalid parameter\n");
- return -1;
- }
- for(i = 0; i < NPRED; i++)
- {
- state->past_qua_en[i] = MIN_ENERGY;
- state->past_qua_en_MR122[i] = MIN_ENERGY_MR122;
- }
- return 0;
- }
- void gc_pred_exit (gc_predState **state)
- {
- if (state == NULL || *state == NULL)
- return;
-
- wfree(*state);
- *state = NULL;
- return;
- }
- void
- gc_pred_copy(
- gc_predState *st_src,
- gc_predState *st_dest
- )
- {
- Copy (st_src->past_qua_en, st_dest->past_qua_en, NPRED);
- Copy (st_src->past_qua_en_MR122, st_dest->past_qua_en_MR122, NPRED);
- }
- void
- gc_pred(
- gc_predState *st,
- enum Mode mode,
- Word16 *code,
-
- Word16 *exp_gcode0,
- Word16 *frac_gcode0,
- Word16 *exp_en,
-
- Word16 *frac_en
-
- )
- {
- Word16 i;
- Word32 ener_code;
- Word16 exp, frac;
-
- ener_code = L_mac_ex((Word32) 0, code[0], code[0]);
-
-
- for (i = 1; i < L_SUBFR; i++)
- ener_code = L_mac_ex(ener_code, code[i], code[i]);
-
- test ();
- if (sub_ex (mode, MR122) == 0)
- {
- Word32 ener;
-
- ener_code = L_mult_ex (round_ex (ener_code), 26214);
-
-
- Log2(ener_code, &exp, &frac);
- ener_code = L_Comp (sub_ex (exp, 30), frac);
-
-
- ener = MEAN_ENER_MR122; move32 ();
- for (i = 0; i < NPRED; i++)
- {
- ener = L_mac_ex (ener, st->past_qua_en_MR122[i], pred_MR122[i]);
-
-
- }
-
- ener = L_shr_ex (L_sub_ex (ener, ener_code), 1);
- L_Extract(ener, exp_gcode0, frac_gcode0);
- }
- else
- {
- Word32 L_tmp;
- Word16 exp_code, gcode0;
-
-
- exp_code = norm_l_ex (ener_code);
- ener_code = L_shl_ex (ener_code, exp_code);
-
-
- Log2_norm (ener_code, exp_code, &exp, &frac);
-
-
- L_tmp = Mpy_32_16(exp, frac, -24660);
-
- if (test (), sub_ex (mode, MR102) == 0)
- {
-
- L_tmp = L_mac_ex(L_tmp, 16678, 64);
- }
- else if (test (), sub_ex (mode, MR795) == 0)
- {
-
- *frac_en = extract_h_ex (ener_code); move16 ();
- *exp_en = sub_ex (-11, exp_code); move16 ();
-
- L_tmp = L_mac_ex(L_tmp, 17062, 64);
- }
- else if (test (), sub_ex (mode, MR74) == 0)
- {
-
- L_tmp = L_mac_ex(L_tmp, 32588, 32);
- }
- else if (test (), sub_ex (mode, MR67) == 0)
- {
-
- L_tmp = L_mac_ex(L_tmp, 32268, 32);
- }
- else
- {
-
- L_tmp = L_mac_ex(L_tmp, 16678, 64);
- }
-
-
- L_tmp = L_shl_ex(L_tmp, 10);
- for (i = 0; i < 4; i++)
- L_tmp = L_mac_ex(L_tmp, pred[i], st->past_qua_en[i]);
-
- gcode0 = extract_h_ex(L_tmp);
-
-
-
- test ();
- if (sub_ex (mode, MR74) == 0)
- L_tmp = L_mult_ex(gcode0, 5439);
- else
- L_tmp = L_mult_ex(gcode0, 5443);
- L_tmp = L_shr_ex(L_tmp, 8);
- L_Extract(L_tmp, exp_gcode0, frac_gcode0);
- }
- }
- void gc_pred_update(
- gc_predState *st,
- Word16 qua_ener_MR122,
-
- Word16 qua_ener
-
- )
- {
- Word16 i;
- for (i = 3; i > 0; i--)
- {
- st->past_qua_en[i] = st->past_qua_en[i - 1]; move16 ();
- st->past_qua_en_MR122[i] = st->past_qua_en_MR122[i - 1]; move16 ();
- }
- st->past_qua_en_MR122[0] = qua_ener_MR122;
- move16 ();
- st->past_qua_en[0] = qua_ener;
- move16 ();
- }
- void gc_pred_average_limited(
- gc_predState *st,
- Word16 *ener_avg_MR122,
-
- Word16 *ener_avg
-
- )
- {
- Word16 av_pred_en;
- Word16 i;
-
- av_pred_en = 0; move16 ();
- for (i = 0; i < NPRED; i++)
- {
- av_pred_en = add_ex (av_pred_en, st->past_qua_en_MR122[i]);
- }
-
- av_pred_en = mult_ex (av_pred_en, 8192);
-
- test ();
- if (sub_ex (av_pred_en, MIN_ENERGY_MR122) < 0)
- {
- av_pred_en = MIN_ENERGY_MR122; move16 ();
- }
- *ener_avg_MR122 = av_pred_en; move16 ();
-
- av_pred_en = 0; move16 ();
- for (i = 0; i < NPRED; i++)
- {
- av_pred_en = add_ex (av_pred_en, st->past_qua_en[i]);
- }
-
- av_pred_en = mult_ex (av_pred_en, 8192);
-
- test ();
- if (sub_ex (av_pred_en, MIN_ENERGY) < 0)
- {
- av_pred_en = MIN_ENERGY; move16 ();
- }
- *ener_avg = av_pred_en; move16 ();
- }
|