[Scummvm-git-logs] scummvm master -> c8b2cdb3815db26a7a500c034c1378e03db96f38

spleen1981 noreply at scummvm.org
Sat Mar 18 09:20:49 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a7d7d1803f LIBRETRO: add environment target refresh rate
c8b2cdb381 LIBRETRO: fix samples_per_frame buffer size and refactoring


Commit: a7d7d1803f23fc1b6b18df9e6f08ce15c3deac9d
    https://github.com/scummvm/scummvm/commit/a7d7d1803f23fc1b6b18df9e6f08ce15c3deac9d
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-03-18T10:17:58+01:00

Commit Message:
LIBRETRO: add environment target refresh rate

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 01bd09a3f6f..956881b236a 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -91,6 +91,7 @@ static uint8 audio_status = 0;
 
 static unsigned retro_audio_buff_occupancy = 0;
 
+float frame_rate;
 static uint16 fps = 0;
 static uint16 sound_len = 0;                // length in samples per frame
 static size_t sound_size = 0;
@@ -368,7 +369,9 @@ void retro_init(void) {
 	else
 		log_cb = NULL;
 
-	audio_buffer_init(SAMPLE_RATE, REFRESH_RATE);
+	frame_rate = environ_cb(RETRO_ENVIRONMENT_GET_TARGET_REFRESH_RATE, &frame_rate) ? frame_rate : REFRESH_RATE;
+
+	audio_buffer_init(SAMPLE_RATE, (uint16) frame_rate);
 	update_variables();
 
 	environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &can_dupe);
@@ -642,7 +645,7 @@ void retro_run(void) {
 		 * available (i.e. when the overlay
 		 * is shown) */
 		if (audio_status & AUDIO_STATUS_MUTE) {
-			audio_buffer_init(SAMPLE_RATE, REFRESH_RATE);
+			audio_buffer_init(SAMPLE_RATE, (uint16) frame_rate);
 		}
 #endif
 		audio_batch_cb((audio_status & AUDIO_STATUS_MUTE) ? NULL : sound_buffer, count); // Set to NULL to skip sound rendering


Commit: c8b2cdb3815db26a7a500c034c1378e03db96f38
    https://github.com/scummvm/scummvm/commit/c8b2cdb3815db26a7a500c034c1378e03db96f38
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-03-18T10:18:25+01:00

Commit Message:
LIBRETRO: fix samples_per_frame buffer size and refactoring

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 956881b236a..4e5f8d54355 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -92,22 +92,21 @@ static uint8 audio_status = 0;
 static unsigned retro_audio_buff_occupancy = 0;
 
 float frame_rate;
-static uint16 fps = 0;
-static uint16 sound_len = 0;                // length in samples per frame
-static size_t sound_size = 0;
+static uint16 samples_per_frame = 0;                // length in samples per frame
+static size_t samples_per_frame_buffer_size = 0;
 
 static int16_t *sound_buffer = NULL;       // pointer to output buffer
 
 static void audio_buffer_init(uint16 sample_rate, uint16 frame_rate) {
-	fps = 100.0 * frame_rate;
-	sound_len = (sample_rate * 100 + (fps >> 1)) / fps;
-	sound_size = sound_len << 2 * sizeof(int16_t);
+	samples_per_frame = sample_rate / frame_rate;
+	samples_per_frame_buffer_size = samples_per_frame << 1 * sizeof(int16_t);
+
 	if (sound_buffer)
-		sound_buffer = (int16_t *)realloc(sound_buffer, sound_size);
+		sound_buffer = (int16_t *)realloc(sound_buffer, samples_per_frame_buffer_size);
 	else
-		sound_buffer = (int16_t *)malloc(sound_size);
+		sound_buffer = (int16_t *)malloc(samples_per_frame_buffer_size);
 	if (sound_buffer)
-		memset(sound_buffer, 0, sound_size);
+		memset(sound_buffer, 0, samples_per_frame_buffer_size);
 	else
 		log_cb(RETRO_LOG_ERROR, "audio_buffer_init error.\n");
 
@@ -616,7 +615,7 @@ void retro_run(void) {
 		/* Upload audio */
 		size_t count = 0;
 		if (audio_video_enable & 2) {
-			count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *)sound_buffer, sound_size);
+			count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
 		}
 		audio_status = count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
 
@@ -648,7 +647,7 @@ void retro_run(void) {
 			audio_buffer_init(SAMPLE_RATE, (uint16) frame_rate);
 		}
 #endif
-		audio_batch_cb((audio_status & AUDIO_STATUS_MUTE) ? NULL : sound_buffer, count); // Set to NULL to skip sound rendering
+		audio_batch_cb((audio_status & AUDIO_STATUS_MUTE) ? NULL : (int16_t *) sound_buffer, count); // Set to NULL to skip sound rendering
 
 		current_frame++;
 	}
@@ -661,7 +660,7 @@ void retro_run(void) {
 	if (audio_status & AUDIO_STATUS_UPDATE_LATENCY){
 		uint32 audio_latency;
 		if (frameskip_type > 1) {
-			float frame_time_msec = 100000.0f / fps;
+			float frame_time_msec = 1000.0f / frame_rate;
 
 			audio_latency = (uint32)((8.0f * frame_time_msec) + 0.5f);
 			audio_latency = (audio_latency + 0x1F) & ~0x1F;




More information about the Scummvm-git-logs mailing list