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.

104 lines
2.8KB

  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 <stdint.h>
  21. #include "libavutil/avutil.h"
  22. #undef FUNC
  23. #undef FSUF
  24. #undef sample
  25. #undef sample_type
  26. #undef OUT
  27. #undef S
  28. #if SAMPLE_SIZE == 32
  29. # define sample_type int32_t
  30. #else
  31. # define sample_type int16_t
  32. #endif
  33. #if PLANAR
  34. # define FSUF AV_JOIN(SAMPLE_SIZE, p)
  35. # define sample sample_type *
  36. # define OUT(n) n
  37. # define S(s, c, i) (s[c][i])
  38. #else
  39. # define FSUF SAMPLE_SIZE
  40. # define sample sample_type
  41. # define OUT(n) n[0]
  42. # define S(s, c, i) (*s++)
  43. #endif
  44. #define FUNC(n) AV_JOIN(n ## _, FSUF)
  45. static void FUNC(flac_decorrelate_indep_c)(uint8_t **out, int32_t **in,
  46. int channels, int len, int shift)
  47. {
  48. sample *samples = (sample *) OUT(out);
  49. int i, j;
  50. for (j = 0; j < len; j++)
  51. for (i = 0; i < channels; i++)
  52. S(samples, i, j) = in[i][j] << shift;
  53. }
  54. static void FUNC(flac_decorrelate_ls_c)(uint8_t **out, int32_t **in,
  55. int channels, int len, int shift)
  56. {
  57. sample *samples = (sample *) OUT(out);
  58. int i;
  59. for (i = 0; i < len; i++) {
  60. int a = in[0][i];
  61. int b = in[1][i];
  62. S(samples, 0, i) = a << shift;
  63. S(samples, 1, i) = (a - b) << shift;
  64. }
  65. }
  66. static void FUNC(flac_decorrelate_rs_c)(uint8_t **out, int32_t **in,
  67. int channels, int len, int shift)
  68. {
  69. sample *samples = (sample *) OUT(out);
  70. int i;
  71. for (i = 0; i < len; i++) {
  72. int a = in[0][i];
  73. int b = in[1][i];
  74. S(samples, 0, i) = (a + b) << shift;
  75. S(samples, 1, i) = b << shift;
  76. }
  77. }
  78. static void FUNC(flac_decorrelate_ms_c)(uint8_t **out, int32_t **in,
  79. int channels, int len, int shift)
  80. {
  81. sample *samples = (sample *) OUT(out);
  82. int i;
  83. for (i = 0; i < len; i++) {
  84. int a = in[0][i];
  85. int b = in[1][i];
  86. a -= b >> 1;
  87. S(samples, 0, i) = (a + b) << shift;
  88. S(samples, 1, i) = a << shift;
  89. }
  90. }