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.

100 lines
2.9KB

  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  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. /**
  21. * @file mpegaudio.h
  22. * mpeg audio declarations for both encoder and decoder.
  23. */
  24. /* max frame size, in samples */
  25. #define MPA_FRAME_SIZE 1152
  26. /* max compressed frame size */
  27. #define MPA_MAX_CODED_FRAME_SIZE 1792
  28. #define MPA_MAX_CHANNELS 2
  29. #define SBLIMIT 32 /* number of subbands */
  30. #define MPA_STEREO 0
  31. #define MPA_JSTEREO 1
  32. #define MPA_DUAL 2
  33. #define MPA_MONO 3
  34. /* header + layer + bitrate + freq + lsf/mpeg25 */
  35. #define SAME_HEADER_MASK \
  36. (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
  37. #define MP3_MASK 0xFFFE0CCF
  38. /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
  39. audio decoder */
  40. #ifdef USE_HIGHPRECISION
  41. #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
  42. #define WFRAC_BITS 16 /* fractional bits for window */
  43. #else
  44. #define FRAC_BITS 15 /* fractional bits for sb_samples and dct */
  45. #define WFRAC_BITS 14 /* fractional bits for window */
  46. #endif
  47. #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
  48. typedef int32_t OUT_INT;
  49. #define OUT_MAX INT32_MAX
  50. #define OUT_MIN INT32_MIN
  51. #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
  52. #else
  53. typedef int16_t OUT_INT;
  54. #define OUT_MAX INT16_MAX
  55. #define OUT_MIN INT16_MIN
  56. #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
  57. #endif
  58. #if FRAC_BITS <= 15
  59. typedef int16_t MPA_INT;
  60. #else
  61. typedef int32_t MPA_INT;
  62. #endif
  63. int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
  64. int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
  65. void ff_mpa_synth_init(MPA_INT *window);
  66. void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
  67. MPA_INT *window, int *dither_state,
  68. OUT_INT *samples, int incr,
  69. int32_t sb_samples[SBLIMIT]);
  70. /* fast header check for resync */
  71. static inline int ff_mpa_check_header(uint32_t header){
  72. /* header */
  73. if ((header & 0xffe00000) != 0xffe00000)
  74. return -1;
  75. /* layer check */
  76. if ((header & (3<<17)) == 0)
  77. return -1;
  78. /* bit rate */
  79. if ((header & (0xf<<12)) == 0xf<<12)
  80. return -1;
  81. /* frequency */
  82. if ((header & (3<<10)) == 3<<10)
  83. return -1;
  84. return 0;
  85. }