mp3dec.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. * mp3dec.h - public C API for MP3 decoder
  41. **************************************************************************************/
  42. #include <stdint.h>
  43. #define Word64 uint64_t
  44. #ifdef ESP8266
  45. # include "pgmspace.h"
  46. #elif defined(ESP_PLATFORM) && __has_include(<pgm_space.h>)
  47. # include <pgm_space.h>
  48. #else
  49. # define PROGMEM
  50. # define pgm_read_byte(addr) (*(const unsigned char *)(addr))
  51. # define pgm_read_word(addr) (*(const unsigned short *)(addr))
  52. #endif
  53. #ifndef _MP3DEC_H
  54. #define _MP3DEC_H
  55. #if defined(_WIN32) && !defined(_WIN32_WCE)
  56. #
  57. #elif defined(_WIN32) && defined(WINCE_EMULATOR)
  58. #
  59. #elif defined(ARM_ADS)
  60. #
  61. #elif defined(__APPLE__)
  62. #
  63. #elif defined(_SYMBIAN) && defined(__WINS__) /* Symbian emulator for Ix86 */
  64. #
  65. #elif defined(__GNUC__) && defined(__thumb__)
  66. #
  67. #elif defined(__GNUC__) && defined(__i386__)
  68. #
  69. #elif defined(__amd64__)
  70. #
  71. #elif defined(_OPENWAVE_SIMULATOR) || defined(_OPENWAVE_ARMULATOR)
  72. #
  73. #elif defined (ESP_PLATFORM)
  74. #
  75. #else
  76. #error No platform defined. See valid options in mp3dec.h
  77. #endif
  78. #ifdef __cplusplus
  79. extern "C" {
  80. #endif
  81. /* determining MAINBUF_SIZE:
  82. * max mainDataBegin = (2^9 - 1) bytes (since 9-bit offset) = 511
  83. * max nSlots (concatenated with mainDataBegin bytes from before) = 1440 - 9 - 4 + 1 = 1428
  84. * 511 + 1428 = 1939, round up to 1940 (4-byte align)
  85. */
  86. #define MAINBUF_SIZE 1940
  87. #define MAX_NGRAN 2 /* max granules */
  88. #define MAX_NCHAN 2 /* max channels */
  89. #define MAX_NSAMP 576 /* max samples per channel, per granule */
  90. /* map to 0,1,2 to make table indexing easier */
  91. typedef enum {
  92. MPEG1 = 0,
  93. MPEG2 = 1,
  94. MPEG25 = 2
  95. } MPEGVersion;
  96. typedef void *HMP3Decoder;
  97. enum {
  98. ERR_MP3_NONE = 0,
  99. ERR_MP3_INDATA_UNDERFLOW = -1,
  100. ERR_MP3_MAINDATA_UNDERFLOW = -2,
  101. ERR_MP3_FREE_BITRATE_SYNC = -3,
  102. ERR_MP3_OUT_OF_MEMORY = -4,
  103. ERR_MP3_NULL_POINTER = -5,
  104. ERR_MP3_INVALID_FRAMEHEADER = -6,
  105. ERR_MP3_INVALID_SIDEINFO = -7,
  106. ERR_MP3_INVALID_SCALEFACT = -8,
  107. ERR_MP3_INVALID_HUFFCODES = -9,
  108. ERR_MP3_INVALID_DEQUANTIZE = -10,
  109. ERR_MP3_INVALID_IMDCT = -11,
  110. ERR_MP3_INVALID_SUBBAND = -12,
  111. ERR_UNKNOWN = -9999
  112. };
  113. typedef struct _MP3FrameInfo {
  114. int bitrate;
  115. int nChans;
  116. int samprate;
  117. int bitsPerSample;
  118. int outputSamps;
  119. int layer;
  120. int version;
  121. } MP3FrameInfo;
  122. /* public API */
  123. HMP3Decoder MP3InitDecoder(void);
  124. void MP3FreeDecoder(HMP3Decoder hMP3Decoder);
  125. int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, short *outbuf, int useSize);
  126. void MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo);
  127. int MP3GetNextFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo, unsigned char *buf);
  128. int MP3FindSyncWord(unsigned char *buf, int nBytes);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif /* _MP3DEC_H */