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.

152 lines
6.4KB

  1. #ifndef _mpeg4_aac_h_
  2. #define _mpeg4_aac_h_
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #if defined(__cplusplus)
  6. extern "C" {
  7. #endif
  8. struct mpeg4_aac_t
  9. {
  10. uint8_t profile; // 0-NULL, 1-AAC Main, 2-AAC LC, 2-AAC SSR, 3-AAC LTP
  11. uint8_t sampling_frequency_index; // 0-96000, 1-88200, 2-64000, 3-48000, 4-44100, 5-32000, 6-24000, 7-22050, 8-16000, 9-12000, 10-11025, 11-8000, 12-7350, 13/14-reserved, 15-frequency is written explictly
  12. uint8_t channel_configuration; // 0-AOT, 1-1channel,front-center, 2-2channels, front-left/right, 3-3channels: front center/left/right, 4-4channels: front-center/left/right, back-center, 5-5channels: front center/left/right, back-left/right, 6-6channels: front center/left/right, back left/right LFE-channel, 7-8channels
  13. uint32_t extension_frequency; // play frequency(AAC-HE v1/v2 sbr/ps)
  14. uint32_t sampling_frequency; // codec frequency, valid only in decode
  15. uint8_t channels; // valid only in decode
  16. int sbr; // sbr flag, valid only in decode
  17. int ps; // ps flag, valid only in decode
  18. uint8_t pce[64];
  19. int npce; // pce bytes
  20. };
  21. enum mpeg2_aac_profile
  22. {
  23. MPEG2_AAC_MAIN = 0,
  24. MPEG2_AAC_LC,
  25. MPEG2_AAC_SSR,
  26. };
  27. // ISO/IEC 14496-3:2009(E) Table 1.3 - Audio Profiles definition (p41)
  28. // https://en.wikipedia.org/wiki/MPEG-4_Part_3#Audio_Profiles
  29. enum mpeg4_aac_object_type
  30. {
  31. MPEG4_AAC_MAIN = 1,
  32. MPEG4_AAC_LC,
  33. MPEG4_AAC_SSR,
  34. MPEG4_AAC_LTP,
  35. MPEG4_AAC_SBR, // (used with AAC LC in the "High Efficiency AAC Profile" (HE-AAC v1))
  36. MPEG4_AAC_SCALABLE,
  37. MPEG4_AAC_TWINVQ,
  38. MPEG4_AAC_CELP,
  39. MPEG4_AAC_HVXC,
  40. MPEG4_AAC_TTSI = 12,
  41. MPEG4_AAC_MAIN_SYNTHETIC,
  42. MPEG4_AAC_WAVETABLE_SYNTHETIC,
  43. MPEG4_AAC_GENERAL_MIDI,
  44. MPEG4_AAC_ALGORITHMIC_SYNTHESIS, // Algorithmic Synthesis and Audio FX object type
  45. MPEG4_AAC_ER_LC, // Error Resilient (ER) AAC Low Complexity (LC) object type
  46. MPEG4_AAC_ER_LTP = 19, // Error Resilient (ER) AAC Long Term Predictor (LTP) object type
  47. MPEG4_AAC_ER_SCALABLE, // Error Resilient (ER) AAC scalable object type
  48. MPEG4_AAC_ER_TWINVQ, // Error Resilient (ER) TwinVQ object type
  49. MPEG4_AAC_ER_BSAC, // Error Resilient (ER) BSAC object type
  50. MPEG4_AAC_ER_AAC_LD, // Error Resilient (ER) AAC LD object type(used with CELP, ER CELP, HVXC, ER HVXC and TTSI in the "Low Delay Profile")
  51. MPEG4_AAC_ER_CELP, // Error Resilient (ER) CELP object type
  52. MPEG4_AAC_ER_HVXC, // Error Resilient (ER) HVXC object type
  53. MPEG4_AAC_ER_HILN, // Error Resilient (ER) HILN object type
  54. MPEG4_AAC_ER_PARAMTRIC, // Error Resilient (ER) Parametric object type
  55. MPEG4_AAC_SSC, // SSC Audio object type
  56. MPEG4_AAC_PS, // PS object type(used with AAC LC and SBR in the "HE-AAC v2 Profile")
  57. MPEG4_AAC_MPEG_SURROUND, // MPEG Surround object type
  58. MPEG4_AAC_LAYER_1 = 32, // Layer-1 Audio object type
  59. MPEG4_AAC_LAYER_2, // Layer-2 Audio object type
  60. MPEG4_AAC_LAYER_3, // Layer-3 Audio object type
  61. MPEG4_AAC_DST,
  62. MPEG4_AAC_ALS, // ALS Audio object type
  63. MPEG4_AAC_SLS, // SLS Audio object type
  64. MPEG4_AAC_SLS_NON_CORE, // SLS Non-Core Audio object type
  65. MPEG4_AAC_ER_AAC_ELD, // Error Resilient (ER) AAC ELD object type (uses AAC-LD, AAC-ELD and AAC-ELDv2, "Low Delay AAC v2")
  66. MPEG4_AAC_SMR_SIMPLE, // SMR Simple object type: MPEG-4 Part 23 standard (ISO/IEC 14496-23:2008)
  67. MPEG4_AAC_SMR_MAIN, // SMR Main object type
  68. MPEG4_AAC_USAC_NO_SBR, // Unified Speech and Audio Coding (no SBR)
  69. MPEG4_AAC_SAOC, // Spatial Audio Object Coding: MPEG-D Part 2 standard (ISO/IEC 23003-2:2010)
  70. MPEG4_AAC_LD_MEPG_SURROUND, // MPEG-D Part 2 - ISO/IEC 23003-2
  71. MPEG4_AAC_USAC, // MPEG-D Part 3 - ISO/IEC 23003-3
  72. };
  73. enum mpeg4_audio_profile
  74. {
  75. MPEG4_AAC_PROFILE, // AAC LC
  76. MPEG4_HIGH_EFFICIENCY_AAC_PROFILE, // AAC LC, SBR (<=128 kbps)
  77. MPEG4_HE_AAC_V2_PROFILE, // AAC LC, SBR, PS (approx. 16 - 48 kbit/s)
  78. MPEG4_MAIN_AUDIO_PROFILE, // AAC Main, AAC LC, AAC SSR, AAC LTP, AAC Scalable, TwinVQ, CELP, HVXC, TTSI, Main synthesis
  79. MPEG4_SCALABLE_AUDIO_PROFILE, // AAC LC, AAC LTP, AAC Scalable, TwinVQ, CELP, HVXC, TTSI
  80. MPEG4_SPEECH_AUDIO_PROFILE, // CELP, HVXC, TTSI
  81. MPEG4_SYNTHETIC_AUDIO_PRIFILE, // TTSI, Main synthesis
  82. MPEG4_HIGH_QUALITY_AUDIO_PROFILE, // AAC LC, AAC LTP, AAC Scalable, CELP, ER AAC LC, ER AAC LTP, ER AAC Scalable, ER CELP
  83. MPEG4_LOW_DELAY_AUDIO_PROFILE, // CELP, HVXC, TTSI, ER AAC LD, ER CELP, ER HVXC
  84. MPEG4_NATURAL_AUDIO_PRIFILE, // AAC Main, AAC LC, AAC SSR, AAC LTP, AAC Scalable, TwinVQ, CELP, HVXC, TTSI, ER AAC LC, ER AAC LTP, ER AAC Scalable, ER TwinVQ, ER BSAC, ER AAC LD, ER CELP, ER HVXC, ER HILN, ER Parametric
  85. MPEG4_MOBILE_AUDIO_INTERNETWORKING_PROFILE, // ER AAC LC, ER AAC Scalable, ER TwinVQ, ER BSAC, ER AAC LD
  86. MPEG4_HD_AAC_PROFILE, // AAC LC, SLS
  87. MPEG4_ALS_SIMPLE_PROFILE, // ALS
  88. };
  89. enum mpeg4_aac_frequency
  90. {
  91. MPEG4_AAC_96000 = 0,
  92. MPEG4_AAC_88200, // 0x1
  93. MPEG4_AAC_64000, // 0x2
  94. MPEG4_AAC_48000, // 0x3
  95. MPEG4_AAC_44100, // 0x4
  96. MPEG4_AAC_32000, // 0x5
  97. MPEG4_AAC_24000, // 0x6
  98. MPEG4_AAC_22050, // 0x7
  99. MPEG4_AAC_16000, // 0x8
  100. MPEG4_AAC_12000, // 0x9
  101. MPEG4_AAC_11025, // 0xa
  102. MPEG4_AAC_8000, // 0xb
  103. MPEG4_AAC_7350, // 0xc
  104. // reserved
  105. // reserved
  106. // escape value
  107. };
  108. /// @return >=0-adts header length, <0-error
  109. int mpeg4_aac_adts_save(const struct mpeg4_aac_t* aac, size_t payload, uint8_t* data, size_t bytes);
  110. /// @return >=0-adts header length, <0-error
  111. int mpeg4_aac_adts_load(const uint8_t* data, size_t bytes, struct mpeg4_aac_t* aac);
  112. /// @return >=0-audio specific config length, <0-error
  113. int mpeg4_aac_audio_specific_config_load(const uint8_t* data, size_t bytes, struct mpeg4_aac_t* aac);
  114. /// @return >=0-audio specific config length, <0-error
  115. int mpeg4_aac_audio_specific_config_save(const struct mpeg4_aac_t* aac, uint8_t* data, size_t bytes);
  116. /// @return >=0-stream mux config length, <0-error
  117. int mpeg4_aac_stream_mux_config_load(const uint8_t* data, size_t bytes, struct mpeg4_aac_t* aac);
  118. /// @return >=0-stream mux config length, <0-error
  119. int mpeg4_aac_stream_mux_config_save(const struct mpeg4_aac_t* aac, uint8_t* data, size_t bytes);
  120. /// get AAC profile level indication value
  121. int mpeg4_aac_profile_level(const struct mpeg4_aac_t* aac);
  122. /// MPEG4_AAC_96000 => 96000
  123. /// @return -1-error, other-frequency value
  124. int mpeg4_aac_audio_frequency_to(enum mpeg4_aac_frequency index);
  125. /// 96000 => MPEG4_AAC_96000
  126. /// @return -1-error, other-frequency index
  127. int mpeg4_aac_audio_frequency_from(int frequency);
  128. /// @return aac channel count
  129. uint8_t mpeg4_aac_channel_count(uint8_t channel_configuration);
  130. int mpeg4_aac_adts_frame_length(const uint8_t* data, size_t bytes);
  131. #if defined(__cplusplus)
  132. }
  133. #endif
  134. #endif /* !_mpeg4_aac_h_ */