mp3tabs.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: RCSL 1.0/RPSL 1.0
  3. *
  4. * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
  5. *
  6. * The contents of this file, and the files included with this file, are
  7. * subject to the current version of the RealNetworks Public Source License
  8. * Version 1.0 (the "RPSL") available at
  9. * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10. * the file under the RealNetworks Community Source License Version 1.0
  11. * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
  12. * in which case the RCSL will apply. You may also obtain the license terms
  13. * directly from RealNetworks. You may not use this file except in
  14. * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
  15. * applicable to this file, the RCSL. Please see the applicable RPSL or
  16. * RCSL for the rights, obligations and limitations governing use of the
  17. * contents of the file.
  18. *
  19. * This file is part of the Helix DNA Technology. RealNetworks is the
  20. * developer of the Original Code and owns the copyrights in the portions
  21. * it created.
  22. *
  23. * This file, and the files included with this file, is distributed and made
  24. * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  25. * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  26. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
  27. * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  28. *
  29. * Technology Compatibility Kit Test Suite(s) Location:
  30. * http://www.helixcommunity.org/content/tck
  31. *
  32. * Contributor(s):
  33. *
  34. * ***** END LICENSE BLOCK ***** */
  35. /**************************************************************************************
  36. * Fixed-point MP3 decoder
  37. * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com)
  38. * June 2003
  39. *
  40. * mp3tabs.c - platform-independent tables for MP3 decoder (global, read-only)
  41. **************************************************************************************/
  42. #include "mp3common.h"
  43. #include <pgmspace.h>
  44. /* indexing = [version][samplerate index]
  45. * sample rate of frame (Hz)
  46. */
  47. const int samplerateTab[3][3] PROGMEM = {
  48. {44100, 48000, 32000}, /* MPEG-1 */
  49. {22050, 24000, 16000}, /* MPEG-2 */
  50. {11025, 12000, 8000}, /* MPEG-2.5 */
  51. };
  52. /* indexing = [version][layer][bitrate index]
  53. * bitrate (kbps) of frame
  54. * - bitrate index == 0 is "free" mode (bitrate determined on the fly by
  55. * counting bits between successive sync words)
  56. */
  57. const int/*short*/ bitrateTab[3][3][15] PROGMEM = {
  58. {
  59. /* MPEG-1 */
  60. { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448}, /* Layer 1 */
  61. { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384}, /* Layer 2 */
  62. { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320}, /* Layer 3 */
  63. },
  64. {
  65. /* MPEG-2 */
  66. { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256}, /* Layer 1 */
  67. { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}, /* Layer 2 */
  68. { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}, /* Layer 3 */
  69. },
  70. {
  71. /* MPEG-2.5 */
  72. { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256}, /* Layer 1 */
  73. { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}, /* Layer 2 */
  74. { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}, /* Layer 3 */
  75. },
  76. };
  77. /* indexing = [version][layer]
  78. * number of samples in one frame (per channel)
  79. */
  80. const int/*short*/ samplesPerFrameTab[3][3] PROGMEM = {
  81. {384, 1152, 1152 }, /* MPEG1 */
  82. {384, 1152, 576 }, /* MPEG2 */
  83. {384, 1152, 576 }, /* MPEG2.5 */
  84. };
  85. /* layers 1, 2, 3 */
  86. const short bitsPerSlotTab[3] = {32, 8, 8};
  87. /* indexing = [version][mono/stereo]
  88. * number of bytes in side info section of bitstream
  89. */
  90. const int/*short*/ sideBytesTab[3][2] PROGMEM = {
  91. {17, 32}, /* MPEG-1: mono, stereo */
  92. { 9, 17}, /* MPEG-2: mono, stereo */
  93. { 9, 17}, /* MPEG-2.5: mono, stereo */
  94. };
  95. /* indexing = [version][sampleRate][bitRate]
  96. * for layer3, nSlots = floor(samps/frame * bitRate / sampleRate / 8)
  97. * - add one pad slot if necessary
  98. */
  99. const int/*short*/ slotTab[3][3][15] PROGMEM = {
  100. {
  101. /* MPEG-1 */
  102. { 0, 104, 130, 156, 182, 208, 261, 313, 365, 417, 522, 626, 731, 835,1044 }, /* 44 kHz */
  103. { 0, 96, 120, 144, 168, 192, 240, 288, 336, 384, 480, 576, 672, 768, 960 }, /* 48 kHz */
  104. { 0, 144, 180, 216, 252, 288, 360, 432, 504, 576, 720, 864,1008,1152,1440 }, /* 32 kHz */
  105. },
  106. {
  107. /* MPEG-2 */
  108. { 0, 26, 52, 78, 104, 130, 156, 182, 208, 261, 313, 365, 417, 470, 522 }, /* 22 kHz */
  109. { 0, 24, 48, 72, 96, 120, 144, 168, 192, 240, 288, 336, 384, 432, 480 }, /* 24 kHz */
  110. { 0, 36, 72, 108, 144, 180, 216, 252, 288, 360, 432, 504, 576, 648, 720 }, /* 16 kHz */
  111. },
  112. {
  113. /* MPEG-2.5 */
  114. { 0, 52, 104, 156, 208, 261, 313, 365, 417, 522, 626, 731, 835, 940,1044 }, /* 11 kHz */
  115. { 0, 48, 96, 144, 192, 240, 288, 336, 384, 480, 576, 672, 768, 864, 960 }, /* 12 kHz */
  116. { 0, 72, 144, 216, 288, 360, 432, 504, 576, 720, 864,1008,1152,1296,1440 }, /* 8 kHz */
  117. },
  118. };
  119. /* indexing = [version][sampleRate][long (.l) or short (.s) block]
  120. * sfBandTable[v][s].l[cb] = index of first bin in critical band cb (long blocks)
  121. * sfBandTable[v][s].s[cb] = index of first bin in critical band cb (short blocks)
  122. */
  123. const SFBandTable sfBandTable[3][3] PROGMEM = {
  124. {
  125. /* MPEG-1 (44, 48, 32 kHz) */
  126. {
  127. { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90,110,134,162,196,238,288,342,418,576 },
  128. { 0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84,106,136,192 }
  129. },
  130. {
  131. { 0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88,106,128,156,190,230,276,330,384,576 },
  132. { 0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80,100,126,192 }
  133. },
  134. {
  135. { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82,102,126,156,194,240,296,364,448,550,576 },
  136. { 0, 4, 8, 12, 16, 22, 30, 42, 58, 78,104,138,180,192 }
  137. }
  138. },
  139. {
  140. /* MPEG-2 (22, 24, 16 kHz) */
  141. {
  142. { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96,116,140,168,200,238,284,336,396,464,522,576 },
  143. { 0, 4, 8, 12, 18, 24, 32, 42, 56, 74,100,132,174,192 }
  144. },
  145. {
  146. { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96,114,136,162,194,232,278,332,394,464,540,576 },
  147. { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80,104,136,180,192 }
  148. },
  149. {
  150. { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96,116,140,168,200,238,284,336,396,464,522,576 },
  151. { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80,104,134,174,192 }
  152. },
  153. },
  154. {
  155. /* MPEG-2.5 (11, 12, 8 kHz) */
  156. {
  157. { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96,116,140,168,200,238,284,336,396,464,522,576 },
  158. { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80,104,134,174,192 }
  159. },
  160. {
  161. { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96,116,140,168,200,238,284,336,396,464,522,576 },
  162. { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80,104,134,174,192 }
  163. },
  164. {
  165. { 0, 12, 24, 36, 48, 60, 72, 88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576 },
  166. { 0, 8, 16, 24, 36, 52, 72, 96,124,160,162,164,166,192 }
  167. },
  168. },
  169. };