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.

116 lines
2.9KB

  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  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. /**
  21. * @file
  22. * mpeg audio declarations for both encoder and decoder.
  23. */
  24. #ifndef AVCODEC_MPEGAUDIO_H
  25. #define AVCODEC_MPEGAUDIO_H
  26. #ifndef CONFIG_FLOAT
  27. # define CONFIG_FLOAT 0
  28. #endif
  29. #include "avcodec.h"
  30. /* max frame size, in samples */
  31. #define MPA_FRAME_SIZE 1152
  32. /* max compressed frame size */
  33. #define MPA_MAX_CODED_FRAME_SIZE 1792
  34. #define MPA_MAX_CHANNELS 2
  35. #define SBLIMIT 32 /* number of subbands */
  36. #define MPA_STEREO 0
  37. #define MPA_JSTEREO 1
  38. #define MPA_DUAL 2
  39. #define MPA_MONO 3
  40. /* header + layer + bitrate + freq + lsf/mpeg25 */
  41. #define SAME_HEADER_MASK \
  42. (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
  43. #define MP3_MASK 0xFFFE0CCF
  44. #ifndef FRAC_BITS
  45. #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
  46. #define WFRAC_BITS 16 /* fractional bits for window */
  47. #endif
  48. #define FRAC_ONE (1 << FRAC_BITS)
  49. #define FIX(a) ((int)((a) * FRAC_ONE))
  50. #if CONFIG_FLOAT
  51. # define INTFLOAT float
  52. typedef float MPA_INT;
  53. typedef float OUT_INT;
  54. #elif FRAC_BITS <= 15
  55. # define INTFLOAT int
  56. typedef int16_t MPA_INT;
  57. typedef int16_t OUT_INT;
  58. #else
  59. # define INTFLOAT int
  60. typedef int32_t MPA_INT;
  61. typedef int16_t OUT_INT;
  62. #endif
  63. #define MPA_DECODE_HEADER \
  64. int frame_size; \
  65. int error_protection; \
  66. int layer; \
  67. int sample_rate; \
  68. int sample_rate_index; /* between 0 and 8 */ \
  69. int bit_rate; \
  70. int nb_channels; \
  71. int mode; \
  72. int mode_ext; \
  73. int lsf;
  74. typedef struct MPADecodeHeader {
  75. MPA_DECODE_HEADER
  76. } MPADecodeHeader;
  77. int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
  78. int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
  79. /* fast header check for resync */
  80. static inline int ff_mpa_check_header(uint32_t header){
  81. /* header */
  82. if ((header & 0xffe00000) != 0xffe00000)
  83. return -1;
  84. /* layer check */
  85. if ((header & (3<<17)) == 0)
  86. return -1;
  87. /* bit rate */
  88. if ((header & (0xf<<12)) == 0xf<<12)
  89. return -1;
  90. /* frequency */
  91. if ((header & (3<<10)) == 3<<10)
  92. return -1;
  93. return 0;
  94. }
  95. #endif /* AVCODEC_MPEGAUDIO_H */