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.

95 lines
2.8KB

  1. /*
  2. * Copyright (c) 2012 Mans Rullgard <mans@mansr.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/attributes.h"
  21. #include "libavutil/samplefmt.h"
  22. #include "flacdsp.h"
  23. #define SAMPLE_SIZE 16
  24. #include "flacdsp_template.c"
  25. #undef SAMPLE_SIZE
  26. #define SAMPLE_SIZE 32
  27. #include "flacdsp_template.c"
  28. static void flac_lpc_16_c(int32_t *decoded, const int coeffs[32],
  29. int pred_order, int qlevel, int len)
  30. {
  31. int i, j;
  32. for (i = pred_order; i < len - 1; i += 2) {
  33. int c;
  34. int d = decoded[i-pred_order];
  35. int s0 = 0, s1 = 0;
  36. for (j = pred_order-1; j > 0; j--) {
  37. c = coeffs[j];
  38. s0 += c*d;
  39. d = decoded[i-j];
  40. s1 += c*d;
  41. }
  42. c = coeffs[0];
  43. s0 += c*d;
  44. d = decoded[i] += s0 >> qlevel;
  45. s1 += c*d;
  46. decoded[i+1] += s1 >> qlevel;
  47. }
  48. if (i < len) {
  49. int sum = 0;
  50. for (j = 0; j < pred_order; j++)
  51. sum += coeffs[j] * decoded[i-j-1];
  52. decoded[i] += sum >> qlevel;
  53. }
  54. }
  55. static void flac_lpc_32_c(int32_t *decoded, const int coeffs[32],
  56. int pred_order, int qlevel, int len)
  57. {
  58. int i, j;
  59. for (i = pred_order; i < len; i++) {
  60. int64_t sum = 0;
  61. for (j = 0; j < pred_order; j++)
  62. sum += (int64_t)coeffs[j] * decoded[i-j-1];
  63. decoded[i] += sum >> qlevel;
  64. }
  65. }
  66. av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt)
  67. {
  68. switch (fmt) {
  69. case AV_SAMPLE_FMT_S32:
  70. c->decorrelate[0] = flac_decorrelate_indep_c_32;
  71. c->decorrelate[1] = flac_decorrelate_ls_c_32;
  72. c->decorrelate[2] = flac_decorrelate_rs_c_32;
  73. c->decorrelate[3] = flac_decorrelate_ms_c_32;
  74. c->lpc = flac_lpc_32_c;
  75. break;
  76. case AV_SAMPLE_FMT_S16:
  77. c->decorrelate[0] = flac_decorrelate_indep_c_16;
  78. c->decorrelate[1] = flac_decorrelate_ls_c_16;
  79. c->decorrelate[2] = flac_decorrelate_rs_c_16;
  80. c->decorrelate[3] = flac_decorrelate_ms_c_16;
  81. c->lpc = flac_lpc_16_c;
  82. break;
  83. }
  84. }