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.

156 lines
4.4KB

  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 FFMPEG_MPEGAUDIO_H
  25. #define FFMPEG_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. #define FRAC_ONE (1 << FRAC_BITS)
  53. #define FIX(a) ((int)((a) * FRAC_ONE))
  54. #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
  55. typedef int32_t OUT_INT;
  56. #define OUT_MAX INT32_MAX
  57. #define OUT_MIN INT32_MIN
  58. #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
  59. #else
  60. typedef int16_t OUT_INT;
  61. #define OUT_MAX INT16_MAX
  62. #define OUT_MIN INT16_MIN
  63. #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
  64. #endif
  65. #if FRAC_BITS <= 15
  66. typedef int16_t MPA_INT;
  67. #else
  68. typedef int32_t MPA_INT;
  69. #endif
  70. #define BACKSTEP_SIZE 512
  71. #define EXTRABYTES 24
  72. struct GranuleDef;
  73. typedef struct MPADecodeContext {
  74. DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
  75. int last_buf_size;
  76. int frame_size;
  77. /* next header (used in free format parsing) */
  78. uint32_t free_format_next_header;
  79. int error_protection;
  80. int layer;
  81. int sample_rate;
  82. int sample_rate_index; /* between 0 and 8 */
  83. int bit_rate;
  84. GetBitContext gb;
  85. GetBitContext in_gb;
  86. int nb_channels;
  87. int mode;
  88. int mode_ext;
  89. int lsf;
  90. DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
  91. int synth_buf_offset[MPA_MAX_CHANNELS];
  92. DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
  93. int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
  94. #ifdef DEBUG
  95. int frame_count;
  96. #endif
  97. void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
  98. int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
  99. int dither_state;
  100. int error_resilience;
  101. AVCodecContext* avctx;
  102. } MPADecodeContext;
  103. /* layer 3 huffman tables */
  104. typedef struct HuffTable {
  105. int xsize;
  106. const uint8_t *bits;
  107. const uint16_t *codes;
  108. } HuffTable;
  109. int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
  110. int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
  111. void ff_mpa_synth_init(MPA_INT *window);
  112. void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
  113. MPA_INT *window, int *dither_state,
  114. OUT_INT *samples, int incr,
  115. int32_t sb_samples[SBLIMIT]);
  116. /* fast header check for resync */
  117. static inline int ff_mpa_check_header(uint32_t header){
  118. /* header */
  119. if ((header & 0xffe00000) != 0xffe00000)
  120. return -1;
  121. /* layer check */
  122. if ((header & (3<<17)) == 0)
  123. return -1;
  124. /* bit rate */
  125. if ((header & (0xf<<12)) == 0xf<<12)
  126. return -1;
  127. /* frequency */
  128. if ((header & (3<<10)) == 3<<10)
  129. return -1;
  130. return 0;
  131. }
  132. #endif /* FFMPEG_MPEGAUDIO_H */