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.

82 lines
2.2KB

  1. /*
  2. * QCELP decoder
  3. * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavcodec/qcelp_lsp.c
  23. * QCELP decoder
  24. * @author Reynaldo H. Verdejo Pinochet
  25. * @remark FFmpeg merging spearheaded by Kenan Gillet
  26. * @remark Development mentored by Benjamin Larson
  27. */
  28. #include "libavutil/mathematics.h"
  29. /**
  30. * Computes the Pa / (1 + z(-1)) or Qa / (1 - z(-1)) coefficients
  31. * needed for LSP to LPC conversion.
  32. * We only need to calculate the 6 first elements of the polynomial.
  33. *
  34. * @param lspf line spectral pair frequencies
  35. * @param f [out] polynomial input/output as a vector
  36. *
  37. * TIA/EIA/IS-733 2.4.3.3.5-1/2
  38. */
  39. static void lsp2polyf(const double *lspf, double *f, int lp_half_order)
  40. {
  41. int i, j;
  42. f[0] = 1.0;
  43. f[1] = -2 * lspf[0];
  44. lspf -= 2;
  45. for(i=2; i<=lp_half_order; i++)
  46. {
  47. double val = -2 * lspf[2*i];
  48. f[i] = val * f[i-1] + 2*f[i-2];
  49. for(j=i-1; j>1; j--)
  50. f[j] += f[j-1] * val + f[j-2];
  51. f[1] += val;
  52. }
  53. }
  54. /**
  55. * Reconstructs LPC coefficients from the line spectral pair frequencies.
  56. *
  57. * @param lspf line spectral pair frequencies
  58. * @param lpc linear predictive coding coefficients
  59. */
  60. void ff_celp_lspf2lpc(const double *lspf, float *lpc)
  61. {
  62. double pa[6], qa[6];
  63. int i;
  64. lsp2polyf(lspf, pa, 5);
  65. lsp2polyf(lspf + 1, qa, 5);
  66. for (i=4; i>=0; i--)
  67. {
  68. double paf = pa[i+1] + pa[i];
  69. double qaf = qa[i+1] - qa[i];
  70. lpc[i ] = 0.5*(paf+qaf);
  71. lpc[9-i] = 0.5*(paf-qaf);
  72. }
  73. }