Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1625 lines
49 KiB

  1. /*#define __TEST
  2. #ifdef __TEST
  3. #include <stdio.h>
  4. FILE *test;
  5. FILE *codage;
  6. #endif*/
  7. /*
  8. * Project: Direct Subband 16000 bps coder and SBCELP 4800 bps coder
  9. * Workfile: encoder.c
  10. * Author: Alfred Wiesen
  11. * Created: 30 August 1995
  12. * Last update: 4 September 1995
  13. * DLL Version: 1.00
  14. * Revision: Single DLL for coder and decoder.
  15. * Comment:
  16. *
  17. * (C) Copyright 1993-95 Lernout & Hauspie Speech Products N.V. (TM)
  18. * All rights reserved. Company confidential.
  19. */
  20. // ------------------------------------------------------------------------
  21. // ------------------------------------------------------------------------
  22. // Included files
  23. // ------------------------------------------------------------------------
  24. // ------------------------------------------------------------------------
  25. #include <math.h>
  26. #include <windows.h>
  27. #include <windowsx.h>
  28. #include "fv_x8.h"
  29. #include "data.h"
  30. #include "bib_32.h"
  31. // ------------------------------------------------------------------------
  32. // ------------------------------------------------------------------------
  33. // Function prototypes
  34. // ------------------------------------------------------------------------
  35. // ------------------------------------------------------------------------
  36. void InitializeCoderInstanceData(PVOID p, DWORD dwMaxBitRate);
  37. void decimation_I(short input_I[],short coef_I[],short low_part_mem_I[],short order);
  38. #if 0
  39. // PhilF: The following is never called!!!
  40. void quant_0a16_I2(short z1, short z2 ,short vec[], short maxv, short B1[], short B2[], long *code);
  41. #endif
  42. void quant_sous_bandes(PC16008DATA p,short *in,short *codes_max, long *codes_sb, short *indic_br/*, short *code_max_br*/);
  43. void code_res_I(PC16008DATA p,short input[],short coef[],short qmf_mem[],short v_code[],long cod_long[], short ind_br[]/*, short c_max_br*/);
  44. #ifdef CELP4800
  45. void COEFF_A(PC4808DATA p),CALPITCH(PC4808DATA p),CHERCHE(PC4808DATA p);
  46. void PERIODE(PC4808DATA p,short no),FRAME(PC4808DATA p);
  47. void lsp_quant(PC4808DATA p,short lsp[],short nbit[],short bitdi[],short vcode[]);
  48. void cal_dic1(PC4808DATA p,short *y,short *sr,short *espopt,short *posit,short dec,short esp,short sigpit[],short soulong,long tlsp[],long vmax[]);
  49. //void cal_dic2(short q,short espace,short phase,short *s_r,short *hy,short *b,short *vois,short *esp,short *qq,short *phas,short sigpit[],short soulong,long tlsp[],long vmax[]);
  50. void cal_dic2(PC4808DATA p,short q,short espace,short phase,short *s_r,short *hy,short *b,short *vois,short *esp,short *qq,short *phas);
  51. #endif
  52. void decimation(short *vin,short *vout,short nech);
  53. /*void iConvert64To8(int *in, int *out, int N, int *mem);
  54. void iConvert8To64(int *in, int *out, int N, int *mem);
  55. void BandPass(int *,int *,int *,int);*/
  56. // ------------------------------------------------------------------------
  57. // ------------------------------------------------------------------------
  58. // Global variables for coder
  59. // ------------------------------------------------------------------------
  60. // ------------------------------------------------------------------------
  61. /*#define MAXCODINGHANDLES 10
  62. // Instance data structure
  63. PC16008DATA pCoderData;
  64. C16008DATA CoderData[MAXCODINGHANDLES];
  65. int CodingHandles[MAXCODINGHANDLES];*/
  66. // ROM tables :
  67. extern short coef_I[]; // QMF filter coeffs
  68. extern short B3_I[]; // Five levels quantification table
  69. extern short B4_I[]; // Four levels quantification table
  70. extern short B5_I[]; // Five levels quantification table
  71. extern short B6_I[]; // Nine levels quantification table
  72. extern short B7_I[]; // Nine levels quantification table
  73. extern short B8_I[]; // Nine levels quantification table
  74. extern short B9_I[]; // Nine levels quantification table
  75. extern short max_level[]; // Quantified maximum sample level
  76. extern long coeffs[];
  77. extern long Mask[];
  78. extern short hamming[];
  79. extern short A0[];
  80. extern short tabcos[];
  81. extern short LSP_Q[];
  82. extern short TAB_DI[];
  83. extern short GQ[];
  84. extern short GV[];
  85. extern short BQ[];
  86. extern short BV[];
  87. extern short NBB[];
  88. extern short BITDD[];
  89. extern short LSP0ROM[];
  90. //extern short quantif[];
  91. //extern short bits[];
  92. //extern short bytes[];
  93. // RAM variables :
  94. /*extern short codes_max[]; // Quantized max. of each subband
  95. extern long codes_sb[]; // Two codes for each of the quantized subband
  96. extern short indic_sp[]; // type of subband (1=noise; 0=to be decoded)
  97. extern short code_max_br; // 1 bit for coding the noise
  98. extern short DATA_I[]; // Intermediate vector = input and output of QMF
  99. extern char stream[]; // Coded data buffer*/
  100. // ------------------------------------------------------------------------
  101. // ------------------------------------------------------------------------
  102. // Function implementation
  103. // ------------------------------------------------------------------------
  104. // ------------------------------------------------------------------------
  105. // ------------------------------------------------------------------------
  106. void InitializeCoderInstanceData(PVOID p, DWORD dwMaxBitRate)
  107. // Instance data initializations
  108. {
  109. short i;
  110. #ifdef CELP4800
  111. if (dwMaxBitRate == 4800)
  112. {
  113. ((PC4808DATA)p)->dwMaxBitRate = dwMaxBitRate;
  114. ((PC4808DATA)p)->mem_pit[0]=((PC4808DATA)p)->mem_pit[1]=69;
  115. for (i=0;i<10;i++)
  116. ((PC4808DATA)p)->LSP0[i]=LSP0ROM[i];
  117. }
  118. else
  119. #endif
  120. {
  121. ((PC16008DATA)p)->dwMaxBitRate = dwMaxBitRate;
  122. for (i=0;i<NBFAC;i++) ((PC16008DATA)p)->nbbit[i]=8; // On met les compteurs a "zero";
  123. // on suppose demarrer par du bruit
  124. ((PC16008DATA)p)->MAX_LEVEL = MAX_LEVEL1; // valeur par defaut si le debit n'augmente pas trop
  125. ((PC16008DATA)p)->DIV_MAX = DIV_MAX1; // cad on ne traite pas les sb < 5% du max[i]
  126. ((PC16008DATA)p)->quantif[0] = 9;
  127. ((PC16008DATA)p)->quantif[1] = 9;
  128. ((PC16008DATA)p)->quantif[4] = 5;
  129. ((PC16008DATA)p)->quantif[5] = 5;
  130. ((PC16008DATA)p)->quantif[6] = 5;
  131. ((PC16008DATA)p)->quantif[7] = 5;
  132. ((PC16008DATA)p)->quantif[8] = 5;
  133. ((PC16008DATA)p)->quantif[9] = 5;
  134. ((PC16008DATA)p)->bits[0] = 52;
  135. ((PC16008DATA)p)->bits[2] = 38;
  136. ((PC16008DATA)p)->bits[3] = 38;
  137. ((PC16008DATA)p)->bits[4] = 38;
  138. // Bug 3214: Just in case we get carried away, init the end of the arrays in both configurations
  139. ((PC16008DATA)p)->quantif[10] = 5;
  140. ((PC16008DATA)p)->quantif[11] = 5;
  141. ((PC16008DATA)p)->bits[5] = 38;
  142. if (dwMaxBitRate == 16000)
  143. {
  144. ((PC16008DATA)p)->NBSB_SP_MAX = NBSB_SP_MAX1_16000; // nbre max de sb pouvant etre du signal
  145. ((PC16008DATA)p)->quantif[2] = 7;
  146. ((PC16008DATA)p)->quantif[3] = 7;
  147. ((PC16008DATA)p)->bits[1] = 46;
  148. }
  149. else
  150. {
  151. ((PC16008DATA)p)->NBSB_SP_MAX = NBSB_SP_MAX1_8000_12000; // nbre max de sb pouvant etre du signal
  152. ((PC16008DATA)p)->quantif[2] = 9;
  153. ((PC16008DATA)p)->quantif[3] = 9;
  154. ((PC16008DATA)p)->bits[1] = 52;
  155. }
  156. }
  157. return;
  158. }
  159. //------------------------------------------------------------------------
  160. void decimation_I(short input_I[],short coef_I[],short low_part_mem_I[],short order)
  161. //
  162. // Purpose : from data stored in DATA[], create the N_SB subbands
  163. // Remark : output subband is stored at (input[]+N_SB*L_RES)
  164. //
  165. {
  166. short i,j,lng;
  167. short *low_out_part_I;
  168. short *high_out_part_I;
  169. short *buffer_I,*sa_vec_I;
  170. buffer_I = low_part_mem_I;
  171. for (i=0;i<N_SB;i++)
  172. {
  173. low_out_part_I=input_I+L_RES;
  174. lng = L_RES >> (i+1);
  175. high_out_part_I=low_out_part_I+lng;
  176. sa_vec_I=low_out_part_I;
  177. for (j=0;j<(1<<i);j++)
  178. {
  179. low_part_mem_I=buffer_I;
  180. QMFilter(input_I,coef_I,low_out_part_I,high_out_part_I,low_part_mem_I,lng);
  181. input_I += 2*lng; low_out_part_I += lng; high_out_part_I += lng;
  182. if (j&1) high_out_part_I += 2*lng;
  183. else low_out_part_I += 2*lng;
  184. buffer_I += 2*order;
  185. }
  186. input_I=sa_vec_I;
  187. }
  188. }
  189. #if 0
  190. // PhilF: The following is never called!!!
  191. //------------------------------------------------------------------------
  192. void quant_0a16_I2(short z1, short z2, short vec[], short maxv, short B1[], short B2[], long *code)
  193. // Quantifies the 16 samples of a subband on z levels using the table B[]
  194. // Result stored in code[] (two long codes pro subband).
  195. {
  196. short i,x;
  197. short ftmp;
  198. long result;
  199. result=0;
  200. for (i=0;i<8;i++) // Quantify the first eight samples of the subband
  201. {
  202. ftmp=(((long)vec[i])<<13)/maxv;
  203. x=0;
  204. if (i==2*(short)(i/2))
  205. {
  206. while((ftmp>B1[x])&&(x<z1-1)) x++; result*=z1;
  207. }
  208. else
  209. {
  210. while((ftmp>B2[x])&&(x<z2-1)) x++; result*=z2;
  211. }
  212. result+=x; // Construct long code
  213. }
  214. *code=result; // Store code
  215. result=0;
  216. for (i=0;i<8;i++) // Quantify the last eight samples of the subband
  217. {
  218. ftmp=(((long)vec[i+8])<<13)/maxv;
  219. x=0;
  220. if (i==2*(short)(i/2))
  221. {
  222. while((ftmp>B1[x])&&(x<z1-1)) x++; result*=z1;
  223. }
  224. else
  225. {
  226. while((ftmp>B2[x])&&(x<z2-1)) x++; result*=z2;
  227. }
  228. result+=x; // Construct long code
  229. }
  230. *(code+1)=result; // Store code
  231. }
  232. #endif
  233. void quant_0a16_I3(short z1, short z2, short vec[], short maxv, long *code)
  234. // Quantifies the 16 samples of a subband on z levels using the table B[]
  235. // Result stored in code[] (two long codes pro subband).
  236. {
  237. short i,x;
  238. short ftmp;
  239. long result;
  240. short *B1,*B2;
  241. switch (z1)
  242. {
  243. case 3: B1=B3_I; break;
  244. case 4: B1=B4_I; break;
  245. case 5: B1=B5_I; break;
  246. case 6: B1=B6_I; break;
  247. case 7: B1=B7_I; break;
  248. case 8: B1=B8_I; break;
  249. case 9: B1=B9_I; break;
  250. // Bug 3214: Just in case we're passed a bogus value, set a default quantizer
  251. default: B1=B5_I; break;
  252. }
  253. switch (z2)
  254. {
  255. case 3: B2=B3_I; break;
  256. case 4: B2=B4_I; break;
  257. case 5: B2=B5_I; break;
  258. case 6: B2=B6_I; break;
  259. case 7: B2=B7_I; break;
  260. case 8: B2=B8_I; break;
  261. case 9: B2=B9_I; break;
  262. // Bug 3214: Just in case we're passed a bogus value, set a default quantizer
  263. default: B2=B5_I; break;
  264. }
  265. result=0;
  266. for (i=0;i<8;i++) // Quantify the first eight samples of the subband
  267. {
  268. ftmp=(((long)vec[i])<<13)/maxv;
  269. x=0;
  270. if (i==2*(short)(i/2))
  271. {
  272. while((ftmp>B1[x])&&(x<z1-1)) x++; result*=z1;
  273. }
  274. else
  275. {
  276. while((ftmp>B2[x])&&(x<z2-1)) x++; result*=z2;
  277. }
  278. result+=x; // Construct long code
  279. }
  280. *code=result; // Store code
  281. result=0;
  282. for (i=0;i<8;i++) // Quantify the last eight samples of the subband
  283. {
  284. ftmp=(((long)vec[i+8])<<13)/maxv;
  285. x=0;
  286. if (i==2*(short)(i/2))
  287. {
  288. while((ftmp>B1[x])&&(x<z1-1)) x++; result*=z1;
  289. }
  290. else
  291. {
  292. while((ftmp>B2[x])&&(x<z2-1)) x++; result*=z2;
  293. }
  294. result+=x; // Construct long code
  295. }
  296. *(code+1)=result; // Store code
  297. }
  298. //------------------------------------------------------------------------
  299. void quant_sous_bandes(PC16008DATA p,short *in,short *codes_max, long *codes_sb, short *indic_sp)
  300. // Quantifies the eight subbands
  301. {
  302. short max[8];
  303. short order[8]={0,0,0,0,0,0,0,0};
  304. short codes_max_loc[8]={0,0,0,0,0,0,0,0};
  305. short maximum,max_num,ord,maxmax;
  306. short i,j;
  307. #ifdef MAX_SB_ABSOLU
  308. short sb_count;
  309. #endif
  310. for (i=0;i<8;i++) // Quantify the maximums of the subbands
  311. {
  312. max[i]=0;
  313. for (j=0;j<16;j++)
  314. if (abs(*(in+16*i+j))>max[i]) max[i]=abs(*(in+16*i+j));
  315. }
  316. for (i=0;i<8;i++)
  317. {
  318. if (max[i]>2*max_level[31]) j = 31;
  319. else for (j=0; max[i]>2*max_level[j]; j++);
  320. codes_max_loc[i]=j;
  321. max[i]=2*max_level[j];
  322. } // fin quantifiation
  323. p->nbbit_cf+=8; // 8 bits for the indic_sp
  324. maxmax=0;
  325. for (i=0;i<8;i++) // On cherche le plus grand maximum
  326. {
  327. if (max[i]>maxmax) maxmax=max[i];
  328. }
  329. maxmax/=p->DIV_MAX; // On le divise par 10 a 20 (cad a peu pres 10 a 5 %)
  330. ord=8;
  331. p->nbsb_sp=0;
  332. for (i=0;i<8;i++) // Calculates the order of the subbands
  333. { // 1 is higher energy than 2 than 3,..
  334. maximum=32767;
  335. for (j=7;j>=0;j--)
  336. {
  337. if ((order[j]==0)&&(max[j]<maximum))
  338. {
  339. max_num=j; maximum=max[j];
  340. }
  341. }
  342. order[max_num]=ord;
  343. if ( (ord>p->NBSB_SP_MAX)||(maximum<=p->MAX_LEVEL)||(maximum<=maxmax) )
  344. {
  345. indic_sp[max_num]=0; // c'est 1 bande qui sera du bruit
  346. }
  347. else
  348. {
  349. indic_sp[max_num]=1;
  350. p->nbsb_sp++;
  351. }
  352. ord--;
  353. }
  354. j=0;
  355. for (i=0;i<8;i++)
  356. {
  357. if (indic_sp[i]==1)
  358. {
  359. codes_max[j]=codes_max_loc[i]; //5* 4 ou 5 bits suffisent
  360. j++;
  361. p->nbbit_cf+=5; // 5 bits per coded max
  362. }
  363. }
  364. for (i=p->nbsb_sp-1;i>=0;i--)
  365. {
  366. j=0;
  367. while (order[j]!=i+1) j++;
  368. quant_0a16_I3(p->quantif[2*i],p->quantif[2*i+1],in+j*16,max[j],codes_sb+2*i);
  369. p->nbbit_cf+=p->bits[i];
  370. }
  371. if (p->dwMaxBitRate == 16000)
  372. {
  373. j=0;
  374. #ifdef MAX_SB_ABSOLU
  375. sb_count=p->nbsb_sp;
  376. if (sb_count>=MAX_SB_ABSOLU) return;
  377. #endif
  378. for (i=0;i<8;i++)
  379. {
  380. if (indic_sp[i]==0)
  381. {
  382. codes_max[p->nbsb_sp+j]=codes_max_loc[i]; //5* 4 ou 5 bits suffisent
  383. j++;
  384. p->nbbit_cf+=5; // 5 bits per coded max
  385. #ifdef MAX_SB_ABSOLU
  386. sb_count++;
  387. quant_0a16_I3(SILENCE_QUANT_LEVEL_16000,SILENCE_QUANT_LEVEL_16000,in+i*16,max[i],codes_sb+2*sb_count);
  388. p->nbbit_cf+=SILENCE_CODING_BIT_16000;
  389. if (sb_count>=MAX_SB_ABSOLU) break;
  390. #endif
  391. }
  392. }
  393. #ifndef MAX_SB_ABSOLU
  394. for (i=7;i>=p->nbsb_sp;i--)
  395. {
  396. j=0;
  397. while (order[j]!=i+1) j++;
  398. quant_0a16_I3(SILENCE_QUANT_LEVEL_16000,SILENCE_QUANT_LEVEL_16000,in+j*16,max[j],codes_sb+2*i);
  399. p->nbbit_cf+=SILENCE_CODING_BIT_16000;
  400. }
  401. #endif
  402. }
  403. }
  404. //------------------------------------------------------------------------
  405. void code_res_I(PC16008DATA p,short input[],short coef[],short qmf_mem[],short v_code[],long cod_long[], short ind_br[]/*, short c_max_br*/)
  406. {
  407. decimation_I(input,coef,qmf_mem,Fil_Lenght);
  408. quant_sous_bandes(p,input+3*L_RES,v_code,cod_long,ind_br/*AW,&c_max_br*/);
  409. }
  410. //------------------------------------------------------------------------
  411. short Multiplexing(
  412. char *Stream,
  413. long *Codes,
  414. short *CodeSizes,
  415. short NumCodes,
  416. short StreamSize)
  417. {
  418. short B,P; // B=bits � coder, P=bits libres
  419. short i,j;
  420. #ifdef __CHECK_FORMAT
  421. long TotalBytes=0;
  422. for (i=0;i<NumCodes;i++) TotalBytes+=CodeSizes[i];
  423. if (TotalBytes>StreamSize*8) return 1;
  424. #endif
  425. i=0;
  426. j=0;
  427. B=CodeSizes[i]; // bits � coder
  428. P=8; // 1 octet libre au d�part
  429. Stream[j]=0;
  430. while (i<NumCodes)
  431. {
  432. if (P>B)
  433. {
  434. Stream[j]|=(Codes[i]&Mask[B])<<(P-B);
  435. P-=B;
  436. i++;
  437. B=CodeSizes[i];
  438. }
  439. else if (P<B)
  440. {
  441. Stream[j]|=(Codes[i]>>(B-P))&Mask[P];
  442. B-=P;
  443. P=8;
  444. j++;
  445. Stream[j]=0;
  446. }
  447. else
  448. {
  449. Stream[j]|=Codes[i]&Mask[P];
  450. i++;
  451. j++;
  452. P=8;
  453. B=CodeSizes[i];
  454. Stream[j]=0;
  455. }
  456. }
  457. return 0;
  458. }
  459. // ------------------------------------------------------------------------
  460. #ifdef CELP4800
  461. void iteration(PC4808DATA p,long *P,short n,short *s)
  462. {
  463. short i;
  464. p->a=0x7fffffffL;
  465. for(i=0;i<7 ;i++)
  466. {
  467. horner(P,p->ttt,&p->a,n,*s);
  468. horner(p->ttt,p->TLSP+12,&p->b,(short)(n-1),*s);
  469. *s += calcul_s(p->a,p->b);
  470. }
  471. horner(P,p->ttt,&p->a,n,*s);
  472. *(P+n) = 0;
  473. long_to_long(p->ttt,P,n);
  474. }
  475. // ------------------------------------------------------------------------
  476. void ai_to_lsp(PC4808DATA p,long *ai_pq,short *lsp)
  477. {
  478. short s; short n;
  479. ai_to_pq(ai_pq,10);
  480. s=0x7fff;
  481. p->ptr1 = lsp;
  482. for(n=5; n>2; n--)
  483. {
  484. iteration(p,ai_pq,n,&s);
  485. *p->ptr1++ = s;
  486. if (lsp[0]<0) lsp[0]=s=32765;
  487. iteration(p,ai_pq+6,n,&s);
  488. *p->ptr1++ = s;
  489. }
  490. binome(lsp+6,ai_pq);
  491. }
  492. // ------------------------------------------------------------------------
  493. void cal_dic1(PC4808DATA p,short *y,short *sr,short *espopt,short *posit,short dec,short esp,
  494. short *sigpi,short soulong,long *tlsp,long *vmax)
  495. {
  496. short i,k,limite;
  497. long *vene;
  498. vene = (long *)(sigpi+150);
  499. venergy(y,vene,soulong);
  500. k=soulong-1;
  501. for (i=0;i<dec;i++)
  502. {
  503. p->ptr1 = sr;limite=i;
  504. *tlsp = *(p->ptr1+limite); limite += esp;
  505. while (limite<soulong) { *tlsp += *(p->ptr1+limite); limite += esp;}
  506. *(tlsp+1) = *(vene+k-i);
  507. limite=upd_max_d(tlsp,vmax);
  508. if (limite) {*posit=i; *espopt=esp; *posit=i; *espopt=esp;}
  509. }
  510. }
  511. // ------------------------------------------------------------------------
  512. void cal_dic2(PC4808DATA p,short q,short espace,short phase,short *s_r,short *hy,
  513. short *b,short *vois,short *esp,short *qq,short *phas)
  514. {
  515. short i,j,i0,k;
  516. short src[10],*y2; short cc[10];
  517. long R11;
  518. y2 = p->SIGPI+75;
  519. R11 = 0;
  520. init_zero(y2,p->SOULONG);
  521. for (j=0;j<q;j++)
  522. {
  523. i0=espace*j+phase;
  524. src[j]=s_r[i0];
  525. }
  526. for (j=0;j<q;j++) if (src[j]>0) cc[j]=1;
  527. else cc[j]=-1;
  528. for (i=0;i<q;i++) R11 += abs(src[i]);
  529. for (j=0;j<q;j++)
  530. {
  531. i0=espace*j+phase;
  532. k=cc[j];
  533. if (k>0)
  534. {
  535. add_sf_vect(y2,hy,i0,p->SOULONG);
  536. }
  537. else
  538. {
  539. sub_sf_vect(y2,hy,i0,p->SOULONG);
  540. }
  541. }
  542. energy2(y2,p->TLSP+1,p->SOULONG);
  543. *p->TLSP=R11;
  544. i = upd_max_d(p->TLSP,p->VMAX);
  545. if (i) { short_to_short(cc,b,q); *vois=0; *esp=espace; *qq=q; *phas=phase; }
  546. /* for (i=0;i<q;i++)
  547. {
  548. cc[i]=-cc[i];
  549. *TLSP = R11 + 2*src[i]*cc[i];
  550. k=2*cc[i];
  551. i0=espace*i+phase;
  552. update_dic(y1,y2,hy,SOULONG,i0,k);
  553. energy2(y1,TLSP+1,SOULONG);
  554. k = upd_max_d(TLSP,VMAX);
  555. if (k)
  556. {
  557. short_to_short(cc,b,q);
  558. R11 = *TLSP;
  559. my2=y1; y1=y2; y2=my2;
  560. *vois=0; *esp=espace; *qq=q; *phas=phase;
  561. }
  562. else cc[i]=-cc[i];
  563. }*/
  564. }
  565. /*-------------------------------------------------------------------------
  566. Review version of CAL_DIC2
  567. {
  568. R11 = 0;
  569. init_zero(y2,SOULONG);
  570. i0=phase-espace;
  571. for (j=0;j<q;j++)
  572. {
  573. i0+=espace;
  574. src[j]=s_r[i0];
  575. if (src[j]>0)
  576. {
  577. cc[j]=1;
  578. R11 += (long)(src[j]);
  579. add_sf_vect(y2,hy,i0,SOULONG);
  580. }
  581. else
  582. {
  583. cc[j]=-1;
  584. R11 -= (long)(src[j]);
  585. sub_sf_vect(y2,hy,i0,SOULONG);
  586. }
  587. }
  588. energy2(y2,TLSP+1,SOULONG);
  589. *TLSP=R11;
  590. i = upd_max_d(TLSP,VMAX);
  591. if (i) { short_to_short(cc,b,q); *vois=0; *esp=espace; *qq=q; *phas=phase; }
  592. i0=phase-espace;
  593. for (i=0;i<q;i++)
  594. {
  595. cc[i]=-cc[i];
  596. *TLSP = R11 + 2*src[i]*cc[i];
  597. k=2*cc[i];
  598. i0+=espace;
  599. update_dic(y1,y2,hy,SOULONG,i0,k);
  600. energy2(y1,TLSP+1,SOULONG);
  601. k = upd_max_d(TLSP,VMAX);
  602. if (k)
  603. {
  604. short_to_short(cc,b,q);
  605. R11 = *TLSP;
  606. my2=y1; y1=y2; y2=my2;
  607. *vois=0; *esp=espace; *qq=q; *phas=phase;
  608. }
  609. else cc[i]=-cc[i];
  610. }
  611. }
  612. -----------------------------------------------------------------------*/
  613. // ------------------------------------------------------------------------
  614. void left_correl(PC4808DATA p,short vech[],short debut,short fin,short pitch,short delta,long *vv)
  615. {
  616. short i,k,lng;
  617. lng=fin-debut+1;
  618. i=pitch-delta;
  619. energy(vech+debut-i,p->TLSP+2,lng);
  620. correlation(vech+debut-i,vech+debut,p->TLSP,lng);
  621. norm_corrl(vv,p->TLSP);
  622. for (i=pitch-delta+1;i<=pitch+delta;i++)
  623. {
  624. correlation(vech+debut-i,vech+debut,p->TLSP,lng);
  625. p->TLSP[10] = (long)vech[debut-i]*(long)vech[debut-i];
  626. p->TLSP[11] = (long)vech[fin-i+1]*(long)vech[fin-i+1];
  627. upd_ene(p->TLSP+2,p->TLSP+10);
  628. k=i-pitch+delta;
  629. norm_corrl(vv+2*k,p->TLSP);
  630. }
  631. }
  632. // ------------------------------------------------------------------------
  633. void right_correl(PC4808DATA p,short vech[],short debut,short fin,short pitch,short delta,long *vv)
  634. {
  635. short i,k,lng;
  636. lng=fin-debut+1;
  637. i=pitch-delta;
  638. energy(vech+debut+i,p->TLSP+2,lng);
  639. correlation(vech+debut+i,vech+debut,p->TLSP,lng);
  640. norm_corrr(vv,p->TLSP);
  641. for (i=pitch-delta+1;i<=pitch+delta;i++)
  642. {
  643. correlation(vech+debut+i,vech+debut,p->TLSP,lng);
  644. p->TLSP[11]=(long)vech[debut+i-1]*(long)vech[debut+i-1];
  645. p->TLSP[10]=(long)vech[fin+i]*(long)vech[fin+i];
  646. upd_ene(p->TLSP+2,p->TLSP+10);
  647. k=i-pitch+delta;
  648. norm_corrr(vv+2*k,p->TLSP);
  649. }
  650. }
  651. // ------------------------------------------------------------------------
  652. void COEFF_A(PC4808DATA p)
  653. {
  654. fenetre(p->SIG+SOUDECAL1-RECS2,hamming,p->SIGPI,NECHFEN);
  655. autocor(p->SIGPI,p->TLSP,NECHFEN,NETAGES);
  656. // TLSP[0]=ldiv(TLSP[0]*1001L,1000L);
  657. if (*p->TLSP)
  658. {
  659. schur(p->LSP,p->TLSP,NETAGES);
  660. ki_to_ai(p->LSP,p->TLSP,NETAGES);
  661. ai_to_lsp(p,p->TLSP,p->LSP);
  662. cos_to_teta(tabcos,p->LSP,10);
  663. }
  664. else short_to_short(p->LSP0,p->LSP,10);
  665. lsp_quant(p,p->LSP,NBB,BITDD,p->code);
  666. short_to_short(p->LSP,p->A3,10);
  667. teta_to_cos(tabcos,p->A3,10);
  668. lsp_to_ai(p->A3,p->TLSP,10);
  669. interpol(p->LSP0,p->LSP,p->A1,NETAGES);
  670. teta_to_cos(tabcos,p->A1,10);
  671. lsp_to_ai(p->A1,p->TLSP,10);
  672. interpol(p->LSP,p->LSP0,p->A2,NETAGES);
  673. teta_to_cos(tabcos,p->A2,10);
  674. lsp_to_ai(p->A2,p->TLSP,10);
  675. short_to_short(p->LSP,p->LSP0,NETAGES);
  676. }
  677. // ------------------------------------------------------------------------
  678. void lsp_quant(PC4808DATA p,short lsp[],short nbit[],short bitdi[],short vcode[])
  679. {
  680. short i,iopt,k,nombi,m,m1,k2;
  681. short *delta,*lsptab,dmin,tmp,demi;
  682. delta = p->E;
  683. lsptab = LSP_Q;
  684. m1 = NETAGES/2;
  685. for (i=0;i<nbit[0];i++) delta[i]=abs(lsp[0] - *(lsptab+i) );
  686. dmin=delta[0];
  687. iopt=0;
  688. for (i=1;i<nbit[0];i++)
  689. if (delta[i]<dmin)
  690. {
  691. dmin=delta[i];
  692. iopt=i;
  693. }
  694. lsp[0] = *(lsptab+iopt);
  695. vcode[0]=iopt;
  696. for (k=1;k<m1;k++)
  697. {
  698. k2=2*k;
  699. lsptab += nbit[k-1];
  700. for (i=0;i<nbit[k];i++) delta[i]=abs(lsp[k2] - *(lsptab+i));
  701. dmin=32767;
  702. tmp=lsp[k2-1];
  703. if (tmp<lsp[k2-2]) tmp=lsp[k2-2];
  704. for (i=0;i<nbit[k];i++)
  705. if (*(lsptab+i)>tmp)
  706. if (delta[i]<dmin)
  707. {
  708. dmin=delta[i];
  709. iopt=i;
  710. }
  711. lsp[k2] = *(lsptab+iopt);
  712. vcode[k2] = iopt;
  713. }
  714. lsptab = TAB_DI;
  715. for (k=0; k<m1-1; k++)
  716. {
  717. k2 = k<<1;
  718. m=bitdi[k];
  719. nombi = (m-1)<<1;
  720. demi=(lsp[k2+2]-lsp[k2]+1)>>1;
  721. for (i=0;i<m;i++)
  722. delta[i]=lsp[k2] + (short)(((long)*(lsptab++)* (long)demi+(long)16384<<1)>>16);
  723. for (i=0;i<m-2;i++) delta[m+i]=lsp[k2+2] - (short)(((long)*(lsptab++) * (long)demi+(long)16384<<1)>>16);
  724. dmin=32767;
  725. for (i=0;i<nombi;i++)
  726. {
  727. tmp = abs(lsp[k2+1]-delta[i]);
  728. if (tmp<dmin)
  729. {
  730. iopt=i;
  731. dmin=tmp;
  732. }
  733. }
  734. lsp[k2+1]=delta[iopt];
  735. vcode[k2+1]=iopt;
  736. }
  737. m=bitdi[k];
  738. nombi=(m-1)<<1;
  739. demi=(32767-lsp[8]+1)>>1;
  740. for (i=0;i<m;i++) delta[i] = lsp[8] + (short)(((long)*(lsptab++) * (long)demi+(long)16384<<1)>>16);
  741. dmin=32767;
  742. for (i=0;i<nombi;i++)
  743. {
  744. tmp = abs(lsp[9]-delta[i]);
  745. if (tmp<dmin)
  746. {
  747. iopt=i;
  748. dmin=tmp;
  749. }
  750. }
  751. lsp[9]=delta[iopt];
  752. vcode[9]=iopt;
  753. }
  754. // ------------------------------------------------------------------------
  755. void RESIDU(PC4808DATA p,short no)
  756. {
  757. short i0;
  758. switch (no)
  759. {
  760. case 0:
  761. i0=0;
  762. break;
  763. case 1: short_to_short(p->A2,p->A1,11);
  764. i0=SOUDECAL1;
  765. break;
  766. case 2: short_to_short(p->A3,p->A1,11);
  767. i0=SOUDECAL1+SOUDECAL;
  768. break;
  769. }
  770. f_inverse(p->MINV,p->A1,p->SIG+i0,p->E,p->SOULONG,NETAGES);
  771. }
  772. // ------------------------------------------------------------------------
  773. void PERIODE(PC4808DATA p,short no)
  774. {
  775. short i,P1,P2;
  776. short *y0,*y1,*y2;
  777. short MAX,MAX2,j,bit_garde;
  778. y0=p->SIGPI; y2=y0+75; y1=p->E_PE;
  779. fenetre(p->A1,A0,p->Aw,11);
  780. init_zero(p->zz,12);
  781. p->H[0]=4096;
  782. init_zero(p->H+1,(short)(p->SOULONG-1));
  783. synthesis(p->zz,p->Aw,p->H,p->H,35,NETAGES,0);
  784. if (no)
  785. {
  786. P1=p->PITCH-3;
  787. if (P1<LIM_P1) P1=LIM_P1;
  788. P2=p->PITCH+4;
  789. if (P2>LIM_P2) P2=LIM_P2;
  790. }
  791. else
  792. {
  793. P1=p->PITCH-5;
  794. if (P1<LIM_P1) P1=LIM_P1;
  795. P2=p->PITCH+5;
  796. if (P2>LIM_P2) P2=LIM_P2;
  797. }
  798. // calc_p(&P1,&P2,PITCH,LIM_P1,LIM_P2,no);
  799. MAX = max_vect(p->E,p->SOULONG);
  800. if (P2<p->SOULONG) MAX2 = max_vect(p->EE+lngEE-P2,P2);
  801. else
  802. {
  803. if (P1<p->SOULONG) j=P1+16;
  804. else j=p->SOULONG+16;
  805. MAX2 = max_vect(p->EE+lngEE-P2,j);
  806. }
  807. if (MAX2>MAX) MAX=MAX2;
  808. if (MAX & 0xe000)
  809. {
  810. i=MAX >> 13;
  811. if (!(i>>1)) bit_garde=1;
  812. else bit_garde=2;
  813. }
  814. else bit_garde=0;
  815. init_zero(p->zz,12);
  816. synthesis(p->zz,p->Aw,p->E,y1,p->SOULONG,NETAGES,bit_garde);
  817. if (P1<p->SOULONG)
  818. {
  819. short_to_short(p->EE+lngEE-P1,y0,P1);
  820. for (i=P1;i<p->SOULONG;i++) y0[i]=0;
  821. }
  822. else short_to_short(p->EE+lngEE-P1,y0,p->SOULONG);
  823. init_zero(p->zz,12);
  824. synthesis(p->zz,p->Aw,y0,y0,p->SOULONG,NETAGES,bit_garde);
  825. short_to_short(y0,y2,p->SOULONG);
  826. if (P1<p->SOULONG) add_sf_vect(y2,y0,P1,p->SOULONG);
  827. if (2*P1<p->SOULONG) add_sf_vect(y2,y0,(short)(P1<<1),p->SOULONG);
  828. energy(y2,p->TLSP+2,p->SOULONG);
  829. correlation(y1,y2,p->TLSP,p->SOULONG);
  830. p->VMAX[1]=-6969;
  831. p->VMAX[4]=P1;
  832. upd_max(p->TLSP,p->VMAX,P1);
  833. for (i=P1+1;i<=P2;i++)
  834. {
  835. p->ptr1=y0; y0=y2; y2=p->ptr1;
  836. update_ltp(y0,y2,p->H+1,p->SOULONG,bit_garde,p->EE[lngEE-i]);
  837. if (i<p->SOULONG)
  838. {
  839. short_to_short(y0,y2,p->SOULONG);
  840. add_sf_vect(y2,y0,i,p->SOULONG);
  841. if (2*i<p->SOULONG) add_sf_vect(y2,y0,(short)(i<<1),p->SOULONG);
  842. energy(y2,p->TLSP+2,p->SOULONG);
  843. correlation(y1,y2,p->TLSP,p->SOULONG);
  844. }
  845. else
  846. {
  847. energy(y0,p->TLSP+2,p->SOULONG);
  848. correlation(y1,y0,p->TLSP,p->SOULONG);
  849. }
  850. upd_max(p->TLSP,p->VMAX,i);
  851. }
  852. #if 0
  853. //*(p->VMAX+2) = 28265821L;
  854. //*(p->VMAX+3) = 61L;
  855. //*(p->VMAX+2) = 881427L;
  856. //*(p->VMAX+3) = 1L;
  857. //*(p->VMAX+2) = 9851363L;
  858. //*(p->VMAX+3) = 6L;
  859. //*(p->VMAX+2) = 812881L;
  860. //*(p->VMAX+3) = 2L;
  861. #if 1
  862. // Save jmp
  863. if ((*(p->VMAX+2) < 0L) || (*(p->VMAX+3) == 0L) || (((long)((long)(*(p->VMAX+2))/(long)(*(p->VMAX+3))) & 0xFFFC0000) == 0L))
  864. proc_gain(p->VMAX+2,p->ttt);
  865. else
  866. *(p->ttt) = 0L; // *(p->VMAX+3) = 0L;
  867. #else
  868. if ((*(p->VMAX+2) > 0L) && (*(p->VMAX+3)) && ((long)((long)(*(p->VMAX+2))/(long)(*(p->VMAX+3))) & 0x0FFC0000))
  869. {
  870. *(p->ttt) = 0L; // *(p->VMAX+3) = 0L;
  871. }
  872. else
  873. proc_gain(p->VMAX+2,p->ttt);
  874. #endif
  875. #else
  876. //*(p->VMAX+2) = 28265821L;
  877. //*(p->VMAX+3) = 61L;
  878. //*(p->VMAX+2) = 881427L;
  879. //*(p->VMAX+3) = 1L;
  880. //*(p->VMAX+2) = 9851363L;
  881. //*(p->VMAX+3) = 6L;
  882. //*(p->VMAX+2) = 812881L;
  883. //*(p->VMAX+3) = 2L;
  884. proc_gain(p->VMAX+2,p->ttt);
  885. #endif
  886. p->PITCH=(short)p->VMAX[4];
  887. /*
  888. if (ttt[0]>32767) GLTP=32767;
  889. else
  890. if (ttt[0]<-32767) GLTP=-32767;
  891. else GLTP=ttt[0];
  892. m = abs(GLTP);
  893. for (i=1;i<=10;i++) if ((m>=BQ[i-1])&&(m<BQ[i]))
  894. {
  895. if (GLTP>0) { GLTP=BV[i] ; k=i-1; }
  896. else { GLTP=-BV[i]; k=i+10-1; }
  897. break;
  898. }
  899. if (GLTP>=BQ[10]) { GLTP=BV[10]; k=9; }
  900. if (GLTP<-BQ[6]) { GLTP=-BV[6]; k=15 ; }
  901. */
  902. p->code[11+p->depl]=calc_gltp(&p->GLTP,BQ,BV,p->ttt[0]);;
  903. p->code[10+p->depl]=p->PITCH;
  904. if (p->PITCH<p->SOULONG)
  905. {
  906. short_to_short(p->EE+lngEE-p->PITCH,p->E_PE,p->PITCH);
  907. short_to_short(p->E_PE,p->E_PE+p->PITCH,(short)(p->SOULONG-p->PITCH));
  908. mult_fact(p->E_PE,p->E_PE,p->GLTP,p->SOULONG);
  909. }
  910. else
  911. {
  912. mult_fact(p->EE+lngEE-p->PITCH,p->E_PE,p->GLTP,p->SOULONG);
  913. }
  914. }
  915. // ------------------------------------------------------------------------
  916. void CHERCHE(PC4808DATA p)
  917. {
  918. short i;
  919. short position,esp_opt;
  920. short k,j;
  921. short c[10],VOISE,npopt,phas_opt,cod,sign;
  922. short Gopt;
  923. short *sr,*y0;
  924. short MAX,bit_garde;
  925. sr=p->SIGPI; y0=sr+75;
  926. for (i=0;i<p->SOULONG;i++) p->E[i] -= p->E_PE[i];
  927. init_zero(p->zz,12);
  928. synthesis(p->zz,p->Aw,p->E,sr,p->SOULONG,NETAGES,0);
  929. MAX = max_vect(sr,p->SOULONG);
  930. /* if (MAX & 0xfe00)
  931. {
  932. i=MAX >> 9;
  933. if (!(i>>1)) bit_garde=1;
  934. else if (!(i>>2)) bit_garde=2;
  935. else if (!(i>>3)) bit_garde=3;
  936. else if (!(i>>4)) bit_garde=4;
  937. else if (!(i>>5)) bit_garde=5;
  938. else bit_garde=6;
  939. }
  940. else bit_garde=0;
  941. */
  942. bit_garde=calc_garde(MAX);
  943. inver_v_int(sr,y0,p->SOULONG);
  944. init_zero(p->zz,12);
  945. synthesis(p->zz,p->Aw,y0,y0,p->SOULONG,NETAGES,bit_garde);
  946. inver_v_int(y0,sr,p->SOULONG);
  947. p->VMAX[0]=-6969;
  948. Gopt=position=0;
  949. VOISE=1;
  950. if ( !p->UNVOIS )
  951. {
  952. esp_opt=p->PITCH;
  953. short_to_short(p->H,y0,p->SOULONG);
  954. if (p->PITCH<p->SOULONG) add_sf_vect(y0,p->H,p->PITCH,p->SOULONG);
  955. // cal_dic1(y0,sr,&esp_opt,&position,SOULONG,PITCH);
  956. cal_dic1(p,y0,sr,&esp_opt,&position,p->SOULONG,p->PITCH,p->SIGPI,p->SOULONG,p->TLSP,p->VMAX);
  957. /* if (PITCH>=SOULONG)
  958. {
  959. if (PITCH/2<SOULONG) sign = PITCH/2;
  960. else sign=PITCH/3;
  961. short_to_short(H,y0,SOULONG);
  962. add_sf_vect(y0,H,sign,SOULONG);
  963. // cal_dic1(y0,sr,&esp_opt,&position,54,sign);
  964. cal_dic1(y0,sr,&esp_opt,&position,54,sign,SIGPI,SOULONG,TLSP,VMAX);
  965. }
  966. // else cal_dic1(H,sr,&esp_opt,&position,54,SOULONG+5);
  967. else cal_dic1(H,sr,&esp_opt,&position,54,SOULONG+5,SIGPI,SOULONG,TLSP,VMAX);
  968. */
  969. }
  970. cal_dic2(p,8,7,0,sr,p->H,c,&VOISE,&esp_opt,&npopt,&phas_opt);
  971. cal_dic2(p,7,8,3,sr,p->H,c,&VOISE,&esp_opt,&npopt,&phas_opt);
  972. /*
  973. cal_dic2(8,7,0,sr,H,c,&VOISE,&esp_opt,&npopt,&phas_opt,SIGPI,SOULONG,TLSP,VMAX);
  974. cal_dic2(7,8,3,sr,H,c,&VOISE,&esp_opt,&npopt,&phas_opt,SIGPI,SOULONG,TLSP,VMAX);
  975. */
  976. proc_gain2(p->VMAX+1,p->VMAX,bit_garde);
  977. if (p->VMAX[0]>32767) Gopt=32767;
  978. else if (p->VMAX[0]<-32767) Gopt=-32767;
  979. else Gopt=(short)p->VMAX[0];
  980. if (VOISE==0)
  981. {
  982. if (c[0]==-1)
  983. {
  984. Gopt=-Gopt;
  985. for (k=0;k<npopt;k++) c[k]=-c[k];
  986. }
  987. if (npopt==7) cod = 64;
  988. else cod = 128;
  989. for (j=1;j<npopt;j++)
  990. if (c[j]==1) cod += 1 << (npopt-j-1);
  991. }
  992. else
  993. {
  994. if (esp_opt == p->PITCH) cod=position;
  995. else cod = position+SOUDECAL1;
  996. }
  997. p->code[12+p->depl]=cod;
  998. if (Gopt<0) { Gopt=-Gopt; sign=1; }
  999. else sign=0;
  1000. for (i=1;i<=16;i++) if ((Gopt>=GQ[i-1])&&(Gopt<GQ[i]))
  1001. {
  1002. Gopt=GV[i];
  1003. cod=i-1;
  1004. break;
  1005. }
  1006. if (Gopt>=GQ[16]) { Gopt=GV[16]; cod=15; }
  1007. if (sign) { Gopt = -Gopt; cod += 16; }
  1008. p->code[13+p->depl]=cod;
  1009. // Gopt=calc_gopt(c,code,GQ,GV,VOISE,npopt,PITCH,esp_opt,depl,position,SOUDECAL1,VMAX[0]);
  1010. short_to_short(p->E_PE,p->E,p->SOULONG);
  1011. if (VOISE==1)
  1012. {
  1013. i=0;
  1014. do
  1015. {
  1016. p->E[position+i] += Gopt;
  1017. i += esp_opt;
  1018. }
  1019. while ((position+i)<p->SOULONG);
  1020. }
  1021. else
  1022. for (j=0;j<npopt;j++)
  1023. p->E[esp_opt*j+phas_opt] += c[j]*Gopt;
  1024. short_to_short(p->EE+p->SOULONG,p->EE,(short)(lngEE-p->SOULONG));
  1025. short_to_short(p->E,p->EE+lngEE-p->SOULONG,p->SOULONG);
  1026. }
  1027. // ------------------------------------------------------------------------
  1028. void FRAME(PC4808DATA p)
  1029. // Purpose : concatenate all parameters
  1030. // Input parameter :
  1031. // code[] : parameters code
  1032. // Output parameter :
  1033. // output_stream[] : multiplexed code
  1034. //
  1035. // Comments: The LTP or Adaptive codebook is also called PITCH.
  1036. //
  1037. // Bit allocation : Codebook or gain "i" is the codebook for suboutput_stream "i".
  1038. // code[0] = LSP(0) : 3bits code[10] = LTP codebook 1 : 7bits
  1039. // code[1] = LSP(1) : 4bits code[11] = LTP gain 1 : 4bits
  1040. // code[2] = LSP(2) : 4bits code[12] = Binary codebook 1 : 8bits
  1041. // code[3] = LSP(3) : 3bits code[13] = Binary gain 1 : 5bits
  1042. // code[4] = LSP(4) : 4bits code[14] = LTP codebook 2 : 4bits
  1043. // code[5] = LSP(5) : 3bits code[15] = LTP gain 2 : 4bits
  1044. // code[6] = LSP(6) : 3bits code[16] = Binary codebook 2 : 8bits
  1045. // code[7] = LSP(7) : 2bits code[17] = Binary gain 2 : 5bits
  1046. // code[8] = LSP(8) : 3bits code[18] = LTP codebook 3 : 4bits
  1047. // code[9] = LSP(9) : 1bits code[19] = LTP gain 3 : 4bits
  1048. // code[20] = Binary codebook 3 : 8bits
  1049. // code[21] = Binary gain 3 : 5bits
  1050. //
  1051. // output_stream[0] = LSP[0] | LSP[1] | LSP[2] | (Binary gain 2)
  1052. // output_stream[1] = LSP[3] | (Binary gain 3) | (Binary codebook 1)
  1053. // output_stream[2] = LSP[4] | LSP[5] | LSP[6] | LSP[7] | LSP[8] | LSP[9]
  1054. // output_stream[3] = (LTP codebook 1) | (LTP gain 1) | (Binary gain 1)
  1055. // output_stream[4] = (LTP codebook 2) | (LTP gain 2) | (Binary codebook 2)
  1056. // output_stream[5] = (LTP codebook 3) | (LTP gain 3) | (Binary codebook 3)
  1057. {
  1058. p->code[18] = p->code[18]-p->code[14]+7;
  1059. p->code[14] = p->code[14]-p->code[10]+7;
  1060. p->code[10] -= LIM_P1;
  1061. p->output_frame[0] = (p->code[0]<<13) | (p->code[1]<<9) | (p->code[2]<<5) | p->code[17];
  1062. p->output_frame[1] = (p->code[3]<<13) | (p->code[21]<<8) | p->code[12];
  1063. p->output_frame[2] = (p->code[4]<<12) | (p->code[5]<<9) | (p->code[6]<<6) | (p->code[7]<<4) | (p->code[8]<<1) | p->code[9];
  1064. p->output_frame[3] = (p->code[10]<<9) | (p->code[11]<<5) | p->code[13];
  1065. p->output_frame[4] = (p->code[14]<<12) | (p->code[15]<<8) | p->code[16];
  1066. p->output_frame[5] = (p->code[18]<<12) | (p->code[19]<<8) | p->code[20];
  1067. /*
  1068. code[18] = code[18]-code[14]+3;
  1069. code[14] = code[14]-code[10]+3;
  1070. code[10] -= LIM_P1;
  1071. output_frame[0] = (code[0]<<13) | (code[1]<<9) | code[12];
  1072. output_frame[1] = (code[3]<<13) | (code[2]<<9) | code[16];
  1073. output_frame[2] = (code[5]<<13) | (code[4]<<9) | code[20];
  1074. output_frame[3] = (code[10]<<9) | (code[6]<<6) | (code[14]<<3) | code[18];
  1075. output_frame[4] = (code[11]<<12) | (code[15]<<8) | (code[19]<<4) | (code[7]<<2) | code[8];
  1076. output_frame[5] = (code[13]<<11) | (code[17]<<6) | (code[21]<<1) | code[9];
  1077. */
  1078. }
  1079. // ------------------------------------------------------------------------
  1080. void CALPITCH(PC4808DATA p)
  1081. {
  1082. short P1,P2,P3,j0,j1,L;
  1083. /* long GG;
  1084. GG=0;
  1085. for (j=0;j<NECHFEN;j++) GG += (long)abs(SIG[SOUDECAL1-RECS2+j]);
  1086. GG /= NECHFEN;
  1087. if (GG<69) UNVOIS=1;
  1088. else UNVOIS=0;*/
  1089. L=NECHFEN+DECAL;
  1090. p->ialf=0;
  1091. deacc(p->M_PIT,p->SIGPI+10,29491,150,&p->ialf);
  1092. deacc(p->SIG+SOUDECAL1-RECS2,p->SIGPI+160,29491,211,&p->ialf);
  1093. j0=(L-80)/2;
  1094. j1=j0+80;
  1095. /*
  1096. filt_iir(memfil_calp,coef_calp,SIGPI+10,SIG_CALP,361,3); // filtrage
  1097. for (j=0;j<90;j++) SIG_CALP[j]=SIG_CALP[4*j]; //d�cimation par 4
  1098. */
  1099. //// decime(SIGPI+10,SIG_CALP,coef_calp,Zai,Zbi,361);
  1100. decimation(p->SIGPI+10,p->SIG_CALP,90);
  1101. P1=max_autoc(p->SIG_CALP+40,28,5,14)*4;
  1102. P2=max_autoc(p->SIG_CALP+20,56,13,28)*4;
  1103. /* P1=max_autoc(SIGPI+160,130,LIM_P1,LIM_P1+35);
  1104. P2=max_autoc(SIGPI+160-80,280,LIM_P1+30,LIM_P2);
  1105. */
  1106. P3=P2/2; p->ialf=P2/3;
  1107. if ( (p->ialf>p->mem_pit[0]-17)&&(p->ialf<p->mem_pit[0]+17) && (abs(p->mem_pit[0]-p->ialf)<abs(p->mem_pit[0]-P3))) P3=p->ialf;
  1108. left_correl(p,p->SIGPI,j0,j1,P1,2,p->veci1);
  1109. left_correl(p,p->SIGPI,j0,j1,P2,2,p->veci2);
  1110. left_correl(p,p->SIGPI,j0,j1,P3,2,p->veci3);
  1111. right_correl(p,p->SIGPI,j0,j1,P1,2,p->veci1);
  1112. right_correl(p,p->SIGPI,j0,j1,P2,2,p->veci2);
  1113. right_correl(p,p->SIGPI,j0,j1,P3,2,p->veci3);
  1114. P1=max_posit(p->veci1,p->TLSP,P1,5);
  1115. P2=max_posit(p->veci2,p->TLSP+2,P2,5);
  1116. P3=max_posit(p->veci3,p->TLSP+4,P3,5);
  1117. if (p->TLSP[1]>p->TLSP[3]) p->PITCH =P1;
  1118. else if ((p->TLSP[1]==p->TLSP[3]) && (p->TLSP[0]>p->TLSP[2])) p->PITCH=P1;
  1119. else { p->PITCH=P2; p->TLSP[0]=p->TLSP[2]; p->TLSP[1]=p->TLSP[3];}
  1120. if ( (P3>p->mem_pit[0]-17) && (P3<p->mem_pit[0]+17))
  1121. {
  1122. if (abs(p->mem_pit[1]-p->mem_pit[0])<15) p->TLSP[0] = p->TLSP[0]>>1 + p->TLSP[0]>>2;
  1123. if (abs(P3-P1)>6) p->TLSP[0] = p->TLSP[0]>>1 + p->TLSP[0]>>2;
  1124. if (p->TLSP[0]<0x40000000L) { p->TLSP[0]<<=1; p->TLSP[1]--;}
  1125. // if (TLSP[0]<0x40000000) { TLSP[0]<<=1; TLSP[1]--;}
  1126. if (p->TLSP[1]<p->TLSP[5]) p->PITCH =P3;
  1127. else if ((p->TLSP[1]==p->TLSP[5]) && (p->TLSP[0]<p->TLSP[4])) p->PITCH=P3;
  1128. }
  1129. p->mem_pit[1]=p->mem_pit[0];
  1130. p->mem_pit[0]=p->PITCH;
  1131. }
  1132. #endif
  1133. // ------------------------------------------------------------------------
  1134. // ------------------------------------------------------------------------
  1135. // DLL entry points
  1136. // ------------------------------------------------------------------------
  1137. // ------------------------------------------------------------------------
  1138. // ------------------------------------------------------------------------
  1139. LH_PREFIX HANDLE LH_SUFFIX MSLHSB_Open_Coder(DWORD dwMaxBitRate)
  1140. {
  1141. PVOID pCoderData;
  1142. /*short i,flag=0;
  1143. // Test if there are free handles
  1144. for (i=0;i<MAXCODINGHANDLES;i++)
  1145. if (CodingHandles[i]==0) {CodingHandles[i]=1; flag=1; break;}
  1146. if (flag==0) return 0;
  1147. pCoderData=&CoderData[i];*/
  1148. // Check the input bit rate param.
  1149. if (
  1150. #ifdef CELP4800
  1151. (dwMaxBitRate != 4800) &&
  1152. #endif
  1153. (dwMaxBitRate != 8000) && (dwMaxBitRate != 12000) && (dwMaxBitRate != 16000))
  1154. return (HANDLE)0;
  1155. // pCoderData=(PVOID)GlobalAllocPtr(GMEM_MOVEABLE, dwMaxBitRate == 4800 ? sizeof(C4808DATA) : sizeof(C16008DATA));
  1156. #ifdef CELP4800
  1157. pCoderData=(PVOID)GlobalAllocPtr(GHND, dwMaxBitRate == 4800 ? sizeof(C4808DATA) : sizeof(C16008DATA));
  1158. #else
  1159. pCoderData=(PVOID)GlobalAllocPtr(GHND, sizeof(C16008DATA));
  1160. #endif
  1161. if (pCoderData==NULL)
  1162. return (HANDLE)0;
  1163. InitializeCoderInstanceData(pCoderData, dwMaxBitRate);
  1164. #ifdef __TEST
  1165. codage=(FILE*)fopen("codage.dat","wb");
  1166. test=(FILE*)fopen("codes_c2.dat","wt");
  1167. #endif
  1168. return((HANDLE)pCoderData);
  1169. }
  1170. // ------------------------------------------------------------------------
  1171. LH_PREFIX LH_ERRCODE LH_SUFFIX MSLHSB_Encode(
  1172. HANDLE hAccess,
  1173. LPBYTE lpSrcBuf,
  1174. LPWORD lpSrcBufSize,
  1175. LPBYTE lpDstBuf,
  1176. LPWORD lpDstBufSize)
  1177. {
  1178. short i,iNBSPF,iMOD_TH1,iMOD_TH2,iMOD_TH3,k,flag=0;
  1179. short iNBSB_SP_MAX1,iNBSB_SP_MAX2,iNBSB_SP_MAX3,iNBSB_SP_MAX4;
  1180. short *input;
  1181. short *in;
  1182. unsigned short *ptr2,*ptr4;
  1183. unsigned char *ptr1,*ptr3;
  1184. long nbb_ave; // Average bit rate on the previous NBFAC frames of speech
  1185. short codesizes[24];
  1186. long codes[24];
  1187. short numcodes,temp;
  1188. short ivect8[160];
  1189. PVOID pCoderData;
  1190. if ((!hAccess) || (!lpSrcBuf) || (!lpDstBuf))
  1191. return LH_EBADARG;
  1192. // First check that the handle provided as argument is correct
  1193. /*for (i=0;i<MAXCODINGHANDLES;i++)
  1194. if ((CodingHandles[i]==1)&&(hAccess==(HANDLE)&CoderData[i])) {flag=1; break;}
  1195. if (flag==0) return LH_BADHANDLE;*/
  1196. pCoderData=(PVOID)hAccess;
  1197. // Check the input bit rate param.
  1198. if (
  1199. #ifdef CELP4800
  1200. (((PC4808DATA)pCoderData)->dwMaxBitRate != 4800) &&
  1201. #endif
  1202. (((PC16008DATA)pCoderData)->dwMaxBitRate != 8000) &&
  1203. (((PC16008DATA)pCoderData)->dwMaxBitRate != 12000) &&
  1204. (((PC16008DATA)pCoderData)->dwMaxBitRate != 16000))
  1205. return (LH_ERRCODE)LH_EBADARG;
  1206. #ifdef CELP4800
  1207. if ((((PC4808DATA)pCoderData)->dwMaxBitRate == 4800))
  1208. {
  1209. // then check the buffer sizes passed as argument.
  1210. if ((*lpSrcBufSize<2*NECHDECAL)||(*lpDstBufSize<12))
  1211. return (LH_ERRCODE)LH_EBADARG;
  1212. *lpSrcBufSize=2*NECHDECAL;
  1213. *lpDstBufSize=12;
  1214. input = (short *)lpSrcBuf;
  1215. in=((PC4808DATA)pCoderData)->SIG+SOUDECAL1+RECS2;
  1216. for (i=0;i<DECAL;i++) *in++=*input++;
  1217. filt_in(((PC4808DATA)pCoderData)->mem2,((PC4808DATA)pCoderData)->SIG+SOUDECAL1+RECS2,((PC4808DATA)pCoderData)->SIG+SOUDECAL1+RECS2,DECAL);
  1218. CALPITCH(((PC4808DATA)pCoderData));
  1219. COEFF_A(((PC4808DATA)pCoderData));
  1220. for (i=0;i<3;i++)
  1221. {
  1222. if (i==0) ((PC4808DATA)pCoderData)->SOULONG=SOUDECAL1;
  1223. else ((PC4808DATA)pCoderData)->SOULONG=SOUDECAL;
  1224. ((PC4808DATA)pCoderData)->depl=i*4;
  1225. RESIDU(((PC4808DATA)pCoderData),i);
  1226. PERIODE(((PC4808DATA)pCoderData),i);
  1227. CHERCHE(((PC4808DATA)pCoderData));
  1228. dsynthesis(((PC4808DATA)pCoderData)->DMSY,((PC4808DATA)pCoderData)->A1,((PC4808DATA)pCoderData)->E,((PC4808DATA)pCoderData)->E_PE,((PC4808DATA)pCoderData)->SOULONG,NETAGES);
  1229. for (k=0;k<=11;k++) ((PC4808DATA)pCoderData)->MINV[12-k] = ((PC4808DATA)pCoderData)->E_PE[((PC4808DATA)pCoderData)->SOULONG-12+k];
  1230. ((PC4808DATA)pCoderData)->MINV[0]=(short)(((PC4808DATA)pCoderData)->DMSY[0] >> 16);
  1231. }
  1232. FRAME(((PC4808DATA)pCoderData));
  1233. short_to_short(((PC4808DATA)pCoderData)->SIG+SOUDECAL1-RECS2,((PC4808DATA)pCoderData)->M_PIT,160);
  1234. short_to_short(((PC4808DATA)pCoderData)->SIG+NECHDECAL,((PC4808DATA)pCoderData)->SIG,SOUDECAL1+RECS2);
  1235. ptr4 = (unsigned short *)&((PC4808DATA)pCoderData)->output_frame;
  1236. ptr2 = (unsigned short *)lpDstBuf;
  1237. for (i =0;i<6;i++) ptr2[i] = ptr4[i];
  1238. }
  1239. else
  1240. #endif
  1241. {
  1242. input = (short *)lpSrcBuf;
  1243. ((PC16008DATA)pCoderData)->nbbit_cf=0;
  1244. // then check the buffer sizes passed as argument.
  1245. switch (((PC16008DATA)pCoderData)->dwMaxBitRate)
  1246. {
  1247. case 8000:
  1248. if ((*lpSrcBufSize<2*160)||(*lpDstBufSize<MAX_OUTPUT_BYTES_8000_12000))
  1249. return (LH_ERRCODE)LH_EBADARG;
  1250. *lpSrcBufSize=2*160;
  1251. for (i=0;i<160;i++) ((PC16008DATA)pCoderData)->DATA_I[i]=(*input++)>>1; // TEST >>2
  1252. #ifdef _X86_
  1253. PassLow8(((PC16008DATA)pCoderData)->DATA_I,ivect8,((PC16008DATA)pCoderData)->memBP,160);
  1254. iConvert8To64(ivect8,((PC16008DATA)pCoderData)->DATA_I,160,((PC16008DATA)pCoderData)->imem1);
  1255. #else
  1256. SampleRate8000To6400(((PC16008DATA)pCoderData)->DATA_I,
  1257. ((PC16008DATA)pCoderData)->DATA_I,
  1258. 160,
  1259. ((PC16008DATA)pCoderData)->imem1,
  1260. &((PC16008DATA)pCoderData)->uiDelayPosition,
  1261. &((PC16008DATA)pCoderData)->iInputStreamTime,
  1262. &((PC16008DATA)pCoderData)->iOutputStreamTime );
  1263. #endif
  1264. break;
  1265. case 12000:
  1266. if ((*lpSrcBufSize<2*128)||(*lpDstBufSize<MAX_OUTPUT_BYTES_8000_12000))
  1267. return (LH_ERRCODE)LH_EBADARG;
  1268. *lpSrcBufSize=2*128;
  1269. for (i=0;i<128;i++) ((PC16008DATA)pCoderData)->DATA_I[i]=(*input++)>>1; // TEST >>2
  1270. break;
  1271. case 16000:
  1272. if ((*lpSrcBufSize<2*128)||(*lpDstBufSize<MAX_OUTPUT_BYTES_16000))
  1273. return (LH_ERRCODE)LH_EBADARG;
  1274. *lpSrcBufSize=2*128;
  1275. for (i=0;i<128;i++) ((PC16008DATA)pCoderData)->DATA_I[i]=(*input++)>>1; // TEST >>2
  1276. break;
  1277. }
  1278. code_res_I(((PC16008DATA)pCoderData),((PC16008DATA)pCoderData)->DATA_I,coef_I,((PC16008DATA)pCoderData)->QMF_MEM_ANAL_I,((PC16008DATA)pCoderData)->codes_max,
  1279. ((PC16008DATA)pCoderData)->codes_sb,((PC16008DATA)pCoderData)->indic_sp);
  1280. //*#ifdef __VARIABLE__
  1281. for (i=NBFAC-1;i>0;i--)
  1282. {
  1283. ((PC16008DATA)pCoderData)->nbbit[i]=((PC16008DATA)pCoderData)->nbbit[i-1]; // on re-adapte les tranches precedentes
  1284. }
  1285. ((PC16008DATA)pCoderData)->nbbit[0]=((PC16008DATA)pCoderData)->nbbit_cf; // valeur pour la tranche actuelle
  1286. nbb_ave=0L;
  1287. for (i=0;i<NBFAC;i++) nbb_ave+=(long)((PC16008DATA)pCoderData)->nbbit[i];
  1288. if (((PC16008DATA)pCoderData)->dwMaxBitRate == 8000)
  1289. {
  1290. iNBSPF = NBSPF_4800_8000;
  1291. iMOD_TH1 = MOD_TH1_8000;
  1292. iMOD_TH2 = MOD_TH2_8000;
  1293. iMOD_TH3 = MOD_TH3_8000;
  1294. iNBSB_SP_MAX1 = NBSB_SP_MAX1_8000_12000;
  1295. iNBSB_SP_MAX2 = NBSB_SP_MAX2_8000_12000;
  1296. iNBSB_SP_MAX3 = NBSB_SP_MAX3_8000_12000;
  1297. iNBSB_SP_MAX4 = NBSB_SP_MAX4_8000_12000;
  1298. }
  1299. else
  1300. {
  1301. iNBSPF = NBSPF_12000_16000;
  1302. iMOD_TH1 = MOD_TH1_12000_16000;
  1303. if (((PC16008DATA)pCoderData)->dwMaxBitRate == 12000)
  1304. {
  1305. iMOD_TH2 = MOD_TH2_12000;
  1306. iMOD_TH3 = MOD_TH3_12000;
  1307. iNBSB_SP_MAX1 = NBSB_SP_MAX1_8000_12000;
  1308. iNBSB_SP_MAX2 = NBSB_SP_MAX2_8000_12000;
  1309. iNBSB_SP_MAX3 = NBSB_SP_MAX3_8000_12000;
  1310. iNBSB_SP_MAX4 = NBSB_SP_MAX4_8000_12000;
  1311. }
  1312. else
  1313. {
  1314. iMOD_TH2 = MOD_TH2_16000;
  1315. iMOD_TH3 = MOD_TH3_16000;
  1316. iNBSB_SP_MAX1 = NBSB_SP_MAX1_16000;
  1317. iNBSB_SP_MAX2 = NBSB_SP_MAX2_16000;
  1318. iNBSB_SP_MAX3 = NBSB_SP_MAX3_16000;
  1319. iNBSB_SP_MAX4 = NBSB_SP_MAX4_16000;
  1320. }
  1321. }
  1322. nbb_ave=(short)((nbb_ave*F_ECH)/(NBFAC*iNBSPF));
  1323. // On retablit les seuils en fonction de la moyenne calculee
  1324. if (nbb_ave<=iMOD_TH1)
  1325. {
  1326. ((PC16008DATA)pCoderData)->MAX_LEVEL = MAX_LEVEL1; // valeur par defaut si le debit n'augmente pas trop
  1327. ((PC16008DATA)pCoderData)->DIV_MAX = DIV_MAX1; // cad on ne traite pas les sb < 5% du max[i]
  1328. ((PC16008DATA)pCoderData)->NBSB_SP_MAX = iNBSB_SP_MAX1; // nbre max de sb pouvant etre du signal
  1329. }
  1330. else
  1331. {
  1332. if (nbb_ave<=iMOD_TH2) // on a depasse le 1er seuils mais pas le 2eme
  1333. {
  1334. ((PC16008DATA)pCoderData)->MAX_LEVEL = MAX_LEVEL2; // on rejette plus de tranches
  1335. ((PC16008DATA)pCoderData)->DIV_MAX = DIV_MAX2; // cad on ne traite pas les sb < 7% du max[i]
  1336. ((PC16008DATA)pCoderData)->NBSB_SP_MAX = iNBSB_SP_MAX2; // nbre max de sb pouvant etre du signal
  1337. }
  1338. else
  1339. {
  1340. if (nbb_ave<=iMOD_TH3) // on a depasse le 1er seuils mais pas le 2eme
  1341. {
  1342. ((PC16008DATA)pCoderData)->MAX_LEVEL = MAX_LEVEL3; // on rejette un max
  1343. ((PC16008DATA)pCoderData)->DIV_MAX = DIV_MAX3; // cad on ne traite pas les sb < 5% du max[i]
  1344. ((PC16008DATA)pCoderData)->NBSB_SP_MAX = iNBSB_SP_MAX3; // nbre max de sb pouvant etre du signal
  1345. }
  1346. else // on a depasse le troisieme seuil; il faut descendre!
  1347. {
  1348. ((PC16008DATA)pCoderData)->MAX_LEVEL = MAX_LEVEL4; // meme seuil de rejet
  1349. ((PC16008DATA)pCoderData)->DIV_MAX = DIV_MAX4; // cad on ne traite pas les sb <10% du max[i]
  1350. ((PC16008DATA)pCoderData)->NBSB_SP_MAX = iNBSB_SP_MAX4; // nbre max de sb pouvant etre du signal
  1351. }
  1352. }
  1353. }/**/
  1354. ((PC16008DATA)pCoderData)->stream[0]=0;
  1355. for (i=0;i<8;i++)
  1356. ((PC16008DATA)pCoderData)->stream[0]|=(((PC16008DATA)pCoderData)->indic_sp[i]&0x01)<<i;
  1357. numcodes=0;
  1358. //temp=bytes[((PC16008DATA)pCoderData)->nbsb_sp];
  1359. #if 0
  1360. temp=(short)((float)((PC16008DATA)pCoderData)->nbbit_cf/8.0+0.99);
  1361. #else
  1362. // We want to go away of libcmt, msvcrt... and
  1363. // floating point is not really essential here...
  1364. if (((PC16008DATA)pCoderData)->nbbit_cf)
  1365. temp=(short)((((PC16008DATA)pCoderData)->nbbit_cf-1)/8+1);
  1366. else
  1367. temp=0;
  1368. #endif
  1369. for (i=0;i<24;i++) codesizes[i]=0;
  1370. for (i=0;i<((PC16008DATA)pCoderData)->nbsb_sp;i++)
  1371. {
  1372. codes[i]=(long)((PC16008DATA)pCoderData)->codes_max[i];
  1373. codes[((PC16008DATA)pCoderData)->nbsb_sp+2*i]=(long)((PC16008DATA)pCoderData)->codes_sb[2*i];
  1374. codes[((PC16008DATA)pCoderData)->nbsb_sp+2*i+1]=(long)((PC16008DATA)pCoderData)->codes_sb[2*i+1];
  1375. codesizes[i]=5;
  1376. codesizes[((PC16008DATA)pCoderData)->nbsb_sp+2*i]=((PC16008DATA)pCoderData)->bits[i]/2;
  1377. codesizes[((PC16008DATA)pCoderData)->nbsb_sp+2*i+1]=((PC16008DATA)pCoderData)->bits[i]/2;
  1378. numcodes+=3;
  1379. }
  1380. if (((PC16008DATA)pCoderData)->dwMaxBitRate == 16000)
  1381. {
  1382. for (i=((PC16008DATA)pCoderData)->nbsb_sp;i<8;i++)
  1383. {
  1384. codes[2*((PC16008DATA)pCoderData)->nbsb_sp+i]=(long)((PC16008DATA)pCoderData)->codes_max[i];
  1385. codes[8+2*i]=(long)((PC16008DATA)pCoderData)->codes_sb[2*i];
  1386. codes[8+2*i+1]=(long)((PC16008DATA)pCoderData)->codes_sb[2*i+1];
  1387. codesizes[2*((PC16008DATA)pCoderData)->nbsb_sp+i]=5;
  1388. codesizes[8+2*i]=SILENCE_CODING_BIT_16000/2;
  1389. codesizes[8+2*i+1]=SILENCE_CODING_BIT_16000/2;
  1390. numcodes+=3;
  1391. }
  1392. Multiplexing(((PC16008DATA)pCoderData)->stream+1,codes,codesizes,numcodes,(short)(temp-1));
  1393. }
  1394. else
  1395. if (((PC16008DATA)pCoderData)->nbsb_sp)
  1396. Multiplexing(((PC16008DATA)pCoderData)->stream+1,codes,codesizes,numcodes,(short)(temp-1));
  1397. *lpDstBufSize=temp;
  1398. ptr3 = (unsigned char *)&((PC16008DATA)pCoderData)->stream;
  1399. ptr1 = (unsigned char *)lpDstBuf;
  1400. for (i =0;i<*lpDstBufSize;i++) ptr1[i] = ptr3[i];
  1401. }
  1402. return (LH_SUCCESS);
  1403. }
  1404. // ------------------------------------------------------------------------
  1405. LH_PREFIX LH_ERRCODE LH_SUFFIX MSLHSB_Close_Coder(HANDLE hAccess)
  1406. {
  1407. PVOID pCoderData;
  1408. /*short i,flag=0;
  1409. // Check if right handle
  1410. for (i=0;i<MAXCODINGHANDLES;i++)
  1411. if ((CodingHandles[i]==1)&&(hAccess==(HANDLE)&CoderData[i])) {flag=1; break;}
  1412. if (flag==0) return LH_BADHANDLE;
  1413. // Free handle
  1414. CodingHandles[i]=0;*/
  1415. if (!hAccess)
  1416. return LH_EBADARG;
  1417. pCoderData=(PVOID)hAccess;
  1418. GlobalFreePtr(pCoderData);
  1419. #ifdef __TEST
  1420. fclose(codage);
  1421. fclose(test);
  1422. #endif
  1423. return LH_SUCCESS;
  1424. }