static void scfCount(const short *scalefacGain, const unsigned short *maxValueInSfb, SECTION_DATA * sectionData) { /* counter */ int i = 0; /* section counter */ int j = 0; /* sfb counter */ int k = 0; /* current section auxiliary counter */ int m = 0; /* other section auxiliary counter */ int n = 0; /* other sfb auxiliary counter */ /* further variables */ int lastValScf = 0; int deltaScf = 0; int found = 0; int scfSkipCounter = 0; COUNT_sub_start("scfCount"); MOVE(9); /* counting previous operations */ INDIRECT(1); MOVE(1); sectionData->scalefacBits = 0; BRANCH(1); if (scalefacGain == NULL) { COUNT_sub_end(); return; } INDIRECT(1); MOVE(2); lastValScf = 0; sectionData->firstScf = 0; PTR_INIT(1); /* sectionData->section[] */ INDIRECT(1); LOOP(1); for (i = 0; i < sectionData->noOfSections; i++) { ADD(1); BRANCH(1); if (sectionData->section[i].codeBook != CODE_BOOK_ZERO_NO) { INDIRECT(1); MOVE(1); sectionData->firstScf = sectionData->section[i].sfbStart; INDIRECT(1); MOVE(1); lastValScf = scalefacGain[sectionData->firstScf]; break; } } PTR_INIT(1); /* sectionData->section[] */ INDIRECT(1); LOOP(1); for (i = 0; i < sectionData->noOfSections; i++) { ADD(2); LOGIC(1); BRANCH(1); if ((sectionData->section[i].codeBook != CODE_BOOK_ZERO_NO) && (sectionData->section[i].codeBook != CODE_BOOK_PNS_NO)) { PTR_INIT(2); /* maxValueInSfb[] scalefacGain[] */ ADD(1); LOOP(1); for (j = sectionData->section[i].sfbStart; j < sectionData->section[i].sfbStart + sectionData->section[i].sfbCnt; j++) { BRANCH(1); if (maxValueInSfb[j] == 0) { MOVE(1); found = 0; BRANCH(1); if (scfSkipCounter == 0) { ADD(3); BRANCH(1); if (j == (sectionData->section[i].sfbStart + sectionData->section[i].sfbCnt - 1) ) { MOVE(1); found = 0; } else { PTR_INIT(2); /* maxValueInSfb[] scalefacGain[] */ LOOP(1); for (k = (j+1); k < sectionData->section[i].sfbStart + sectionData->section[i].sfbCnt; k++) { BRANCH(1); if (maxValueInSfb[k] != 0) { MOVE(1); found = 1; ADD(2); MISC(1); BRANCH(1); if ( (abs(scalefacGain[k] - lastValScf)) < CODE_BOOK_SCF_LAV) { MOVE(1); deltaScf = 0; } else { ADD(1); MULT(1); deltaScf = -(scalefacGain[j] - lastValScf); MOVE(2); lastValScf = scalefacGain[j]; scfSkipCounter = 0; } break; } /* count scalefactor skip */ ADD(1); scfSkipCounter = scfSkipCounter + 1; } } /* search for the next maxValueInSfb[] != 0 in all other sections */ PTR_INIT(1); /* sectionData->section[] */ INDIRECT(1); LOOP(1); for (m = (i+1); (m < sectionData->noOfSections) && (found == 0); m++) { ADD(2); LOGIC(1); BRANCH(1); if ((sectionData->section[m].codeBook != CODE_BOOK_ZERO_NO) && (sectionData->section[m].codeBook != CODE_BOOK_PNS_NO)) { PTR_INIT(2); /* maxValueInSfb[] scalefacGain[] */ LOOP(1); for (n = sectionData->section[m].sfbStart; n < sectionData->section[m].sfbStart + sectionData->section[m].sfbCnt; n++) { BRANCH(1); if (maxValueInSfb[n] != 0) { MOVE(1); found = 1; ADD(2); MISC(1); BRANCH(1); if ( (abs(scalefacGain[n] - lastValScf)) < CODE_BOOK_SCF_LAV) { MOVE(1); deltaScf = 0; } else { ADD(1); MULT(1); deltaScf = -(scalefacGain[j] - lastValScf); MOVE(2); lastValScf = scalefacGain[j]; scfSkipCounter = 0; } break; } ADD(1); scfSkipCounter = scfSkipCounter + 1; } } } BRANCH(1); if (found == 0) { MOVE(2); deltaScf = 0; scfSkipCounter = 0; } } else { MOVE(1); deltaScf = 0; ADD(1); scfSkipCounter = scfSkipCounter - 1; } } else { ADD(1); MULT(1); deltaScf = -(scalefacGain[j] - lastValScf); MOVE(1); lastValScf = scalefacGain[j]; } INDIRECT(1); FUNC(1); ADD(1); STORE(1); sectionData->scalefacBits += bitCountScalefactorDelta(deltaScf); } } } COUNT_sub_end(); }
/******************************************************************************* * * functionname: scfCount * returns : --- * description : count bits used by scalefactors. * ********************************************************************************/ static void scfCount(const Word16 *scalefacGain, const UWord16 *maxValueInSfb, SECTION_DATA * sectionData) { SECTION_INFO *psectionInfo; SECTION_INFO *psectionInfom; /* counter */ Word32 i = 0; /* section counter */ Word32 j = 0; /* sfb counter */ Word32 k = 0; /* current section auxiliary counter */ Word32 m = 0; /* other section auxiliary counter */ Word32 n = 0; /* other sfb auxiliary counter */ /* further variables */ Word32 lastValScf = 0; Word32 deltaScf = 0; Flag found = 0; Word32 scfSkipCounter = 0; sectionData->scalefacBits = 0; if (scalefacGain == NULL) { return; } lastValScf = 0; sectionData->firstScf = 0; psectionInfo = sectionData->sectionInfo; for (i=0; i<sectionData->noOfSections; i++) { if (psectionInfo->codeBook != CODE_BOOK_ZERO_NO) { sectionData->firstScf = psectionInfo->sfbStart; lastValScf = scalefacGain[sectionData->firstScf]; break; } psectionInfo += 1; } psectionInfo = sectionData->sectionInfo; for (i=0; i<sectionData->noOfSections; i++, psectionInfo += 1) { if (psectionInfo->codeBook != CODE_BOOK_ZERO_NO && psectionInfo->codeBook != CODE_BOOK_PNS_NO) { for (j = psectionInfo->sfbStart; j < (psectionInfo->sfbStart + psectionInfo->sfbCnt); j++) { /* check if we can repeat the last value to save bits */ if (maxValueInSfb[j] == 0) { found = 0; if (scfSkipCounter == 0) { /* end of section */ if (j - ((psectionInfo->sfbStart + psectionInfo->sfbCnt) - 1) == 0) { found = 0; } else { for (k = j + 1; k < psectionInfo->sfbStart + psectionInfo->sfbCnt; k++) { if (maxValueInSfb[k] != 0) { int tmp = L_abs(scalefacGain[k] - lastValScf); found = 1; if ( tmp < CODE_BOOK_SCF_LAV) { /* save bits */ deltaScf = 0; } else { /* do not save bits */ deltaScf = lastValScf - scalefacGain[j]; lastValScf = scalefacGain[j]; scfSkipCounter = 0; } break; } /* count scalefactor skip */ scfSkipCounter = scfSkipCounter + 1; } } psectionInfom = psectionInfo + 1; /* search for the next maxValueInSfb[] != 0 in all other sections */ for (m = i + 1; (m < sectionData->noOfSections) && (found == 0); m++) { if ((psectionInfom->codeBook != CODE_BOOK_ZERO_NO) && (psectionInfom->codeBook != CODE_BOOK_PNS_NO)) { for (n = psectionInfom->sfbStart; n < (psectionInfom->sfbStart + psectionInfom->sfbCnt); n++) { if (maxValueInSfb[n] != 0) { found = 1; if ( (abs_s(scalefacGain[n] - lastValScf) < CODE_BOOK_SCF_LAV)) { deltaScf = 0; } else { deltaScf = (lastValScf - scalefacGain[j]); lastValScf = scalefacGain[j]; scfSkipCounter = 0; } break; } /* count scalefactor skip */ scfSkipCounter = scfSkipCounter + 1; } } psectionInfom += 1; } if (found == 0) { deltaScf = 0; scfSkipCounter = 0; } } else { deltaScf = 0; scfSkipCounter = scfSkipCounter - 1; } } else { deltaScf = lastValScf - scalefacGain[j]; lastValScf = scalefacGain[j]; } sectionData->scalefacBits += bitCountScalefactorDelta(deltaScf); } } } }