diff options
Diffstat (limited to 'src/audio_core/common/common.h')
| -rw-r--r-- | src/audio_core/common/common.h | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/audio_core/common/common.h b/src/audio_core/common/common.h new file mode 100644 index 000000000..6abd9be45 --- /dev/null +++ b/src/audio_core/common/common.h | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <numeric> | ||
| 7 | #include <span> | ||
| 8 | |||
| 9 | #include "common/assert.h" | ||
| 10 | #include "common/common_funcs.h" | ||
| 11 | #include "common/common_types.h" | ||
| 12 | |||
| 13 | namespace AudioCore { | ||
| 14 | using CpuAddr = std::uintptr_t; | ||
| 15 | |||
| 16 | enum class PlayState : u8 { | ||
| 17 | Started, | ||
| 18 | Stopped, | ||
| 19 | Paused, | ||
| 20 | }; | ||
| 21 | |||
| 22 | enum class SrcQuality : u8 { | ||
| 23 | Medium, | ||
| 24 | High, | ||
| 25 | Low, | ||
| 26 | }; | ||
| 27 | |||
| 28 | enum class SampleFormat : u8 { | ||
| 29 | Invalid, | ||
| 30 | PcmInt8, | ||
| 31 | PcmInt16, | ||
| 32 | PcmInt24, | ||
| 33 | PcmInt32, | ||
| 34 | PcmFloat, | ||
| 35 | Adpcm, | ||
| 36 | }; | ||
| 37 | |||
| 38 | enum class SessionTypes { | ||
| 39 | AudioIn, | ||
| 40 | AudioOut, | ||
| 41 | FinalOutputRecorder, | ||
| 42 | }; | ||
| 43 | |||
| 44 | enum class Channels : u32 { | ||
| 45 | FrontLeft, | ||
| 46 | FrontRight, | ||
| 47 | Center, | ||
| 48 | LFE, | ||
| 49 | BackLeft, | ||
| 50 | BackRight, | ||
| 51 | }; | ||
| 52 | |||
| 53 | // These are used by Delay, Reverb and I3dl2Reverb prior to Revision 11. | ||
| 54 | enum class OldChannels : u32 { | ||
| 55 | FrontLeft, | ||
| 56 | FrontRight, | ||
| 57 | BackLeft, | ||
| 58 | BackRight, | ||
| 59 | Center, | ||
| 60 | LFE, | ||
| 61 | }; | ||
| 62 | |||
| 63 | constexpr u32 BufferCount = 32; | ||
| 64 | |||
| 65 | constexpr u32 MaxRendererSessions = 2; | ||
| 66 | constexpr u32 TargetSampleCount = 240; | ||
| 67 | constexpr u32 TargetSampleRate = 48'000; | ||
| 68 | constexpr u32 MaxChannels = 6; | ||
| 69 | constexpr u32 MaxMixBuffers = 24; | ||
| 70 | constexpr u32 MaxWaveBuffers = 4; | ||
| 71 | constexpr s32 LowestVoicePriority = 0xFF; | ||
| 72 | constexpr s32 HighestVoicePriority = 0; | ||
| 73 | constexpr u32 BufferAlignment = 0x40; | ||
| 74 | constexpr u32 WorkbufferAlignment = 0x1000; | ||
| 75 | constexpr s32 FinalMixId = 0; | ||
| 76 | constexpr s32 InvalidDistanceFromFinalMix = std::numeric_limits<s32>::min(); | ||
| 77 | constexpr s32 UnusedSplitterId = -1; | ||
| 78 | constexpr s32 UnusedMixId = std::numeric_limits<s32>::max(); | ||
| 79 | constexpr u32 InvalidNodeId = 0xF0000000; | ||
| 80 | constexpr s32 InvalidProcessOrder = -1; | ||
| 81 | constexpr u32 MaxBiquadFilters = 2; | ||
| 82 | constexpr u32 MaxEffects = 256; | ||
| 83 | |||
| 84 | constexpr bool IsChannelCountValid(u16 channel_count) { | ||
| 85 | return channel_count <= 6 && | ||
| 86 | (channel_count == 1 || channel_count == 2 || channel_count == 4 || channel_count == 6); | ||
| 87 | } | ||
| 88 | |||
| 89 | constexpr void UseOldChannelMapping(std::span<s16> inputs, std::span<s16> outputs) { | ||
| 90 | constexpr auto old_center{static_cast<u32>(OldChannels::Center)}; | ||
| 91 | constexpr auto new_center{static_cast<u32>(Channels::Center)}; | ||
| 92 | constexpr auto old_lfe{static_cast<u32>(OldChannels::LFE)}; | ||
| 93 | constexpr auto new_lfe{static_cast<u32>(Channels::LFE)}; | ||
| 94 | |||
| 95 | auto center{inputs[old_center]}; | ||
| 96 | auto lfe{inputs[old_lfe]}; | ||
| 97 | inputs[old_center] = inputs[new_center]; | ||
| 98 | inputs[old_lfe] = inputs[new_lfe]; | ||
| 99 | inputs[new_center] = center; | ||
| 100 | inputs[new_lfe] = lfe; | ||
| 101 | |||
| 102 | center = outputs[old_center]; | ||
| 103 | lfe = outputs[old_lfe]; | ||
| 104 | outputs[old_center] = outputs[new_center]; | ||
| 105 | outputs[old_lfe] = outputs[new_lfe]; | ||
| 106 | outputs[new_center] = center; | ||
| 107 | outputs[new_lfe] = lfe; | ||
| 108 | } | ||
| 109 | |||
| 110 | constexpr u32 GetSplitterInParamHeaderMagic() { | ||
| 111 | return Common::MakeMagic('S', 'N', 'D', 'H'); | ||
| 112 | } | ||
| 113 | |||
| 114 | constexpr u32 GetSplitterInfoMagic() { | ||
| 115 | return Common::MakeMagic('S', 'N', 'D', 'I'); | ||
| 116 | } | ||
| 117 | |||
| 118 | constexpr u32 GetSplitterSendDataMagic() { | ||
| 119 | return Common::MakeMagic('S', 'N', 'D', 'D'); | ||
| 120 | } | ||
| 121 | |||
| 122 | constexpr size_t GetSampleFormatByteSize(SampleFormat format) { | ||
| 123 | switch (format) { | ||
| 124 | case SampleFormat::PcmInt8: | ||
| 125 | return 1; | ||
| 126 | case SampleFormat::PcmInt16: | ||
| 127 | return 2; | ||
| 128 | case SampleFormat::PcmInt24: | ||
| 129 | return 3; | ||
| 130 | case SampleFormat::PcmInt32: | ||
| 131 | case SampleFormat::PcmFloat: | ||
| 132 | return 4; | ||
| 133 | default: | ||
| 134 | return 2; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | } // namespace AudioCore | ||