?? vselp.c
字號:
if (packedStream) { if ((fpstream = fopen(OutFile, "w")) == NULL) HARAKIRI("Error creating code file\n", 2); } else { if ((fpstream = fopen(OutFile, WB)) == NULL) HARAKIRI("Error creating code file\n", 2); } } if (!encode_only && fpout == NULL) { GET_PAR_S(i, "Output speech file: ....... ", OutFile); if ((fpout = fopen(OutFile, WB)) == NULL) KILL(OutFile, 3); i++; } if (makeLog || performMeas && fplog == NULL) { GET_PAR_S(i, "Log file name: .............", LogFile); i++; fplog = fopen(LogFile, "w"); } } /* Define bitstream read/write functions */ get_codes = packedStream ? getCodesHex : getCodesBin; put_codes = packedStream ? putCodesHex : putCodesBin; /* Initialize parameters that are fixed but need to be calculated */ calcParams(); /* Allocate short data buffer, allocate buffers and fill tables */ shBuf = (short *) calloc((long)F_LEN, sizeof(short)); initTables(); /* allocation of coefficient space and initialization of pointers into */ /* this space */ initState(); /* fill input buffer, excluding last frame (this doesn't get high-passed) */ if (!decode_only) { fread(shBuf, sizeof(short), INBUFSIZ - F_LEN, fpin); tmpPtr = inBuf; shPtr = shBuf - 1;#if INTEL_FORMAT swap_byte(shPtr, (long)(INBUFSIZ - F_LEN));#endif for (endPtr = tmpPtr + INBUFSIZ - F_LEN; tmpPtr < endPtr; tmpPtr++) *tmpPtr = *++shPtr * inScale; } FILT4(inBuf, INBUFSIZ - F_LEN); /* HPF 1st INBUFSIZ-F_LEN points */ /*-------------------------------------------------------------------------*/ /* main loop */ while (1) { if (!quiet) fprintf(stderr, "%c\r", funny[frCnt % 8]); if (decode_only) goto receiveLabel; if (feof(fpin)) break; /* read one frame into short buffer, scale, and transfer into floating- */ /* point input buffer */ if ((numRead = fread(shBuf, sizeof(short), F_LEN, fpin)) < F_LEN) { /* Zero-pad the input buffer when no.of samples less than F_LEN */ short *eshPtr = shBuf + F_LEN; shPtr = shBuf + numRead; for (; shPtr < eshPtr; shPtr++) *shPtr = 0; } tmpPtr = inBuf + INBUFSIZ - F_LEN; shPtr = shBuf - 1;#if INTEL_FORMAT swap_byte(shBuf, F_LEN);#endif for (endPtr = tmpPtr + F_LEN; tmpPtr < endPtr; tmpPtr++) *tmpPtr = *++shPtr * inScale; /* ENCODER SIDE */ codes = codeBuf; /* reset code pointer to beginning of buffer */ /* hpf the last F_LEN of input */ FILT4(inBuf + INBUFSIZ - F_LEN, F_LEN); FLATV(); /* get reflection coefs and rq0. */ /* get direct-form coef's from rc's, calculate bandwidth- */ /* widened coefs */ RCTOA(T_NEW.k, T_NEW.a); widen(W_ALPHA, 't'); /* This for loop does coefficient interpolation (stored in I_CBUFF) */ /* and calculates the residual energy estimate, RS (stored in RS_BUFF), */ /* for all subframes. */ for (i = 0; i < N_SUB; i++) { if (i == N_SUB - 1) { /* Final subframe, no interpolation done. Move coefs and */ /* calculate RS. Store a duplicate of RS in RS_BUFF */ RQ_TMP = T_NEW.rq0; I_MOV(T_NEW, 2, RQ_TMP); *(RS_BUFF + 2 * N_SUB - 1) = *(RS_BUFF + 2 * N_SUB - 2); /* copy last rs. */ } else if (i * 2 == N_SUB - 2) { /* Middle subframe. Interpolate coefs. If result is */ /* unstable, use coefs from frame with larger energy. */ /* Perform a geometric average on last and current Rq's, */ /* use this value to calculate RS. */ /* Calculate another RS based on last or current rc's */ /* (if it has not been calculated already due to instability, */ /* if that is so, just copy it). */ RQ_TMP = sqrt(T_NEW.rq0 * T_OLD.rq0); if (T_NEW.rq0 > T_OLD.rq0) { us = INTERPOLATE(T_NEW, 2, T_OLD, i, RQ_TMP); if (us) *(RS_BUFF + 2 * i + 1) = *(RS_BUFF + 2 * i); else *(RS_BUFF + 2 * i + 1) = RES_ENG(RQ_TMP, T_NEW.k); } else { us = INTERPOLATE(T_OLD, 2, T_NEW, i, RQ_TMP); if (us) *(RS_BUFF + 2 * i + 1) = *(RS_BUFF + 2 * i); else *(RS_BUFF + 2 * i + 1) = RES_ENG(RQ_TMP, T_OLD.k); } } else if (i * 2 < N_SUB - 2) { /* Subframe closer to last frame. Interpolate coefs. */ /* If result is unstable, use last frame's coefs. */ /* Calculate RS based on last frame's Rq. Calculate */ /* another RS based on last rc's (if it has */ /* not been calculated already due to instability, if that */ /* is so, just copy it) */ RQ_TMP = T_OLD.rq0; us = INTERPOLATE(T_OLD, 2, T_NEW, i, RQ_TMP); if (us) *(RS_BUFF + 2 * i + 1) = *(RS_BUFF + 2 * i); else *(RS_BUFF + 2 * i + 1) = RES_ENG(RQ_TMP, T_OLD.k); } else { /* Subframe closer to current frame. Interpolate coefs. */ /* If result is unstable, use current frame's coefs. */ /* Calculate RS based on current frame's Rq. Calculate */ /* another RS based on current rc's (if it has */ /* not been calculated already due to instability, if that */ /* is so, just copy it) */ RQ_TMP = T_NEW.rq0; us = INTERPOLATE(T_NEW, 2, T_OLD, i, RQ_TMP); if (us) *(RS_BUFF + 2 * i + 1) = *(RS_BUFF + 2 * i); else *(RS_BUFF + 2 * i + 1) = RES_ENG(RQ_TMP, T_NEW.k); } } for (i = 0; i < N_SUB; i++) { sfCnt = i + 1; /* Load/point-to the values that */ /* are needed in the subframe processing. */ RS = *(RS_BUFF + i * 2); COEF = I_CBUFF + i * 2 * NP; W_COEF = COEF + NP; T_SUB(i); /* Do subframe processing. */ } /* perform delay on input buffer. */ tmpPtr2 = inBuf + F_LEN - 1; tmpPtr = inBuf; for (endPtr = tmpPtr + (INBUFSIZ - F_LEN); tmpPtr < endPtr; tmpPtr++) *tmpPtr = *++tmpPtr2; /* update xmt old values and pointers, */ /* new pointers set to old space. */ T_OLD.rq0 = T_NEW.rq0; tmpPtr = T_OLD.k; T_OLD.k = T_NEW.k; T_NEW.k = tmpPtr; tmpPtr = T_OLD.a; T_OLD.a = T_NEW.a; T_NEW.a = tmpPtr; tmpPtr = T_OLD.widen; T_OLD.widen = T_NEW.widen; T_NEW.widen = tmpPtr; /* output routine for packed ascii-hex output. */ if (encode_only) bs_saved += put_codes(fpstream, codeBuf);receiveLabel: if (decode_only) { if ((i = get_codes(fpstream, codeBuf))==0) { /* Quit on end of file OR abort on error */ if(feof(fpstream)) break; else HARAKIRI("Error reading bitstream file\n", 3); } else bs_read += i; } /* output routine for diagnostic code output */ if (makeLog) putCodesLog(); /*------------------------------------------------------------------------*/ /* --- DECODER SIDE --- */ if (!encode_only) { /* get Rq0 and rc's from codes */ codes = codeBuf; R_NEW.rq0 = lookup(0); tmpPtr = R_NEW.k; for (endPtr = tmpPtr + NP, i = 1; tmpPtr < endPtr; tmpPtr++, i++) *tmpPtr = lookup(i); /* get direct-form coef's from rc's, calculate bandwidth- */ /* widened coefs (denominator of spectral post-filter) and spectrally- */ /* smoothed numerator coefs. */ RCTOA(R_NEW.k, R_NEW.a); widen(POST_W_D, 'r'); A_SST(R_NEW.widen, R_NEW.sst); /* Calculate geometric average of Rq0's. */ RQ_HOLD = sqrt(R_NEW.rq0 * R_OLD.rq0); /* Calculate interpolated coefs for all subframes */ for (i = 0; i < N_SUB; i++) { if (i == N_SUB - 1) I_MOV(R_NEW, 3, R_NEW.rq0); else if (i * 2 == N_SUB - 2) { if (R_NEW.rq0 > R_OLD.rq0) INTERPOLATE(R_NEW, 3, R_OLD, i, RQ_HOLD); else INTERPOLATE(R_OLD, 3, R_NEW, i, RQ_HOLD); } else if (i * 2 < N_SUB - 2) INTERPOLATE(R_OLD, 3, R_NEW, i, R_OLD.rq0); else INTERPOLATE(R_NEW, 3, R_OLD, i, R_NEW.rq0); } for (i = 0; i < N_SUB; i++) { sfCnt = i + 1; /* Load/point-to values needed for */ /* subframe processing. */ RS = *(RS_BUFF + 2 * i); COEF = I_CBUFF + i * 3 * NP; W_COEF = COEF + NP; N_COEF = W_COEF + NP; R_SUB(); /* Do subframe processing. */ /* Scale and transfer synthesized speech to short buffer. Write to */ /* output file. */ tmpPtr = outBuf; shPtr = shBuf - 1; for (endPtr = tmpPtr + S_LEN; tmpPtr < endPtr; tmpPtr++) { if (*tmpPtr >= 0.0) { f1 = *tmpPtr * 32768.0 + 0.5; *++shPtr = (f1 >= 32768.0) ? 32767 : (short) f1; } else { f1 = *tmpPtr * 32768.0 - 0.5; *++shPtr = (f1 <= -32769.0) ? -32768 : (short) f1; } } fwrite(shBuf, sizeof(short), S_LEN, fpout); } } /* update rcv pointers */ R_OLD.rq0 = R_NEW.rq0; tmpPtr = R_OLD.k; R_OLD.k = R_NEW.k; R_NEW.k = tmpPtr; tmpPtr = R_OLD.a; R_OLD.a = R_NEW.a; R_NEW.a = tmpPtr; tmpPtr = R_OLD.widen; R_OLD.widen = R_NEW.widen; R_NEW.widen = tmpPtr; tmpPtr = R_OLD.sst; R_OLD.sst = R_NEW.sst; R_NEW.sst = tmpPtr; if (frCnt == finalCnt) { break; } frCnt++; } /* main loop end */ if (performMeas && !decode_only) printSnr(fplog); frCnt--; if (encode_only) { fprintf(stderr, "VSELP: %ld input samples encoded as %ld IS54 codes\n", (long)frCnt*(long)F_LEN, bs_saved); } else if (decode_only) { fprintf(stderr, "VSELP: %ld IS54 codes generated %ld output samples\n", bs_read, (long)frCnt*(long)F_LEN); } else { fprintf(stderr, "VSELP: %ld samples processed\n", (long)frCnt*(long)F_LEN); } /* Free memory */ free(shBuf); free(T_NEW.k); freeSpace();#ifdef VMS /* ** Fill the rest of the file with zeros */ if ((((long)frCnt*(long)F_LEN) % 256) != 0) { zero_values = 256 - (((long)frCnt*(long)F_LEN) % 256); zero_vector = (short *) calloc(zero_values,sizeof(short)); lwrite = fwrite(zero_vector,sizeof (short),zero_values,fpout); if (lwrite != zero_values) { printf (" Error writing zero vector \n"); exit (1); } }#endif /* Close files, if open */ if (fpin) fclose(fpin); if (fpout) fclose(fpout); if (fpcode) fclose(fpcode); if (fplog) fclose(fplog); if (fpstream) fclose(fpstream); /* Return OK status to the OS */ return 0;}/* ............................. End of main() ........................... *//* DEC/CMS REPLACEMENT HISTORY, Element VSELP.C *//* *4 28-AUG-1995 15:56:00 SCHROEDER "Change the date due th some changes in h-files" *//* *3 24-AUG-1995 11:52:08 STEGMANN "2nd update considering VMS 512-Byte record structure for output speech file" *//* *2 23-AUG-1995 14:15:37 KIRCHHERR "Update to run under OpenVMS/AXP" *//* *1 23-AUG-1995 11:02:30 KIRCHHERR "Original by UGST" *//* DEC/CMS REPLACEMENT HISTORY, Element VSELP.C */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -