common.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_funcs.h"
  6. #include "common/common_types.h"
  7. #include "common/swap.h"
  8. #include "core/hle/result.h"
  9. namespace AudioCommon {
  10. namespace Audren {
  11. constexpr ResultCode ERR_INVALID_PARAMETERS{ErrorModule::Audio, 41};
  12. constexpr ResultCode ERR_SPLITTER_SORT_FAILED{ErrorModule::Audio, 43};
  13. } // namespace Audren
  14. constexpr u32_le CURRENT_PROCESS_REVISION = Common::MakeMagic('R', 'E', 'V', '8');
  15. constexpr std::size_t MAX_MIX_BUFFERS = 24;
  16. constexpr std::size_t MAX_BIQUAD_FILTERS = 2;
  17. constexpr std::size_t MAX_CHANNEL_COUNT = 6;
  18. constexpr std::size_t MAX_WAVE_BUFFERS = 4;
  19. constexpr std::size_t MAX_SAMPLE_HISTORY = 4;
  20. constexpr u32 STREAM_SAMPLE_RATE = 48000;
  21. constexpr u32 STREAM_NUM_CHANNELS = 2;
  22. constexpr s32 NO_SPLITTER = -1;
  23. constexpr s32 NO_MIX = 0x7fffffff;
  24. constexpr s32 NO_FINAL_MIX = std::numeric_limits<s32>::min();
  25. constexpr s32 FINAL_MIX = 0;
  26. constexpr s32 NO_EFFECT_ORDER = -1;
  27. constexpr std::size_t TEMP_MIX_BASE_SIZE = 0x3f00; // TODO(ogniK): Work out this constant
  28. // Any size checks seem to take the sample history into account
  29. // and our const ends up being 0x3f04, the 4 bytes are most
  30. // likely the sample history
  31. constexpr std::size_t TOTAL_TEMP_MIX_SIZE = TEMP_MIX_BASE_SIZE + AudioCommon::MAX_SAMPLE_HISTORY;
  32. static constexpr u32 VersionFromRevision(u32_le rev) {
  33. // "REV7" -> 7
  34. return ((rev >> 24) & 0xff) - 0x30;
  35. }
  36. static constexpr bool IsRevisionSupported(u32 required, u32_le user_revision) {
  37. const auto base = VersionFromRevision(user_revision);
  38. return required <= base;
  39. }
  40. static constexpr bool IsValidRevision(u32_le revision) {
  41. const auto base = VersionFromRevision(revision);
  42. constexpr auto max_rev = VersionFromRevision(CURRENT_PROCESS_REVISION);
  43. return base <= max_rev;
  44. }
  45. static constexpr bool CanConsumeBuffer(std::size_t size, std::size_t offset, std::size_t required) {
  46. if (offset > size) {
  47. return false;
  48. }
  49. if (size < required) {
  50. return false;
  51. }
  52. if ((size - offset) < required) {
  53. return false;
  54. }
  55. return true;
  56. }
  57. struct UpdateDataSizes {
  58. u32_le behavior{};
  59. u32_le memory_pool{};
  60. u32_le voice{};
  61. u32_le voice_channel_resource{};
  62. u32_le effect{};
  63. u32_le mixer{};
  64. u32_le sink{};
  65. u32_le performance{};
  66. u32_le splitter{};
  67. u32_le render_info{};
  68. INSERT_PADDING_WORDS(4);
  69. };
  70. static_assert(sizeof(UpdateDataSizes) == 0x38, "UpdateDataSizes is an invalid size");
  71. struct UpdateDataHeader {
  72. u32_le revision{};
  73. UpdateDataSizes size{};
  74. u32_le total_size{};
  75. };
  76. static_assert(sizeof(UpdateDataHeader) == 0x40, "UpdateDataHeader is an invalid size");
  77. struct AudioRendererParameter {
  78. u32_le sample_rate;
  79. u32_le sample_count;
  80. u32_le mix_buffer_count;
  81. u32_le submix_count;
  82. u32_le voice_count;
  83. u32_le sink_count;
  84. u32_le effect_count;
  85. u32_le performance_frame_count;
  86. u8 is_voice_drop_enabled;
  87. u8 unknown_21;
  88. u8 unknown_22;
  89. u8 execution_mode;
  90. u32_le splitter_count;
  91. u32_le num_splitter_send_channels;
  92. u32_le unknown_30;
  93. u32_le revision;
  94. };
  95. static_assert(sizeof(AudioRendererParameter) == 52, "AudioRendererParameter is an invalid size");
  96. } // namespace AudioCommon