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.

151 lines
6.0KB

  1. /*
  2. * Fixed-point MPEG audio decoder
  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. #include "config.h"
  21. #include "libavutil/samplefmt.h"
  22. #define USE_FLOATS 0
  23. #include "mpegaudio.h"
  24. #define SHR(a,b) (((int)(a))>>(b))
  25. /* WARNING: only correct for positive numbers */
  26. #define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
  27. #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
  28. #define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
  29. #define MULH3(x, y, s) MULH((s)*(x), y)
  30. #define MULLx(x, y, s) MULL((int)(x),(y),s)
  31. #define RENAME(a) a ## _fixed
  32. #define OUT_FMT AV_SAMPLE_FMT_S16
  33. #define OUT_FMT_P AV_SAMPLE_FMT_S16P
  34. /* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
  35. * (float based mp1/mp2/mp3 decoders.) for how they were created. */
  36. static const int32_t is_table[2][16] = {
  37. { 0x000000, 0x1B0CB1, 0x2ED9EC, 0x400000, 0x512614, 0x64F34F, 0x800000 },
  38. { 0x800000, 0x64F34F, 0x512614, 0x400000, 0x2ED9EC, 0x1B0CB1, 0x000000 }
  39. };
  40. /* Antialiasing table. See commit ce4a29c066cddfc180979ed86396812f24337985
  41. * (optimize antialias) for how they were created. */
  42. static const int32_t csa_table[8][4] = {
  43. { 0x36E129F8, 0xDF128056, 0x15F3AA4E, 0xA831565E },
  44. { 0x386E75F2, 0xE1CF24A5, 0x1A3D9A97, 0xA960AEB3 },
  45. { 0x3CC6B73A, 0xEBF19FA6, 0x28B856E0, 0xAF2AE86C },
  46. { 0x3EEEA054, 0xF45B88BC, 0x334A2910, 0xB56CE868 },
  47. { 0x3FB6905C, 0xF9F27F18, 0x39A90F74, 0xBA3BEEBC },
  48. { 0x3FF23F20, 0xFD60D1E4, 0x3D531104, 0xBD6E92C4 },
  49. { 0x3FFE5932, 0xFF175EE4, 0x3F15B816, 0xBF1905B2 },
  50. { 0x3FFFE34A, 0xFFC3612F, 0x3FC34479, 0xBFC37DE5 }
  51. };
  52. #include "mpegaudiodec_template.c"
  53. #if CONFIG_MP1_DECODER
  54. AVCodec ff_mp1_decoder = {
  55. .name = "mp1",
  56. .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
  57. .type = AVMEDIA_TYPE_AUDIO,
  58. .id = AV_CODEC_ID_MP1,
  59. .priv_data_size = sizeof(MPADecodeContext),
  60. .init = decode_init,
  61. .decode = decode_frame,
  62. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  63. AV_CODEC_CAP_DR1,
  64. .flush = flush,
  65. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
  66. AV_SAMPLE_FMT_S16,
  67. AV_SAMPLE_FMT_NONE },
  68. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  69. };
  70. #endif
  71. #if CONFIG_MP2_DECODER
  72. AVCodec ff_mp2_decoder = {
  73. .name = "mp2",
  74. .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
  75. .type = AVMEDIA_TYPE_AUDIO,
  76. .id = AV_CODEC_ID_MP2,
  77. .priv_data_size = sizeof(MPADecodeContext),
  78. .init = decode_init,
  79. .decode = decode_frame,
  80. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  81. AV_CODEC_CAP_DR1,
  82. .flush = flush,
  83. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
  84. AV_SAMPLE_FMT_S16,
  85. AV_SAMPLE_FMT_NONE },
  86. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  87. };
  88. #endif
  89. #if CONFIG_MP3_DECODER
  90. AVCodec ff_mp3_decoder = {
  91. .name = "mp3",
  92. .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
  93. .type = AVMEDIA_TYPE_AUDIO,
  94. .id = AV_CODEC_ID_MP3,
  95. .priv_data_size = sizeof(MPADecodeContext),
  96. .init = decode_init,
  97. .decode = decode_frame,
  98. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  99. AV_CODEC_CAP_DR1,
  100. .flush = flush,
  101. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
  102. AV_SAMPLE_FMT_S16,
  103. AV_SAMPLE_FMT_NONE },
  104. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  105. };
  106. #endif
  107. #if CONFIG_MP3ADU_DECODER
  108. AVCodec ff_mp3adu_decoder = {
  109. .name = "mp3adu",
  110. .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
  111. .type = AVMEDIA_TYPE_AUDIO,
  112. .id = AV_CODEC_ID_MP3ADU,
  113. .priv_data_size = sizeof(MPADecodeContext),
  114. .init = decode_init,
  115. .decode = decode_frame_adu,
  116. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  117. AV_CODEC_CAP_DR1,
  118. .flush = flush,
  119. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
  120. AV_SAMPLE_FMT_S16,
  121. AV_SAMPLE_FMT_NONE },
  122. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  123. };
  124. #endif
  125. #if CONFIG_MP3ON4_DECODER
  126. AVCodec ff_mp3on4_decoder = {
  127. .name = "mp3on4",
  128. .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
  129. .type = AVMEDIA_TYPE_AUDIO,
  130. .id = AV_CODEC_ID_MP3ON4,
  131. .priv_data_size = sizeof(MP3On4DecodeContext),
  132. .init = decode_init_mp3on4,
  133. .close = decode_close_mp3on4,
  134. .decode = decode_frame_mp3on4,
  135. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  136. AV_CODEC_CAP_DR1,
  137. .flush = flush_mp3on4,
  138. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
  139. AV_SAMPLE_FMT_NONE },
  140. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  141. };
  142. #endif