MP3Types.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2021, Arne Elster <arne@elster.li>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Array.h>
  8. #include <AK/EnumBits.h>
  9. #include <AK/FixedArray.h>
  10. namespace Audio::MP3 {
  11. enum class Mode {
  12. Stereo = 0,
  13. JointStereo = 1,
  14. DualChannel = 2,
  15. SingleChannel = 3,
  16. };
  17. enum class ModeExtension {
  18. Stereo = 0,
  19. IntensityStereo = 1,
  20. MsStereo = 2,
  21. };
  22. AK_ENUM_BITWISE_OPERATORS(ModeExtension)
  23. enum class Emphasis {
  24. None = 0,
  25. Microseconds_50_15 = 1,
  26. Reserved = 2,
  27. CCITT_J17 = 3,
  28. };
  29. enum class BlockType {
  30. Normal = 0,
  31. Start = 1,
  32. Short = 2,
  33. End = 3,
  34. };
  35. struct Header {
  36. i32 id;
  37. i32 layer;
  38. bool protection_bit;
  39. i32 bitrate;
  40. i32 samplerate;
  41. bool padding_bit;
  42. bool private_bit;
  43. Mode mode;
  44. ModeExtension mode_extension;
  45. bool copyright_bit;
  46. bool original_bit;
  47. Emphasis emphasis;
  48. u16 crc16;
  49. size_t frame_size;
  50. size_t slot_count;
  51. size_t channel_count() const { return mode == Mode::SingleChannel ? 1 : 2; }
  52. };
  53. struct Granule {
  54. Array<double, 576> samples;
  55. Array<Array<double, 18>, 32> filter_bank_input;
  56. Array<Array<double, 32>, 18> pcm;
  57. u32 part_2_3_length;
  58. u32 big_values;
  59. u32 global_gain;
  60. u32 scalefac_compress;
  61. bool window_switching_flag;
  62. BlockType block_type;
  63. bool mixed_block_flag;
  64. Array<int, 3> table_select;
  65. Array<int, 3> sub_block_gain;
  66. u32 region0_count;
  67. u32 region1_count;
  68. bool preflag;
  69. bool scalefac_scale;
  70. bool count1table_select;
  71. };
  72. struct Channel {
  73. Array<Granule, 2> granules;
  74. Array<int, 39> scale_factors;
  75. Array<int, 4> scale_factor_selection_info;
  76. };
  77. struct MP3Frame {
  78. Header header;
  79. FixedArray<Channel> channels;
  80. off_t main_data_begin;
  81. u32 private_bits;
  82. MP3Frame(Header header)
  83. : header(header)
  84. , channels(FixedArray<Channel>::must_create_but_fixme_should_propagate_errors(header.channel_count()))
  85. {
  86. }
  87. };
  88. }