iCBConstruct.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /******************************************************************
  2. iLBC Speech Coder ANSI-C Source Code
  3. iCBConstruct.c
  4. Copyright (c) 2001,
  5. Global IP Sound AB.
  6. All rights reserved.
  7. ******************************************************************/
  8. #include <math.h>
  9. #include "iLBC_define.h"
  10. #include "gainquant.h"
  11. #include "getCBvec.h"
  12. #include "iCBConstruct.h"
  13. /*----------------------------------------------------------------*
  14. * Convert the codebook indexes to make the search easier
  15. *---------------------------------------------------------------*/
  16. void index_conv_enc(
  17. int *index /* (i/o) Codebook indexes */
  18. ){
  19. int k;
  20. for (k=1;k<CB_NSTAGES;k++) {
  21. if ((index[k]>=108)&&(index[k]<172)) {
  22. index[k]-=64;
  23. } else if (index[k]>=236) {
  24. index[k]-=128;
  25. } else {
  26. /* ERROR */
  27. }
  28. }
  29. }
  30. void index_conv_dec(
  31. int *index /* (i/o) Codebook indexes */
  32. ){
  33. int k;
  34. for (k=1;k<CB_NSTAGES;k++) {
  35. if ((index[k]>=44)&&(index[k]<108)) {
  36. index[k]+=64;
  37. } else if ((index[k]>=108)&&(index[k]<128)) {
  38. index[k]+=128;
  39. } else {
  40. /* ERROR */
  41. }
  42. }
  43. }
  44. /*----------------------------------------------------------------*
  45. * Construct decoded vector from codebook and gains.
  46. *---------------------------------------------------------------*/
  47. void iCBConstruct(
  48. float *decvector, /* (o) Decoded vector */
  49. int *index, /* (i) Codebook indices */
  50. int *gain_index,/* (i) Gain quantization indices */
  51. float *mem, /* (i) Buffer for codevector construction */
  52. int lMem, /* (i) Length of buffer */
  53. int veclen, /* (i) Length of vector */
  54. int nStages /* (i) Number of codebook stages */
  55. ){
  56. int j,k;
  57. float gain[CB_NSTAGES];
  58. float cbvec[SUBL];
  59. /* gain de-quantization */
  60. gain[0] = gaindequant(gain_index[0], 1.0, 32);
  61. if (nStages > 1) {
  62. gain[1] = gaindequant(gain_index[1],
  63. (float)fabs(gain[0]), 16);
  64. }
  65. if (nStages > 2) {
  66. gain[2] = gaindequant(gain_index[2],
  67. (float)fabs(gain[1]), 8);
  68. }
  69. /* codebook vector construction and construction of
  70. total vector */
  71. getCBvec(cbvec, mem, index[0], lMem, veclen);
  72. for (j=0;j<veclen;j++){
  73. decvector[j] = gain[0]*cbvec[j];
  74. }
  75. if (nStages > 1) {
  76. for (k=1; k<nStages; k++) {
  77. getCBvec(cbvec, mem, index[k], lMem, veclen);
  78. for (j=0;j<veclen;j++) {
  79. decvector[j] += gain[k]*cbvec[j];
  80. }
  81. }
  82. }
  83. }