summaryrefslogtreecommitdiff
path: root/src/audio_core/hle/dsp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio_core/hle/dsp.cpp')
-rw-r--r--src/audio_core/hle/dsp.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp
index c89356edc..5759a5b9e 100644
--- a/src/audio_core/hle/dsp.cpp
+++ b/src/audio_core/hle/dsp.cpp
@@ -8,8 +8,32 @@
8namespace DSP { 8namespace DSP {
9namespace HLE { 9namespace HLE {
10 10
11SharedMemory g_region0; 11std::array<SharedMemory, 2> g_regions;
12SharedMemory g_region1; 12
13static size_t CurrentRegionIndex() {
14 // The region with the higher frame counter is chosen unless there is wraparound.
15 // This function only returns a 0 or 1.
16
17 if (g_regions[0].frame_counter == 0xFFFFu && g_regions[1].frame_counter != 0xFFFEu) {
18 // Wraparound has occured.
19 return 1;
20 }
21
22 if (g_regions[1].frame_counter == 0xFFFFu && g_regions[0].frame_counter != 0xFFFEu) {
23 // Wraparound has occured.
24 return 0;
25 }
26
27 return (g_regions[0].frame_counter > g_regions[1].frame_counter) ? 0 : 1;
28}
29
30static SharedMemory& ReadRegion() {
31 return g_regions[CurrentRegionIndex()];
32}
33
34static SharedMemory& WriteRegion() {
35 return g_regions[1 - CurrentRegionIndex()];
36}
13 37
14void Init() { 38void Init() {
15 DSP::HLE::ResetPipes(); 39 DSP::HLE::ResetPipes();
@@ -22,21 +46,5 @@ bool Tick() {
22 return true; 46 return true;
23} 47}
24 48
25SharedMemory& CurrentRegion() {
26 // The region with the higher frame counter is chosen unless there is wraparound.
27
28 if (g_region0.frame_counter == 0xFFFFu && g_region1.frame_counter != 0xFFFEu) {
29 // Wraparound has occured.
30 return g_region1;
31 }
32
33 if (g_region1.frame_counter == 0xFFFFu && g_region0.frame_counter != 0xFFFEu) {
34 // Wraparound has occured.
35 return g_region0;
36 }
37
38 return (g_region0.frame_counter > g_region1.frame_counter) ? g_region0 : g_region1;
39}
40
41} // namespace HLE 49} // namespace HLE
42} // namespace DSP 50} // namespace DSP