diff options
Diffstat (limited to 'src/audio_core/common.h')
| -rw-r--r-- | src/audio_core/common.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/audio_core/common.h b/src/audio_core/common.h new file mode 100644 index 000000000..98478b66b --- /dev/null +++ b/src/audio_core/common.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/hle/result.h" | ||
| 10 | |||
| 11 | namespace AudioCore { | ||
| 12 | namespace Audren { | ||
| 13 | constexpr ResultCode ERR_INVALID_PARAMETERS{ErrorModule::Audio, 41}; | ||
| 14 | } | ||
| 15 | |||
| 16 | constexpr u32_le CURRENT_PROCESS_REVISION = Common::MakeMagic('R', 'E', 'V', '8'); | ||
| 17 | |||
| 18 | static constexpr u32 VersionFromRevision(u32_le rev) { | ||
| 19 | // "REV7" -> 7 | ||
| 20 | return ((rev >> 24) & 0xff) - 0x30; | ||
| 21 | } | ||
| 22 | |||
| 23 | static constexpr bool IsRevisionSupported(u32 required, u32_le user_revision) { | ||
| 24 | const auto base = VersionFromRevision(user_revision); | ||
| 25 | return required <= base; | ||
| 26 | } | ||
| 27 | |||
| 28 | static constexpr bool IsValidRevision(u32_le revision) { | ||
| 29 | const auto base = VersionFromRevision(revision); | ||
| 30 | constexpr auto max_rev = VersionFromRevision(CURRENT_PROCESS_REVISION); | ||
| 31 | return base <= max_rev; | ||
| 32 | } | ||
| 33 | |||
| 34 | static constexpr bool CanConsumeBuffer(std::size_t size, std::size_t offset, std::size_t required) { | ||
| 35 | if (offset > size) { | ||
| 36 | return false; | ||
| 37 | } | ||
| 38 | if (size < required) { | ||
| 39 | return false; | ||
| 40 | } | ||
| 41 | if ((size - offset) < required) { | ||
| 42 | return false; | ||
| 43 | } | ||
| 44 | return true; | ||
| 45 | } | ||
| 46 | |||
| 47 | } // namespace AudioCore | ||