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.

74 lines
2.2KB

  1. /*
  2. * DCA compatible decoder data
  3. * Copyright (C) 2004 Gildas Bazin
  4. * Copyright (C) 2004 Benjamin Zores
  5. * Copyright (C) 2006 Benjamin Larsson
  6. * Copyright (C) 2007 Konstantin Shishkov
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <stdint.h>
  25. #include <string.h>
  26. #include "libavutil/error.h"
  27. #include "dca.h"
  28. #include "dca_syncwords.h"
  29. #include "put_bits.h"
  30. const uint32_t avpriv_dca_sample_rates[16] = {
  31. 0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
  32. 12000, 24000, 48000, 96000, 192000
  33. };
  34. int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
  35. int max_size)
  36. {
  37. uint32_t mrk;
  38. int i, tmp;
  39. PutBitContext pb;
  40. if ((unsigned) src_size > (unsigned) max_size)
  41. src_size = max_size;
  42. mrk = AV_RB32(src);
  43. switch (mrk) {
  44. case DCA_SYNCWORD_CORE_BE:
  45. memcpy(dst, src, src_size);
  46. return src_size;
  47. case DCA_SYNCWORD_CORE_LE:
  48. for (i = 0; i < (src_size + 1) >> 1; i++) {
  49. AV_WB16(dst, AV_RL16(src));
  50. src += 2;
  51. dst += 2;
  52. }
  53. return src_size;
  54. case DCA_SYNCWORD_CORE_14B_BE:
  55. case DCA_SYNCWORD_CORE_14B_LE:
  56. init_put_bits(&pb, dst, max_size);
  57. for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
  58. tmp = ((mrk == DCA_SYNCWORD_CORE_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
  59. put_bits(&pb, 14, tmp);
  60. }
  61. flush_put_bits(&pb);
  62. return (put_bits_count(&pb) + 7) >> 3;
  63. default:
  64. return AVERROR_INVALIDDATA;
  65. }
  66. }