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.

164 lines
6.8KB

  1. /*
  2. * Float MPEG Audio decoder
  3. * Copyright (c) 2010 Michael Niedermayer
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "config.h"
  22. #include "libavutil/samplefmt.h"
  23. #define USE_FLOATS 1
  24. #include "mpegaudio.h"
  25. #define SHR(a,b) ((a)*(1.0f/(1<<(b))))
  26. #define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
  27. #define FIXR(x) ((float)(x))
  28. #define FIXHR(x) ((float)(x))
  29. #define MULH3(x, y, s) ((s)*(y)*(x))
  30. #define MULLx(x, y, s) ((y)*(x))
  31. #define RENAME(a) a ## _float
  32. #define OUT_FMT AV_SAMPLE_FMT_FLT
  33. #define OUT_FMT_P AV_SAMPLE_FMT_FLTP
  34. /* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
  35. * (float based mp1/mp2/mp3 decoders.) for how they were created. */
  36. static const float is_table[2][16] = {
  37. { 0.000000000000000000e+00, 2.113248705863952637e-01, 3.660253882408142090e-01,
  38. 5.000000000000000000e-01, 6.339746117591857910e-01, 7.886751294136047363e-01,
  39. 1.000000000000000000e+00 },
  40. { 1.000000000000000000e+00, 7.886751294136047363e-01, 6.339746117591857910e-01,
  41. 5.000000000000000000e-01, 3.660253882408142090e-01, 2.113248705863952637e-01,
  42. 0.000000000000000000e+00 }
  43. };
  44. /* Antialiasing table. See commit 6f1ec38ce2193d3d4cacd87edb452c6d7ba751ec
  45. * (mpegaudio: clean up compute_antialias() definition) for how they were
  46. * created. */
  47. static const float csa_table[8][4] = {
  48. { 8.574929237365722656e-01, -5.144957900047302246e-01,
  49. 3.429971337318420410e-01, -1.371988654136657715e+00 },
  50. { 8.817420005798339844e-01, -4.717319905757904053e-01,
  51. 4.100100100040435791e-01, -1.353474020957946777e+00 },
  52. { 9.496286511421203613e-01, -3.133774697780609131e-01,
  53. 6.362511515617370605e-01, -1.263006091117858887e+00 },
  54. { 9.833145737648010254e-01, -1.819131970405578613e-01,
  55. 8.014013767242431641e-01, -1.165227770805358887e+00 },
  56. { 9.955177903175354004e-01, -9.457419067621231079e-02,
  57. 9.009436368942260742e-01, -1.090092062950134277e+00 },
  58. { 9.991605877876281738e-01, -4.096558317542076111e-02,
  59. 9.581949710845947266e-01, -1.040126085281372070e+00 },
  60. { 9.998992085456848145e-01, -1.419856864959001541e-02,
  61. 9.857006072998046875e-01, -1.014097809791564941e+00 },
  62. { 9.999931454658508301e-01, -3.699974622577428818e-03,
  63. 9.962931871414184570e-01, -1.003693103790283203e+00 }
  64. };
  65. #include "mpegaudiodec_template.c"
  66. #if CONFIG_MP1FLOAT_DECODER
  67. AVCodec ff_mp1float_decoder = {
  68. .name = "mp1float",
  69. .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
  70. .type = AVMEDIA_TYPE_AUDIO,
  71. .id = AV_CODEC_ID_MP1,
  72. .priv_data_size = sizeof(MPADecodeContext),
  73. .init = decode_init,
  74. .decode = decode_frame,
  75. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  76. AV_CODEC_CAP_DR1,
  77. .flush = flush,
  78. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
  79. AV_SAMPLE_FMT_FLT,
  80. AV_SAMPLE_FMT_NONE },
  81. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  82. };
  83. #endif
  84. #if CONFIG_MP2FLOAT_DECODER
  85. AVCodec ff_mp2float_decoder = {
  86. .name = "mp2float",
  87. .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
  88. .type = AVMEDIA_TYPE_AUDIO,
  89. .id = AV_CODEC_ID_MP2,
  90. .priv_data_size = sizeof(MPADecodeContext),
  91. .init = decode_init,
  92. .decode = decode_frame,
  93. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  94. AV_CODEC_CAP_DR1,
  95. .flush = flush,
  96. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
  97. AV_SAMPLE_FMT_FLT,
  98. AV_SAMPLE_FMT_NONE },
  99. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  100. };
  101. #endif
  102. #if CONFIG_MP3FLOAT_DECODER
  103. AVCodec ff_mp3float_decoder = {
  104. .name = "mp3float",
  105. .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
  106. .type = AVMEDIA_TYPE_AUDIO,
  107. .id = AV_CODEC_ID_MP3,
  108. .priv_data_size = sizeof(MPADecodeContext),
  109. .init = decode_init,
  110. .decode = decode_frame,
  111. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  112. AV_CODEC_CAP_DR1,
  113. .flush = flush,
  114. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
  115. AV_SAMPLE_FMT_FLT,
  116. AV_SAMPLE_FMT_NONE },
  117. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  118. };
  119. #endif
  120. #if CONFIG_MP3ADUFLOAT_DECODER
  121. AVCodec ff_mp3adufloat_decoder = {
  122. .name = "mp3adufloat",
  123. .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
  124. .type = AVMEDIA_TYPE_AUDIO,
  125. .id = AV_CODEC_ID_MP3ADU,
  126. .priv_data_size = sizeof(MPADecodeContext),
  127. .init = decode_init,
  128. .decode = decode_frame_adu,
  129. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  130. AV_CODEC_CAP_DR1,
  131. .flush = flush,
  132. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
  133. AV_SAMPLE_FMT_FLT,
  134. AV_SAMPLE_FMT_NONE },
  135. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  136. };
  137. #endif
  138. #if CONFIG_MP3ON4FLOAT_DECODER
  139. AVCodec ff_mp3on4float_decoder = {
  140. .name = "mp3on4float",
  141. .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
  142. .type = AVMEDIA_TYPE_AUDIO,
  143. .id = AV_CODEC_ID_MP3ON4,
  144. .priv_data_size = sizeof(MP3On4DecodeContext),
  145. .init = decode_init_mp3on4,
  146. .close = decode_close_mp3on4,
  147. .decode = decode_frame_mp3on4,
  148. .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
  149. AV_CODEC_CAP_DR1,
  150. .flush = flush_mp3on4,
  151. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
  152. AV_SAMPLE_FMT_NONE },
  153. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  154. };
  155. #endif