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.

53 lines
1.7 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace JT1078.Flv.Metadata
  5. {
  6. public class AudioSpecificConfig
  7. {
  8. public AudioObjectType AudioType { get; set; } = AudioObjectType.AAC_LC;
  9. public SamplingFrequency SamplingFrequencyIndex { get; set; } = SamplingFrequency.Index_8000;
  10. /// <summary>
  11. /// 其实有很多,这里就固定为立体声
  12. /// </summary>
  13. public int ChannelConfiguration { get; set; } = 1;
  14. public byte[] ToArray()
  15. {
  16. var value = Convert.ToInt16($"{Convert.ToString((int)AudioType, 2).PadLeft(5, '0')}{Convert.ToString((int)SamplingFrequencyIndex, 2).PadLeft(4, '0')}{Convert.ToString(ChannelConfiguration, 2).PadLeft(4, '0')}000", 2);
  17. return new byte[] { (byte)(value >> 8), (byte)value, 0x56, 0xe5, 0x00 };
  18. }
  19. /// <summary>
  20. /// 音频类型
  21. /// 其实有很多,这里就列几个,如有需要再加
  22. /// </summary>
  23. public enum AudioObjectType
  24. {
  25. AAC_MAIN = 1,
  26. AAC_LC = 2,
  27. AAC_SSR = 3,
  28. AAC_LTP = 4,
  29. SBR = 5,
  30. AAC_SCALABLE
  31. }
  32. public enum SamplingFrequency
  33. {
  34. Index_96000 = 0x00,
  35. Index_88200 = 0x01,
  36. Index_64000 = 0x02,
  37. Index_48000 = 0x03,
  38. Index_44100 = 0x04,
  39. Index_32000 = 0x05,
  40. Index_24000 = 0x06,
  41. Index_22050 = 0x07,
  42. Index_16000 = 0x08,
  43. Index_12000 = 0x09,
  44. Index_11025 = 0x0a,
  45. Index_8000 = 0x0b,
  46. Index_7350 = 0x0c,
  47. ESCAPE = 0x0f
  48. }
  49. }
  50. }