1
0

FLVAudioHeader.cpp 874 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "FLVAudioHeader.h"
  2. /*
  3. (c) 2006 Nullsoft, Inc.
  4. Author: Ben Allison [email protected]
  5. */
  6. /*
  7. soundType 1 bit (byte & 0x01) >> 0 0: mono, 1: stereo
  8. soundSize 1 bit (byte & 0x02)>> 1 0: 8-bit, 2: 16-bit
  9. soundRate 2 bits (byte & 0x0C) >> 2 0: 5.5 kHz, 1: 11 kHz, 2: 22 kHz, 3: 44 kHz
  10. soundFormat 4 bits (byte & 0xf0) >> 4 0: Uncompressed, 1: ADPCM, 2: MP3, 5: Nellymoser 8kHz mono, 6: Nellymoser
  11. */
  12. bool FLVAudioHeader::Read(unsigned __int8 *data, size_t size)
  13. {
  14. if (size < 1)
  15. return false; // header size too small
  16. unsigned __int8 byte = data[0];
  17. stereo = !!((byte & 0x01) >> 0);
  18. bits = ((byte & 0x02) >> 1) ? 16 : 8;
  19. switch ((byte & 0x0C) >> 2)
  20. {
  21. case 0: sampleRate = 5512; break;
  22. case 1: sampleRate = 11025; break;
  23. case 2: sampleRate = 22050; break;
  24. case 3: sampleRate = 44100; break;
  25. }
  26. format = (byte & 0xf0) >> 4;
  27. return true;
  28. }