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.

123 lines
3.5KB

  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. #define PLANAR 0
  25. #include "flacdsp_template.c"
  26. #undef PLANAR
  27. #define PLANAR 1
  28. #include "flacdsp_template.c"
  29. #undef SAMPLE_SIZE
  30. #undef PLANAR
  31. #define SAMPLE_SIZE 32
  32. #define PLANAR 0
  33. #include "flacdsp_template.c"
  34. #undef PLANAR
  35. #define PLANAR 1
  36. #include "flacdsp_template.c"
  37. static void flac_lpc_16_c(int32_t *decoded, const int coeffs[32],
  38. int pred_order, int qlevel, int len)
  39. {
  40. int i, j;
  41. for (i = pred_order; i < len - 1; i += 2, decoded += 2) {
  42. int c = coeffs[0];
  43. int d = decoded[0];
  44. int s0 = 0, s1 = 0;
  45. for (j = 1; j < pred_order; j++) {
  46. s0 += c*d;
  47. d = decoded[j];
  48. s1 += c*d;
  49. c = coeffs[j];
  50. }
  51. s0 += c*d;
  52. d = decoded[j] += s0 >> qlevel;
  53. s1 += c*d;
  54. decoded[j + 1] += s1 >> qlevel;
  55. }
  56. if (i < len) {
  57. int sum = 0;
  58. for (j = 0; j < pred_order; j++)
  59. sum += coeffs[j] * decoded[j];
  60. decoded[j] += sum >> qlevel;
  61. }
  62. }
  63. static void flac_lpc_32_c(int32_t *decoded, const int coeffs[32],
  64. int pred_order, int qlevel, int len)
  65. {
  66. int i, j;
  67. for (i = pred_order; i < len; i++, decoded++) {
  68. int64_t sum = 0;
  69. for (j = 0; j < pred_order; j++)
  70. sum += (int64_t)coeffs[j] * decoded[j];
  71. decoded[j] += sum >> qlevel;
  72. }
  73. }
  74. av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt,
  75. int bps)
  76. {
  77. if (bps > 16)
  78. c->lpc = flac_lpc_32_c;
  79. else
  80. c->lpc = flac_lpc_16_c;
  81. switch (fmt) {
  82. case AV_SAMPLE_FMT_S32:
  83. c->decorrelate[0] = flac_decorrelate_indep_c_32;
  84. c->decorrelate[1] = flac_decorrelate_ls_c_32;
  85. c->decorrelate[2] = flac_decorrelate_rs_c_32;
  86. c->decorrelate[3] = flac_decorrelate_ms_c_32;
  87. break;
  88. case AV_SAMPLE_FMT_S32P:
  89. c->decorrelate[0] = flac_decorrelate_indep_c_32p;
  90. c->decorrelate[1] = flac_decorrelate_ls_c_32p;
  91. c->decorrelate[2] = flac_decorrelate_rs_c_32p;
  92. c->decorrelate[3] = flac_decorrelate_ms_c_32p;
  93. break;
  94. case AV_SAMPLE_FMT_S16:
  95. c->decorrelate[0] = flac_decorrelate_indep_c_16;
  96. c->decorrelate[1] = flac_decorrelate_ls_c_16;
  97. c->decorrelate[2] = flac_decorrelate_rs_c_16;
  98. c->decorrelate[3] = flac_decorrelate_ms_c_16;
  99. break;
  100. case AV_SAMPLE_FMT_S16P:
  101. c->decorrelate[0] = flac_decorrelate_indep_c_16p;
  102. c->decorrelate[1] = flac_decorrelate_ls_c_16p;
  103. c->decorrelate[2] = flac_decorrelate_rs_c_16p;
  104. c->decorrelate[3] = flac_decorrelate_ms_c_16p;
  105. break;
  106. }
  107. }