Project Andio

This commit is contained in:
Kelebek1 2022-07-16 23:48:45 +01:00
parent 6e36f4d230
commit 458da8a948
270 changed files with 33712 additions and 8445 deletions

View file

@ -0,0 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "audio_core/renderer/upsampler/upsampler_info.h"
namespace AudioCore::AudioRenderer {} // namespace AudioCore::AudioRenderer

View file

@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include "audio_core/common/common.h"
#include "audio_core/renderer/upsampler/upsampler_state.h"
#include "common/common_types.h"
namespace AudioCore::AudioRenderer {
class UpsamplerManager;
/**
* Manages information needed to upsample a mix buffer.
*/
struct UpsamplerInfo {
/// States used by the AudioRenderer across calls.
std::array<UpsamplerState, MaxChannels> states{};
/// Pointer to the manager
UpsamplerManager* manager{};
/// Pointer to the samples to be upsampled
CpuAddr samples_pos{};
/// Target number of samples to upsample to
u32 sample_count{};
/// Number of channels to upsample
u32 input_count{};
/// Is this upsampler enabled?
bool enabled{};
/// Mix buffer indexes to be upsampled
std::array<s16, MaxChannels> inputs{};
};
} // namespace AudioCore::AudioRenderer

View file

@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "audio_core/renderer/upsampler/upsampler_manager.h"
namespace AudioCore::AudioRenderer {
UpsamplerManager::UpsamplerManager(const u32 count_, std::span<UpsamplerInfo> infos_,
std::span<s32> workbuffer_)
: count{count_}, upsampler_infos{infos_}, workbuffer{workbuffer_} {}
UpsamplerInfo* UpsamplerManager::Allocate() {
std::scoped_lock l{lock};
if (count == 0) {
return nullptr;
}
u32 free_index{0};
for (auto& upsampler : upsampler_infos) {
if (!upsampler.enabled) {
break;
}
free_index++;
}
if (free_index >= count) {
return nullptr;
}
auto& upsampler{upsampler_infos[free_index]};
upsampler.manager = this;
upsampler.sample_count = TargetSampleCount;
upsampler.samples_pos = CpuAddr(&workbuffer[upsampler.sample_count * MaxChannels]);
upsampler.enabled = true;
return &upsampler;
}
void UpsamplerManager::Free(UpsamplerInfo* info) {
std::scoped_lock l{lock};
info->enabled = false;
}
} // namespace AudioCore::AudioRenderer

View file

@ -0,0 +1,45 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <mutex>
#include <span>
#include "audio_core/renderer/upsampler/upsampler_info.h"
#include "common/common_types.h"
namespace AudioCore::AudioRenderer {
/**
* Manages and has utility functions for upsampler infos.
*/
class UpsamplerManager {
public:
UpsamplerManager(u32 count, std::span<UpsamplerInfo> infos, std::span<s32> workbuffer);
/**
* Allocate a new UpsamplerInfo.
*
* @return The allocated upsampler, may be nullptr if alloc failed.
*/
UpsamplerInfo* Allocate();
/**
* Free the given upsampler.
*
* @param The upsampler to be freed.
*/
void Free(UpsamplerInfo* info);
private:
/// Maximum number of upsamplers in the buffer
const u32 count;
/// Upsamplers buffer
std::span<UpsamplerInfo> upsampler_infos;
/// Workbuffer for upsampling samples
std::span<s32> workbuffer;
/// Lock for allocate/free
std::mutex lock{};
};
} // namespace AudioCore::AudioRenderer

View file

@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include "common/common_types.h"
#include "common/fixed_point.h"
namespace AudioCore::AudioRenderer {
/**
* Upsampling state used by the AudioRenderer across calls.
*/
struct UpsamplerState {
static constexpr u16 HistorySize = 20;
/// Source data to target data ratio. E.g 48'000/32'000 = 1.5
Common::FixedPoint<16, 16> ratio;
/// Sample history
std::array<Common::FixedPoint<24, 8>, HistorySize> history;
/// Size of the sinc coefficient window
u16 window_size;
/// Read index for the history
u16 history_output_index;
/// Write index for the history
u16 history_input_index;
/// Start offset within the history, fixed to 0
u16 history_start_index;
/// Ebd offset within the history, fixed to HistorySize
u16 history_end_index;
/// Is this state initialized?
bool initialized;
/// Index of the current sample.
/// E.g 16K -> 48K has a ratio of 3, so this will be 0-2.
/// See the Upsample command in the AudioRenderer for more information.
u8 sample_index;
};
} // namespace AudioCore::AudioRenderer