diff options
| author | 2022-07-16 23:48:45 +0100 | |
|---|---|---|
| committer | 2022-07-22 01:11:32 +0100 | |
| commit | 458da8a94877677f086f06cdeecf959ec4283a33 (patch) | |
| tree | 583166d77602ad90a0d552f37de8729ad80fd6c1 /src/audio_core/renderer/upsampler | |
| parent | Merge pull request #8598 from Link4565/recv-dontwait (diff) | |
| download | yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.gz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.xz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.zip | |
Project Andio
Diffstat (limited to 'src/audio_core/renderer/upsampler')
5 files changed, 170 insertions, 0 deletions
diff --git a/src/audio_core/renderer/upsampler/upsampler_info.cpp b/src/audio_core/renderer/upsampler/upsampler_info.cpp new file mode 100644 index 000000000..e3d2f7db0 --- /dev/null +++ b/src/audio_core/renderer/upsampler/upsampler_info.cpp | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "audio_core/renderer/upsampler/upsampler_info.h" | ||
| 5 | |||
| 6 | namespace AudioCore::AudioRenderer {} // namespace AudioCore::AudioRenderer | ||
diff --git a/src/audio_core/renderer/upsampler/upsampler_info.h b/src/audio_core/renderer/upsampler/upsampler_info.h new file mode 100644 index 000000000..a43c15af3 --- /dev/null +++ b/src/audio_core/renderer/upsampler/upsampler_info.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | |||
| 8 | #include "audio_core/common/common.h" | ||
| 9 | #include "audio_core/renderer/upsampler/upsampler_state.h" | ||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace AudioCore::AudioRenderer { | ||
| 13 | class UpsamplerManager; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Manages information needed to upsample a mix buffer. | ||
| 17 | */ | ||
| 18 | struct UpsamplerInfo { | ||
| 19 | /// States used by the AudioRenderer across calls. | ||
| 20 | std::array<UpsamplerState, MaxChannels> states{}; | ||
| 21 | /// Pointer to the manager | ||
| 22 | UpsamplerManager* manager{}; | ||
| 23 | /// Pointer to the samples to be upsampled | ||
| 24 | CpuAddr samples_pos{}; | ||
| 25 | /// Target number of samples to upsample to | ||
| 26 | u32 sample_count{}; | ||
| 27 | /// Number of channels to upsample | ||
| 28 | u32 input_count{}; | ||
| 29 | /// Is this upsampler enabled? | ||
| 30 | bool enabled{}; | ||
| 31 | /// Mix buffer indexes to be upsampled | ||
| 32 | std::array<s16, MaxChannels> inputs{}; | ||
| 33 | }; | ||
| 34 | |||
| 35 | } // namespace AudioCore::AudioRenderer | ||
diff --git a/src/audio_core/renderer/upsampler/upsampler_manager.cpp b/src/audio_core/renderer/upsampler/upsampler_manager.cpp new file mode 100644 index 000000000..4c76a5066 --- /dev/null +++ b/src/audio_core/renderer/upsampler/upsampler_manager.cpp | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "audio_core/renderer/upsampler/upsampler_manager.h" | ||
| 5 | |||
| 6 | namespace AudioCore::AudioRenderer { | ||
| 7 | |||
| 8 | UpsamplerManager::UpsamplerManager(const u32 count_, std::span<UpsamplerInfo> infos_, | ||
| 9 | std::span<s32> workbuffer_) | ||
| 10 | : count{count_}, upsampler_infos{infos_}, workbuffer{workbuffer_} {} | ||
| 11 | |||
| 12 | UpsamplerInfo* UpsamplerManager::Allocate() { | ||
| 13 | std::scoped_lock l{lock}; | ||
| 14 | |||
| 15 | if (count == 0) { | ||
| 16 | return nullptr; | ||
| 17 | } | ||
| 18 | |||
| 19 | u32 free_index{0}; | ||
| 20 | for (auto& upsampler : upsampler_infos) { | ||
| 21 | if (!upsampler.enabled) { | ||
| 22 | break; | ||
| 23 | } | ||
| 24 | free_index++; | ||
| 25 | } | ||
| 26 | |||
| 27 | if (free_index >= count) { | ||
| 28 | return nullptr; | ||
| 29 | } | ||
| 30 | |||
| 31 | auto& upsampler{upsampler_infos[free_index]}; | ||
| 32 | upsampler.manager = this; | ||
| 33 | upsampler.sample_count = TargetSampleCount; | ||
| 34 | upsampler.samples_pos = CpuAddr(&workbuffer[upsampler.sample_count * MaxChannels]); | ||
| 35 | upsampler.enabled = true; | ||
| 36 | return &upsampler; | ||
| 37 | } | ||
| 38 | |||
| 39 | void UpsamplerManager::Free(UpsamplerInfo* info) { | ||
| 40 | std::scoped_lock l{lock}; | ||
| 41 | info->enabled = false; | ||
| 42 | } | ||
| 43 | |||
| 44 | } // namespace AudioCore::AudioRenderer | ||
diff --git a/src/audio_core/renderer/upsampler/upsampler_manager.h b/src/audio_core/renderer/upsampler/upsampler_manager.h new file mode 100644 index 000000000..70cd42b08 --- /dev/null +++ b/src/audio_core/renderer/upsampler/upsampler_manager.h | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <mutex> | ||
| 7 | #include <span> | ||
| 8 | |||
| 9 | #include "audio_core/renderer/upsampler/upsampler_info.h" | ||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace AudioCore::AudioRenderer { | ||
| 13 | /** | ||
| 14 | * Manages and has utility functions for upsampler infos. | ||
| 15 | */ | ||
| 16 | class UpsamplerManager { | ||
| 17 | public: | ||
| 18 | UpsamplerManager(u32 count, std::span<UpsamplerInfo> infos, std::span<s32> workbuffer); | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Allocate a new UpsamplerInfo. | ||
| 22 | * | ||
| 23 | * @return The allocated upsampler, may be nullptr if alloc failed. | ||
| 24 | */ | ||
| 25 | UpsamplerInfo* Allocate(); | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Free the given upsampler. | ||
| 29 | * | ||
| 30 | * @param The upsampler to be freed. | ||
| 31 | */ | ||
| 32 | void Free(UpsamplerInfo* info); | ||
| 33 | |||
| 34 | private: | ||
| 35 | /// Maximum number of upsamplers in the buffer | ||
| 36 | const u32 count; | ||
| 37 | /// Upsamplers buffer | ||
| 38 | std::span<UpsamplerInfo> upsampler_infos; | ||
| 39 | /// Workbuffer for upsampling samples | ||
| 40 | std::span<s32> workbuffer; | ||
| 41 | /// Lock for allocate/free | ||
| 42 | std::mutex lock{}; | ||
| 43 | }; | ||
| 44 | |||
| 45 | } // namespace AudioCore::AudioRenderer | ||
diff --git a/src/audio_core/renderer/upsampler/upsampler_state.h b/src/audio_core/renderer/upsampler/upsampler_state.h new file mode 100644 index 000000000..28cebe200 --- /dev/null +++ b/src/audio_core/renderer/upsampler/upsampler_state.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | |||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "common/fixed_point.h" | ||
| 10 | |||
| 11 | namespace AudioCore::AudioRenderer { | ||
| 12 | /** | ||
| 13 | * Upsampling state used by the AudioRenderer across calls. | ||
| 14 | */ | ||
| 15 | struct UpsamplerState { | ||
| 16 | static constexpr u16 HistorySize = 20; | ||
| 17 | |||
| 18 | /// Source data to target data ratio. E.g 48'000/32'000 = 1.5 | ||
| 19 | Common::FixedPoint<16, 16> ratio; | ||
| 20 | /// Sample history | ||
| 21 | std::array<Common::FixedPoint<24, 8>, HistorySize> history; | ||
| 22 | /// Size of the sinc coefficient window | ||
| 23 | u16 window_size; | ||
| 24 | /// Read index for the history | ||
| 25 | u16 history_output_index; | ||
| 26 | /// Write index for the history | ||
| 27 | u16 history_input_index; | ||
| 28 | /// Start offset within the history, fixed to 0 | ||
| 29 | u16 history_start_index; | ||
| 30 | /// Ebd offset within the history, fixed to HistorySize | ||
| 31 | u16 history_end_index; | ||
| 32 | /// Is this state initialized? | ||
| 33 | bool initialized; | ||
| 34 | /// Index of the current sample. | ||
| 35 | /// E.g 16K -> 48K has a ratio of 3, so this will be 0-2. | ||
| 36 | /// See the Upsample command in the AudioRenderer for more information. | ||
| 37 | u8 sample_index; | ||
| 38 | }; | ||
| 39 | |||
| 40 | } // namespace AudioCore::AudioRenderer | ||