FlacTypes.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "Queue.h"
  8. #include "SampleFormats.h"
  9. #include <AK/ByteBuffer.h>
  10. #include <AK/Types.h>
  11. #include <AK/Variant.h>
  12. namespace Audio {
  13. // These are not the actual values stored in the file! They are marker constants instead, only used temporarily in the decoder.
  14. // 11.22.3. INTERCHANNEL SAMPLE BLOCK SIZE
  15. #define FLAC_BLOCKSIZE_AT_END_OF_HEADER_8 0xffffffff
  16. #define FLAC_BLOCKSIZE_AT_END_OF_HEADER_16 0xfffffffe
  17. // 11.22.4. SAMPLE RATE
  18. #define FLAC_SAMPLERATE_AT_END_OF_HEADER_8 0xffffffff
  19. #define FLAC_SAMPLERATE_AT_END_OF_HEADER_16 0xfffffffe
  20. #define FLAC_SAMPLERATE_AT_END_OF_HEADER_16X10 0xfffffffd
  21. // 11.8 BLOCK_TYPE (7 bits)
  22. enum class FlacMetadataBlockType : u8 {
  23. STREAMINFO = 0, // Important data about the audio format
  24. PADDING = 1, // Non-data block to be ignored
  25. APPLICATION = 2, // Ignored
  26. SEEKTABLE = 3, // Seeking info, maybe to be used later
  27. VORBIS_COMMENT = 4, // Ignored
  28. CUESHEET = 5, // Ignored
  29. PICTURE = 6, // Ignored
  30. INVALID = 127, // Error
  31. };
  32. // 11.22.5. CHANNEL ASSIGNMENT
  33. enum class FlacFrameChannelType : u8 {
  34. Mono = 0,
  35. Stereo = 1,
  36. StereoCenter = 2, // left, right, center
  37. Surround4p0 = 3, // front left/right, back left/right
  38. Surround5p0 = 4, // front left/right, center, back left/right
  39. Surround5p1 = 5, // front left/right, center, LFE, back left/right
  40. Surround6p1 = 6, // front left/right, center, LFE, back center, side left/right
  41. Surround7p1 = 7, // front left/right, center, LFE, back left/right, side left/right
  42. LeftSideStereo = 8, // channel coupling: left and difference
  43. RightSideStereo = 9, // channel coupling: difference and right
  44. MidSideStereo = 10, // channel coupling: center and difference
  45. // others are reserved
  46. };
  47. // 11.25.1. SUBFRAME TYPE
  48. enum class FlacSubframeType : u8 {
  49. Constant = 0,
  50. Verbatim = 1,
  51. Fixed = 0b001000,
  52. LPC = 0b100000,
  53. // others are reserved
  54. };
  55. // 11.30.1. RESIDUAL_CODING_METHOD
  56. enum class FlacResidualMode : u8 {
  57. Rice4Bit = 0,
  58. Rice5Bit = 1,
  59. };
  60. // 11.6. METADATA_BLOCK
  61. struct FlacRawMetadataBlock {
  62. bool is_last_block;
  63. FlacMetadataBlockType type;
  64. u32 length; // 24 bits
  65. ByteBuffer data;
  66. };
  67. // 11.22. FRAME_HEADER
  68. struct FlacFrameHeader {
  69. u32 sample_count;
  70. u32 sample_rate;
  71. FlacFrameChannelType channels;
  72. u8 bit_depth;
  73. };
  74. // 11.25. SUBFRAME_HEADER
  75. struct FlacSubframeHeader {
  76. FlacSubframeType type;
  77. // order for fixed and LPC subframes
  78. u8 order;
  79. u8 wasted_bits_per_sample;
  80. u8 bits_per_sample;
  81. };
  82. }