Commit a901142b authored by Adrien Plazas's avatar Adrien Plazas

environment: Bufferize the single audio frames

This improves the performances significantly in cores sending single
audio samples rather than batches, as sending them in batches avoids
emitting many costly signals stupidly often.

Fixes #20
parent a6eb5657
Pipeline #58455 passed with stages
in 5 minutes and 21 seconds
......@@ -55,6 +55,8 @@ struct _RetroCore
gboolean variable_updated;
guint runahead;
gssize run_remaining;
gint16 *audio_samples;
gulong audio_samples_length;
};
void retro_core_push_cb_data (RetroCore *self);
......
......@@ -162,6 +162,7 @@ retro_core_finalize (GObject *object)
g_free (self->content_directory);
g_free (self->save_directory);
g_clear_object (&self->keyboard_widget);
g_free (self->audio_samples);
G_OBJECT_CLASS (retro_core_parent_class)->finalize (object);
}
......
......@@ -6,6 +6,8 @@
#include "retro-input-private.h"
#include "retro-pixdata-private.h"
#define AUDIO_SAMPLES_LENGTH 512
#define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000
#define RETRO_ENVIRONMENT_PRIVATE 0x20000
#define RETRO_ENVIRONMENT_SET_ROTATION 1
......@@ -581,7 +583,6 @@ on_audio_sample (gint16 left,
gint16 right)
{
RetroCore *self;
gint16 samples[] = { left, right };
self = retro_core_get_cb_data ();
......@@ -594,7 +595,19 @@ on_audio_sample (gint16 left,
if (self->sample_rate <= 0.0)
return;
g_signal_emit_by_name (self, "audio_output", samples, 2, self->sample_rate);
if (self->audio_samples == NULL) {
self->audio_samples = g_malloc (AUDIO_SAMPLES_LENGTH * sizeof (gint16));
self->audio_samples_length = 0;
}
self->audio_samples[self->audio_samples_length] = left;
self->audio_samples[self->audio_samples_length + 1] = right;
self->audio_samples_length += 2;
if (self->audio_samples_length == AUDIO_SAMPLES_LENGTH) {
g_signal_emit_by_name (self, "audio_output", self->audio_samples, AUDIO_SAMPLES_LENGTH, self->sample_rate);
self->audio_samples_length = 0;
}
}
static gsize
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment