1
0

AACFrame.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "AACFrame.h"
  2. #include "api__in_mp3.h"
  3. #include "resource.h"
  4. #include "in2.h"
  5. extern In_Module mod;
  6. void AACFrame::ReadBuffer( unsigned __int8 *buffer )
  7. {
  8. syncword = ( buffer[ 0 ] << 4 ) | ( buffer[ 1 ] >> 4 );
  9. id = ( buffer[ 1 ] >> 3 ) & 1;
  10. layer = ( buffer[ 1 ] >> 1 ) & 3;
  11. protection = ( buffer[ 1 ] ) & 1;
  12. profile = ( buffer[ 2 ] >> 6 ) & 3;
  13. sampleRateIndex = ( buffer[ 2 ] >> 2 ) & 0xF;
  14. privateBit = ( buffer[ 2 ] >> 1 ) & 1;
  15. channelConfiguration = ( ( buffer[ 2 ] & 1 ) << 2 ) | ( ( buffer[ 3 ] >> 6 ) & 3 );
  16. original = ( buffer[ 3 ] >> 5 ) & 1;
  17. home = ( buffer[ 3 ] >> 4 ) & 1;
  18. //copyright_identification_bit = (buffer[3] >> 3) & 1;
  19. //copyright_identification_start = (buffer[3] >> 2) & 1;
  20. frameLength = ( ( buffer[ 3 ] & 3 ) << 11 ) | ( buffer[ 4 ] << 3 ) | ( ( buffer[ 5 ] >> 5 ) & 7 );
  21. bufferFullness = ( ( buffer[ 5 ] & 0xF8 ) << 5 ) | ( ( buffer[ 6 ] >> 2 ) & 0x3F );
  22. numDataBlocks = buffer[ 6 ] & 3;
  23. }
  24. bool AACFrame::OK()
  25. {
  26. if (syncword == SYNC
  27. && layer == 0
  28. && sampleRateIndex < 13
  29. //&& profile != LTP // TODO: can coding technologies decoder do LTP?
  30. )
  31. return true;
  32. else
  33. return false;
  34. }
  35. static const unsigned int aac_sratetab[] =
  36. {
  37. 96000,
  38. 88200,
  39. 64000,
  40. 48000,
  41. 44100,
  42. 32000,
  43. 24000,
  44. 22050,
  45. 16000,
  46. 12000,
  47. 11025,
  48. 8000,
  49. 7350,
  50. };
  51. int AACFrame::GetSampleRate()
  52. {
  53. return aac_sratetab[sampleRateIndex];
  54. }
  55. static const wchar_t *aac_profiletab[] = {L"Main", L"LC", L"SSR", L"LTP"};
  56. const wchar_t *AACFrame::GetProfileName()
  57. {
  58. return aac_profiletab[profile];
  59. }
  60. //static const char *aac_channels[] = {"Custom", "Mono", "Stereo", "3 channel", "4 channel", "surround", "5.1", "7.1"};
  61. static wchar_t aac_channels_str[64];
  62. static int aac_channels_id[] = {IDS_CUSTOM, IDS_MONO, IDS_STEREO, IDS_3_CHANNEL, IDS_4_CHANNEL, IDS_SURROUND, IDS_5_1, IDS_7_1};
  63. const wchar_t *AACFrame::GetChannelConfigurationName()
  64. {
  65. return WASABI_API_LNGSTRINGW_BUF(aac_channels_id[channelConfiguration],aac_channels_str,64);
  66. }
  67. int AACFrame::GetNumChannels()
  68. {
  69. switch(channelConfiguration)
  70. {
  71. case 7:
  72. return 8;
  73. default:
  74. return channelConfiguration;
  75. }
  76. }
  77. int AACFrame::GetMPEGVersion()
  78. {
  79. if (id == 0)
  80. return 2;
  81. else
  82. return 4;
  83. }