Home | History | Annotate | Download | only in lib

Lines Matching refs:cep

154  //    Function:    subobject definition for the cep processing
155 // Shortcut: cep
244 static void initSmoothing(cep_subobj_t * cep);
250 static void invMatrix(cep_subobj_t * cep, picoos_uint16 N,
254 static picoos_uint8 makeWUWandWUm(cep_subobj_t * cep, picokpdf_PdfMUL pdf,
268 static void treat_phone(cep_subobj_t * cep, picodata_itemhead_t * ihead);
281 * initialization of a cep PU (processing unit)
282 * @param this : handle to a cep PU struct
291 cep_subobj_t * cep;
295 cep = (cep_subobj_t *) this->subObj;
297 cep->inBufSize = PICODATA_BUFSIZE_CEP;
298 cep->inReadPos = 0;
299 cep->inWritePos = 0;
301 cep->headxBottom = cep->headxWritePos = 0;
302 cep->cbufBufSize = PICOCEP_MAXSIZE_CBUF;
303 cep->cbufWritePos = 0;
305 cep->outBufSize = PICODATA_MAX_ITEMSIZE;
306 cep->outReadPos = 0;
307 cep->outWritePos = 0;
309 cep->indexReadPos = 0;
310 cep->indexWritePos = 0;
312 cep->outXCepReadPos = 0;
313 cep->outXCepWritePos = 0;
314 cep->outVoicedReadPos = 0;
315 cep->outVoicedWritePos = 0;
316 cep->outF0ReadPos = 0;
317 cep->outF0WritePos = 0;
319 cep->needMoreInput = 0;
320 cep->inIgnoreState = 0;
321 cep->sentenceEnd = FALSE;
322 cep->procState = PICOCEP_STEPSTATE_COLLECT;
324 cep->nNumFrames = 0;
329 cep->activeEndPos = PICOCEP_MAXWINLEN;
333 cep->pdflfz = picokpdf_getPdfMUL(
337 cep->pdfmgc = picokpdf_getPdfMUL(
341 /* cep->phones =
346 cep->framehead.type = PICODATA_ITEM_FRAME_PAR;
347 cep->framehead.info1 = PICOCEP_OUT_DATA_FORMAT;
348 cep->framehead.info2 = cep->pdfmgc->ceporder;
349 cep->framehead.len = sizeof(picoos_uint16) + (cep->framehead.info2 + 4)
351 cep->scmeanpowLFZ = cep->pdflfz->bigpow - cep->pdflfz->meanpow;
352 cep->scmeanpowMGC = cep->pdfmgc->bigpow - cep->pdfmgc->meanpow;
354 cep->scmeanLFZ = (1 << (picoos_uint32) cep->scmeanpowLFZ);
356 cep->scmeanMGC = (1 << (picoos_uint32) cep->scmeanpowMGC);
360 initSmoothing(cep);
367 * termination of a cep PU (processing unit)
368 * @param this : handle to a cep PU struct
380 * deallocation of a cep PU internal sub object
381 * @param this : handle to a cep PU struct
399 cep_subobj_t * cep = (cep_subobj_t *) this->subObj;
400 picoos_deallocate(this->common->mm, (void *) &cep->outXCep);
401 picoos_deallocate(this->common->mm, (void *) &cep->outVoiced);
402 picoos_deallocate(this->common->mm, (void *) &cep->outF0);
409 * creates a new cep PU (processing unit)
426 cep_subobj_t * cep;
440 cep = (cep_subobj_t *) this->subObj;
448 cep->outF0 = (picoos_int16 *) picoos_allocate(this->common->mm,
451 cep->outXCep = (picoos_int16 *) picoos_allocate(this->common->mm,
454 cep->outVoiced = (picoos_uint8 *) picoos_allocate(this->common->mm,
457 if ((NULL == cep->outF0) || (NULL == cep->outXCep) || (NULL
458 == cep->outVoiced)) {
459 picoos_deallocate(this->common->mm, (void *) &(cep->outF0));
460 picoos_deallocate(this->common->mm, (void *) &(cep->outXCep));
461 picoos_deallocate(this->common->mm, (void *) &(cep->outVoiced));
462 picoos_deallocate(mm, (void*) &cep);
805 * @param cep : the CEP PU sub-object handle
809 static void initSmoothing(cep_subobj_t * cep)
811 cep->xi[0] = 1;
812 cep->xi[1] = -1;
813 cep->xi[2] = 2;
814 cep->xi[3] = -4;
815 cep->xi[4] = 2;
816 cep->xsqi[0] = 1;
817 cep->xsqi[1] = 1;
818 cep->xsqi[2] = 4;
819 cep->xsqi[3] = 16;
820 cep->xsqi[4] = 4;
822 cep->x1[0] = -1;
823 cep->x1[1] = 2;
824 cep->xsq1[0] = 1;
825 cep->xsq1[1] = 4;
827 cep->x2[0] = -1;
828 cep->x2[1] = -4;
829 cep->x2[2] = 2;
830 cep->xsq2[0] = 1;
831 cep->xsq2[1] = 16;
832 cep->xsq2[2] = 4;
834 cep->xm[0] = 1;
835 cep->xm[1] = 2;
836 cep->xm[2] = -4;
837 cep->xsqm[0] = 1;
838 cep->xsqm[1] = 4;
839 cep->xsqm[2] = 16;
841 cep->xn[0] = 1;
842 cep->xn[1] = 2;
843 cep->xsqn[0] = 1;
844 cep->xsqn[1] = 4;
849 * @param cep : PU sub object pointer
862 static void invMatrix(cep_subobj_t * cep, picoos_uint16 N,
875 cep->invdiag0[0] = picocep_fixptInvDiagEle(cep->diag0[0], &rowscpow,
877 cep->diag1[0] = picocep_fixptinv((cep->diag1[0]) << rowscpow,
878 cep->invdiag0[0], bigpow, invpow, invDoubleDec); /* perform division via inverse */
879 cep->diag2[0] = picocep_fixptinv((cep->diag2[0]) << rowscpow,
880 cep->invdiag0[0], bigpow, invpow, invDoubleDec);
881 cep->WUm[0] = (cep->WUm[0]) << rowscpow; /* if diag0 too low, multiply LHS and RHS of row in matrix equation by 1<<rowscpow */
884 cep->WUm[j] = cep->WUm[j] - picocep_fixptmult(cep->diag1[j - 1],
885 cep->WUm[j - 1], bigpow, invDoubleDec);
887 cep->WUm[j] = cep->WUm[j] - picocep_fixptmult(cep->diag2[j - 2],
888 cep->WUm[j - 2], bigpow, invDoubleDec);
892 v1 = picocep_fixptmult((cep->diag1[j - 1]) / (1 << rowscpow),
893 cep->diag0[j - 1], bigpow, invDoubleDec); /* undo scaling by 1<<rowscpow because diag1(j-1) refers to symm ele in column j-1 not in row j-1 */
894 cep->diag0[j] = cep->diag0[j] - picocep_fixptmult(cep->diag1[j - 1],
897 v2 = picocep_fixptmult((cep->diag2[j - 2]) / (1 << prevrowscpow),
898 cep->diag0[j - 2], bigpow, invDoubleDec); /* undo scaling by 1<<prevrowscpow because diag1(j-2) refers to symm ele in column j-2 not in row j-2 */
899 cep->diag0[j] = cep->diag0[j] - picocep_fixptmult(
900 cep->diag2[j - 2], v2, bigpow, invDoubleDec);
903 cep->invdiag0[j] = picocep_fixptInvDiagEle(cep->diag0[j], &rowscpow,
905 cep->WUm[j] = (cep->WUm[j]) << rowscpow;
907 h = picocep_fixptmult(cep->diag2[j - 1], v1, bigpow, invDoubleDec);
908 cep->diag1[j] = picocep_fixptinv((cep->diag1[j] - h) << rowscpow,
909 cep->invdiag0[j], bigpow, invpow, invDoubleDec); /* eliminate column j below pivot */
912 cep->diag2[j] = picocep_fixptinv((cep->diag2[j]) << rowscpow,
913 cep->invdiag0[j], bigpow, invpow, invDoubleDec); /* eliminate column j below pivot */
919 cep->WUm[j] = picocep_fixptinv(cep->WUm[j], cep->invdiag0[j], bigpow,
922 cep->WUm[j] = picocep_fixptdivpow(cep
928 cep->WUm[j] = cep->WUm[j] - picocep_fixptmult(cep->diag1[j], cep->WUm[j
931 cep->WUm[j] = cep->WUm[j] - picocep_fixptmult(cep->diag2[j],
932 cep->WUm[j + 2], bigpow, invDoubleDec);
939 smoothcep[k] = (picoos_int16)(cep->WUm[j]/(1<<meanpow));
947 * @param cep : PU sub object pointer
959 static picoos_uint8 makeWUWandWUm(cep_subobj_t * cep, picokpdf_PdfMUL pdf,
976 x = cep->xi;
977 xsq = cep->xsqi;
984 x = cep->x1;
985 xsq = cep->xsq1;
989 x = cep->x2;
990 xsq = cep->xsq2;
996 x = cep->xm;
997 xsq = cep->xsqm;
1003 x = cep->xn;
1004 xsq = cep->xsqn;
1011 cep->diag0[i] = prev_diag0;
1012 cep->WUm[i] = prev_WUm;
1017 prev_diag0 = cep->diag0[i] = ivar << 2; /* multiply ivar by 4 (4 used to be first entry of xsq) */
1020 prev_WUm = cep->WUm[i] = mean << 1; /* multiply mean by 2 (2 used to be first entry of x) */
1028 cep->diag0[i] += xsq[j] * ivar;
1033 cep->WUm[i] += x[j] * mean;
1042 cep->diag0[i] += xsq[numd + j] * ivar;
1047 cep->WUm[i] += x[numd + j] * mean;
1051 cep->diag0[i] = (cep->diag0[i] + 2) / 4; /* long DIV with rounding */
1052 cep->WUm[i] = (cep->WUm[i] + 1) / 2; /* long DIV with rounding */
1058 cep->diag1[i] = prev_diag1;
1065 prev_diag1 = cep->diag1[i] = getFromPdf(pdf, vecstart,
1071 cep->diag1[i] = (picoos_int32)(pdf->content[k]) << pdf->bigpow;
1074 cep->diag1[i] = 0;
1078 cep->diag1[i] += prev_diag1_1;
1083 cep->diag1[i] += (picoos_int32)(pdf->content[k]) << pdf->bigpow; */
1088 cep->diag1[i] += prev_diag1_1;
1092 cep->diag1[i] *= -2;
1099 cep->diag2[i] = prev_diag2;
1104 cep->diag2[i] = (picoos_int32)(pdf->content[k]) << pdf->bigpow;
1108 cep->diag2[i] = getFromPdf(pdf, vecstart, cepnum, PICOCEP_WANTIVAR,
1112 cep->diag2[i] -= (ivar + 2) / 4;
1113 prev_diag2 = cep->diag2[i];
1377 * @param cep : the CEP PU sub object pointer
1382 static void treat_phone(cep_subobj_t * cep, picodata_itemhead_t * ihead)
1397 pos = cep->inReadPos + PICODATA_ITEM_HEADSIZE + state * 6;
1401 frames = get_pi_uint16(cep->inBuf, &pos);
1407 bufferFull = cep->indexWritePos >= PICOCEP_MAXWINLEN;
1414 indlfz = get_pi_uint16(cep->inBuf, &pos); /* lfz index */
1415 indlfz += -1 + cep->pdflfz->stateoffset[state]; /* transform index */
1416 indmgc = get_pi_uint16(cep->inBuf, &pos); /* mgc index */
1417 indmgc += -1 + cep->pdfmgc->stateoffset[state]; /* transform index */
1420 if ((cep->indexWritePos - frame) + frames > PICOCEP_MAXWINLEN) {
1422 frames = PICOCEP_MAXWINLEN - (cep->indexWritePos - frame);
1427 cep->indicesMGC[cep->indexWritePos] = indmgc;
1428 cep->indicesLFZ[cep->indexWritePos] = indlfz;
1429 cep->phoneId[cep->indexWritePos] = ihead->info1;
1430 cep->indexWritePos++;
1435 state, frames,cep->indexWritePos));
1439 frames = get_pi_uint16(cep->inBuf, &pos);
1443 cep->inReadPos = cep->nextInPos;
1445 PICODBG_DEBUG(("finished phone, advancing inReadPos to %i",cep->inReadPos));
1467 * performs a step of the cep processing
1478 register cep_subobj_t * cep;
1494 cep = (cep_subobj_t *) this->subObj;
1502 PICODBG_DEBUG(("doing pu state %i", cep->procState));
1504 switch (cep->procState) {
1513 &(cep->inBuf[cep->inWritePos]), cep->inBufSize
1514 - cep->inWritePos, &blen);
1524 cep->inWritePos += blen;
1525 cep->procState = PICOCEP_STEPSTATE_PROCESS_PARSE;
1529 cep->inReadPos = cep->inWritePos = 0;
1539 PICODBG_DEBUG(("getting info from inBuf in range: [%i,%i[", cep->inReadPos, cep->inWritePos));
1540 if (cep->inWritePos <= cep->inReadPos) {
1544 /* cep->needMoreInput = TRUE; */
1545 cep->inReadPos = cep->inWritePos = 0;
1546 cep->procState = PICOCEP_STEPSTATE_COLLECT;
1551 if (!picodata_is_valid_item(cep->inBuf + cep->inReadPos,
1552 cep->inWritePos - cep->inReadPos)) {
1555 cep->inBuf + cep->inReadPos, cep->inWritePos
1556 - cep->inReadPos, &ihead, &icontents);PICODBG_DEBUG(("PARSE bad item %s",picodata_head_to_string(&ihead,msgstr,PICOCEP_MSGSTR_SIZE)));
1561 sResult = picodata_get_iteminfo(cep->inBuf + cep->inReadPos,
1562 cep->inWritePos - cep->inReadPos, &ihead, &icontents);
1568 /* cep->needMoreInput = TRUE; */
1569 cep->inReadPos = cep->inWritePos = 0;
1570 cep->procState = PICOCEP_STEPSTATE_COLLECT;
1581 cep->nextInPos = PICODATA_ITEM_HEADSIZE + ihead.len;
1589 if (cep->inIgnoreState) {
1593 cep->inIgnoreState = 0;
1594 }PICODBG_DEBUG(("cep: PARSE consuming item of inBuf"));
1595 cep->inReadPos = cep->nextInPos;
1603 && (cep->indexWritePos > 0)) {
1605 cep->activeEndPos = cep->indexWritePos;
1606 cep->sentenceEnd = TRUE;
1608 PICODBG_DEBUG(("cep: PARSE found sentence terminator; setting activeEndPos to %i",cep->activeEndPos));
1609 cep->procState = PICOCEP_STEPSTATE_PROCESS_SMOOTH;
1613 PICODBG_DEBUG(("cep: PARSE treating PHONE"));
1614 treat_phone(cep, &ihead);
1620 cep->inIgnoreState = 1;
1626 if (cep->indexWritePos <= 0) {
1629 picodata_copy_item(cep->inBuf + cep->inReadPos,
1630 cep->inWritePos - cep->inReadPos,
1631 cep->outBuf, cep->outBufSize, &blen);
1632 cep->outWritePos += blen;
1634 (picoos_uint8 *)"cep: do forward item ",
1635 cep->outBuf, PICODATA_MAX_ITEMSIZE);
1637 cep->feedFollowState
1639 cep->procState = PICOCEP_STEPSTATE_FEED;
1640 } else if ((cep->headxWritePos < PICOCEP_MAXNR_HEADX)
1641 && (cep->cbufWritePos + ihead.len
1642 < cep->cbufBufSize)) {
1644 PICODBG_DEBUG(("unhandled item (type %c, length %i). Storing associated with index %i",ihead.type, ihead.len, cep->indexWritePos));
1647 cep->inBuf + cep->inReadPos,
1648 cep->inWritePos - cep->inReadPos,
1649 &(cep->headx[cep->headxWritePos].head),
1650 &(cep->cbuf[cep->cbufWritePos]),
1651 cep->cbufBufSize
1652 - cep->cbufWritePos, &clen);
1661 cep->headx[cep->headxWritePos].frame
1662 = cep->indexWritePos;
1665 cep->headx[cep->headxWritePos].cind
1666 = cep->cbufWritePos;
1667 cep->cbufWritePos += clen;
1669 cep->headx[cep->headxWritePos].cind = 0;
1671 cep->headxWritePos++;
1674 PICODBG_DEBUG(("PARSE is forced to smooth prematurely; setting activeEndPos to %i", cep->activeEndPos));
1675 cep->procState = PICOCEP_STEPSTATE_PROCESS_SMOOTH;
1680 }PICODBG_DEBUG(("cep: PARSE consuming item of inBuf"));
1681 cep->inReadPos = cep->nextInPos;
1696 N = cep->activeEndPos; /* numframes in current step */
1704 cep->outXCepReadPos = cep->outXCepWritePos = 0;
1705 cep->outVoicedReadPos = cep->outVoicedWritePos = 0;
1706 cep->outF0ReadPos = cep->outF0WritePos = 0;
1711 pdf = cep->pdflfz;
1713 if (cep->activeEndPos <= 0) {
1716 makeWUWandWUm(cep, pdf, cep->indicesLFZ, 0, N,
1718 invMatrix(cep, N, cep->outF0 + cep->outF0WritePos, cepnum, pdf,
1721 getDirect(pdf, cep->indicesLFZ, cep->activeEndPos,
1722 cepnum, cep->outF0 + cep->outF0WritePos);
1725 cep->outF0WritePos += cep->activeEndPos * pdf->ceporder;
1728 pdf = cep->pdfmgc;
1730 if (cep->activeEndPos <= 0) {
1733 makeWUWandWUm(cep, pdf, cep->indicesMGC, 0, N,
1735 invMatrix(cep, N, cep->outXCep
1736 + cep->outXCepWritePos, cepnum,
1740 getDirect(pdf, cep->indicesMGC, cep->activeEndPos,
1741 cepnum, cep->outXCep + cep->outXCepWritePos);
1744 cep->outXCepWritePos += cep->activeEndPos * pdf->ceporder;
1746 getVoiced(pdf, cep->indicesMGC, cep->activeEndPos, cep->outVoiced
1747 + cep->outVoicedWritePos);
1748 cep->outVoicedWritePos += cep->activeEndPos;
1753 cep->indexReadPos = 0;
1754 cep->procState = PICOCEP_STEPSTATE_PROCESS_FRAME;
1765 if ((cep->headxBottom < cep->headxWritePos)
1766 && (cep->headx[cep->headxBottom].frame
1767 <= cep->indexReadPos)) {
1773 &(cep->headx[cep->headxBottom].head),
1774 &(cep->cbuf[cep->headx[cep->headxBottom].cind]),
1775 cep->headx[cep->headxBottom].head.len, cep->outBuf,
1776 cep->outBufSize, &blen);
1777 cep->outWritePos += blen;
1780 cep->headxBottom++;
1783 cep->feedFollowState = PICOCEP_STEPSTATE_PROCESS_FRAME;
1784 cep->procState = PICOCEP_STEPSTATE_FEED;
1788 if (cep->indexReadPos < cep->activeEndPos) {
1792 cep->nNumFrames++;
1795 cep->activeEndPos, cep->indexReadPos, cep->indexWritePos
1798 /* create FRAME_PAR items from cep->outXX one by one */
1806 cep->outWritePos = cep->outReadPos = 0;
1807 cep->outBuf[cep->outWritePos++] = cep->framehead.type;
1808 cep->outBuf[cep->outWritePos++] = cep->framehead.info1;
1809 cep->outBuf[cep->outWritePos++] = cep->framehead.info2;
1810 cep->outBuf[cep->outWritePos++] = cep->framehead.len;
1812 PICODBG_DEBUG(("FRAME writing position after header: %i",cep->outWritePos));
1820 PICODBG_DEBUG(("FRAME reading phoneId[%i] = %c:",cep->indexReadPos, cep->phoneId[cep->indexReadPos]));
1824 = (picoos_uint16) cep->phoneId[cep->indexReadPos];
1827 (void *) &cep->outBuf[cep->outWritePos],
1830 cep->outWritePos += sizeof(tmpUint16);
1832 PICODBG_DEBUG(("FRAME writing position after phone id: %i",cep->outWritePos));
1834 for (i = 0; i < cep->pdflfz->ceporder; i++) {
1836 tmpUint16 = (cep->outVoiced[cep->outVoicedReadPos]
1837 & 0x01) ? cep->outF0[cep->outF0ReadPos]
1841 (void *) &cep->outBuf[cep->outWritePos],
1843 cep->outWritePos += sizeof(tmpUint16);
1846 = (picoos_uint16) (cep->outVoiced[cep->outVoicedReadPos]);
1848 (void *) &cep->outBuf[cep->outWritePos],
1850 cep->outWritePos += sizeof(tmpUint16);
1852 = (picoos_uint16) (cep->outF0[cep->outF0ReadPos]);
1854 (void *) &cep->outBuf[cep->outWritePos],
1856 cep->outWritePos += sizeof(tmpUint16);
1858 cep->outVoicedReadPos++;
1859 cep->outF0ReadPos++;
1862 PICODBG_DEBUG(("FRAME writing position after f0: %i",cep->outWritePos));
1864 for (i = 0; i < cep->pdfmgc->ceporder; i++) {
1865 tmpInt16 = cep->outXCep[cep->outXCepReadPos++];
1867 (void *) &cep->outBuf[cep->outWritePos],
1869 cep->outWritePos += sizeof(tmpInt16);
1872 PICODBG_DEBUG(("FRAME writing position after cepstrals: %i",cep->outWritePos));
1875 = (picoos_uint16) cep->indicesMGC[cep->indexReadPos++];
1878 (void *) &cep->outBuf[cep->outWritePos],
1881 PICODBG_DEBUG(("FRAME writing position after mgc index: %i",cep->outWritePos));
1883 cep->outWritePos += sizeof(tmpUint16);
1887 cep->feedFollowState = PICOCEP_STEPSTATE_PROCESS_FRAME;
1888 cep->procState = PICOCEP_STEPSTATE_FEED;
1890 } else if (cep->sentenceEnd) {
1893 cep->nNumFrames));
1894 cep->nNumFrames = 0;PICODBG_DEBUG(("FRAME no more active frames for this sentence"));
1897 initSmoothing(cep);
1898 cep->sentenceEnd = FALSE;
1899 cep->indexReadPos = cep->indexWritePos = 0;
1900 cep->activeEndPos = PICOCEP_MAXWINLEN;
1901 cep->headxBottom = cep->headxWritePos = 0;
1902 cep->cbufWritePos = 0;
1903 cep->procState = PICOCEP_STEPSTATE_PROCESS_PARSE;
1907 cep->procState = PICOCEP_STEPSTATE_PROCESS_PARSE;
1922 sResult = picodata_cbPutItem(this->cbOut, cep->outBuf,
1923 cep->outBufSize, &blen);
1931 if (cep->outBuf[0] != 'k') {
1933 (picoos_uint8 *)"cep: ",
1934 cep->outBuf, PICODATA_MAX_ITEMSIZE);
1941 if (cep->outReadPos >= cep->outWritePos) {
1942 cep->outReadPos = 0;
1943 cep->outWritePos = 0;
1945 cep->procState = cep->feedFollowState;
1946 PICODBG_DEBUG(("FEED ok, going back to procState %i", cep->procState));
1950 cep->procState = cep->feedFollowState;
1959 }/*end switch (cep->procState) */