[retro-gtk/wip/aplazas/audio-samples] environment: Bufferize the single audio frames
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/audio-samples] environment: Bufferize the single audio frames
- Date: Mon, 11 Feb 2019 16:09:28 +0000 (UTC)
commit 93cd305db359107df032c8ceb26a3eb78aa51de6
Author: Adrien Plazas <kekun plazas laposte net>
Date: Mon Feb 11 17:06:37 2019 +0100
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.
retro-gtk/retro-core-private.h | 2 ++
retro-gtk/retro-core.c | 1 +
retro-gtk/retro-environment.c | 17 +++++++++++++++--
3 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/retro-gtk/retro-core-private.h b/retro-gtk/retro-core-private.h
index 4a12d7c..ab1cf11 100644
--- a/retro-gtk/retro-core-private.h
+++ b/retro-gtk/retro-core-private.h
@@ -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);
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index a640405..a8b6a72 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -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);
}
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index 7f5b052..a8b3ddd 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]