1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| int main(int argc, char *argv[])
{
Longword length;
mode = ANALYSIS;
rate = RATE2400;
chwordsize = 8; // this is for packed bitstream
Shortword speech_in[BLOCK], speech_out[BLOCK];
Shortword bitBufSize, bitBufSize12, bitBufSize24;
/* size of the bitstream buffer */
BOOLEAN eof_reached = FALSE;
FILE *fp_in, *fp_out;
char in_name[100]="org.wav", out_name[100]="syn.wav";
/* ====== Open input, output, and parameter files ====== */
if ((fp_in = fopen(in_name,"rb")) == NULL){
fprintf(stderr, " ERROR: cannot read file %s.\n", in_name);
exit(1);
}
if ((fp_out = fopen(out_name,"wb")) == NULL){
fprintf(stderr, " ERROR: cannot write file %s.\n", out_name);
exit(1);
}
/* ====== Initialize MELP analysis and synthesis ====== */
if (rate == RATE2400)
frameSize = (Shortword) FRAME;
else
frameSize = (Shortword) BLOCK;
/* Computing bit=Num = rate * frameSize / FSAMP. Note that bitNum */
/* computes the number of bytes written to the channel and it has to be */
/* exact. We first carry out the division and then have the multiplica- */
/* tion with rounding. */
bitNum12 = 81;
bitNum24 = 54;
if( chwordsize == 8 ){
// packing the bitstream
bitBufSize12 = 11;
bitBufSize24 = 7;
}else if( chwordsize == 6 ){
bitBufSize12 = 14;
bitBufSize24 = 9;
}else{
fprintf(stderr,"Channel word size is wrong!\n");
exit(-1);
}
if (rate == RATE2400){
frameSize = FRAME;
bitBufSize = bitBufSize24;
} else {
frameSize = BLOCK;
bitBufSize = bitBufSize12;
}
if (mode != SYNTHESIS)
melp_ana_init();
/* ====== Run MELP coder on input signal ====== */
frame_count = 0;
eof_reached = FALSE;
while (!eof_reached){ // la boucle principale , le compteur c'est frame_count, elle s’arrête lorsque ( length < bitBufSize24)
fprintf(stderr, "Frame = %ld\r", frame_count);
/* Perform MELP analysis */
if (mode != SYNTHESIS){
/* read input speech */
length = readbl(speech_in, fp_in, frameSize);
if (length < frameSize){
v_zap(&speech_in[length], (Shortword) (FRAME - length));
eof_reached = TRUE;
}
analysis(speech_in, melp_par);
/* ---- Write channel output if needed ---- */
if (mode == ANALYSIS){
if( chwordsize == 8 ){
fwrite(chbuf, sizeof(unsigned char), bitBufSize, fp_out);
}else{
int i;
unsigned int bitData;
for(i = 0; i < bitBufSize; i++){
bitData = (unsigned int)(chbuf[i]);
fwrite(&bitData, sizeof(unsigned int), 1, fp_out);
}
}
}
}
}
frame_count ++;
}
fclose(fp_in);
fclose(fp_out);
fprintf(stderr, "\n\n");
return(0);
} |
Partager