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.

145 lines
4.2KB

  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. #ifndef MPEGAUDIO_H
  25. #define MPEGAUDIO_H
  26. #include "avcodec.h"
  27. #include "bitstream.h"
  28. #include "dsputil.h"
  29. /* max frame size, in samples */
  30. #define MPA_FRAME_SIZE 1152
  31. /* max compressed frame size */
  32. #define MPA_MAX_CODED_FRAME_SIZE 1792
  33. #define MPA_MAX_CHANNELS 2
  34. #define SBLIMIT 32 /* number of subbands */
  35. #define MPA_STEREO 0
  36. #define MPA_JSTEREO 1
  37. #define MPA_DUAL 2
  38. #define MPA_MONO 3
  39. /* header + layer + bitrate + freq + lsf/mpeg25 */
  40. #define SAME_HEADER_MASK \
  41. (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
  42. #define MP3_MASK 0xFFFE0CCF
  43. /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
  44. audio decoder */
  45. #ifdef USE_HIGHPRECISION
  46. #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
  47. #define WFRAC_BITS 16 /* fractional bits for window */
  48. #else
  49. #define FRAC_BITS 15 /* fractional bits for sb_samples and dct */
  50. #define WFRAC_BITS 14 /* fractional bits for window */
  51. #endif
  52. #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
  53. typedef int32_t OUT_INT;
  54. #define OUT_MAX INT32_MAX
  55. #define OUT_MIN INT32_MIN
  56. #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
  57. #else
  58. typedef int16_t OUT_INT;
  59. #define OUT_MAX INT16_MAX
  60. #define OUT_MIN INT16_MIN
  61. #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
  62. #endif
  63. #if FRAC_BITS <= 15
  64. typedef int16_t MPA_INT;
  65. #else
  66. typedef int32_t MPA_INT;
  67. #endif
  68. #define BACKSTEP_SIZE 512
  69. #define EXTRABYTES 24
  70. struct GranuleDef;
  71. typedef struct MPADecodeContext {
  72. DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
  73. int last_buf_size;
  74. int frame_size;
  75. /* next header (used in free format parsing) */
  76. uint32_t free_format_next_header;
  77. int error_protection;
  78. int layer;
  79. int sample_rate;
  80. int sample_rate_index; /* between 0 and 8 */
  81. int bit_rate;
  82. GetBitContext gb;
  83. GetBitContext in_gb;
  84. int nb_channels;
  85. int mode;
  86. int mode_ext;
  87. int lsf;
  88. DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
  89. int synth_buf_offset[MPA_MAX_CHANNELS];
  90. DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
  91. int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
  92. #ifdef DEBUG
  93. int frame_count;
  94. #endif
  95. void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
  96. int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
  97. int dither_state;
  98. int error_resilience;
  99. AVCodecContext* avctx;
  100. } MPADecodeContext;
  101. int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
  102. int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
  103. void ff_mpa_synth_init(MPA_INT *window);
  104. void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
  105. MPA_INT *window, int *dither_state,
  106. OUT_INT *samples, int incr,
  107. int32_t sb_samples[SBLIMIT]);
  108. /* fast header check for resync */
  109. static inline int ff_mpa_check_header(uint32_t header){
  110. /* header */
  111. if ((header & 0xffe00000) != 0xffe00000)
  112. return -1;
  113. /* layer check */
  114. if ((header & (3<<17)) == 0)
  115. return -1;
  116. /* bit rate */
  117. if ((header & (0xf<<12)) == 0xf<<12)
  118. return -1;
  119. /* frequency */
  120. if ((header & (3<<10)) == 3<<10)
  121. return -1;
  122. return 0;
  123. }
  124. #endif /* MPEGAUDIO_H */