mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-19 09:54:54 +00:00
Ajm (#1456)
* ajm: Initial ajm implementation * AJM code improvements (#1453) * Fix sideband buffer order (#1454) * ajm: Attempt to add gapless support * ajm_at9: Return superframes decoded in a single job * WIP (#1460) * Fix gapless decode and combine split buffers * Fixed linux build * fix number of samples reported with gapless decoding * fixed number of remaining samples calculation should fix the small crackling sounds that play every now and again * refactor half ajm * refactored most of ajm * refactored ajm * clang-format, in-repo libatrac9, removed debug stuff --------- Co-authored-by: auser1337 <aaravsandhu10@outlook.com> Co-authored-by: Vladislav Mikhalin <mikhalinvlad@gmail.com> Co-authored-by: IndecisiveTurtle <geoster3d@gmail.com>
This commit is contained in:
parent
76f440889b
commit
f068f13e4a
17 changed files with 1678 additions and 58 deletions
63
src/common/slot_array.h
Normal file
63
src/common/slot_array.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// #include <boost/icl/interval_set.hpp>
|
||||
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <class IndexType, class ResourceType,
|
||||
IndexType MaxIndex = std::numeric_limits<IndexType>::max(), IndexType MinIndex = 0>
|
||||
class SlotArray {
|
||||
public:
|
||||
SlotArray() {
|
||||
std::iota(m_free_indices.begin(), m_free_indices.end(), MinIndex);
|
||||
}
|
||||
|
||||
template <class... Types>
|
||||
std::optional<IndexType> Create(Types&&... args) {
|
||||
if (!HasFreeSlots()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto index = m_free_indices[m_curr_cursor];
|
||||
m_resources[index - MinIndex] = ResourceType(std::forward<Types>(args)...);
|
||||
m_curr_cursor += 1;
|
||||
return index;
|
||||
}
|
||||
|
||||
bool Destroy(IndexType index) {
|
||||
if (!m_resources[index - MinIndex].has_value()) {
|
||||
return false;
|
||||
}
|
||||
m_curr_cursor -= 1;
|
||||
m_free_indices[m_curr_cursor] = index;
|
||||
m_resources[index - MinIndex] = std::nullopt;
|
||||
return true;
|
||||
}
|
||||
|
||||
ResourceType* Get(IndexType index) {
|
||||
auto& resource = m_resources[index - MinIndex];
|
||||
if (!resource.has_value()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &resource.value();
|
||||
}
|
||||
|
||||
bool HasFreeSlots() {
|
||||
return m_curr_cursor < m_free_indices.size();
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_curr_cursor = 0;
|
||||
std::array<IndexType, MaxIndex - MinIndex> m_free_indices;
|
||||
std::array<std::optional<ResourceType>, MaxIndex - MinIndex> m_resources;
|
||||
};
|
||||
|
||||
} // namespace Common
|
Loading…
Add table
Add a link
Reference in a new issue