diff -ruN qc13_tia_50_ansi733_20040315-025/code/cb.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/cb.c --- qc13_tia_50_ansi733_20040315-025/code/cb.c 2005-03-16 00:43:04.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/cb.c 2008-10-22 04:51:50.000000000 -0400 @@ -57,7 +57,7 @@ #include "celp.h" #include "cb.h" -void compute_cb( +int compute_cb( int mode, float *target, struct ENCODER_MEM *e_mem, @@ -75,53 +75,55 @@ float Eyyopt[MAXNUMCB]; float y[FSIZE]; float subtarget[FSIZE]; + int ret; - if(mode == QUARTERRATE_UNVOICED){ + if(mode == QUARTERRATE_UNVOICED) + { fprintf(stderr,"compute_cb(): Illegal mode = %d\n", mode); - exit(-4); + return QCELPERR_MODE; } - for (i=0; idec.wght_syn_filt.pole_coeff[i]=lpc[i]; - } /* get LPC impulse response */ - get_impulse_response_pole(lpc_ir, LENGTH_OF_IMPULSE_RESPONSE, - &(e_mem->dec.wght_syn_filt)); + if ((ret=get_impulse_response_pole(lpc_ir, LENGTH_OF_IMPULSE_RESPONSE,&(e_mem->dec.wght_syn_filt))) != QCELPERR_OK) + return ret; - - for (cbnum=0; cbnumdec.lastG, cbsf, e_mem->dec.G_pred); } - + return QCELPERR_OK; }/* end of compute_cb_gain() */ diff -ruN qc13_tia_50_ansi733_20040315-025/code/cb_tabs.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/cb_tabs.c --- qc13_tia_50_ansi733_20040315-025/code/cb_tabs.c 2005-03-16 00:43:04.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/cb_tabs.c 2008-10-22 05:35:44.000000000 -0400 @@ -55,39 +55,38 @@ float CODEBOOK_HALF[CBLENGTH]= { - 0.0, -2.0, 0.0, -1.5, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, -1.5, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.5, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, - 0.0, 1.5, 1.0, 0.0, 1.5, 2.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, - -1.5, 1.5, 0.0, 0.0, -1.0, 0.0, 1.5, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -2.5, 0.0, - 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, 0.0, 1.5, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 1.5, 3.0, -1.5, -2.0, 0.0, -1.5, -1.5, - 1.5, -1.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + 0.0f, -2.0f, 0.0f, -1.5f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.5f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f, + 0.0f, 1.5f, 1.0f, 0.0f, 1.5f, 2.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.5f, 0.0f, 0.0f, + -1.5f, 1.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.5f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -2.5f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.5f, 0.0f, 0.0f, 0.0f, 1.5f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.5f, 3.0f, -1.5f, -2.0f, 0.0f, -1.5f, -1.5f, + 1.5f, -1.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; float CODEBOOK[CBLENGTH]= { - 0.10, -0.65, -0.59, 0.12, 1.10, 0.34, -1.34, 1.57, - 1.04, -0.84, -0.34, -1.15, 0.23, -1.01, 0.03, 0.45, --1.01, -0.16, -0.59, 0.28, -0.45, 1.34, -0.67, 0.22, - 0.61, -0.29, 2.26, -0.26, -0.55, -1.79, 1.57, -0.51, --2.20, -0.93, -0.37, 0.60, 1.18, 0.74, -0.48, -0.95, --1.81, 1.11, 0.36, -0.52, -2.15, 0.78, -1.12, 0.39, --0.17, -0.47, -2.23, 0.19, 0.12, -0.98, -1.42, 1.30, - 0.54, -1.27, 0.21, -0.12, 0.39, -0.48, 0.12, 1.28, - 0.06, -1.67, 0.82, -1.02, -0.79, 0.55, -0.44, 0.48, --0.20, -0.53, 0.08, -0.61, 0.11, -0.70, -1.57, -1.68, - 0.20, -0.56, -0.74, 0.78, 0.33, -0.63, -1.73, -0.02, --0.75, -0.53, -1.46, 0.77, 0.66, -0.29, 0.09, -0.75, - 0.65, 1.19, -0.43, 0.76, 2.33, 0.98, 1.25, -1.56, --0.27, 0.78, -0.09, 1.70, 1.76, 1.43, -1.48, -0.07, - 0.27, -1.36, 0.05, 0.27, 0.18, 1.39, 2.04, 0.07, --1.84, -1.97, 0.52, -0.03, 0.78, -1.89, 0.08, -0.65 + 0.10f, -0.65f, -0.59f, 0.12f, 1.10f, 0.34f, -1.34f, 1.57f, + 1.04f, -0.84f, -0.34f, -1.15f, 0.23f, -1.01f, 0.03f, 0.45f, +-1.01f, -0.16f, -0.59f, 0.28f, -0.45f, 1.34f, -0.67f, 0.22f, + 0.61f, -0.29f, 2.26f, -0.26f, -0.55f, -1.79f, 1.57f, -0.51f, +-2.20f, -0.93f, -0.37f, 0.60f, 1.18f, 0.74f, -0.48f, -0.95f, +-1.81f, 1.11f, 0.36f, -0.52f, -2.15f, 0.78f, -1.12f, 0.39f, +-0.17f, -0.47f, -2.23f, 0.19f, 0.12f, -0.98f, -1.42f, 1.30f, + 0.54f, -1.27f, 0.21f, -0.12f, 0.39f, -0.48f, 0.12f, 1.28f, + 0.06f, -1.67f, 0.82f, -1.02f, -0.79f, 0.55f, -0.44f, 0.48f, +-0.20f, -0.53f, 0.08f, -0.61f, 0.11f, -0.70f, -1.57f, -1.68f, + 0.20f, -0.56f, -0.74f, 0.78f, 0.33f, -0.63f, -1.73f, -0.02f, +-0.75f, -0.53f, -1.46f, 0.77f, 0.66f, -0.29f, 0.09f, -0.75f, + 0.65f, 1.19f, -0.43f, 0.76f, 2.33f, 0.98f, 1.25f, -1.56f, +-0.27f, 0.78f, -0.09f, 1.70f, 1.76f, 1.43f, -1.48f, -0.07f, + 0.27f, -1.36f, 0.05f, 0.27f, 0.18f, 1.39f, 2.04f, 0.07f, +-1.84f, -1.97f, 0.52f, -0.03f, 0.78f, -1.89f, 0.08f, -0.65f }; - diff -ruN qc13_tia_50_ansi733_20040315-025/code/celp13k.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/celp13k.c --- qc13_tia_50_ansi733_20040315-025/code/celp13k.c 2005-03-16 00:43:04.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/celp13k.c 2009-01-14 09:08:16.000000000 -0500 @@ -51,6 +51,7 @@ such commitments. *******************************************************************/ /* celp13k.c - Basic Framework Code for Speech Coder Work */ +/* modified and extended for reusability and handling qcelp-bytestreams - RetroPatch 0.2, January 2009 */ #include #include @@ -58,13 +59,14 @@ #include #include #include +#ifndef WIN32 #include +#endif #include #include #ifndef __SUNOS__ -#include +#include "getopt.h" #endif - #include "celp.h" #include "tty.h" #include "tty_dbg.h" @@ -77,7 +79,7 @@ */ char *prog; -char prog_desc[] = "\n\nCELP 13K coder - \nRevision Date: 03 Mar 2004\n"; +char prog_desc[] = "\n\nCELP 13K coder - \nRevision Date: 03 Mar 2004\nRetroPatch 0.2 Date: 10 Jan 2009"; char *rates_str[NUMMODES] = {"BLANK", "EIGHTH", "QUARTER", "HALF", "FULL"}; extern char *trans_fname; @@ -87,13 +89,14 @@ void usage( struct CONTROL *control ) { -printf("\n%s: %s\n",prog, prog_desc); + printf("\n%s: %s\n",prog, prog_desc); printf("Usage : %s -i infn -o outfn [-c] [-p] [-f frames] [-k] [-e] \n\t\t [-r] [-l minrate] [-h maxrate]\n",prog); printf("\t-i\tinfn\t: input speech file\n"); printf("\t-o\toutfn\t: output speech file\n"); printf("\t-e\t\t: output from encoder rather than decoder\n"); printf("\t-E\t\t: encode only, output (after -o ) will be a packet file\n"); printf("\t-D\t\t: decode only, input must be a packet file\n"); + printf("\t-q\t\t: handle qcp-compatible datastream\n"); printf("\t-r\t\t: output formant residual, rather than speech\n"); printf("\t-t\t\t: output target after cdbk search, rather than speech\n"); printf("\t-c\t\t: output codebook output, rather than speech\n"); @@ -118,15 +121,7 @@ void print_welcome_message() { -printf(" -\n\ -===============================================\n\ - CDMA 13K Speech Coder TTY EDITION\n\ - Ballot Version 1.0\n\ - July 12, 1999\n\ -===============================================\n\n\ -"); - + printf("\n===============================================\nCDMA 13K Speech Coder TTY EDITION\nBallot Version 1.0\nJuly 12, 1999\nRetroPatch 0.2\nJanuary 10,2009\n===============================================\n\n"); } void print_farewell_message() @@ -155,7 +150,7 @@ return(numFrames); } -char prog_opts[] = "abcd:DEeF:f:h:i:kl:M:m:o:pPrS:s:T:tuvwz"; /* command line flags */ +char prog_opts[] = "abcd:DEeF:f:h:i:kl:M:m:o:pPqrS:s:T:tuvwz"; /* command line flags */ extern char *optarg; extern int optind; @@ -188,6 +183,7 @@ control->target_after_out=NO; control->decode_only=NO; control->encode_only=NO; + control->qcp_compatible=NO; control->fractional_pitch=YES; /* TTY OPTIONS */ @@ -199,6 +195,10 @@ while ((i = getopt(argc, argv, prog_opts)) != EOF) { switch (i) { + case 'q': + control->qcp_compatible=YES; + printf("handling qcp-compatible streams\n"); + break; case 'u': control->unvoiced_off=YES; printf("unvoiced mode is turned off (only meaningful in RRM)\n"); @@ -280,9 +280,7 @@ control->reduced_rate_flag = 0; } else if(control->reduced_rate_flag == 3){ - printf("Operating in reduced rate mode=%d: %f kbps for active speech\ - (channel rate) \n", - control->reduced_rate_flag, control->avg_rate); + printf("Operating in reduced rate mode=%d: %f kbps for active speech (channel rate) \n", control->reduced_rate_flag, control->avg_rate); } else printf("Operating in reduced rate mode=%d\n", @@ -351,9 +349,7 @@ if(control->min_rate == QUARTERRATE_VOICED || control->max_rate ==QUARTERRATE_VOICED ){ - fprintf(stderr, - "parse_command_line: min_rate (%d) or max_rate (%d) is currently illegal\n", - control->min_rate, control->max_rate); + fprintf(stderr, "parse_command_line: min_rate (%d) or max_rate (%d) is currently illegal\n", control->min_rate, control->max_rate); exit(-2); } @@ -390,7 +386,8 @@ #if USE_CALLOC - alloc_mem_for_speech(&in_speech, &out_speech); + if ((ret=alloc_mem_for_speech(&in_speech, &out_speech)) != QCELPERR_OK) + exit(-1); #endif for(i = 0; i < argc; i++) @@ -399,8 +396,8 @@ parse_command_line(argc, argv, fn_inspeech, fn_outspeech, &control); - initialize_encoder_and_decoder(&encoder_memory, &decoder_memory, - &control); + if ((initialize_encoder_and_decoder(&encoder_memory, &decoder_memory, &control)) != QCELPERR_OK) + exit (-1); print_welcome_message(); @@ -440,7 +437,10 @@ if( control.decode_only == YES ) { - total_frames = GetNumFrames(fin,sizeof(short)*WORDS_PER_PACKET); + if (control.qcp_compatible) + total_frames = GetNumFrames(fin,sizeof(char)*BYTES_PER_PACKET_QCP); + else + total_frames = GetNumFrames(fin,sizeof(short)*WORDS_PER_PACKET); } else { @@ -463,17 +463,13 @@ } #endif } - - - /*----------------------------------------------- * Main Loop *------------------------------------------------*/ while( control.num_frames == UNLIMITED || frame_num < control.num_frames ) { - fprintf(stderr,"Processing %lu of %lu FER = %.2f%%\r", - frame_num, total_frames, 100.0*fer_count/(frame_num+1)); + fprintf(stderr,"Processing %lu of %lu FER = %.2f%%\r",frame_num, total_frames, 100.0*fer_count/(frame_num+1)); if (control.decode_only==NO) { @@ -489,40 +485,47 @@ in_speech[LPCSIZE-FSIZE+LPCOFFSET+i]=0; } } - - encoder(in_speech, &packet, &control, - &encoder_memory, out_speech); - + encoder(in_speech, &packet, &control,&encoder_memory, out_speech); update_snr(ENCODER, in_speech, out_speech, &(control.snr)); - } if (control.decode_only==YES) { - numread = read_packet(fin, packet.data, WORDS_PER_PACKET); - if( numread != WORDS_PER_PACKET) - { - if(numread != 0) - { - fprintf(stderr, - "%s: Wrong number of words read: %d\n", argv[0], numread); - } - break; - } + if (control.qcp_compatible) + { + numread = read_packet_qcp(fin, packet.data, BYTES_PER_PACKET_QCP); + if( numread != BYTES_PER_PACKET_QCP) + { + if(numread != 0) + { + fprintf(stderr,"%s: Wrong number of bytes read: %d\n", argv[0], numread); + } + break; + } + } + else + { + numread = read_packet(fin, packet.data, WORDS_PER_PACKET); + if( numread != WORDS_PER_PACKET) + { + if(numread != 0) + { + fprintf(stderr,"%s: Wrong number of words read: %d\n", argv[0], numread); + } + break; + } + } } if(control.encode_only==NO) { - if (control.output_encoder_speech==NO) { decoder(out_speech, &packet, &control, &decoder_memory); - if( packet.data[0] == ERASURE ) { fer_count++; } - if(control.decode_only==NO) { update_snr(DECODER, in_speech, out_speech, &(control.snr)); @@ -540,10 +543,12 @@ { fer_count++; } - i = write_packet(fout, packet.data, WORDS_PER_PACKET); + if (control.qcp_compatible) + i = write_packet_qcp(fout, packet.data, BYTES_PER_PACKET_QCP); + else + i = write_packet(fout, packet.data, WORDS_PER_PACKET); } - /***** Update in_speech buffer ***************/ for (i=0; i #include @@ -62,8 +62,8 @@ /* #include */ /* for ERASURE processing */ -static float ERA_LSP_DEC[4]={1.0, 0.9, 0.9, 0.7}; -static float ERA_B_SAT[4]={0.8984375, 0.6015625, 0.30078125, 0.0}; /* Q8 */ +static float ERA_LSP_DEC[4]={1.0f, 0.9f, 0.9f, 0.7f}; +static float ERA_B_SAT[4]={0.8984375f, 0.6015625f, 0.30078125f, 0.0f}; /* Q8 */ int erasure_count = 0; void agc( @@ -123,7 +123,7 @@ }/* end of agc_prefilter() */ -void run_decoder( +int run_decoder( int mode, struct DECODER_MEM *d_mem, float lpc[2][LPCORDER], @@ -136,8 +136,8 @@ int numcb ) { + int ret; int j, k, l; - float cb_out[FSIZE], pitch_out[FSIZE]; float white_out[FSIZE]; float pitch_pre_out[FSIZE]; @@ -186,9 +186,8 @@ stmp = (((cb_params[0][0].sd+0x7fff)&(0xffff))-0x7fff); white_out[j+k*length/numcbsf]=stmp; } - do_fir_linear_filter(&white_out[k*length/numcbsf], - &cb_out[k*length/numcbsf], - length/numcbsf, &(d_mem->bpf_unv), UPDATE) ; + if ((ret=do_fir_linear_filter(&white_out[k*length/numcbsf], &cb_out[k*length/numcbsf],length/numcbsf, &(d_mem->bpf_unv), UPDATE)) != QCELPERR_OK) + return ret; for (j=0; jwght_syn_filt.pole_coeff[j]=lpc[WGHTED][j]; } - debug_do_pole_filter(pitch_out, out_buffer, length, - &(d_mem->lpc_filt), UPDATE); + debug_do_pole_filter(pitch_out, out_buffer, length, &(d_mem->lpc_filt), UPDATE); - do_pole_filter(pitch_out, d_mem->pw_speech_out, length, - &(d_mem->wght_syn_filt), UPDATE); + do_pole_filter(pitch_out, d_mem->pw_speech_out, length, &(d_mem->wght_syn_filt), UPDATE); } else {/* DECODER */ @@ -282,7 +279,7 @@ for (j=0; jdata[0]) ); } - unpack_frame(packet); + if (control->qcp_compatible) + unpack_frame_qcp(packet); + else + unpack_frame(packet); mode=packet->mode; if( tty_option == TTY_NO_GAIN ) @@ -395,8 +391,7 @@ /* Convert from short to float */ for( j=0 ; j < FSIZE/PITCHSF[mode] ; j++ ) { - out_speech[j+i*FSIZE/PITCHSF[mode]] = - (float) tty_outbuf[j+i*FSIZE/PITCHSF[mode]]/4.0; + out_speech[j+i*FSIZE/PITCHSF[mode]] =(float) tty_outbuf[j+i*FSIZE/PITCHSF[mode]]/4.0; } } @@ -404,13 +399,16 @@ if( tty_dec_flag ) { - initialize_decoder(d_mem); - return; + return initialize_decoder(d_mem); } } /* end if( TTY_NO_GAIN ) */ - if (mode==EIGHTH) { + // + //decode eighth-rate + // + if (mode==EIGHTH) + { unpack_lpc(mode, &lpc_params, packet); unquantize_lpc(mode, qlsp, d_mem, &lpc_params); @@ -422,36 +420,31 @@ pitch_params.frac=0; unpack_cb(mode, packet, cb_params, 0, 0); - unquantize_G_8th(&(cb_params[0][0].G), - &(cb_params[0][0].qcode_G), - d_mem->G_pred); + unquantize_G_8th(&(cb_params[0][0].G),&(cb_params[0][0].qcode_G), d_mem->G_pred); cb_params[0][0].G=fabs(cb_params[0][0].G); - cb_params[0][0].sd=packet->sd_dec; last_G= (0.5*(cb_params[0][0].G+d_mem->last_G)); - for (i=0; ilast_G*(PITCHSF8TH-1-i)/PITCHSF8TH - +last_G*(i+1.0)/PITCHSF8TH; - - run_decoder(mode, d_mem, lpc[PITCH][0], - &pitch_params, cb_params, - &out_speech[i*FSIZE/PITCHSF8TH], FSIZE/PITCHSF8TH, - control, 1, 1); - } + for (i=0; ilast_G*(PITCHSF8TH-1-i)/PITCHSF8TH+last_G*(i+1.0)/PITCHSF8TH; + if ((ret=run_decoder(mode, d_mem, lpc[PITCH][0],&pitch_params, cb_params,&out_speech[i*FSIZE/PITCHSF8TH], FSIZE/PITCHSF8TH,control, 1, 1)) != QCELPERR_OK) + return ret; + } cb_params[0][0].seed = cb_params[0][0].sd; /* for erasure processing */ - d_mem->last_G=cb_params[0][0].G; - d_mem->low_rate_cnt+=1; d_mem->err_cnt=0; } - else if (mode == QUARTERRATE_UNVOICED){ - + // + //decode quarter-rate + // + else if (mode == QUARTERRATE_UNVOICED) + { unpack_lpc(mode, &lpc_params, packet); - - if(lsp_erasure_check(mode, lpc_params.qcode_lsp)){ + if(lsp_erasure_check(mode, lpc_params.qcode_lsp)) + { erasure_count++; packet->mode = mode = ERASURE; goto erasure; @@ -460,146 +453,120 @@ for (i=0, j = 0; imode = mode = ERASURE; goto erasure; } - unquantize_lpc(mode, qlsp, d_mem, &lpc_params); - - interp_lpcs(mode, d_mem->last_qlsp, qlsp, - lpc, ONLY_UNWGHTED, control); - + interp_lpcs(mode, d_mem->last_qlsp, qlsp,lpc, ONLY_UNWGHTED, control); pitch_params.b=0; pitch_params.lag=0; pitch_params.frac=0; j = 0; - for (i=0; ilastG, j, d_mem->G_pred); - Gtmp[i] = cb_params[i][j].G; - if(Gtmp[i] < 0.0){ - fprintf(stderr,"QUARTERRATE Gain is negative: Gtmp[%d] = %f\n", - i, Gtmp[i]); - exit(-2); - } + for (i=0; ilastG, j, d_mem->G_pred); + Gtmp[i] = cb_params[i][j].G; + if(Gtmp[i] < 0.0) + { + fprintf(stderr,"QUARTERRATE Gain is negative: Gtmp[%d] = %f\n", i, Gtmp[i]); + return QCELPERR_NEGGAIN; + } } - - - cb_params[0][0].sd = ((packet->data[2] & 0xffc ) << 4) | - ((packet->data[1] & 0x1f8) >> 3); - + cb_params[0][0].sd = ((packet->data[2] & 0xffc ) << 4) | ((packet->data[1] & 0x1f8) >> 3); /* produce 8 interpolated CB Gains from 5 CB Gains */ - for(i = 0; i < PITCHSF[mode]; i++){ - switch(i){ - case 0: - cb_params[0][0].G = Gtmp[0]; - cb_params[1][0].G = 0.6 *Gtmp[0] + 0.4 * Gtmp[1]; - break; - case 1: - cb_params[0][0].G = Gtmp[1]; - cb_params[1][0].G = 0.2 *Gtmp[1] + 0.8 * Gtmp[2]; - break; - case 2: - cb_params[0][0].G = 0.8 *Gtmp[2] + 0.2 * Gtmp[3]; - cb_params[1][0].G = Gtmp[3]; - break; - case 3: - cb_params[0][0].G = 0.4 *Gtmp[3] + 0.6 * Gtmp[4]; - cb_params[1][0].G = Gtmp[4]; - break; - } - run_decoder(mode, d_mem, lpc[PITCH][i], &pitch_params, - cb_params, &out_speech[i*FSIZE/PITCHSF[mode]], - FSIZE/PITCHSF[mode], control, 2, - NUMCB[mode]); + for(i = 0; i < PITCHSF[mode]; i++) + { + switch(i) + { + case 0: + cb_params[0][0].G = Gtmp[0]; + cb_params[1][0].G = 0.6 *Gtmp[0] + 0.4 * Gtmp[1]; + break; + case 1: + cb_params[0][0].G = Gtmp[1]; + cb_params[1][0].G = 0.2 *Gtmp[1] + 0.8 * Gtmp[2]; + break; + case 2: + cb_params[0][0].G = 0.8 *Gtmp[2] + 0.2 * Gtmp[3]; + cb_params[1][0].G = Gtmp[3]; + break; + case 3: + cb_params[0][0].G = 0.4 *Gtmp[3] + 0.6 * Gtmp[4]; + cb_params[1][0].G = Gtmp[4]; + break; + } + if ((ret=run_decoder(mode, d_mem, lpc[PITCH][i], &pitch_params,cb_params, &out_speech[i*FSIZE/PITCHSF[mode]],FSIZE/PITCHSF[mode], control, 2,NUMCB[mode])) != QCELPERR_OK) + return ret; } cb_params[0][0].seed = cb_params[0][0].sd; d_mem->last_G=fabs(Gtmp[4]); d_mem->low_rate_cnt=0; d_mem->err_cnt=0; }/* end of QUARTERRATE_UNVOICED */ - - else if(mode == BLANK){ - - d_mem->last_G=cb_params[0][0].G=0; - cb_params[0][0].i=0; /* arbitrary */ - pitch_params.b =d_mem->last_b; - pitch_params.frac=d_mem->last_frac; - - if (pitch_params.b>1.0) { - pitch_params.b=1.0; - } - pitch_params.lag=d_mem->last_lag; - - for (i=0; ilast_qlsp[i]; - } - - lsp2lpc(qlsp, lpc[PITCH][0][NOT_WGHTED], LPCORDER); - wght_factor=1; - for (j=0; jmode = mode = ERASURE; - goto erasure; - } - - unquantize_lpc(mode, qlsp, d_mem, &lpc_params); - interp_lpcs(mode, d_mem->last_qlsp, qlsp, - lpc, ONLY_UNWGHTED, control); - - unquantize_min_lag(&(pitch_params.min_lag), packet->min_lag); - - cb_params[0][0].sd=packet->sd_dec; - for (i=0; ilastG, j, d_mem->G_pred); - - unquantize_i(&(cb_params[j][k].i), - &(cb_params[j][k].qcode_i)); + else if(mode == BLANK) + { + d_mem->last_G=cb_params[0][0].G=0; + cb_params[0][0].i=0; /* arbitrary */ + pitch_params.b =d_mem->last_b; + pitch_params.frac=d_mem->last_frac; + if (pitch_params.b>1.0) + pitch_params.b=1.0; + pitch_params.lag=d_mem->last_lag; + for (i=0; ilast_qlsp[i]; + lsp2lpc(qlsp, lpc[PITCH][0][NOT_WGHTED], LPCORDER); + wght_factor=1; + for (j=0; jmode = mode = ERASURE; + goto erasure; + } + unquantize_lpc(mode, qlsp, d_mem, &lpc_params); + interp_lpcs(mode, d_mem->last_qlsp, qlsp,lpc, ONLY_UNWGHTED, control); + unquantize_min_lag(&(pitch_params.min_lag), packet->min_lag); + cb_params[0][0].sd=packet->sd_dec; + for (i=0; ilastG, j, d_mem->G_pred); + unquantize_i(&(cb_params[j][k].i), &(cb_params[j][k].qcode_i)); + } + } + if ((ret=run_decoder(mode, d_mem, lpc[PITCH][i], &pitch_params,cb_params, &out_speech[i*FSIZE/PITCHSF[mode]],FSIZE/PITCHSF[mode], control, CBSF[mode]/PITCHSF[mode],NUMCB[mode])) != QCELPERR_OK) + return ret; + d_mem->last_G=fabs(cb_params[CBSF[mode]/PITCHSF[mode]-1][0].G); + d_mem->low_rate_cnt=0; + d_mem->err_cnt=0; + } } - } - run_decoder(mode, d_mem, lpc[PITCH][i], &pitch_params, - cb_params, &out_speech[i*FSIZE/PITCHSF[mode]], - FSIZE/PITCHSF[mode], control, CBSF[mode]/PITCHSF[mode], - NUMCB[mode]); - d_mem->last_G=fabs(cb_params[CBSF[mode]/PITCHSF[mode]-1][0].G); - d_mem->low_rate_cnt=0; - d_mem->err_cnt=0; - } - } erasure: if (mode== ERASURE) { /* ERASURES */ @@ -676,10 +643,8 @@ cb_params[i][0].G=d_mem->last_G*(PITCHSF_ERASURE-1-i)/PITCHSF_ERASURE +last_G*(i+1.0)/PITCHSF_ERASURE; - run_decoder(FULLRATE_VOICED, d_mem, lpc[PITCH][0], - &pitch_params, cb_params, - &out_speech[i*FSIZE/PITCHSF_ERASURE], FSIZE/PITCHSF_ERASURE, - control, 1, 1); + if ((ret=run_decoder(FULLRATE_VOICED, d_mem, lpc[PITCH][0],&pitch_params, cb_params,&out_speech[i*FSIZE/PITCHSF_ERASURE], FSIZE/PITCHSF_ERASURE,control, 1, 1)) != QCELPERR_OK) + return ret; cb_params[0][0].i = (cb_params[0][0].i - 40) & 0x7f; } d_mem->last_G=cb_params[0][0].G; @@ -698,7 +663,7 @@ for (i=0; ilast_qlsp[i]=qlsp[i]; } - + return QCELPERR_OK; }/* end of decoder() */ void print_erasure_count() diff -ruN qc13_tia_50_ansi733_20040315-025/code/encode.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/encode.c --- qc13_tia_50_ansi733_20040315-025/code/encode.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/encode.c 2009-01-14 09:30:12.000000000 -0500 @@ -51,6 +51,7 @@ such commitments. *******************************************************************/ /* encode.c - main CELP encoder */ +/* modified and extended for reusability and handling qcelp-bytestreams - RetroPatch 0.2, January 2009 */ #include #include @@ -60,7 +61,7 @@ #include "tty_dbg.h" -void encoder( +int encoder( float *in_buffer, struct PACKET *packet, struct CONTROL *control, @@ -68,6 +69,7 @@ float *out_buffer ) { + int ret; static int hysteresis = 0; int i,j,index; float lpc[LPCORDER], interp_lpc[2][MAXSF][2][LPCORDER]; @@ -99,8 +101,8 @@ FSIZE ); } - compute_lpc(&in_buffer[LPCOFFSET], LPCSIZE, HAMMING, LPCORDER, - lpc, Rs, control); + if ((ret=compute_lpc(&in_buffer[LPCOFFSET], LPCSIZE, HAMMING, LPCORDER,lpc, Rs, control)) != QCELPERR_OK) + return ret; #if PREV_LSP_FIX lpc2lsp(lpc, lsp, e_mem->features.last_lsp, LPCORDER); @@ -123,22 +125,20 @@ } } - packet->mode=mode; - - quantize_lpc(mode, lpc, lsp, qlsp, Rs, &lpc_params, e_mem); - pack_lpc(mode, &lpc_params, packet); + interp_lpcs(mode, e_mem->dec.last_qlsp, qlsp, interp_lpc, BOTH,control); + create_target_speech( mode, + in_buffer, + form_resid, + pw_speech, + interp_lpc, + &(e_mem->form_res_filt), + &(e_mem->spch_wght_syn_filt) ); - interp_lpcs(mode, e_mem->dec.last_qlsp, qlsp, - interp_lpc, BOTH,control); - - create_target_speech(mode, in_buffer, form_resid, pw_speech, - interp_lpc, &(e_mem->form_res_filt), - &(e_mem->spch_wght_syn_filt)); - - select_mode2(&mode, form_resid, Rs, control, e_mem,in_buffer,lpc,lsp); + if ((ret=select_mode2(&mode, form_resid, Rs, control, e_mem,in_buffer,lpc,lsp)) != QCELPERR_OK) + return ret; /* Force the rate during TTY transmissions */ if( tty_option == TTY_NO_GAIN && tty_enc_flag ) @@ -170,9 +170,12 @@ wght_factor*=PERCEPT_WGHT_FACTOR; interp_lpc[PITCH][0][WGHTED][i]=wght_factor*interp_lpc[PITCH][0][NOT_WGHTED][i]; } - run_decoder(mode, &(e_mem->dec), interp_lpc[PITCH][0], &pitch_params, - cb_params, out_buffer, FSIZE, control, 1, 1); - pack_frame(mode, packet); + run_decoder(mode, &(e_mem->dec), interp_lpc[PITCH][0], &pitch_params, cb_params, out_buffer, FSIZE, control, 1, 1); + + if (control->qcp_compatible) + pack_frame_qcp(mode, packet); + else + pack_frame(mode, packet); /* don't use formant residual here, but need to update the */ /* memories for the following frames */ @@ -243,47 +246,28 @@ save_target(target,before_search, FSIZE/PITCHSF[mode]); - for(j=0; jdec)); - compute_cb(mode, &target[j*FSIZE/CBSF[mode]], e_mem, - interp_lpc[PITCH][i][WGHTED], cb_params, j); - - pack_cb(mode, cb_params, packet, i, j); - - run_decoder(mode, &(e_mem->dec), interp_lpc[PITCH][i], - &pitch_params, cb_params+j, - &out_buffer[sf_pointer], FSIZE/CBSF[mode], - control, 1, - NUMCB[mode]); - - for(index=0;index - dec.pw_speech_out[index]; - - - - target_reduction(&target[j*FSIZE/CBSF[mode]], - &before_search[j*FSIZE/CBSF[mode]], - &e_mem->codebook_target_energy[j+ - i*CBSF[mode]/PITCHSF[mode]], - &e_mem->codebook_target_energy_after[j+ - i*CBSF[mode]/PITCHSF[mode]], - FSIZE/CBSF[mode]); - - save_target(&target[j*FSIZE/CBSF[mode]],&target_after_save - [j*FSIZE/CBSF[mode]+i*FSIZE/PITCHSF[mode]],FSIZE/CBSF[mode]); - - sf_pointer+=FSIZE/CBSF[mode]; + for(j=0; jdec)); + if ((ret=compute_cb(mode, &target[j*FSIZE/CBSF[mode]], e_mem, interp_lpc[PITCH][i][WGHTED], cb_params, j)) != QCELPERR_OK) + return ret; + pack_cb(mode, cb_params, packet, i, j); + run_decoder(mode, &(e_mem->dec), interp_lpc[PITCH][i], &pitch_params, cb_params+j, &out_buffer[sf_pointer], FSIZE/CBSF[mode], control, 1, NUMCB[mode]); + for(index=0;indexdec.pw_speech_out[index]; + target_reduction(&target[j*FSIZE/CBSF[mode]],&before_search[j*FSIZE/CBSF[mode]],&e_mem->codebook_target_energy[j+i*CBSF[mode]/PITCHSF[mode]],&e_mem->codebook_target_energy_after[j+i*CBSF[mode]/PITCHSF[mode]],FSIZE/CBSF[mode]); + save_target(&target[j*FSIZE/CBSF[mode]],&target_after_save[j*FSIZE/CBSF[mode]+i*FSIZE/PITCHSF[mode]],FSIZE/CBSF[mode]); + sf_pointer+=FSIZE/CBSF[mode]; }/* end of for(j = 0; j < CBSF[mode]/PITCHSF[mode]; j++) */ }/* end of for(i = 0; i < PITCHSF[mode]; i++) */ compute_target_snr(mode, e_mem); } - pack_frame(mode, packet); + if (control->qcp_compatible) + pack_frame_qcp(mode, packet); + else + pack_frame(mode, packet); e_mem->dec.last_G=fabs(cb_params[CBSF[mode]/PITCHSF[mode]-1][0].G); e_mem->dec.low_rate_cnt=0; @@ -300,16 +284,23 @@ sf_pointer = 0; /* need to compute 5 gain parameters which get interpolated */ - for(j = 0; j < CBSF[mode]; j++){ - compute_cb_gain(mode, e_mem, cb_params, &in_buffer[sf_pointer], j); + for(j = 0; j < CBSF[mode]; j++) + { + int ret; + if ((ret=compute_cb_gain(mode, e_mem, cb_params, &in_buffer[sf_pointer], j)) != QCELPERR_OK) + return ret; + + pack_cb(mode, cb_params, packet, 0, j); + + Gtmp[j] = cb_params[j][0].G; + sf_pointer += FSIZE/CBSF[mode]; + + } + if (control->qcp_compatible) + pack_frame_qcp(mode, packet); + else + pack_frame(mode, packet); - pack_cb(mode, cb_params, packet, 0, j); - - Gtmp[j] = cb_params[j][0].G; - sf_pointer += FSIZE/CBSF[mode]; - - } - pack_frame(mode, packet); cb_params[0][0].sd = ((packet->data[2] & 0xffc ) << 4) | ((packet->data[1] & 0x1f8) >> 3); @@ -337,7 +328,7 @@ fprintf(stderr, "encoder(): mode=%d Does not support this many pitch sub frames: %d\n", mode, PITCHSF[mode]); - exit(-4); + return QCELPERR_PITCHCOUNT; break; } run_decoder(mode, &(e_mem->dec), interp_lpc[PITCH][i], @@ -391,13 +382,21 @@ #endif packet->sd_enc=((521*(packet->sd_enc)+259)&0xffff); - pack_frame(mode, packet); + if (control->qcp_compatible) + pack_frame_qcp(mode, packet); + else + pack_frame(mode, packet); /* check for null Traffic Channel data */ - while (packet->data[1]==0xffff) { + while (packet->data[1]==0xffff) + { packet->sd_enc &= 0xfff7; - pack_frame(mode, packet); + if (control->qcp_compatible) + pack_frame_qcp(mode, packet); + else + pack_frame(mode, packet); + } cb_params[0][0].sd = packet->sd_enc; @@ -455,4 +454,5 @@ } printf("\n\n"); } + return QCELPERR_OK; }/* end of encoder() */ diff -ruN qc13_tia_50_ansi733_20040315-025/code/fer_sim.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/fer_sim.c --- qc13_tia_50_ansi733_20040315-025/code/fer_sim.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/fer_sim.c 2008-09-28 17:00:06.000000000 -0400 @@ -148,7 +148,11 @@ int frame_cnt; /* frame counter */ /* file pointers */ +#ifdef WIN32 +FILE *log_fp = NULL; +#else FILE *log_fp = stdout; +#endif FILE *trans_fp = NULL; char *trans_fname = NULL; diff -ruN qc13_tia_50_ansi733_20040315-025/code/filter.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/filter.c --- qc13_tia_50_ansi733_20040315-025/code/filter.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/filter.c 2008-10-22 04:59:36.000000000 -0400 @@ -62,7 +62,7 @@ #define DEBUG(x) -void initialize_pole_filter( +int initialize_pole_filter( struct POLE_FILTER *filter, int order ) @@ -73,23 +73,24 @@ if( (filter->memory =(float *)(calloc((unsigned)order, sizeof(float)))) == NULL ) { fprintf(stderr,"ERROR: initialize_pole_filter(): Cannot allocate %d words for memory\n", order); - exit(0); + // exit(0); + return QCELPERR_NOMEM; } if( (filter->pole_coeff=(float *)(calloc((unsigned)order, sizeof(float)))) == NULL ) { fprintf(stderr,"ERROR: initialize_pole_filter(): Cannot allocate %d words for coeff\n", order); - exit(0); + return QCELPERR_NOMEM; } for( i=0 ; i < order ; i++ ) { filter->memory[i] = 0; } - + return QCELPERR_OK; } -void initialize_pole_1_tap_filter( +int initialize_pole_1_tap_filter( struct POLE_FILTER_1_TAP *filter, int max_order ) @@ -100,17 +101,17 @@ if( (filter->memory =(float *)(calloc((unsigned)max_order, sizeof(float)))) == NULL ) { fprintf(stderr,"ERROR: initialize_pole_1_tap_filter(): Cannot allocate %d words for memory\n", max_order); - exit(0); + return QCELPERR_NOMEM; } for( i=0 ; i < max_order ; i++ ) { filter->memory[i] = 0; } - + return QCELPERR_OK; } -void initialize_zero_filter( +int initialize_zero_filter( struct ZERO_FILTER *filter, int order ) @@ -121,19 +122,19 @@ if( (filter->memory =(float *)(calloc((unsigned)order, sizeof(float)))) == NULL ) { fprintf(stderr,"ERROR: initialize_zero_filter(): Cannot allocate %d words for memory\n", order); - exit(0); + return QCELPERR_NOMEM; } if( (filter->zero_coeff=(float *)(calloc((unsigned)order, sizeof(float)))) == NULL ) { fprintf(stderr,"ERROR: initialize_zero_filter(): Cannot allocate %d words for coeff\n", order); - exit(0); + return QCELPERR_NOMEM; } for( i=0 ; i < order ; i++ ) { filter->memory[i] = 0; } - + return QCELPERR_OK; } void free_pole_filter( @@ -487,7 +488,7 @@ #endif -void do_fir_linear_filter( +int do_fir_linear_filter( float *input, float *output, int numsamples, @@ -501,73 +502,67 @@ if( (tmpbuf=(float *)(calloc((unsigned)numsamples+filter->order, sizeof(float)))) == NULL ) { - fprintf(stderr,"ERROR: do_fir_linear_filter(): Cannot allocate %d words for tmpbuf[]\n", - numsamples+filter->order); - exit(0); + fprintf(stderr,"ERROR: do_fir_linear_filter(): Cannot allocate %d words for tmpbuf[]\n",numsamples+filter->order); + return QCELPERR_NOMEM; } - /* initialize first "order-1" locations to */ /* previous memories */ - for (i=0; iorder-1; i++) { + for (i=0; iorder-1; i++) tmpbuf[i]=filter->memory[filter->order-i-2]; - } /* initialize next locations to the input */ - for (i=0; iorder-1]=input[i]; - } /* filter the buffer */ - for (i=0; iorder; j++) { + for (j=i; jorder; j++) output[i]+=tmpbuf[j]*filter->zero_coeff[filter->order+i-j-1]; - } } /* if flag is set, update the memories */ - if (update_flag==UPDATE) { - for (i=0; iorder-1; i++) { + if (update_flag==UPDATE) + { + for (i=0; iorder-1; i++) filter->memory[i]=tmpbuf[filter->order+numsamples-i-2]; - } } free((char*)tmpbuf); + return QCELPERR_OK; } -void get_impulse_response_pole( +int get_impulse_response_pole( float *response, int length, struct POLE_FILTER *filter ) { - int i; - float *tmpmemory; - float *impulse; - - if( (tmpmemory=(float *)(calloc((unsigned)filter->order, sizeof(float)))) == NULL ) - { - fprintf(stderr,"ERROR: get_impulse_response_pole(): Cannot allocate %d words for tmpmemory[]\n", - filter->order); - exit(0); - } - - if( (impulse =(float *)(calloc((unsigned)length, sizeof(float)))) == NULL ) - { - fprintf(stderr,"ERROR: get_impulse_response_pole(): Cannot allocate %d words for impulse[]\n", - length); - exit(0); - } + int i; + float *tmpmemory; + float *impulse; + + if( (tmpmemory=(float *)(calloc((unsigned)filter->order, sizeof(float)))) == NULL ) + { + fprintf(stderr,"ERROR: get_impulse_response_pole(): Cannot allocate %d words for tmpmemory[]\n",filter->order); + return QCELPERR_NOMEM; + } + if( (impulse =(float *)(calloc((unsigned)length, sizeof(float)))) == NULL ) + { + fprintf(stderr,"ERROR: get_impulse_response_pole(): Cannot allocate %d words for impulse[]\n",length); + return QCELPERR_NOMEM; + } + for (i=0; iorder; i++) + { + tmpmemory[i]=filter->memory[i]; + filter->memory[i]=0.0; + } + impulse[0]=1.0; + do_pole_filter(impulse, response, length, filter, NO_UPDATE); - for (i=0; iorder; i++) { - tmpmemory[i]=filter->memory[i]; - filter->memory[i]=0.0; - } - impulse[0]=1.0; - - do_pole_filter(impulse, response, length, filter, NO_UPDATE); + for (i=0; iorder; i++) + filter->memory[i]=tmpmemory[i]; - for (i=0; iorder; i++) { - filter->memory[i]=tmpmemory[i]; - } - free((char*)tmpmemory); - free((char*)impulse); + free((char*)tmpmemory); + free((char*)impulse); + return QCELPERR_OK; } diff -ruN qc13_tia_50_ansi733_20040315-025/code/init.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/init.c --- qc13_tia_50_ansi733_20040315-025/code/init.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/init.c 2008-10-22 04:15:08.000000000 -0400 @@ -60,96 +60,86 @@ #include "quantize.h" #include "cb.h" -void initialize_decoder( - struct DECODER_MEM *d_mem -) +int initialize_decoder(struct DECODER_MEM *d_mem) { int i; - + int ret; /* initialize the decoder filters */ - d_mem->type=DECODER; - initialize_pole_1_tap_filter(&(d_mem->pitch_filt), - MAXLAG+FR_INTERP_FILTER_LENGTH/2+3); - initialize_pole_1_tap_filter(&(d_mem->pitch_filt_per), - MAXLAG+FR_INTERP_FILTER_LENGTH/2+3); - initialize_pole_filter(&(d_mem->lpc_filt), LPCORDER); - initialize_pole_filter(&(d_mem->post_filt_p), LPCORDER); - initialize_zero_filter(&(d_mem->post_filt_z), LPCORDER); - initialize_zero_filter(&(d_mem->pitch_sm), PSMORDER); - - for (i=0; ipitch_sm.zero_coeff[i] = hammsinc((float)(MAX_FR_RESOLUTION* - (i-PSMORDER/2+.5))); - } - initialize_pole_filter(&(d_mem->bright_filt), 1); + if ((ret=initialize_pole_1_tap_filter(&(d_mem->pitch_filt), MAXLAG+FR_INTERP_FILTER_LENGTH/2+3)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_1_tap_filter(&(d_mem->pitch_filt_per), MAXLAG+FR_INTERP_FILTER_LENGTH/2+3)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(d_mem->lpc_filt), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(d_mem->post_filt_p), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_zero_filter(&(d_mem->post_filt_z), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_zero_filter(&(d_mem->pitch_sm), PSMORDER)) != QCELPERR_OK) + return ret; + for (i=0; ipitch_sm.zero_coeff[i] = hammsinc((float)(MAX_FR_RESOLUTION*(i-PSMORDER/2+.5))); + if ((ret=initialize_pole_filter(&(d_mem->bright_filt), 1)) != QCELPERR_OK) + return ret; d_mem->bright_filt.pole_coeff[0]= -BRIGHT_COEFF; - for (i=0; ilast_qlsp[i]= (float)(i+1)/(float)(LPCORDER+1); - } - for (i=0; ipred_qlsp[i]= 0.0; - } - + for (i=0; ilast_qlsp[i]= (float)(i+1)/(float)(LPCORDER+1); + for (i=0; ipred_qlsp[i]= 0.0; d_mem->low_rate_cnt = 0; d_mem->last_G = 0.0; - - d_mem->agc_factor = 1.0; d_mem->pre_factor = 1.0; - /*d_mem->pitch_post_params.lag = MAXLAG;*/ /*d_mem->pitch_post_params.b = 0.0;*/ - d_mem->err_cnt = 0; d_mem->last_b = 0.0; d_mem->last_lag = 0; d_mem->last_frac = 0; - d_mem->G_pred[0] = d_mem->G_pred[1] = 0; - + return QCELPERR_OK; } /* end initialize_decoder() */ -void initialize_encoder_and_decoder( +int initialize_encoder_and_decoder( struct ENCODER_MEM *e_mem, struct DECODER_MEM *d_mem, struct CONTROL *control ) { int i, j, k; - + int ret; /* initialize the decoder filters */ #if 1 - initialize_decoder( d_mem ); + if ((ret=initialize_decoder( d_mem )) != QCELPERR_OK) + return ret; #else d_mem->type=DECODER; - initialize_pole_1_tap_filter(&(d_mem->pitch_filt), - MAXLAG+FR_INTERP_FILTER_LENGTH/2+3); - initialize_pole_1_tap_filter(&(d_mem->pitch_filt_per), - MAXLAG+FR_INTERP_FILTER_LENGTH/2+3); - initialize_pole_filter(&(d_mem->lpc_filt), LPCORDER); - initialize_pole_filter(&(d_mem->post_filt_p), LPCORDER); - initialize_zero_filter(&(d_mem->post_filt_z), LPCORDER); - initialize_zero_filter(&(d_mem->pitch_sm), PSMORDER); - - for (i=0; ipitch_sm.zero_coeff[i] = hammsinc((float)(MAX_FR_RESOLUTION* - (i-PSMORDER/2+.5))); - } - initialize_pole_filter(&(d_mem->bright_filt), 1); + if ((ret=initialize_pole_1_tap_filter(&(d_mem->pitch_filt), MAXLAG+FR_INTERP_FILTER_LENGTH/2+3)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_1_tap_filter(&(d_mem->pitch_filt_per), MAXLAG+FR_INTERP_FILTER_LENGTH/2+3)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(d_mem->lpc_filt), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(d_mem->post_filt_p), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_zero_filter(&(d_mem->post_filt_z), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_zero_filter(&(d_mem->pitch_sm), PSMORDER)) != QCELPERR_OK) + return ret; + + for (i=0; ipitch_sm.zero_coeff[i] = hammsinc((float)(MAX_FR_RESOLUTION*(i-PSMORDER/2+.5))); + if ((ret=initialize_pole_filter(&(d_mem->bright_filt), 1)) != QCELPERR_OK) + return ret; d_mem->bright_filt.pole_coeff[0]= -BRIGHT_COEFF; - for (i=0; ilast_qlsp[i]= (float)(i+1)/(float)(LPCORDER+1); - } - for (i=0; ipred_qlsp[i]= 0.0; - } - + for (i=0; ilast_qlsp[i]= (float)(i+1)/(float)(LPCORDER+1); + for (i=0; ipred_qlsp[i]= 0.0; d_mem->low_rate_cnt = 0; d_mem->last_G = 0.0; - - d_mem->agc_factor = 1.0; d_mem->pre_factor = 1.0; @@ -163,95 +153,87 @@ d_mem->G_pred[0] = d_mem->G_pred[1] = 0; #endif - - /* initialize the encoder filters */ e_mem->dec.type=ENCODER; - initialize_zero_filter(&(e_mem->hipass_z), 2); - e_mem->hipass_z.zero_coeff[0]= -2.0; + if ((ret=initialize_zero_filter(&(e_mem->hipass_z), 2)) != QCELPERR_OK) + return ret; + e_mem->hipass_z.zero_coeff[0]= -2.0; e_mem->hipass_z.zero_coeff[1]= 1.0; - initialize_pole_filter(&(e_mem->hipass_p), 2); - e_mem->hipass_p.pole_coeff[0]= 1.88; + if ((ret=initialize_pole_filter(&(e_mem->hipass_p), 2)) != QCELPERR_OK) + return ret; + e_mem->hipass_p.pole_coeff[0]= 1.88; e_mem->hipass_p.pole_coeff[1]= -0.8836; /* -0.8836 = 0.94*0.94 */ - initialize_zero_filter(&(e_mem->decimate), DEC_ORDER); - for (i=0; idecimate.zero_coeff[i] = decimate_filter[i]; - } + if ((ret=initialize_zero_filter(&(e_mem->decimate), DEC_ORDER)) != QCELPERR_OK) + return ret; + for (i=0; idecimate.zero_coeff[i] = decimate_filter[i]; /* initialize bpf for unvoiced speech for enc and dec */ - initialize_zero_filter(&(e_mem->dec.bpf_unv), FIR_UNV_LEN); - for (i=0; idec.bpf_unv.zero_coeff[i] = unv_filter[i]; - } - initialize_zero_filter(&(d_mem->bpf_unv), FIR_UNV_LEN); - for (i=0; ibpf_unv.zero_coeff[i] = unv_filter[i]; - } - initialize_zero_filter(&(e_mem->form_res_filt), LPCORDER); - initialize_pole_filter(&(e_mem->spch_wght_syn_filt), LPCORDER); - initialize_pole_filter(&(e_mem->dec.wght_syn_filt), LPCORDER); - initialize_pole_1_tap_filter(&(e_mem->dec.pitch_filt), - MAXLAG+FR_INTERP_FILTER_LENGTH/2+3); - initialize_pole_filter(&(e_mem->dec.lpc_filt), LPCORDER); - initialize_pole_filter(&(e_mem->dec.jt_gain_opt), LPCORDER); - initialize_pole_filter(&(e_mem->target_syn_filter), LPCORDER); - initialize_zero_filter(&(e_mem->dec.pitch_sm), PSMORDER); + if ((ret=initialize_zero_filter(&(e_mem->dec.bpf_unv), FIR_UNV_LEN)) != QCELPERR_OK) + return ret; + for (i=0; idec.bpf_unv.zero_coeff[i] = unv_filter[i]; + if ((ret=initialize_zero_filter(&(d_mem->bpf_unv), FIR_UNV_LEN)) != QCELPERR_OK) + return ret; + for (i=0; ibpf_unv.zero_coeff[i] = unv_filter[i]; + if ((ret=initialize_zero_filter(&(e_mem->form_res_filt), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(e_mem->spch_wght_syn_filt), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(e_mem->dec.wght_syn_filt), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_1_tap_filter(&(e_mem->dec.pitch_filt), MAXLAG+FR_INTERP_FILTER_LENGTH/2+3)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(e_mem->dec.lpc_filt), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(e_mem->dec.jt_gain_opt), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_pole_filter(&(e_mem->target_syn_filter), LPCORDER)) != QCELPERR_OK) + return ret; + if ((ret=initialize_zero_filter(&(e_mem->dec.pitch_sm), PSMORDER)) != QCELPERR_OK) + return ret; e_mem->dec.low_rate_cnt = 0; - for (i=0; idec.pitch_sm.zero_coeff[i] = hammsinc((float)(MAX_FR_RESOLUTION* - (i-PSMORDER/2+.5))); - } + for (i=0; idec.pitch_sm.zero_coeff[i] = hammsinc((float)(MAX_FR_RESOLUTION*(i-PSMORDER/2+.5))); e_mem->dec.last_G = 0.0; - for (i=0; idec.last_qlsp[i]= (float)(i+1)/(float)(LPCORDER+1); - } - for (i=0; idec.pred_qlsp[i]= 0.0; - } - - for (i=0; ilast_lsp[i]= (float)(i+1)/(float)(LPCORDER+1); + for (i=0; idec.last_qlsp[i]= (float)(i+1)/(float)(LPCORDER+1); + for (i=0; idec.pred_qlsp[i]= 0.0; + + for (i=0; ilast_lsp[i]= (float)(i+1)/(float)(LPCORDER+1); + + for (i=0; i<2; i++) + { + control->snr.num_frames[i]=0; + control->snr.signal_energy[i]=0; + control->snr.noise_energy[i]=0; + control->snr.seg_snr[i]=0; } - - for (i=0; i<2; i++) { - control->snr.num_frames[i]=0; - control->snr.signal_energy[i]=0; - control->snr.noise_energy[i]=0; - control->snr.seg_snr[i]=0; - } - e_mem->last_rate = EIGHTH; e_mem->last_rate_1st_stage = EIGHTH; - /* init for average rate calc and thresholds */ - e_mem->avg_rate_thr = control->avg_rate; e_mem->avg_rate = e_mem->avg_rate_thr; - - /* start the target snr threshold at 10 db */ e_mem->target_snr_thr = control->target_snr_thr; - e_mem->target_snr = 1.0; - e_mem->target_snr_var = 1.0; e_mem->target_snr_mean = control->target_snr_thr; e_mem->features.pred_gain_mean = control->target_snr_thr; - for(i =0; i < FREQBANDS; i++){ - e_mem->features.band_snr_inst_last[i] = 0.0; - } - - for (i=0; ifeatures.last_lsp[i]= (float)(i+1)/(float)(LPCORDER+1); - } + for(i =0; i < FREQBANDS; i++) + e_mem->features.band_snr_inst_last[i] = 0.0; + for (i=0; ifeatures.last_lsp[i]= (float)(i+1)/(float)(LPCORDER+1); e_mem->features.last_nacf = 0.0; e_mem->features.last_diff_lsp = 0.0; e_mem->features.last_pred_gain = 0.0; e_mem->features.pred_gain_mean = 0.0; e_mem->features.pred_gain_var = 0.0; - e_mem->block_cnt = STATWINDOW; e_mem->full_force = e_mem->full_cnt = e_mem->full_cnt_t = e_mem->full_force_t = e_mem->half_force = e_mem->half_cnt = e_mem->half_cnt_t = e_mem->quarter_cnt = 0; @@ -260,34 +242,23 @@ e_mem->half_force_t = 0; for(i=0;i< 4;i++) e_mem->hist_above[i] = e_mem->hist_below[i] = 0; - /* rate decision initialization */ initialize_zero_filter(&(e_mem->unq_form_res_filt), LPCORDER); e_mem->num_full_frames=0; e_mem->hangover=10; e_mem->hangover_in_progress=0; - for(i = 0; i < PMAX; i++) e_mem->resid_mem[i] = 0.0; e_mem->adaptcount=0; e_mem->pitchrun=0; - e_mem->frame_energy_sm[0] = 3200000; e_mem->frame_energy_sm[1] = 320000; - - for (i=0; iband_power_last[i] = 0.0; - } - - e_mem->signal_energy[0] = 3200000; - e_mem->signal_energy[1] = 320000; - - + for (i=0; iband_power_last[i] = 0.0; + e_mem->signal_energy[0] = 3200000; + e_mem->signal_energy[1] = 320000; e_mem->snr_stat_once=0; - e_mem->dec.G_pred[0] = e_mem->dec.G_pred[1] = 0; - - for (j=0; jband_noise_sm[j]= HIGH_THRESH_LIM; @@ -336,13 +307,10 @@ CODEBOOK[i] = round_flt(CODEBOOK[i]*8192)/8192.0; } #endif - + return QCELPERR_OK; }/* end of initialize_encoder_and_decoder() */ -void free_encoder_and_decoder( - struct ENCODER_MEM *e_mem, - struct DECODER_MEM *d_mem -) +void free_encoder_and_decoder(struct ENCODER_MEM *e_mem,struct DECODER_MEM *d_mem) { free((char*) d_mem->pitch_filt.memory); free((char*) d_mem->pitch_filt_per.memory); @@ -373,39 +341,28 @@ /* free rate decision */ free_zero_filter(&(e_mem->unq_form_res_filt)); - } -void alloc_mem_for_speech( - float **in_speech, - float **out_speech -) +int alloc_mem_for_speech(float **in_speech,float **out_speech) { int i; float *ptr; - - if( (*in_speech = (float *) - calloc((unsigned) (FSIZE+LPCSIZE-FSIZE+LPCOFFSET), - (unsigned) sizeof(float))) == NULL){ - fprintf(stderr,"Error Allocating memory for in_speech\n"); - exit(-2); - } - - if ((*out_speech = (float *) - calloc((unsigned) FSIZE, sizeof(float))) == NULL){ - fprintf(stderr,"Error Allocating memory for out_speech\n"); - exit(-2); - } - - ptr = *in_speech; - for( i=0 ; i < LPCSIZE+LPCOFFSET ; i++ ) - { - ptr[i] = 0.0; - } - - ptr = *out_speech; - for( i=0 ; i < FSIZE ; i++ ) - { - ptr[i] = 0.0; - } + if( (*in_speech = (float *)calloc((unsigned) (FSIZE+LPCSIZE-FSIZE+LPCOFFSET),(unsigned) sizeof(float))) == NULL) + { + fprintf(stderr,"Error Allocating memory for in_speech\n"); + return QCELPERR_NOMEM; + } + if ((*out_speech = (float *)calloc((unsigned) FSIZE, sizeof(float))) == NULL) + { + fprintf(stderr,"Error Allocating memory for out_speech\n"); + return QCELPERR_NOMEM; + } + ptr = *in_speech; + for( i=0 ; i < LPCSIZE+LPCOFFSET ; i++ ) + ptr[i] = 0.0; + + ptr = *out_speech; + for( i=0 ; i < FSIZE ; i++ ) + ptr[i] = 0.0; + return QCELPERR_OK; } diff -ruN qc13_tia_50_ansi733_20040315-025/code/io.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/io.c --- qc13_tia_50_ansi733_20040315-025/code/io.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/io.c 2009-01-14 08:04:50.000000000 -0500 @@ -58,17 +58,16 @@ #include #include #include +#ifndef WIN32 #include +#endif #include #include "coder.h" #include "tty.h" /* open_binary_input_file - opens a binary input file */ -void open_binary_input_file( - FILE **fin, - char *filename -) +void open_binary_input_file(FILE **fin,char *filename) { if( (*fin=fopen(filename,"rb")) == NULL ) @@ -83,10 +82,7 @@ /* open_binary_output_file - opens a binary output file */ /* 19911017 */ -void open_binary_output_file( - FILE **fout, - char *filename -) +void open_binary_output_file(FILE **fout,char *filename) { printf( "Binary output file - %s\n",filename); if( (*fout=fopen(filename,"wb")) == NULL ) @@ -101,11 +97,7 @@ /* binary input file "fin" to float array "inbuf" */ /* The samples range from -2^15 to 2^15 -1. */ /* Returns the number of samples read. */ -int read_samples( - FILE *fin, - float *inbuf, - int insamples -) +int read_samples(FILE *fin,float *inbuf,int insamples) { int i; @@ -150,11 +142,7 @@ /* float array "outsamples" to binary output file "fout" */ /* Saturates the samples to the allowable range. */ /* Returns the number of samples written. */ -int write_samples( - FILE *fout, - float *outbuf, - int outsamples -) +int write_samples(FILE *fout,float *outbuf,int outsamples) { int num; @@ -185,11 +173,7 @@ }/* end of write_samples() */ -int read_packet( - FILE *fin, - int *inbuf, - int insamples -) +int read_packet(FILE *fin,int *inbuf,int insamples) { int i; int samplesread; @@ -208,11 +192,7 @@ }/* end of read_packet() */ -int write_packet( - FILE *fout, - int *outbuf, - int outsamples -) +int write_packet(FILE *fout,int *outbuf,int outsamples) { int i; int num; @@ -241,7 +221,12 @@ }/* end of write_packet() */ - - - - +int read_packet_qcp(FILE *fin,int *inbuf,int insamples) +{ + return fread(inbuf,1,insamples,fin); +} + +int write_packet_qcp(FILE *fout,int *outbuf,int outsamples) +{ + return fwrite(outbuf,1,outsamples,fout); +} diff -ruN qc13_tia_50_ansi733_20040315-025/code/lpc.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/lpc.c --- qc13_tia_50_ansi733_20040315-025/code/lpc.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/lpc.c 2009-01-14 09:25:36.000000000 -0500 @@ -142,7 +142,7 @@ return(R); } -void compute_lpc( +int compute_lpc( float *speech, int windowsize, int windowtype, @@ -173,7 +173,7 @@ break; default: printf("Unknown window type in lpc.c\n"); - usage(control); + return QCELPERR_LPCWIN; } for (i=0; i<=FILTERORDER; i++) { @@ -186,7 +186,7 @@ free((char*)lsp); free((char*)wspeech); #endif - + return QCELPERR_OK; } void interp_lpcs( diff -ruN qc13_tia_50_ansi733_20040315-025/code/pack.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/pack.c --- qc13_tia_50_ansi733_20040315-025/code/pack.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/pack.c 2009-01-14 09:04:06.000000000 -0500 @@ -51,8 +51,7 @@ such commitments. *******************************************************************/ /* pack.c - pack various parameters into the packet */ - - +/* modified and extended for reusability and handling qcelp-bytestreams - RetroPatch 0.2, January 2009 */ #include "celp.h" #include "pack.h" @@ -208,6 +207,8 @@ }/* end of pack_frame() */ + + void unpack_frame( struct PACKET *packet ) @@ -486,3 +487,170 @@ } } } + + +void pack_frame_qcp(int mode,struct PACKET *packet) +{ + int i, j; + int *data_ptr; + int bit[(WORDS_PER_PACKET-1)*16]; + int cnt; + + unsigned char *data=(unsigned char *)packet->data; + + switch(mode) { + case 4: /* full rate */ + data_ptr= &BIT_DATA2[0][0]; + break; + case 3: /* half rate */ + data_ptr= &BIT_DATA1[0][0]; + break; + case 2: /* quarter rate */ + data_ptr= &BIT_DATA3[0][0]; + break; + case 1: + data_ptr= &BIT_DATA0[0][0]; + break; + } + + +#if 0 + /* The next few lines helps with debugging */ + if(mode == EIGHTH || mode == QUARTERRATE_UNVOICED){ + for(i = 0; i < MAXSF; i++) + bzero((char*)packet->i[i], MAXNUMCB*sizeof(int)); + } +#else + if(mode == EIGHTH || mode == QUARTERRATE_UNVOICED){ + for(i = 0; i < MAXSF; i++) + for(j = 0; j < MAXNUMCB; j++) + packet->i[i][j] = 0; + } +#endif + + for (i=0; idata[0]=(unsigned char)mode; + data[0]=(unsigned char)mode; + + cnt=0; + // example + // input bitstream + // BIT Number 76543210 + // 103 = 01100111 + // bit field internal storage + // 0,1,1,0,1,1,1 + for (i=1; i < BYTES_PER_PACKET_QCP; i++) + { + data[i]=0; + if(mode != BLANK) + { + for (j=7; j >= 0; j--) + data[i]=(data[i]<<1)|(unsigned char)bit[cnt++]; + } + } + if(mode == EIGHTH ) + packet->sd_enc = data[1]; +} + +void unpack_frame_qcp(struct PACKET *packet) +{ + int i, j; + int *data_ptr; + unsigned char *data=(unsigned char *)packet->data; + int bit[(WORDS_PER_PACKET-1)*16]; + int cnt; + +#if ANSI_733_ALL_ZEROS + unsigned long ULtmp; +#endif /* ANSI_733_ALL_ZEROS */ + + packet->mode=(int)data[0]; + +#if ANSI_733_ALL_ZEROS + /* Check for all zeros full, half, or quarter-rate packet */ + /* and force that to Erasure */ + switch(packet->mode) + { + case 4: /* rate 4 */ + ULtmp = 0; + for (i=0; i < 34-1; i++) + ULtmp += (unsigned long) data[1+i]; + /* i=33, points to last byte, Need to mask out 10 MSBs, bits 256:265 */ + ULtmp += (unsigned long) (data[1+i]&&(0xC0)); + if (ULtmp ==0) + packet->mode = ERASURE; + break; + case 3: /* rate 3 */ + ULtmp = 0; + for (i=0; i < 16-1; i++) + ULtmp += (unsigned long) data[1+i]; + /* i=15, points to last byte, Need to mask out 12 MSBs, bits 112:123 */ + ULtmp += (unsigned long) (data[1+i]&&(0xF0)); + if (ULtmp ==0) + packet->mode = ERASURE; + break; + case 2: /* rate 2 */ + ULtmp = 0; + for (i=0; i < 8-1; i++) + ULtmp += (unsigned long) data[1+i]; + /* i=7, points to last byte, Need to mask out 6 MSBs, bits 48:53 */ + ULtmp += (unsigned long) (data[1+i]&&(0xFC)); + if (ULtmp ==0) + packet->mode = ERASURE; + break; + } + +#endif /* ANSI_733_ALL_ZEROS */ + + switch(packet->mode) + { + case 4: /* rate 1 */ + data_ptr= &BIT_DATA2[0][0]; + break; + case 3: /* rate 1/2 */ + data_ptr= &BIT_DATA1[0][0]; + break; + case 2: /* rate 1/4 */ + data_ptr= &BIT_DATA3[0][0]; + break; + case 1: /* rate 1/8 */ + data_ptr= &BIT_DATA0[0][0]; + break; + case 14:/* ERASURE */ + break; + case 0: /* BLANK */ + break; + default: + fprintf(stderr, "unpack_frame: Irregular mode=%d\n", packet->mode); + } + + + if(packet->mode == EIGHTH) + packet->sd_dec = data[1]; + + if (packet->mode!=ERASURE) + { + //create internal bitstream array out of the packed bytes + // example + // input bitstream + // BIT Number 76543210 + // 103 = 01100111 + // bit field internal storage + // 0,1,1,0,1,1,1 + cnt=0; + for (i=1; i < BYTES_PER_PACKET_QCP; i++) + { + for (j=7; j>=0; j--) + bit[cnt++] = ((data[i] & ( (unsigned int) 1<mode != BLANK) + { + for (i=0; imode]; i++) + putbit(packet, data_ptr[i*3], data_ptr[i*3+1], data_ptr[i*3+2], bit[i]); + } +} diff -ruN qc13_tia_50_ansi733_20040315-025/code/quantabs.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/quantabs.c --- qc13_tia_50_ansi733_20040315-025/code/quantabs.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/quantabs.c 2008-10-22 05:46:24.000000000 -0400 @@ -79,36 +79,36 @@ /* 10^(i/20) */ float GA[73] = -{ 0.5, 0.5, 0.625, 0.75, 0.75, 0.875, 1.0, 1.125, 1.25, 1.375, 1.625, - 1.75, 2.0, 2.25, 2.5, 2.875, 3.125, 3.5, 4.0, 4.5, 5.0, - 5.625, 6.25, 7.125, 8.0, 8.875, 10.0, 11.25, 12.625, 14.125, - 15.875, 17.75, 20.0, 22.375, 25.125, 28.125, 31.625, - 35.5, 39.75, 44.625, 50.125, 56.25, 63.125, 70.75, 79.375, - 89.125, 100.0, 112.25, 125.875, 141.25, 158.5, 177.875, 199.5, - 223.875, 251.25, 281.875, 316.25, 354.875, 398.125, 446.625, - 501.125, 562.375, 631.0, 708.0, 794.375, 891.25, 1000.0, 1122.0, - 1258.875, 1412.5, 1584.875, 1778.25, 1995.25}; +{ 0.5f, 0.5f, 0.625f, 0.75f, 0.75f, 0.875f, 1.0f, 1.125f, 1.25f, 1.375f, 1.625f, + 1.75f, 2.0f, 2.25f, 2.5f, 2.875f, 3.125f, 3.5f, 4.0f, 4.5f, 5.0f, + 5.625f, 6.25f, 7.125f, 8.0f, 8.875f, 10.0f, 11.25f, 12.625f, 14.125f, + 15.875f, 17.75f, 20.0f, 22.375f, 25.125f, 28.125f, 31.625f, + 35.5f, 39.75f, 44.625f, 50.125f, 56.25f, 63.125f, 70.75f, 79.375f, + 89.125f, 100.0f, 112.25f, 125.875f, 141.25f, 158.5f, 177.875f, 199.5f, + 223.875f, 251.25f, 281.875f, 316.25f, 354.875f, 398.125f, 446.625f, + 501.125f, 562.375f, 631.0f, 708.0f, 794.375f, 891.25f, 1000.0f, 1122.0f, + 1258.875f, 1412.5f, 1584.875f, 1778.25f, 1995.25f}; /* Begin quantize */ int LSP_QTYPE[NUMMODES] = {VQT, PRED, VQT, VQT, VQT}; -float LSP_DPCM_DECAY[NUMMODES]= {0.0, 0.90625, 0.0, 0.0, 0.0}; +float LSP_DPCM_DECAY[NUMMODES]= {0.0f, 0.90625f, 0.0f, 0.0f, 0.0f}; float MIN_DELTA_LSP[NUMMODES][LPCORDER] = -{{ -.05, -.08, -.14, -.14, -.12, -.12, -.10, -.10, -.08, -.08 }, -{-.02, -.02, -.02, -.02, -.02, -.02, -.02, -.02, -.02, -.02 }, -{ -.05, -.08, -.14, -.14, -.12, -.12, -.10, -.10, -.08, -.08 }, -{ -.05, -.08, -.14, -.14, -.12, -.12, -.10, -.10, -.08, -.08 }, -{ -.05, -.08, -.14, -.14, -.12, -.12, -.10, -.10, -.08, -.08 }}; +{{ -.05f, -.08f, -.14f, -.14f, -.12f, -.12f, -.10f, -.10f, -.08f, -.08f }, +{ -.02f, -.02f, -.02f, -.02f, -.02f, -.02f, -.02f, -.02f, -.02f, -.02f }, +{ -.05f, -.08f, -.14f, -.14f, -.12f, -.12f, -.10f, -.10f, -.08f, -.08f }, +{ -.05f, -.08f, -.14f, -.14f, -.12f, -.12f, -.10f, -.10f, -.08f, -.08f }, +{ -.05f, -.08f, -.14f, -.14f, -.12f, -.12f, -.10f, -.10f, -.08f, -.08f }}; float MAX_DELTA_LSP[NUMMODES][LPCORDER] = -{{ .05, .08, .14, .14, .12, .12, .10, .10, .08, .08 }, -{ .02, .02, .02, .02, .02, .02, .02, .02, .02, .02 }, -{ .05, .08, .14, .14, .12, .12, .10, .10, .08, .08 }, -{ .05, .08, .14, .14, .12, .12, .10, .10, .08, .08 }, -{ .05, .08, .14, .14, .12, .12, .10, .10, .08, .08 }}; +{{ .05f, .08f, .14f, .14f, .12f, .12f, .10f, .10f, .08f, .08f }, +{ .02f, .02f, .02f, .02f, .02f, .02f, .02f, .02f, .02f, .02f }, +{ .05f, .08f, .14f, .14f, .12f, .12f, .10f, .10f, .08f, .08f }, +{ .05f, .08f, .14f, .14f, .12f, .12f, .10f, .10f, .08f, .08f }, +{ .05f, .08f, .14f, .14f, .12f, .12f, .10f, .10f, .08f, .08f }}; int NUM_LSP_QLEVELS[NUMMODES][LPCORDER] = {{ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 }, @@ -119,468 +119,466 @@ float LSPVQSIZE[5]={64, 128, 128, 64, 64}; - float LSPVQ0[][2]= { -{ 0.0327, 0.0118}, -{ 0.0919, 0.0111}, -{ 0.0427, 0.0440}, -{ 0.1327, 0.0185}, -{ 0.0469, 0.0050}, -{ 0.1272, 0.0091}, -{ 0.0892, 0.0059}, -{ 0.1771, 0.0193}, -{ 0.0222, 0.0158}, -{ 0.1100, 0.0127}, -{ 0.0827, 0.0055}, -{ 0.0978, 0.0791}, -{ 0.0665, 0.0047}, -{ 0.0700, 0.1401}, -{ 0.0670, 0.0859}, -{ 0.1913, 0.1048}, -{ 0.0471, 0.0215}, -{ 0.1046, 0.0125}, -{ 0.0645, 0.0298}, -{ 0.1599, 0.0160}, -{ 0.0593, 0.0039}, -{ 0.1187, 0.0462}, -{ 0.0749, 0.0341}, -{ 0.1520, 0.0511}, -{ 0.0290, 0.0792}, -{ 0.0909, 0.0362}, -{ 0.0753, 0.0081}, -{ 0.1111, 0.1058}, -{ 0.0519, 0.0253}, -{ 0.0828, 0.0839}, -{ 0.0685, 0.0541}, -{ 0.1421, 0.1258}, -{ 0.0386, 0.0130}, -{ 0.0962, 0.0119}, -{ 0.0542, 0.0387}, -{ 0.1431, 0.0185}, -{ 0.0526, 0.0051}, -{ 0.1175, 0.0260}, -{ 0.0831, 0.0167}, -{ 0.1728, 0.0510}, -{ 0.0273, 0.0437}, -{ 0.1172, 0.0113}, -{ 0.0771, 0.0144}, -{ 0.1122, 0.0751}, -{ 0.0619, 0.0119}, -{ 0.0492, 0.1276}, -{ 0.0658, 0.0695}, -{ 0.1882, 0.0615}, -{ 0.0415, 0.0200}, -{ 0.1018, 0.0088}, -{ 0.0681, 0.0339}, -{ 0.1436, 0.0325}, -{ 0.0555, 0.0122}, -{ 0.1042, 0.0485}, -{ 0.0826, 0.0345}, -{ 0.1374, 0.0743}, -{ 0.0383, 0.1018}, -{ 0.1005, 0.0358}, -{ 0.0704, 0.0086}, -{ 0.1301, 0.0586}, -{ 0.0597, 0.0241}, -{ 0.0832, 0.0621}, -{ 0.0555, 0.0573}, -{ 0.1504, 0.0839}, +{ 0.0327f, 0.0118f}, +{ 0.0919f, 0.0111f}, +{ 0.0427f, 0.0440f}, +{ 0.1327f, 0.0185f}, +{ 0.0469f, 0.0050f}, +{ 0.1272f, 0.0091f}, +{ 0.0892f, 0.0059f}, +{ 0.1771f, 0.0193f}, +{ 0.0222f, 0.0158f}, +{ 0.1100f, 0.0127f}, +{ 0.0827f, 0.0055f}, +{ 0.0978f, 0.0791f}, +{ 0.0665f, 0.0047f}, +{ 0.0700f, 0.1401f}, +{ 0.0670f, 0.0859f}, +{ 0.1913f, 0.1048f}, +{ 0.0471f, 0.0215f}, +{ 0.1046f, 0.0125f}, +{ 0.0645f, 0.0298f}, +{ 0.1599f, 0.0160f}, +{ 0.0593f, 0.0039f}, +{ 0.1187f, 0.0462f}, +{ 0.0749f, 0.0341f}, +{ 0.1520f, 0.0511f}, +{ 0.0290f, 0.0792f}, +{ 0.0909f, 0.0362f}, +{ 0.0753f, 0.0081f}, +{ 0.1111f, 0.1058f}, +{ 0.0519f, 0.0253f}, +{ 0.0828f, 0.0839f}, +{ 0.0685f, 0.0541f}, +{ 0.1421f, 0.1258f}, +{ 0.0386f, 0.0130f}, +{ 0.0962f, 0.0119f}, +{ 0.0542f, 0.0387f}, +{ 0.1431f, 0.0185f}, +{ 0.0526f, 0.0051f}, +{ 0.1175f, 0.0260f}, +{ 0.0831f, 0.0167f}, +{ 0.1728f, 0.0510f}, +{ 0.0273f, 0.0437f}, +{ 0.1172f, 0.0113f}, +{ 0.0771f, 0.0144f}, +{ 0.1122f, 0.0751f}, +{ 0.0619f, 0.0119f}, +{ 0.0492f, 0.1276f}, +{ 0.0658f, 0.0695f}, +{ 0.1882f, 0.0615f}, +{ 0.0415f, 0.0200f}, +{ 0.1018f, 0.0088f}, +{ 0.0681f, 0.0339f}, +{ 0.1436f, 0.0325f}, +{ 0.0555f, 0.0122f}, +{ 0.1042f, 0.0485f}, +{ 0.0826f, 0.0345f}, +{ 0.1374f, 0.0743f}, +{ 0.0383f, 0.1018f}, +{ 0.1005f, 0.0358f}, +{ 0.0704f, 0.0086f}, +{ 0.1301f, 0.0586f}, +{ 0.0597f, 0.0241f}, +{ 0.0832f, 0.0621f}, +{ 0.0555f, 0.0573f}, +{ 0.1504f, 0.0839f}, }; - float LSPVQ1[][2]= { -{ 0.0255, 0.0293}, -{ 0.0904, 0.0219}, -{ 0.0151, 0.1211}, -{ 0.1447, 0.0498}, -{ 0.0470, 0.0253}, -{ 0.1559, 0.0177}, -{ 0.1547, 0.0994}, -{ 0.2394, 0.0242}, -{ 0.0091, 0.0813}, -{ 0.0857, 0.0590}, -{ 0.0934, 0.1326}, -{ 0.1889, 0.0282}, -{ 0.0813, 0.0472}, -{ 0.1057, 0.1494}, -{ 0.0450, 0.3315}, -{ 0.2163, 0.1895}, -{ 0.0538, 0.0532}, -{ 0.1399, 0.0218}, -{ 0.0146, 0.1552}, -{ 0.1755, 0.0626}, -{ 0.0822, 0.0202}, -{ 0.1299, 0.0663}, -{ 0.0706, 0.1732}, -{ 0.2656, 0.0401}, -{ 0.0418, 0.0745}, -{ 0.0762, 0.1038}, -{ 0.0583, 0.1748}, -{ 0.1746, 0.1285}, -{ 0.0527, 0.1169}, -{ 0.1314, 0.0830}, -{ 0.0556, 0.2116}, -{ 0.1073, 0.2321}, -{ 0.0297, 0.0570}, -{ 0.0981, 0.0403}, -{ 0.0468, 0.1103}, -{ 0.1740, 0.0243}, -{ 0.0725, 0.0179}, -{ 0.1255, 0.0474}, -{ 0.1374, 0.1362}, -{ 0.1922, 0.0912}, -{ 0.0285, 0.0947}, -{ 0.0930, 0.0700}, -{ 0.0593, 0.1372}, -{ 0.1909, 0.0576}, -{ 0.0588, 0.0916}, -{ 0.1110, 0.1116}, -{ 0.0224, 0.2719}, -{ 0.1633, 0.2220}, -{ 0.0402, 0.0520}, -{ 0.1061, 0.0448}, -{ 0.0402, 0.1352}, -{ 0.1499, 0.0775}, -{ 0.0664, 0.0589}, -{ 0.1081, 0.0727}, -{ 0.0801, 0.2206}, -{ 0.2165, 0.1157}, -{ 0.0566, 0.0802}, -{ 0.0911, 0.1116}, -{ 0.0306, 0.1703}, -{ 0.1792, 0.0836}, -{ 0.0655, 0.0999}, -{ 0.1061, 0.1038}, -{ 0.0298, 0.2089}, -{ 0.1110, 0.1753}, -{ 0.0361, 0.0311}, -{ 0.0970, 0.0239}, -{ 0.0265, 0.1231}, -{ 0.1495, 0.0573}, -{ 0.0566, 0.0262}, -{ 0.1569, 0.0293}, -{ 0.1341, 0.1144}, -{ 0.2271, 0.0544}, -{ 0.0214, 0.0877}, -{ 0.0847, 0.0719}, -{ 0.0794, 0.1384}, -{ 0.2067, 0.0274}, -{ 0.0703, 0.0688}, -{ 0.1099, 0.1306}, -{ 0.0391, 0.2947}, -{ 0.2024, 0.1670}, -{ 0.0471, 0.0525}, -{ 0.1245, 0.0290}, -{ 0.0264, 0.1557}, -{ 0.1568, 0.0807}, -{ 0.0718, 0.0399}, -{ 0.1193, 0.0685}, -{ 0.0883, 0.1594}, -{ 0.2729, 0.0764}, -{ 0.0500, 0.0754}, -{ 0.0809, 0.1108}, -{ 0.0541, 0.1648}, -{ 0.1523, 0.1385}, -{ 0.0614, 0.1196}, -{ 0.1209, 0.0847}, -{ 0.0345, 0.2242}, -{ 0.1442, 0.1747}, -{ 0.0199, 0.0560}, -{ 0.1092, 0.0194}, -{ 0.0349, 0.1253}, -{ 0.1653, 0.0507}, -{ 0.0625, 0.0354}, -{ 0.1376, 0.0431}, -{ 0.1187, 0.1465}, -{ 0.2164, 0.0872}, -{ 0.0360, 0.0974}, -{ 0.1008, 0.0698}, -{ 0.0704, 0.1346}, -{ 0.2114, 0.0452}, -{ 0.0720, 0.0816}, -{ 0.1240, 0.1089}, -{ 0.0439, 0.2475}, -{ 0.1498, 0.2040}, -{ 0.0336, 0.0718}, -{ 0.1213, 0.0187}, -{ 0.0451, 0.1450}, -{ 0.1368, 0.0885}, -{ 0.0592, 0.0578}, -{ 0.1131, 0.0531}, -{ 0.0861, 0.1855}, -{ 0.1764, 0.1500}, -{ 0.0444, 0.0970}, -{ 0.0935, 0.0903}, -{ 0.0424, 0.1687}, -{ 0.1633, 0.1102}, -{ 0.0793, 0.0897}, -{ 0.1060, 0.0897}, -{ 0.0185, 0.2011}, -{ 0.1205, 0.1855}, +{ 0.0255f, 0.0293f}, +{ 0.0904f, 0.0219f}, +{ 0.0151f, 0.1211f}, +{ 0.1447f, 0.0498f}, +{ 0.0470f, 0.0253f}, +{ 0.1559f, 0.0177f}, +{ 0.1547f, 0.0994f}, +{ 0.2394f, 0.0242f}, +{ 0.0091f, 0.0813f}, +{ 0.0857f, 0.0590f}, +{ 0.0934f, 0.1326f}, +{ 0.1889f, 0.0282f}, +{ 0.0813f, 0.0472f}, +{ 0.1057f, 0.1494f}, +{ 0.0450f, 0.3315f}, +{ 0.2163f, 0.1895f}, +{ 0.0538f, 0.0532f}, +{ 0.1399f, 0.0218f}, +{ 0.0146f, 0.1552f}, +{ 0.1755f, 0.0626f}, +{ 0.0822f, 0.0202f}, +{ 0.1299f, 0.0663f}, +{ 0.0706f, 0.1732f}, +{ 0.2656f, 0.0401f}, +{ 0.0418f, 0.0745f}, +{ 0.0762f, 0.1038f}, +{ 0.0583f, 0.1748f}, +{ 0.1746f, 0.1285f}, +{ 0.0527f, 0.1169f}, +{ 0.1314f, 0.0830f}, +{ 0.0556f, 0.2116f}, +{ 0.1073f, 0.2321f}, +{ 0.0297f, 0.0570f}, +{ 0.0981f, 0.0403f}, +{ 0.0468f, 0.1103f}, +{ 0.1740f, 0.0243f}, +{ 0.0725f, 0.0179f}, +{ 0.1255f, 0.0474f}, +{ 0.1374f, 0.1362f}, +{ 0.1922f, 0.0912f}, +{ 0.0285f, 0.0947f}, +{ 0.0930f, 0.0700f}, +{ 0.0593f, 0.1372f}, +{ 0.1909f, 0.0576f}, +{ 0.0588f, 0.0916f}, +{ 0.1110f, 0.1116f}, +{ 0.0224f, 0.2719f}, +{ 0.1633f, 0.2220f}, +{ 0.0402f, 0.0520f}, +{ 0.1061f, 0.0448f}, +{ 0.0402f, 0.1352f}, +{ 0.1499f, 0.0775f}, +{ 0.0664f, 0.0589f}, +{ 0.1081f, 0.0727f}, +{ 0.0801f, 0.2206f}, +{ 0.2165f, 0.1157f}, +{ 0.0566f, 0.0802f}, +{ 0.0911f, 0.1116f}, +{ 0.0306f, 0.1703f}, +{ 0.1792f, 0.0836f}, +{ 0.0655f, 0.0999f}, +{ 0.1061f, 0.1038f}, +{ 0.0298f, 0.2089f}, +{ 0.1110f, 0.1753f}, +{ 0.0361f, 0.0311f}, +{ 0.0970f, 0.0239f}, +{ 0.0265f, 0.1231f}, +{ 0.1495f, 0.0573f}, +{ 0.0566f, 0.0262f}, +{ 0.1569f, 0.0293f}, +{ 0.1341f, 0.1144f}, +{ 0.2271f, 0.0544f}, +{ 0.0214f, 0.0877f}, +{ 0.0847f, 0.0719f}, +{ 0.0794f, 0.1384f}, +{ 0.2067f, 0.0274f}, +{ 0.0703f, 0.0688f}, +{ 0.1099f, 0.1306f}, +{ 0.0391f, 0.2947f}, +{ 0.2024f, 0.1670f}, +{ 0.0471f, 0.0525f}, +{ 0.1245f, 0.0290f}, +{ 0.0264f, 0.1557f}, +{ 0.1568f, 0.0807f}, +{ 0.0718f, 0.0399f}, +{ 0.1193f, 0.0685f}, +{ 0.0883f, 0.1594f}, +{ 0.2729f, 0.0764f}, +{ 0.0500f, 0.0754f}, +{ 0.0809f, 0.1108f}, +{ 0.0541f, 0.1648f}, +{ 0.1523f, 0.1385f}, +{ 0.0614f, 0.1196f}, +{ 0.1209f, 0.0847f}, +{ 0.0345f, 0.2242f}, +{ 0.1442f, 0.1747f}, +{ 0.0199f, 0.0560f}, +{ 0.1092f, 0.0194f}, +{ 0.0349f, 0.1253f}, +{ 0.1653f, 0.0507f}, +{ 0.0625f, 0.0354f}, +{ 0.1376f, 0.0431f}, +{ 0.1187f, 0.1465f}, +{ 0.2164f, 0.0872f}, +{ 0.0360f, 0.0974f}, +{ 0.1008f, 0.0698f}, +{ 0.0704f, 0.1346f}, +{ 0.2114f, 0.0452f}, +{ 0.0720f, 0.0816f}, +{ 0.1240f, 0.1089f}, +{ 0.0439f, 0.2475f}, +{ 0.1498f, 0.2040f}, +{ 0.0336f, 0.0718f}, +{ 0.1213f, 0.0187f}, +{ 0.0451f, 0.1450f}, +{ 0.1368f, 0.0885f}, +{ 0.0592f, 0.0578f}, +{ 0.1131f, 0.0531f}, +{ 0.0861f, 0.1855f}, +{ 0.1764f, 0.1500f}, +{ 0.0444f, 0.0970f}, +{ 0.0935f, 0.0903f}, +{ 0.0424f, 0.1687f}, +{ 0.1633f, 0.1102f}, +{ 0.0793f, 0.0897f}, +{ 0.1060f, 0.0897f}, +{ 0.0185f, 0.2011f}, +{ 0.1205f, 0.1855f}, }; float LSPVQ2[][2]= { -{ 0.0255, 0.0283}, -{ 0.1296, 0.0355}, -{ 0.0543, 0.0343}, -{ 0.2073, 0.0274}, -{ 0.0204, 0.1099}, -{ 0.1562, 0.0523}, -{ 0.1388, 0.0161}, -{ 0.2784, 0.0274}, -{ 0.0112, 0.0849}, -{ 0.1870, 0.0175}, -{ 0.1189, 0.0160}, -{ 0.1490, 0.1088}, -{ 0.0969, 0.1115}, -{ 0.0659, 0.3322}, -{ 0.1158, 0.1073}, -{ 0.3183, 0.1363}, -{ 0.0517, 0.0223}, -{ 0.1740, 0.0223}, -{ 0.0704, 0.0387}, -{ 0.2637, 0.0234}, -{ 0.0692, 0.1005}, -{ 0.1287, 0.1610}, -{ 0.0952, 0.0532}, -{ 0.2393, 0.0646}, -{ 0.0490, 0.0552}, -{ 0.1619, 0.0657}, -{ 0.0845, 0.0670}, -{ 0.1784, 0.2280}, -{ 0.0191, 0.1775}, -{ 0.0272, 0.2868}, -{ 0.0942, 0.0952}, -{ 0.2628, 0.1479}, -{ 0.0278, 0.0579}, -{ 0.1565, 0.0218}, -{ 0.0814, 0.0180}, -{ 0.2379, 0.0187}, -{ 0.0276, 0.1444}, -{ 0.1199, 0.1223}, -{ 0.1200, 0.0349}, -{ 0.3009, 0.0307}, -{ 0.0312, 0.0844}, -{ 0.1898, 0.0306}, -{ 0.0863, 0.0470}, -{ 0.1685, 0.1241}, -{ 0.0513, 0.1727}, -{ 0.0711, 0.2233}, -{ 0.1085, 0.0864}, -{ 0.3398, 0.0527}, -{ 0.0414, 0.0440}, -{ 0.1356, 0.0612}, -{ 0.0964, 0.0147}, -{ 0.2173, 0.0738}, -{ 0.0465, 0.1292}, -{ 0.0877, 0.1749}, -{ 0.1104, 0.0689}, -{ 0.2105, 0.1311}, -{ 0.0580, 0.0864}, -{ 0.1895, 0.0752}, -{ 0.0652, 0.0609}, -{ 0.1485, 0.1699}, -{ 0.0514, 0.1400}, -{ 0.0386, 0.2131}, -{ 0.0933, 0.0798}, -{ 0.2473, 0.0986}, -{ 0.0334, 0.0360}, -{ 0.1375, 0.0398}, -{ 0.0621, 0.0276}, -{ 0.2183, 0.0280}, -{ 0.0311, 0.1114}, -{ 0.1382, 0.0807}, -{ 0.1284, 0.0175}, -{ 0.2605, 0.0636}, -{ 0.0230, 0.0816}, -{ 0.1739, 0.0408}, -{ 0.1074, 0.0176}, -{ 0.1619, 0.1120}, -{ 0.0784, 0.1371}, -{ 0.0448, 0.3050}, -{ 0.1189, 0.0880}, -{ 0.3039, 0.1165}, -{ 0.0424, 0.0241}, -{ 0.1672, 0.0186}, -{ 0.0815, 0.0333}, -{ 0.2432, 0.0324}, -{ 0.0584, 0.1029}, -{ 0.1137, 0.1546}, -{ 0.1015, 0.0585}, -{ 0.2198, 0.0995}, -{ 0.0574, 0.0581}, -{ 0.1746, 0.0647}, -{ 0.0733, 0.0740}, -{ 0.1938, 0.1737}, -{ 0.0347, 0.1710}, -{ 0.0373, 0.2429}, -{ 0.0787, 0.1061}, -{ 0.2439, 0.1438}, -{ 0.0185, 0.0536}, -{ 0.1489, 0.0178}, -{ 0.0703, 0.0216}, -{ 0.2178, 0.0482}, -{ 0.0154, 0.1421}, -{ 0.1414, 0.0994}, -{ 0.1103, 0.0352}, -{ 0.3072, 0.0473}, -{ 0.0408, 0.0819}, -{ 0.2055, 0.0168}, -{ 0.0998, 0.0354}, -{ 0.1917, 0.1140}, -{ 0.0665, 0.1799}, -{ 0.0993, 0.2213}, -{ 0.1234, 0.0631}, -{ 0.3003, 0.0762}, -{ 0.0373, 0.0620}, -{ 0.1518, 0.0425}, -{ 0.0913, 0.0300}, -{ 0.1966, 0.0836}, -{ 0.0402, 0.1185}, -{ 0.0948, 0.1385}, -{ 0.1121, 0.0555}, -{ 0.1802, 0.1509}, -{ 0.0474, 0.0886}, -{ 0.1888, 0.0610}, -{ 0.0739, 0.0585}, -{ 0.1231, 0.2379}, -{ 0.0661, 0.1335}, -{ 0.0205, 0.2211}, -{ 0.0823, 0.0822}, -{ 0.2480, 0.1179}, +{ 0.0255f, 0.0283f}, +{ 0.1296f, 0.0355f}, +{ 0.0543f, 0.0343f}, +{ 0.2073f, 0.0274f}, +{ 0.0204f, 0.1099f}, +{ 0.1562f, 0.0523f}, +{ 0.1388f, 0.0161f}, +{ 0.2784f, 0.0274f}, +{ 0.0112f, 0.0849f}, +{ 0.1870f, 0.0175f}, +{ 0.1189f, 0.0160f}, +{ 0.1490f, 0.1088f}, +{ 0.0969f, 0.1115f}, +{ 0.0659f, 0.3322f}, +{ 0.1158f, 0.1073f}, +{ 0.3183f, 0.1363f}, +{ 0.0517f, 0.0223f}, +{ 0.1740f, 0.0223f}, +{ 0.0704f, 0.0387f}, +{ 0.2637f, 0.0234f}, +{ 0.0692f, 0.1005f}, +{ 0.1287f, 0.1610f}, +{ 0.0952f, 0.0532f}, +{ 0.2393f, 0.0646f}, +{ 0.0490f, 0.0552f}, +{ 0.1619f, 0.0657f}, +{ 0.0845f, 0.0670f}, +{ 0.1784f, 0.2280f}, +{ 0.0191f, 0.1775f}, +{ 0.0272f, 0.2868f}, +{ 0.0942f, 0.0952f}, +{ 0.2628f, 0.1479f}, +{ 0.0278f, 0.0579f}, +{ 0.1565f, 0.0218f}, +{ 0.0814f, 0.0180f}, +{ 0.2379f, 0.0187f}, +{ 0.0276f, 0.1444f}, +{ 0.1199f, 0.1223f}, +{ 0.1200f, 0.0349f}, +{ 0.3009f, 0.0307f}, +{ 0.0312f, 0.0844f}, +{ 0.1898f, 0.0306f}, +{ 0.0863f, 0.0470f}, +{ 0.1685f, 0.1241f}, +{ 0.0513f, 0.1727f}, +{ 0.0711f, 0.2233f}, +{ 0.1085f, 0.0864f}, +{ 0.3398f, 0.0527f}, +{ 0.0414f, 0.0440f}, +{ 0.1356f, 0.0612f}, +{ 0.0964f, 0.0147f}, +{ 0.2173f, 0.0738f}, +{ 0.0465f, 0.1292f}, +{ 0.0877f, 0.1749f}, +{ 0.1104f, 0.0689f}, +{ 0.2105f, 0.1311f}, +{ 0.0580f, 0.0864f}, +{ 0.1895f, 0.0752f}, +{ 0.0652f, 0.0609f}, +{ 0.1485f, 0.1699f}, +{ 0.0514f, 0.1400f}, +{ 0.0386f, 0.2131f}, +{ 0.0933f, 0.0798f}, +{ 0.2473f, 0.0986f}, +{ 0.0334f, 0.0360f}, +{ 0.1375f, 0.0398f}, +{ 0.0621f, 0.0276f}, +{ 0.2183f, 0.0280f}, +{ 0.0311f, 0.1114f}, +{ 0.1382f, 0.0807f}, +{ 0.1284f, 0.0175f}, +{ 0.2605f, 0.0636f}, +{ 0.0230f, 0.0816f}, +{ 0.1739f, 0.0408f}, +{ 0.1074f, 0.0176f}, +{ 0.1619f, 0.1120f}, +{ 0.0784f, 0.1371f}, +{ 0.0448f, 0.3050f}, +{ 0.1189f, 0.0880f}, +{ 0.3039f, 0.1165f}, +{ 0.0424f, 0.0241f}, +{ 0.1672f, 0.0186f}, +{ 0.0815f, 0.0333f}, +{ 0.2432f, 0.0324f}, +{ 0.0584f, 0.1029f}, +{ 0.1137f, 0.1546f}, +{ 0.1015f, 0.0585f}, +{ 0.2198f, 0.0995f}, +{ 0.0574f, 0.0581f}, +{ 0.1746f, 0.0647f}, +{ 0.0733f, 0.0740f}, +{ 0.1938f, 0.1737f}, +{ 0.0347f, 0.1710f}, +{ 0.0373f, 0.2429f}, +{ 0.0787f, 0.1061f}, +{ 0.2439f, 0.1438f}, +{ 0.0185f, 0.0536f}, +{ 0.1489f, 0.0178f}, +{ 0.0703f, 0.0216f}, +{ 0.2178f, 0.0482f}, +{ 0.0154f, 0.1421f}, +{ 0.1414f, 0.0994f}, +{ 0.1103f, 0.0352f}, +{ 0.3072f, 0.0473f}, +{ 0.0408f, 0.0819f}, +{ 0.2055f, 0.0168f}, +{ 0.0998f, 0.0354f}, +{ 0.1917f, 0.1140f}, +{ 0.0665f, 0.1799f}, +{ 0.0993f, 0.2213f}, +{ 0.1234f, 0.0631f}, +{ 0.3003f, 0.0762f}, +{ 0.0373f, 0.0620f}, +{ 0.1518f, 0.0425f}, +{ 0.0913f, 0.0300f}, +{ 0.1966f, 0.0836f}, +{ 0.0402f, 0.1185f}, +{ 0.0948f, 0.1385f}, +{ 0.1121f, 0.0555f}, +{ 0.1802f, 0.1509f}, +{ 0.0474f, 0.0886f}, +{ 0.1888f, 0.0610f}, +{ 0.0739f, 0.0585f}, +{ 0.1231f, 0.2379f}, +{ 0.0661f, 0.1335f}, +{ 0.0205f, 0.2211f}, +{ 0.0823f, 0.0822f}, +{ 0.2480f, 0.1179f}, }; float LSPVQ3[][2]= { -{ 0.0348, 0.0311}, -{ 0.0812, 0.1145}, -{ 0.0552, 0.0461}, -{ 0.1826, 0.0263}, -{ 0.0601, 0.0675}, -{ 0.1730, 0.0172}, -{ 0.1523, 0.0193}, -{ 0.2449, 0.0277}, -{ 0.0334, 0.0668}, -{ 0.0805, 0.1441}, -{ 0.1319, 0.0207}, -{ 0.1684, 0.0910}, -{ 0.0582, 0.1318}, -{ 0.1403, 0.1098}, -{ 0.0979, 0.0832}, -{ 0.2700, 0.1359}, -{ 0.0624, 0.0228}, -{ 0.1292, 0.0979}, -{ 0.0800, 0.0195}, -{ 0.2226, 0.0285}, -{ 0.0730, 0.0862}, -{ 0.1537, 0.0601}, -{ 0.1115, 0.0509}, -{ 0.2720, 0.0354}, -{ 0.0218, 0.1167}, -{ 0.1212, 0.1538}, -{ 0.1074, 0.0247}, -{ 0.1674, 0.1710}, -{ 0.0322, 0.2142}, -{ 0.1263, 0.0777}, -{ 0.0981, 0.0556}, -{ 0.2119, 0.1710}, -{ 0.0193, 0.0596}, -{ 0.1035, 0.0957}, -{ 0.0694, 0.0397}, -{ 0.1997, 0.0253}, -{ 0.0743, 0.0603}, -{ 0.1584, 0.0321}, -{ 0.1346, 0.0346}, -{ 0.2221, 0.0708}, -{ 0.0451, 0.0732}, -{ 0.1040, 0.1415}, -{ 0.1184, 0.0230}, -{ 0.1853, 0.0919}, -{ 0.0310, 0.1661}, -{ 0.1625, 0.0706}, -{ 0.0856, 0.0843}, -{ 0.2902, 0.0702}, -{ 0.0467, 0.0348}, -{ 0.1108, 0.1048}, -{ 0.0859, 0.0306}, -{ 0.1964, 0.0463}, -{ 0.0560, 0.1013}, -{ 0.1425, 0.0533}, -{ 0.1142, 0.0634}, -{ 0.2391, 0.0879}, -{ 0.0397, 0.1084}, -{ 0.1345, 0.1700}, -{ 0.0976, 0.0248}, -{ 0.1887, 0.1189}, -{ 0.0644, 0.2087}, -{ 0.1262, 0.0603}, -{ 0.0877, 0.0550}, -{ 0.2203, 0.1307}, +{ 0.0348f, 0.0311f}, +{ 0.0812f, 0.1145f}, +{ 0.0552f, 0.0461f}, +{ 0.1826f, 0.0263f}, +{ 0.0601f, 0.0675f}, +{ 0.1730f, 0.0172f}, +{ 0.1523f, 0.0193f}, +{ 0.2449f, 0.0277f}, +{ 0.0334f, 0.0668f}, +{ 0.0805f, 0.1441f}, +{ 0.1319f, 0.0207f}, +{ 0.1684f, 0.0910f}, +{ 0.0582f, 0.1318f}, +{ 0.1403f, 0.1098f}, +{ 0.0979f, 0.0832f}, +{ 0.2700f, 0.1359f}, +{ 0.0624f, 0.0228f}, +{ 0.1292f, 0.0979f}, +{ 0.0800f, 0.0195f}, +{ 0.2226f, 0.0285f}, +{ 0.0730f, 0.0862f}, +{ 0.1537f, 0.0601f}, +{ 0.1115f, 0.0509f}, +{ 0.2720f, 0.0354f}, +{ 0.0218f, 0.1167f}, +{ 0.1212f, 0.1538f}, +{ 0.1074f, 0.0247f}, +{ 0.1674f, 0.1710f}, +{ 0.0322f, 0.2142f}, +{ 0.1263f, 0.0777f}, +{ 0.0981f, 0.0556f}, +{ 0.2119f, 0.1710f}, +{ 0.0193f, 0.0596f}, +{ 0.1035f, 0.0957f}, +{ 0.0694f, 0.0397f}, +{ 0.1997f, 0.0253f}, +{ 0.0743f, 0.0603f}, +{ 0.1584f, 0.0321f}, +{ 0.1346f, 0.0346f}, +{ 0.2221f, 0.0708f}, +{ 0.0451f, 0.0732f}, +{ 0.1040f, 0.1415f}, +{ 0.1184f, 0.0230f}, +{ 0.1853f, 0.0919f}, +{ 0.0310f, 0.1661f}, +{ 0.1625f, 0.0706f}, +{ 0.0856f, 0.0843f}, +{ 0.2902f, 0.0702f}, +{ 0.0467f, 0.0348f}, +{ 0.1108f, 0.1048f}, +{ 0.0859f, 0.0306f}, +{ 0.1964f, 0.0463f}, +{ 0.0560f, 0.1013f}, +{ 0.1425f, 0.0533f}, +{ 0.1142f, 0.0634f}, +{ 0.2391f, 0.0879f}, +{ 0.0397f, 0.1084f}, +{ 0.1345f, 0.1700f}, +{ 0.0976f, 0.0248f}, +{ 0.1887f, 0.1189f}, +{ 0.0644f, 0.2087f}, +{ 0.1262f, 0.0603f}, +{ 0.0877f, 0.0550f}, +{ 0.2203f, 0.1307f}, }; float LSPVQ4[][2]= { -{ 0.0360, 0.0222}, -{ 0.0820, 0.1097}, -{ 0.0601, 0.0319}, -{ 0.1656, 0.0198}, -{ 0.0604, 0.0513}, -{ 0.1552, 0.0141}, -{ 0.1391, 0.0155}, -{ 0.2474, 0.0261}, -{ 0.0269, 0.0785}, -{ 0.1463, 0.0646}, -{ 0.1123, 0.0191}, -{ 0.2015, 0.0223}, -{ 0.0785, 0.0844}, -{ 0.1202, 0.1011}, -{ 0.0980, 0.0807}, -{ 0.3014, 0.0793}, -{ 0.0570, 0.0180}, -{ 0.1135, 0.1382}, -{ 0.0778, 0.0256}, -{ 0.1901, 0.0179}, -{ 0.0807, 0.0622}, -{ 0.1461, 0.0458}, -{ 0.1231, 0.0178}, -{ 0.2028, 0.0821}, -{ 0.0387, 0.0927}, -{ 0.1496, 0.1004}, -{ 0.0888, 0.0392}, -{ 0.2246, 0.0341}, -{ 0.0295, 0.1462}, -{ 0.1156, 0.0694}, -{ 0.1022, 0.0473}, -{ 0.2226, 0.1364}, -{ 0.0210, 0.0478}, -{ 0.1029, 0.1020}, -{ 0.0722, 0.0181}, -{ 0.1731, 0.0251}, -{ 0.0730, 0.0488}, -{ 0.1465, 0.0293}, -{ 0.1303, 0.0326}, -{ 0.2595, 0.0387}, -{ 0.0458, 0.0584}, -{ 0.1569, 0.0742}, -{ 0.1029, 0.0173}, -{ 0.1910, 0.0495}, -{ 0.0605, 0.1159}, -{ 0.1268, 0.0719}, -{ 0.0973, 0.0646}, -{ 0.2872, 0.0428}, -{ 0.0443, 0.0334}, -{ 0.0835, 0.1465}, -{ 0.0912, 0.0138}, -{ 0.1716, 0.0442}, -{ 0.0620, 0.0778}, -{ 0.1316, 0.0450}, -{ 0.1186, 0.0335}, -{ 0.1446, 0.1665}, -{ 0.0486, 0.1050}, -{ 0.1675, 0.1019}, -{ 0.0880, 0.0278}, -{ 0.2214, 0.0202}, -{ 0.0539, 0.1564}, -{ 0.1142, 0.0533}, -{ 0.0984, 0.0391}, -{ 0.2130, 0.1089}, +{ 0.0360f, 0.0222f}, +{ 0.0820f, 0.1097f}, +{ 0.0601f, 0.0319f}, +{ 0.1656f, 0.0198f}, +{ 0.0604f, 0.0513f}, +{ 0.1552f, 0.0141f}, +{ 0.1391f, 0.0155f}, +{ 0.2474f, 0.0261f}, +{ 0.0269f, 0.0785f}, +{ 0.1463f, 0.0646f}, +{ 0.1123f, 0.0191f}, +{ 0.2015f, 0.0223f}, +{ 0.0785f, 0.0844f}, +{ 0.1202f, 0.1011f}, +{ 0.0980f, 0.0807f}, +{ 0.3014f, 0.0793f}, +{ 0.0570f, 0.0180f}, +{ 0.1135f, 0.1382f}, +{ 0.0778f, 0.0256f}, +{ 0.1901f, 0.0179f}, +{ 0.0807f, 0.0622f}, +{ 0.1461f, 0.0458f}, +{ 0.1231f, 0.0178f}, +{ 0.2028f, 0.0821f}, +{ 0.0387f, 0.0927f}, +{ 0.1496f, 0.1004f}, +{ 0.0888f, 0.0392f}, +{ 0.2246f, 0.0341f}, +{ 0.0295f, 0.1462f}, +{ 0.1156f, 0.0694f}, +{ 0.1022f, 0.0473f}, +{ 0.2226f, 0.1364f}, +{ 0.0210f, 0.0478f}, +{ 0.1029f, 0.1020f}, +{ 0.0722f, 0.0181f}, +{ 0.1731f, 0.0251f}, +{ 0.0730f, 0.0488f}, +{ 0.1465f, 0.0293f}, +{ 0.1303f, 0.0326f}, +{ 0.2595f, 0.0387f}, +{ 0.0458f, 0.0584f}, +{ 0.1569f, 0.0742f}, +{ 0.1029f, 0.0173f}, +{ 0.1910f, 0.0495f}, +{ 0.0605f, 0.1159f}, +{ 0.1268f, 0.0719f}, +{ 0.0973f, 0.0646f}, +{ 0.2872f, 0.0428f}, +{ 0.0443f, 0.0334f}, +{ 0.0835f, 0.1465f}, +{ 0.0912f, 0.0138f}, +{ 0.1716f, 0.0442f}, +{ 0.0620f, 0.0778f}, +{ 0.1316f, 0.0450f}, +{ 0.1186f, 0.0335f}, +{ 0.1446f, 0.1665f}, +{ 0.0486f, 0.1050f}, +{ 0.1675f, 0.1019f}, +{ 0.0880f, 0.0278f}, +{ 0.2214f, 0.0202f}, +{ 0.0539f, 0.1564f}, +{ 0.1142f, 0.0533f}, +{ 0.0984f, 0.0391f}, +{ 0.2130f, 0.1089f}, }; /* End quantize */ diff -ruN qc13_tia_50_ansi733_20040315-025/code/quantize.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/quantize.c --- qc13_tia_50_ansi733_20040315-025/code/quantize.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/quantize.c 2009-01-14 08:39:02.000000000 -0500 @@ -512,7 +512,7 @@ unquantize_i(i, qcode_i); } -void unquantize_lag( +int unquantize_lag( int *lag, int *qcode_lag, int *frac, @@ -534,8 +534,9 @@ } else{ printf("unquantize_lag: qcode_lag %d and qcode_frac %d\n", *qcode_lag, *qcode_frac); - exit(-4); + return QCELPERR_LAG; } + return QCELPERR_OK; } /* quantize/encode pitch lag and pitch lag fraction bit */ @@ -719,34 +720,36 @@ int i; float pred; - if (G_QUANT_TYPE[mode]==LINEAR) { - if ((mode!=FULLRATE_VOICED)||((cbsf+1)%4 !=0)) { - if (unq_G>0.01) { - lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], - 20*log_10((double)unq_G) ); - - *qcode_Gsign=POSITIVE; - } - else if (unq_G< -0.01){ - lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], - 20*log_10((double)(-unq_G)) ); - *qcode_Gsign=NEGATIVE; - } - else { - lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], - 20*log_10((double)(0.01)) ); - *qcode_Gsign=NEGATIVE; - - if(mode == EIGHTH || mode == QUARTERRATE_UNVOICED){ - *qcode_Gsign=POSITIVE; - } - } - } - else { - pred=0; - for (i=0; i0.01) + { + lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode],20*log_10((double)unq_G) ); + *qcode_Gsign=POSITIVE; + } + else if (unq_G< -0.01) + { + lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], 20*log_10((double)(-unq_G)) ); + *qcode_Gsign=NEGATIVE; + } + else + { + lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], 20*log_10((double)(0.01)) ); + *qcode_Gsign=NEGATIVE; + + if(mode == EIGHTH || mode == QUARTERRATE_UNVOICED) + *qcode_Gsign=POSITIVE; + } + } + else + { + pred=0; + for (i=0; i0.01) { - lin_quant(qcode_G, RELMING, RELMAXG, - RELNUMBER_OF_G_LEVELS[mode], - ((int) 20*log_10((double)unq_G)) - pred ); + lin_quant(qcode_G, RELMING, RELMAXG, RELNUMBER_OF_G_LEVELS[mode], ((int) 20*log_10((double)unq_G)) - pred ); *qcode_Gsign=POSITIVE; } else if (unq_G< -0.01){ - lin_quant(qcode_G, RELMING, RELMAXG, - RELNUMBER_OF_G_LEVELS[mode], - ((int) 20*log_10((double)(-unq_G)))- pred ); + lin_quant(qcode_G, RELMING, RELMAXG, RELNUMBER_OF_G_LEVELS[mode], ((int) 20*log_10((double)(-unq_G)))- pred ); *qcode_Gsign=NEGATIVE; } else { - lin_quant(qcode_G, RELMING, RELMAXG, - RELNUMBER_OF_G_LEVELS[mode], - ((int) 20*log_10((double)(0.01))) - pred ); + lin_quant(qcode_G, RELMING, RELMAXG, RELNUMBER_OF_G_LEVELS[mode], ((int) 20*log_10((double)(0.01))) - pred ); *qcode_Gsign=NEGATIVE; } } @@ -781,13 +778,11 @@ pred+=lastG[i]*GPRED_COEFF[i]; } if (unq_G>0) { - lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], - 20*log_10((double)unq_G)-pred ); + lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], 20*log_10((double)unq_G)-pred ); *qcode_Gsign=POSITIVE; } else { - lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], - 20*log_10((double)(-unq_G))-pred ); + lin_quant(qcode_G, MING[mode], MAXG[mode], NUMBER_OF_G_LEVELS[mode], 20*log_10((double)(-unq_G))-pred ); *qcode_Gsign=NEGATIVE; } } diff -ruN qc13_tia_50_ansi733_20040315-025/code/ratedec.c qc13_tia_50_ansi733_20040315-025_retropatch02/code/ratedec.c --- qc13_tia_50_ansi733_20040315-025/code/ratedec.c 2005-03-16 00:43:06.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/code/ratedec.c 2008-10-22 05:01:38.000000000 -0400 @@ -197,75 +197,66 @@ } } -void update_hist_cnt( - struct ENCODER_MEM *e_mem, - int rate -) +int update_hist_cnt(struct ENCODER_MEM *e_mem,int rate) { /* this routine will keep track of the number of frames in each rate */ /* and will update 2 histograms: target_snr's when frame is full rate */ /* and target_snr's when frame is 1/2 rate */ - if(rate == FULLRATE_VOICED){ - if(e_mem->target_snr <= e_mem->target_snr_thr){ - e_mem->full_cnt += 1; - - } + if(rate == FULLRATE_VOICED) + { + if(e_mem->target_snr <= e_mem->target_snr_thr) + e_mem->full_cnt += 1; else - { - e_mem->full_force += 1; - } + e_mem->full_force += 1; } - else if(rate == HALFRATE_VOICED){ - if(e_mem->target_snr > e_mem->target_snr_thr){ - e_mem->half_cnt += 1; - } + else if(rate == HALFRATE_VOICED) + { + if(e_mem->target_snr > e_mem->target_snr_thr) + e_mem->half_cnt += 1; else - { - e_mem->half_force += 1; - } + e_mem->half_force += 1; } - else if(rate == QUARTERRATE_UNVOICED){ - e_mem->quarter_cnt += 1; - } - else{ + else if(rate == QUARTERRATE_UNVOICED) + e_mem->quarter_cnt += 1; + else + { fprintf(stderr,"Illegal rate/mode assignment: %d\n", rate); - exit(-4); + return QCELPERR_MODE; } - if(rate == FULLRATE_VOICED || rate == HALFRATE_VOICED){ - if(e_mem->target_snr <= e_mem->target_snr_thr){ - + if(rate == FULLRATE_VOICED || rate == HALFRATE_VOICED) + { + if(e_mem->target_snr <= e_mem->target_snr_thr) + { /* note that hist_below[0] contains count of full or half frames that */ /* were less than 1 db below threshold, hist_below[3] contains count*/ /* of frames declared full that were greater than 3 db below */ /* the threshold */ - if((e_mem->target_snr_thr - e_mem->target_snr) >= 3){ - e_mem->hist_below[3] += 1; - } + if((e_mem->target_snr_thr - e_mem->target_snr) >= 3) + e_mem->hist_below[3] += 1; else - e_mem->hist_below[(int)(e_mem->target_snr_thr - e_mem->target_snr)] += 1; + e_mem->hist_below[(int)(e_mem->target_snr_thr - e_mem->target_snr)] += 1; } - else{ + else + { /* note that hist_above3[0] contains count of full and half frames that */ /* were less than 1 db above threshold, hist_above[3] contains count*/ /* of frames declared full that were greater than 3 db above */ /* the threshold */ - if((e_mem->target_snr - e_mem->target_snr_thr) >= 3){ - e_mem->hist_above[3] += 1; - } + if((e_mem->target_snr - e_mem->target_snr_thr) >= 3) + e_mem->hist_above[3] += 1; else - e_mem->hist_above[(int)(e_mem->target_snr - e_mem->target_snr_thr)] += 1; + e_mem->hist_above[(int)(e_mem->target_snr - e_mem->target_snr_thr)] += 1; } } + return QCELPERR_OK; }/* end of update_hist_cnt() */ -void adjust_rate_down( - struct ENCODER_MEM *e_mem -) +void adjust_rate_down(struct ENCODER_MEM *e_mem) { /* look at histogram of target_snr's when frame was declared full and */ /* adjust threshold so that a larger % of full rate frames get declared */ @@ -438,7 +429,7 @@ int last_solid_voiced = 0; -void select_mode2( +int select_mode2( int *rate, float *form_resid, float *acf, @@ -464,22 +455,23 @@ float resid[(FSIZE+PMAX)/DECIMATE_F]; float pitch_cor[PITCH_NUM+1]; + int ret; + /* Section 2.4.4.2 */ /* now filter the prediction residual and decimate by a factor of 2 */ /* for computing NACF as a periodicity measure */ - do_fir_linear_filter(form_resid, tmpbuf, FSIZE, &(e_mem->decimate), UPDATE); - for (i=0; idecimate), UPDATE)) != QCELPERR_OK) + return ret; + + for (i=0; iresid_mem[i]; - } - for (i=0; iresid_mem[i]=resid[i+FSIZE/DECIMATE_F]; - } /* now do open loop pitch prediction */ maxlag = PMIN/DECIMATE_F; @@ -497,15 +489,11 @@ pitch_cor[0] = max_cor; /* Calculate ACF and other unvoiced detection parameters */ - compute_features(&pitch_cor[0],&pitch[0],resid,speech, - &(e_mem->features),acf,lpc,lsp,e_mem->band_power, - e_mem ); + compute_features(&pitch_cor[0],&pitch[0],resid,speech,&(e_mem->features),acf,lpc,lsp,e_mem->band_power,e_mem ); /* Updating Smooth Energy estimate Esmb(i)(k), Eq. (2.4.4.1-3) */ - for(i=0;iframe_energy_sm[i] = SMSNR*e_mem->frame_energy_sm[i] - + (1.0-SMSNR)*e_mem->band_power[i]; - } + for(i=0;iframe_energy_sm[i] = SMSNR*e_mem->frame_energy_sm[i] + (1.0-SMSNR)*e_mem->band_power[i]; /************************************************************************/ /* Section 2.4.4.2.2 Updating background noise */ @@ -793,7 +781,8 @@ /* update histogram of target_snr for full rates and 1/2 rates */ /* and update counts for the type of frame */ - update_hist_cnt(e_mem, *rate); + if ((ret=update_hist_cnt(e_mem, *rate)) != QCELPERR_OK) + return ret; e_mem->block_cnt -=1; } else /* the block has expired so make threshold adjustments */ @@ -847,6 +836,5 @@ fprintf(stderr,"error rate after stage 2: rate1=%d rate=%d\n", e_mem->last_rate_1st_stage, e_mem->last_rate); } - + return QCELPERR_OK; }/* end of select_mode2() */ - diff -ruN qc13_tia_50_ansi733_20040315-025/qcelp_research.txt qc13_tia_50_ansi733_20040315-025_retropatch02/qcelp_research.txt --- qc13_tia_50_ansi733_20040315-025/qcelp_research.txt 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/qcelp_research.txt 2008-09-09 20:57:22.000000000 -0400 @@ -0,0 +1,68 @@ +Actual QCELP File: +------------------ +04 +4F B0 F6 D7 80 00 70 59 16 80 9D E8 F4 40 E5 A2 F2 2E 69 F1 0B B1 62 D9 3B A7 67 76 D6 5E 45 44 09 00 + +04 +8F A8 16 8B A5 80 81 97 9F 08 07 54 06 5A 62 E5 FB EA A9 70 2D CA 1A D4 77 42 61 DE 16 6B 9D 23 23 C0 + +04 +A4 A8 9A 22 A6 9C 42 38 01 BB 70 E0 B6 BA 9E 4B E4 9E 84 97 21 AA D1 CD 77 9D CB AA 28 7A 61 88 39 80 + +04 +A5 9C 80 C4 9E B1 62 58 47 24 B3 E1 CA 7B E0 08 30 76 EE D7 9B 62 C2 E3 AD CC C9 E8 46 9C 64 48 14 00 + +04 +DD 92 F8 21 3A E3 DB 4D D1 AA 90 25 DC BC B3 8C D5 18 2D 7D 6A 33 75 8D C1 9A F4 B1 13 20 27 91 35 00 + +04 +63 7C 50 21 CB A7 6C 24 88 3D EF E4 E3 39 79 B5 D4 EB 3C 8D 5B DC 8D 7D FC C9 91 A4 A1 16 9F 14 3E 80 + +04 +87 96 6B 4C D2 99 85 5C C4 45 8C 89 91 2A 2C 55 D5 71 E9 43 61 DD E6 5F 23 20 74 AB B9 96 94 95 25 40 + +04 +07 91 B5 E4 52 A5 3C A7 44 6E C3 FB 31 83 80 F9 A9 C1 EA 34 58 9D 95 2B BB 4B DB AA 4B B1 34 79 1C C0 +04 +07 91 8E 25 46 B1 0C 8F E2 D8 EE 28 D9 2A 7F ; ..%F.(* +000001eah: 73 2B AF AD 1D D5 E5 54 2A D8 83 17 B2 29 40 34 ; s+.T*؃.)@4 +000001fah: D2 0D 00 04 47 81 2D 22 DA DA A5 A9 1B F6 24 16 ; ...G-"ڥ.$. +0000020ah: C7 5B 3D 92 95 B5 6D 15 48 E4 45 3D 41 23 97 BA ; [=m.HE=A# +0000021ah: D7 74 5B B2 27 C0 04 0D A6 26 2B 5E DA 4D 77 41 ; t['..&+^MwA +0000022ah: 68 8D 1E 3D 3B 5F 55 97 9D 2D DF 54 9E 2D 52 AE ; h.=;_U-T-R +0000023ah: 09 38 BA F1 A5 5E 56 2B 00 04 5F CA CF 0F 62 D3 ; .8^V+.._.b +0000024ah: F6 29 C8 6D A8 B9 87 4B 30 57 A3 93 EE 24 D8 6D ; )mK0W$m +0000025ah: 75 81 A1 17 96 B8 C3 63 6C B9 35 00 04 07 DA AF ; u.cl5...گ +0000026ah: 01 D2 F2 74 A5 00 56 A6 4E F5 5B 2D D6 E0 45 2E ; .t.VN[-E. +0000027ah: 89 D2 CE 1B AC 32 83 EE BA 69 38 54 D0 03 80 04 ; .2i8T.. +0000028ah: 07 FC 25 0C 46 F0 9C 2A F8 4C 69 BE 3D 0B 0E 52 ; .%.F*Li=..R +0000029ah: B2 93 30 38 4A 85 34 C4 E8 50 D4 BC 59 3C 07 76 ; 08J4PԼY<.v +000002aah: 1D C0 04 07 FA ; ... + + +RI QCELP Stream: +---------------- +04 00 +B0 5F B5 78 00 00 01 D0 03 02 18 BC 04 72 01 E4 2E F6 F1 61 A9 0D 09 42 9D 1B 78 67 7E A8 85 25 00 09 + +04 00 +A8 8F 8B 16 88 8D E2 41 9D 27 A4 0B 7A 6E 28 94 E0 16 F2 E8 3A 30 F5 91 47 BA E0 27 57 54 E7 5A C0 35 + +04 00 +90 64 A1 95 9C A6 8A 32 B0 01 51 6E DA 6E 8C 8F 9E A4 BE F4 D1 1F 57 42 69 8F AC C5 A2 A6 A8 56 80 00 + +04 00 +9C A5 C4 80 69 17 32 12 28 3F 1D 95 DB 36 6D 73 FE 12 72 62 59 AF 81 32 0E 9B E6 CB 9C 46 88 68 00 14 + +04 00 +92 B5 4C 90 E4 3E 4D DB AA 6E ED 51 BB BE ED DC C8 F2 FF 15 84 6A 44 8E 11 C9 B7 F3 20 8D 8F 27 00 37 + +04 00 +7C 63 21 50 8F 3F 97 33 41 60 A9 4D 6A 21 76 44 13 93 9C BC DC 5B FD FC CF FC A4 13 02 0B B7 85 80 22 +04 00 +96 87 8C 9A C1 4E 95 E4 4C D3 89 CC 3A 17 13 02 D7 D7 43 69 85 65 ; LӉ:...Cie + + + +B0 5F +bitpack diff -ruN qc13_tia_50_ansi733_20040315-025/readme.txt qc13_tia_50_ansi733_20040315-025_retropatch02/readme.txt --- qc13_tia_50_ansi733_20040315-025/readme.txt 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/readme.txt 2009-01-14 10:23:24.000000000 -0500 @@ -0,0 +1,52 @@ +C-code for ANSI-733 - "C11-20040315-025_Qualcomm_ANSI_733_C_code.zip" +Copyright QUALCOMM Incorporated +Patched for reusability and QCELP bytestream usage 2009 + +Directory Structure +---------------------------------------------------------------------- +qcelp - top level directory. + + code - codec core objects. + + dsp_fx - + + fxptlibs - + + test - test files and scripts. + + tty - + + ttylib.45 - + + win32 - solution and library make files for windows. + + +Changes to the reference implementation +---------------------------------------------------------------------- +Added more result handling during initializing and de/coding. +Added qcelp-bytestream handling. +Added windows build solution. + + +Making +---------------------------------------------------------------------- +Windows: Open the libqcelp solution in win32/ and run Build Solution. + + +Testing +---------------------------------------------------------------------- +Within the test-folder there is an example of a binary qcelp stream +(headerless qcp-file), use that one for your first decoding test. + +>qcelp13k.exe -i test/Example_Headerless_Qcelp_Stream.sqcp -o Ouput_Integer_PCM.raw -D -q + +That should produce a 80.000 byte raw pcm file of a male voice sample. + + +ToDo +---------------------------------------------------------------------- +Further testing with all sorts of source material. +Testing compilage and function at least on linux and osx. + + +Till Toenshoff \ No newline at end of file Binary files qc13_tia_50_ansi733_20040315-025/test/Example_Headerless_Qcelp_Stream.sqcp and qc13_tia_50_ansi733_20040315-025_retropatch02/test/Example_Headerless_Qcelp_Stream.sqcp differ diff -ruN qc13_tia_50_ansi733_20040315-025/ttylib.45/CVS/Entries qc13_tia_50_ansi733_20040315-025_retropatch02/ttylib.45/CVS/Entries --- qc13_tia_50_ansi733_20040315-025/ttylib.45/CVS/Entries 2000-11-28 18:05:40.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/ttylib.45/CVS/Entries 1969-12-31 19:00:00.000000000 -0500 @@ -1,13 +0,0 @@ -/bdo2dit.c/1.2/Thu Aug 03 20:49:04 2000// -/makefile/1.2/Thu Aug 03 20:51:34 2000// -/tone_gen.c/1.1/Tue Apr 20 16:54:22 1999// -/tty.h/1.2/Tue Aug 08 20:33:02 2000// -/tty_dbg.c/1.2/Thu Aug 03 20:59:10 2000// -/tty_dbg.h/1.2/Thu Aug 03 21:01:08 2000// -/tty_enc.c/1.2/Tue Aug 08 18:47:26 2000// -/tty_gen.c/1.2/Tue Aug 08 17:20:22 2000// -/tty_glob.c/1.1/Wed Jun 23 21:57:46 1999// -/tty_hdr.c/1.1/Tue Apr 20 16:54:22 1999// -/dit2a.c/1.4/Tue Oct 24 20:17:38 2000// -/tty_dec.c/1.3/Thu Oct 26 22:14:38 2000// -D diff -ruN qc13_tia_50_ansi733_20040315-025/ttylib.45/CVS/Repository qc13_tia_50_ansi733_20040315-025_retropatch02/ttylib.45/CVS/Repository --- qc13_tia_50_ansi733_20040315-025/ttylib.45/CVS/Repository 2000-08-02 17:36:56.000000000 -0400 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/ttylib.45/CVS/Repository 1969-12-31 19:00:00.000000000 -0500 @@ -1 +0,0 @@ -/home/phv/CVSROOT/evrc_tia/evrc_flt/ttylib diff -ruN qc13_tia_50_ansi733_20040315-025/ttylib.45/CVS/Root qc13_tia_50_ansi733_20040315-025_retropatch02/ttylib.45/CVS/Root --- qc13_tia_50_ansi733_20040315-025/ttylib.45/CVS/Root 2000-08-02 17:36:56.000000000 -0400 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/ttylib.45/CVS/Root 1969-12-31 19:00:00.000000000 -0500 @@ -1 +0,0 @@ -pctj2:/home/phv/CVSROOT diff -ruN qc13_tia_50_ansi733_20040315-025/win32/libdsp_fx/libdsp_fx.vcproj qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libdsp_fx/libdsp_fx.vcproj --- qc13_tia_50_ansi733_20040315-025/win32/libdsp_fx/libdsp_fx.vcproj 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libdsp_fx/libdsp_fx.vcproj 2008-09-28 16:46:14.000000000 -0400 @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -ruN qc13_tia_50_ansi733_20040315-025/win32/libops/libops.vcproj qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libops/libops.vcproj --- qc13_tia_50_ansi733_20040315-025/win32/libops/libops.vcproj 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libops/libops.vcproj 2008-09-28 16:57:20.000000000 -0400 @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -ruN qc13_tia_50_ansi733_20040315-025/win32/libqcelp/libqcelp.vcproj qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libqcelp/libqcelp.vcproj --- qc13_tia_50_ansi733_20040315-025/win32/libqcelp/libqcelp.vcproj 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libqcelp/libqcelp.vcproj 2008-09-28 17:18:08.000000000 -0400 @@ -0,0 +1,303 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -ruN qc13_tia_50_ansi733_20040315-025/win32/libqcelp.sln qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libqcelp.sln --- qc13_tia_50_ansi733_20040315-025/win32/libqcelp.sln 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libqcelp.sln 2008-09-28 16:57:20.000000000 -0400 @@ -0,0 +1,58 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libqcelp", "libqcelp\libqcelp.vcproj", "{58EA8243-4154-4161-A45A-B9626082A327}" + ProjectSection(ProjectDependencies) = postProject + {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC} = {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC} + {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C} = {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C} + {6FFDD7FB-2FBF-49CD-9566-082BF845339E} = {6FFDD7FB-2FBF-49CD-9566-082BF845339E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtty", "libtty\libtty.vcproj", "{6FFDD7FB-2FBF-49CD-9566-082BF845339E}" + ProjectSection(ProjectDependencies) = postProject + {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC} = {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdsp_fx", "libdsp_fx\libdsp_fx.vcproj", "{88A0C5EF-E607-41A1-84DA-DFB0D53AE98C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libops", "libops\libops.vcproj", "{C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qcelp13k", "qcelp13k\qcelp13k.vcproj", "{1CDEBD0A-579B-4A31-91ED-27283FCA05F7}" + ProjectSection(ProjectDependencies) = postProject + {58EA8243-4154-4161-A45A-B9626082A327} = {58EA8243-4154-4161-A45A-B9626082A327} + {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC} = {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC} + {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C} = {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C} + {6FFDD7FB-2FBF-49CD-9566-082BF845339E} = {6FFDD7FB-2FBF-49CD-9566-082BF845339E} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {58EA8243-4154-4161-A45A-B9626082A327}.Debug|Win32.ActiveCfg = Debug|Win32 + {58EA8243-4154-4161-A45A-B9626082A327}.Debug|Win32.Build.0 = Debug|Win32 + {58EA8243-4154-4161-A45A-B9626082A327}.Release|Win32.ActiveCfg = Release|Win32 + {58EA8243-4154-4161-A45A-B9626082A327}.Release|Win32.Build.0 = Release|Win32 + {6FFDD7FB-2FBF-49CD-9566-082BF845339E}.Debug|Win32.ActiveCfg = Debug|Win32 + {6FFDD7FB-2FBF-49CD-9566-082BF845339E}.Debug|Win32.Build.0 = Debug|Win32 + {6FFDD7FB-2FBF-49CD-9566-082BF845339E}.Release|Win32.ActiveCfg = Release|Win32 + {6FFDD7FB-2FBF-49CD-9566-082BF845339E}.Release|Win32.Build.0 = Release|Win32 + {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C}.Debug|Win32.ActiveCfg = Debug|Win32 + {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C}.Debug|Win32.Build.0 = Debug|Win32 + {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C}.Release|Win32.ActiveCfg = Release|Win32 + {88A0C5EF-E607-41A1-84DA-DFB0D53AE98C}.Release|Win32.Build.0 = Release|Win32 + {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC}.Debug|Win32.ActiveCfg = Debug|Win32 + {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC}.Debug|Win32.Build.0 = Debug|Win32 + {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC}.Release|Win32.ActiveCfg = Release|Win32 + {C4A82FB7-C3D2-4F85-A2A7-7AAA2B584FEC}.Release|Win32.Build.0 = Release|Win32 + {1CDEBD0A-579B-4A31-91ED-27283FCA05F7}.Debug|Win32.ActiveCfg = Debug|Win32 + {1CDEBD0A-579B-4A31-91ED-27283FCA05F7}.Debug|Win32.Build.0 = Debug|Win32 + {1CDEBD0A-579B-4A31-91ED-27283FCA05F7}.Release|Win32.ActiveCfg = Release|Win32 + {1CDEBD0A-579B-4A31-91ED-27283FCA05F7}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -ruN qc13_tia_50_ansi733_20040315-025/win32/libtty/libtty.vcproj qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libtty/libtty.vcproj --- qc13_tia_50_ansi733_20040315-025/win32/libtty/libtty.vcproj 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/libtty/libtty.vcproj 2008-10-15 03:48:18.000000000 -0400 @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -ruN qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/getopt.h qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/getopt.h --- qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/getopt.h 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/getopt.h 2004-01-18 19:31:00.000000000 -0500 @@ -0,0 +1,56 @@ +/* + * getopt.h - cpp wrapper for my_getopt to make it look like getopt. + * Copyright 1997, 2000, 2001, 2002, Benjamin Sittler + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef MY_WRAPPER_GETOPT_H_INCLUDED +#define MY_WRAPPER_GETOPT_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#include "my_getopt.h" + +#undef getopt +#define getopt my_getopt +#undef getopt_long +#define getopt_long my_getopt_long +#undef getopt_long_only +#define getopt_long_only my_getopt_long_only +#undef _getopt_internal +#define _getopt_internal _my_getopt_internal +#undef opterr +#define opterr my_opterr +#undef optind +#define optind my_optind +#undef optopt +#define optopt my_optopt +#undef optarg +#define optarg my_optarg + +#ifdef __cplusplus +} +#endif + +#endif /* MY_WRAPPER_GETOPT_H_INCLUDED */ diff -ruN qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/my_getopt.c qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/my_getopt.c --- qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/my_getopt.c 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/my_getopt.c 2006-12-09 18:17:04.000000000 -0500 @@ -0,0 +1,281 @@ +/* + * my_getopt.c - my re-implementation of getopt. + * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include "my_getopt.h" + +int my_optind=1, my_opterr=1, my_optopt=0; +char *my_optarg=0; + +/* reset argument parser to start-up values */ +int my_getopt_reset(void) +{ + my_optind = 1; + my_opterr = 1; + my_optopt = 0; + my_optarg = 0; + return 0; +} + +/* this is the plain old UNIX getopt, with GNU-style extensions. */ +/* if you're porting some piece of UNIX software, this is all you need. */ +/* this supports GNU-style permution and optional arguments */ + +int my_getopt(int argc, char * argv[], const char *opts) +{ + static int charind=0; + const char *s; + char mode, colon_mode; + int off = 0, opt = -1; + + if(getenv("POSIXLY_CORRECT")) colon_mode = mode = '+'; + else { + if((colon_mode = *opts) == ':') off ++; + if(((mode = opts[off]) == '+') || (mode == '-')) { + off++; + if((colon_mode != ':') && ((colon_mode = opts[off]) == ':')) + off ++; + } + } + my_optarg = 0; + if(charind) { + my_optopt = argv[my_optind][charind]; + for(s=opts+off; *s; s++) if(my_optopt == *s) { + charind++; + if((*(++s) == ':') || ((my_optopt == 'W') && (*s == ';'))) { + if(argv[my_optind][charind]) { + my_optarg = &(argv[my_optind++][charind]); + charind = 0; + } else if(*(++s) != ':') { + charind = 0; + if(++my_optind >= argc) { + if(my_opterr) fprintf(stderr, + "%s: option requires an argument -- %c\n", + argv[0], my_optopt); + opt = (colon_mode == ':') ? ':' : '?'; + goto my_getopt_ok; + } + my_optarg = argv[my_optind++]; + } + } + opt = my_optopt; + goto my_getopt_ok; + } + if(my_opterr) fprintf(stderr, + "%s: illegal option -- %c\n", + argv[0], my_optopt); + opt = '?'; + if(argv[my_optind][++charind] == '\0') { + my_optind++; + charind = 0; + } + my_getopt_ok: + if(charind && ! argv[my_optind][charind]) { + my_optind++; + charind = 0; + } + } else if((my_optind >= argc) || + ((argv[my_optind][0] == '-') && + (argv[my_optind][1] == '-') && + (argv[my_optind][2] == '\0'))) { + my_optind++; + opt = -1; + } else if((argv[my_optind][0] != '-') || + (argv[my_optind][1] == '\0')) { + char *tmp; + int i, j, k; + + if(mode == '+') opt = -1; + else if(mode == '-') { + my_optarg = argv[my_optind++]; + charind = 0; + opt = 1; + } else { + for(i=j=my_optind; i j) { + tmp=argv[--i]; + for(k=i; k+1 argc) my_optind = argc; + return opt; +} + +/* this is the extended getopt_long{,_only}, with some GNU-like + * extensions. Implements _getopt_internal in case any programs + * expecting GNU libc getopt call it. + */ + +int _my_getopt_internal(int argc, char * argv[], const char *shortopts, + const struct option *longopts, int *longind, + int long_only) +{ + char mode, colon_mode = *shortopts; + int shortoff = 0, opt = -1; + + if(getenv("POSIXLY_CORRECT")) colon_mode = mode = '+'; + else { + if((colon_mode = *shortopts) == ':') shortoff ++; + if(((mode = shortopts[shortoff]) == '+') || (mode == '-')) { + shortoff++; + if((colon_mode != ':') && ((colon_mode = shortopts[shortoff]) == ':')) + shortoff ++; + } + } + my_optarg = 0; + if((my_optind >= argc) || + ((argv[my_optind][0] == '-') && + (argv[my_optind][1] == '-') && + (argv[my_optind][2] == '\0'))) { + my_optind++; + opt = -1; + } else if((argv[my_optind][0] != '-') || + (argv[my_optind][1] == '\0')) { + char *tmp; + int i, j, k; + + opt = -1; + if(mode == '+') return -1; + else if(mode == '-') { + my_optarg = argv[my_optind++]; + return 1; + } + for(i=j=my_optind; i j) { + tmp=argv[--i]; + for(k=i; k+1= argc) { + opt = (colon_mode == ':') ? ':' : '?'; + if(my_opterr) fprintf(stderr, + "%s: option `--%s' requires an argument\n", + argv[0], longopts[found].name); + } else my_optarg = argv[my_optind]; + } + if(!opt) { + if (longind) *longind = found; + if(!longopts[found].flag) opt = longopts[found].val; + else *(longopts[found].flag) = longopts[found].val; + } + my_optind++; + } else if(!hits) { + if(offset == 1) opt = my_getopt(argc, argv, shortopts); + else { + opt = '?'; + if(my_opterr) fprintf(stderr, + "%s: unrecognized option `%s'\n", + argv[0], argv[my_optind++]); + } + } else { + opt = '?'; + if(my_opterr) fprintf(stderr, + "%s: option `%s' is ambiguous\n", + argv[0], argv[my_optind++]); + } + } + if (my_optind > argc) my_optind = argc; + return opt; +} + +int my_getopt_long(int argc, char * argv[], const char *shortopts, + const struct option *longopts, int *longind) +{ + return _my_getopt_internal(argc, argv, shortopts, longopts, longind, 0); +} + +int my_getopt_long_only(int argc, char * argv[], const char *shortopts, + const struct option *longopts, int *longind) +{ + return _my_getopt_internal(argc, argv, shortopts, longopts, longind, 1); +} diff -ruN qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/my_getopt.h qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/my_getopt.h --- qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/my_getopt.h 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/my_getopt.h 2006-12-09 18:16:58.000000000 -0500 @@ -0,0 +1,72 @@ +/* + * my_getopt.h - interface to my re-implementation of getopt. + * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef MY_GETOPT_H_INCLUDED +#define MY_GETOPT_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +/* reset argument parser to start-up values */ +extern int my_getopt_reset(void); + +/* UNIX-style short-argument parser */ +extern int my_getopt(int argc, char * argv[], const char *opts); + +extern int my_optind, my_opterr, my_optopt; +extern char *my_optarg; + +struct option { + const char *name; + int has_arg; + int *flag; + int val; +}; + +/* human-readable values for has_arg */ +#undef no_argument +#define no_argument 0 +#undef required_argument +#define required_argument 1 +#undef optional_argument +#define optional_argument 2 + +/* GNU-style long-argument parsers */ +extern int my_getopt_long(int argc, char * argv[], const char *shortopts, + const struct option *longopts, int *longind); + +extern int my_getopt_long_only(int argc, char * argv[], const char *shortopts, + const struct option *longopts, int *longind); + +extern int _my_getopt_internal(int argc, char * argv[], const char *shortopts, + const struct option *longopts, int *longind, + int long_only); + +#ifdef __cplusplus +} +#endif + +#endif /* MY_GETOPT_H_INCLUDED */ diff -ruN qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/qcelp13k.vcproj qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/qcelp13k.vcproj --- qc13_tia_50_ansi733_20040315-025/win32/qcelp13k/qcelp13k.vcproj 1969-12-31 19:00:00.000000000 -0500 +++ qc13_tia_50_ansi733_20040315-025_retropatch02/win32/qcelp13k/qcelp13k.vcproj 2008-10-15 23:55:30.000000000 -0400 @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +