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.

124 lines
3.5KB

  1. /*
  2. * Copyright (c) 2012 Mans Rullgard <mans@mansr.com>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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) {
  42. int c;
  43. int d = decoded[i-pred_order];
  44. int s0 = 0, s1 = 0;
  45. for (j = pred_order-1; j > 0; j--) {
  46. c = coeffs[j];
  47. s0 += c*d;
  48. d = decoded[i-j];
  49. s1 += c*d;
  50. }
  51. c = coeffs[0];
  52. s0 += c*d;
  53. d = decoded[i] += s0 >> qlevel;
  54. s1 += c*d;
  55. decoded[i+1] += s1 >> qlevel;
  56. }
  57. if (i < len) {
  58. int sum = 0;
  59. for (j = 0; j < pred_order; j++)
  60. sum += coeffs[j] * decoded[i-j-1];
  61. decoded[i] += sum >> qlevel;
  62. }
  63. }
  64. static void flac_lpc_32_c(int32_t *decoded, const int coeffs[32],
  65. int pred_order, int qlevel, int len)
  66. {
  67. int i, j;
  68. for (i = pred_order; i < len; i++) {
  69. int64_t sum = 0;
  70. for (j = 0; j < pred_order; j++)
  71. sum += (int64_t)coeffs[j] * decoded[i-j-1];
  72. decoded[i] += sum >> qlevel;
  73. }
  74. }
  75. av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt,
  76. int bps)
  77. {
  78. if (bps > 16)
  79. c->lpc = flac_lpc_32_c;
  80. else
  81. c->lpc = flac_lpc_16_c;
  82. switch (fmt) {
  83. case AV_SAMPLE_FMT_S32:
  84. c->decorrelate[0] = flac_decorrelate_indep_c_32;
  85. c->decorrelate[1] = flac_decorrelate_ls_c_32;
  86. c->decorrelate[2] = flac_decorrelate_rs_c_32;
  87. c->decorrelate[3] = flac_decorrelate_ms_c_32;
  88. break;
  89. case AV_SAMPLE_FMT_S32P:
  90. c->decorrelate[0] = flac_decorrelate_indep_c_32p;
  91. c->decorrelate[1] = flac_decorrelate_ls_c_32p;
  92. c->decorrelate[2] = flac_decorrelate_rs_c_32p;
  93. c->decorrelate[3] = flac_decorrelate_ms_c_32p;
  94. break;
  95. case AV_SAMPLE_FMT_S16:
  96. c->decorrelate[0] = flac_decorrelate_indep_c_16;
  97. c->decorrelate[1] = flac_decorrelate_ls_c_16;
  98. c->decorrelate[2] = flac_decorrelate_rs_c_16;
  99. c->decorrelate[3] = flac_decorrelate_ms_c_16;
  100. break;
  101. case AV_SAMPLE_FMT_S16P:
  102. c->decorrelate[0] = flac_decorrelate_indep_c_16p;
  103. c->decorrelate[1] = flac_decorrelate_ls_c_16p;
  104. c->decorrelate[2] = flac_decorrelate_rs_c_16p;
  105. c->decorrelate[3] = flac_decorrelate_ms_c_16p;
  106. break;
  107. }
  108. }