aboutsummaryrefslogtreecommitdiff
path: root/patches/pcsx_rearmed/0001-audio-frameskip.patch
blob: e4160c759edc36c38def764a8f2a589a7e26de68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
diff --git a/frontend/libretro.c b/frontend/libretro.c
index 650676f..0243fa0 100644
--- a/frontend/libretro.c
+++ b/frontend/libretro.c
@@ -96,17 +96,25 @@ static int show_advanced_gpu_unai_settings = -1;
 static int show_other_input_settings = -1;
 static float mouse_sensitivity = 1.0f;
 
-unsigned frameskip_type                  = 0;
-unsigned frameskip_threshold             = 0;
-unsigned frameskip_counter               = 0;
-unsigned frameskip_interval              = 0;
+typedef enum
+{
+   FRAMESKIP_NONE = 0,
+   FRAMESKIP_AUTO,
+   FRAMESKIP_AUTO_THRESHOLD,
+   FRAMESKIP_FIXED_INTERVAL
+} frameskip_type_t;
+
+static unsigned frameskip_type                  = FRAMESKIP_NONE;
+static unsigned frameskip_threshold             = 0;
+static unsigned frameskip_interval              = 0;
+static unsigned frameskip_counter               = 0;
 
-int retro_audio_buff_active              = false;
-unsigned retro_audio_buff_occupancy      = 0;
-int retro_audio_buff_underrun            = false;
+static int retro_audio_buff_active              = false;
+static unsigned retro_audio_buff_occupancy      = 0;
+static int retro_audio_buff_underrun            = false;
 
-unsigned retro_audio_latency             = 0;
-int update_audio_latency                 = false;
+static unsigned retro_audio_latency             = 0;
+static int update_audio_latency                 = false;
 
 static unsigned previous_width = 0;
 static unsigned previous_height = 0;
@@ -1217,20 +1225,33 @@ static void retro_audio_buff_status_cb(
 
 static void retro_set_audio_buff_status_cb(void)
 {
-   if (frameskip_type > 0)
+   if (frameskip_type == FRAMESKIP_NONE)
    {
-      struct retro_audio_buffer_status_callback buf_status_cb;
+      environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL);
+      retro_audio_latency = 0;
+   }
+   else
+   {
+      bool calculate_audio_latency = true;
 
-      buf_status_cb.callback = retro_audio_buff_status_cb;
-      if (!environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK,
-            &buf_status_cb))
+      if (frameskip_type == FRAMESKIP_FIXED_INTERVAL)
+         environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL);
+      else
       {
-         retro_audio_buff_active    = false;
-         retro_audio_buff_occupancy = 0;
-         retro_audio_buff_underrun  = false;
-         retro_audio_latency        = 0;
+         struct retro_audio_buffer_status_callback buf_status_cb;
+         buf_status_cb.callback = retro_audio_buff_status_cb;
+         if (!environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK,
+                         &buf_status_cb))
+         {
+            retro_audio_buff_active    = false;
+            retro_audio_buff_occupancy = 0;
+            retro_audio_buff_underrun  = false;
+            retro_audio_latency        = 0;
+            calculate_audio_latency    = false;
+         }
       }
-      else
+
+      if (calculate_audio_latency)
       {
          /* Frameskip is enabled - increase frontend
           * audio latency to minimise potential
@@ -1244,13 +1265,9 @@ static void retro_set_audio_buff_status_cb(void)
          retro_audio_latency = (retro_audio_latency + 0x1F) & ~0x1F;
       }
    }
-   else
-   {
-      environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL);
-      retro_audio_latency = 0;
-   }
 
    update_audio_latency = true;
+   frameskip_counter    = 0;
 }
 
 static void update_variables(bool in_flight);
@@ -1535,23 +1552,23 @@ static void update_variables(bool in_flight)
 #ifdef GPU_PEOPS
    int gpu_peops_fix = 0;
 #endif
-   unsigned prev_frameskip_type;
+   frameskip_type_t prev_frameskip_type;
 
    var.key = "pcsx_rearmed_frameskip_type";
    var.value = NULL;
 
    prev_frameskip_type = frameskip_type;
-   frameskip_type = 0;
+   frameskip_type = FRAMESKIP_NONE;
    pl_rearmed_cbs.frameskip = 0;
 
    if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
    {
       if (strcmp(var.value, "auto") == 0)
-         frameskip_type = 1;
+         frameskip_type = FRAMESKIP_AUTO;
       if (strcmp(var.value, "auto_threshold") == 0)
-         frameskip_type = 2;
+         frameskip_type = FRAMESKIP_AUTO_THRESHOLD;
       if (strcmp(var.value, "fixed_interval") == 0)
-         frameskip_type = 3;
+         frameskip_type = FRAMESKIP_FIXED_INTERVAL;
    }
 
    if (frameskip_type != 0)
@@ -2639,23 +2656,23 @@ void retro_run(void)
     * be skipped */
    pl_rearmed_cbs.fskip_force = 0;
    pl_rearmed_cbs.fskip_dirty = 0;
-   if ((frameskip_type > 0) && retro_audio_buff_active)
+
+   if (frameskip_type != FRAMESKIP_NONE)
    {
-      bool skip_frame;
+      bool skip_frame = false;
 
       switch (frameskip_type)
       {
-         case 1: /* auto */
-            skip_frame = retro_audio_buff_underrun;
+         case FRAMESKIP_AUTO:
+            skip_frame = retro_audio_buff_active && retro_audio_buff_underrun;
             break;
-         case 2: /* threshold */
-            skip_frame = (retro_audio_buff_occupancy < frameskip_threshold);
+         case FRAMESKIP_AUTO_THRESHOLD:
+            skip_frame = retro_audio_buff_active && (retro_audio_buff_occupancy < frameskip_threshold);
             break;
-         case 3: /* fixed */
+         case FRAMESKIP_FIXED_INTERVAL:
             skip_frame = true;
             break;
          default:
-            skip_frame = false;
             break;
       }
 
@@ -3005,8 +3022,9 @@ void retro_deinit(void)
    /* Have to reset disks struct, otherwise
     * fnames/flabels will leak memory */
    disk_init();
-   frameskip_type             = 0;
+   frameskip_type             = FRAMESKIP_NONE;
    frameskip_threshold        = 0;
+   frameskip_interval         = 0;
    frameskip_counter          = 0;
    retro_audio_buff_active    = false;
    retro_audio_buff_occupancy = 0;
diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h
index 9045791..9188f8b 100644
--- a/frontend/libretro_core_options.h
+++ b/frontend/libretro_core_options.h
@@ -105,7 +105,7 @@ struct retro_core_option_definition option_defs_us[] = {
          { "10", NULL },
          { NULL, NULL },
       },
-      "1"
+      "3"
    },
    {
       "pcsx_rearmed_bios",
diff --git a/frontend/main.c b/frontend/main.c
index bf682ee..05c0f9e 100644
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -156,7 +156,9 @@ void emu_set_default_config(void)
 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) /* XXX GPH hack */
 	spu_config.iUseReverb = 0;
 	spu_config.iUseInterpolation = 0;
+#ifndef(_MIYOO)
 	spu_config.iTempo = 1;
+#endif
 #endif
 	new_dynarec_hacks = 0;
 	cycle_multiplier = 200;