[retro-gtk] Replace Audio interface by Core.audio_output()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] Replace Audio interface by Core.audio_output()
- Date: Tue, 24 Jan 2017 16:20:33 +0000 (UTC)
commit 12b9b1ffd830b6aade1e2701551839be7f84f083
Author: Adrien Plazas <kekun plazas laposte net>
Date: Mon Jan 23 14:03:14 2017 +0100
Replace Audio interface by Core.audio_output()
Remove the Audio interface, add the Core.audio_output() signal and adapt
PaPlayer accordingly.
https://bugzilla.gnome.org/show_bug.cgi?id=777489
retro-gobject/Makefile.am | 1 -
retro-gobject/audio.vala | 37 ----------------
retro-gobject/core.vala | 20 +--------
retro-gobject/retro-environment.c | 28 ++++++++----
retro-gtk/audio/pa-player.vala | 86 ++++++++----------------------------
5 files changed, 38 insertions(+), 134 deletions(-)
---
diff --git a/retro-gobject/Makefile.am b/retro-gobject/Makefile.am
index 5d999c1..64e6558 100644
--- a/retro-gobject/Makefile.am
+++ b/retro-gobject/Makefile.am
@@ -38,7 +38,6 @@ libretro_gobject_la_SOURCES = \
loop/main-loop.vala \
variable/options.vala \
variable/variables.vala \
- audio.vala \
av-info.vala \
core.vala \
disk-controller.vala \
diff --git a/retro-gobject/core.vala b/retro-gobject/core.vala
index 005b588..1b8964d 100644
--- a/retro-gobject/core.vala
+++ b/retro-gobject/core.vala
@@ -12,6 +12,7 @@ public class Core : Object {
private static int i = 0;
public signal void video_output (uint8[] data, uint width, uint height, size_t pitch, PixelFormat
pixel_format, float aspect_ratio);
+ public signal void audio_output (int16[] frames, double sample_rate);
/**
* Stores the current Core instance in a stack.
@@ -157,25 +158,6 @@ public class Core : Object {
*/
public DiskControl disk_control_interface { internal set; get; }
- private weak Audio _audio_interface;
- /**
- * The audio interface.
- *
- * It must be set before {@link init} is called.
- */
- public weak Audio audio_interface {
- get { return _audio_interface; }
- construct set {
- if (_audio_interface != null)
- _audio_interface.core = null;
-
- _audio_interface = value;
-
- if (_audio_interface != null && _audio_interface.core != this)
- _audio_interface.core = this;
- }
- }
-
private weak Input _input_interface;
private ulong input_controller_connected_id;
private ulong input_controller_disconnected_id;
diff --git a/retro-gobject/retro-environment.c b/retro-gobject/retro-environment.c
index 9baa1c1..279883b 100644
--- a/retro-gobject/retro-environment.c
+++ b/retro-gobject/retro-environment.c
@@ -333,36 +333,44 @@ gpointer retro_core_get_module_video_refresh_cb (RetroCore *self) {
static void on_audio_sample (gint16 left, gint16 right) {
RetroCore *self;
- RetroAudio *audio;
+ RetroAvInfo *av_info;
+ gdouble sample_rate;
+ gint16 samples[] = { left, right };
self = retro_core_get_cb_data ();
if (self == NULL)
g_return_if_reached ();
- audio = retro_core_get_audio_interface (self);
+ av_info = retro_core_get_av_info (self);
+ sample_rate = retro_av_info_get_sample_rate (av_info);
- if (audio == NULL)
- g_return_if_reached ();
+ if (sample_rate <= 0.0)
+ return;
- retro_audio_play_sample (audio, left, right);
+ g_signal_emit_by_name (self, "audio_output", samples, 2, sample_rate);
}
static gsize on_audio_sample_batch (gint16* data, int frames) {
RetroCore *self;
- RetroAudio *audio;
+ RetroAvInfo *av_info;
+ gdouble sample_rate;
self = retro_core_get_cb_data ();
if (self == NULL)
g_return_val_if_reached (0);
- audio = retro_core_get_audio_interface (self);
+ av_info = retro_core_get_av_info (self);
+ sample_rate = retro_av_info_get_sample_rate (av_info);
+
+ if (sample_rate <= 0.0)
+ return 0;
- if (audio == NULL)
- g_return_val_if_reached (0);
+ g_signal_emit_by_name (self, "audio_output", data, frames * 2, sample_rate);
- return retro_audio_play_batch (audio, data, frames * 2, frames);
+ // FIXME What should be returned?
+ return 0;
}
static void on_input_poll () {
diff --git a/retro-gtk/audio/pa-player.vala b/retro-gtk/audio/pa-player.vala
index 700397f..c9206a3 100644
--- a/retro-gtk/audio/pa-player.vala
+++ b/retro-gtk/audio/pa-player.vala
@@ -6,88 +6,40 @@ using Retro;
namespace RetroGtk {
-public class PaPlayer : GLib.Object, Retro.Audio {
- private ulong av_info_sig = 0;
- private ulong init_sig = 0;
-
- private Core _core;
- public Core core {
- get { return _core; }
- set {
- if (_core == value) return;
-
- if (_core != null && av_info_sig != 0) {
- _core.disconnect (av_info_sig);
- _core.disconnect (init_sig);
- av_info_sig = 0;
- }
-
- _core = value;
+public class PaPlayer : GLib.Object {
+ private Retro.Core core;
+ private ulong on_audio_output_id;
+ private double sample_rate;
+ private Simple simple;
- if (_core != null) {
- update_sample_rate ();
- av_info_sig = _core.notify["av-info"].connect_after (update_sample_rate);
+ public void set_core (Retro.Core core) {
+ if (this.core != null)
+ this.core.disconnect (on_audio_output_id);
- if (_core.audio_interface != this)
- _core.audio_interface = this;
- }
- }
+ this.core = core;
+ on_audio_output_id = core.audio_output.connect (on_audio_output);
+ simple = null;
}
- private Simple simple;
+ private void on_audio_output (int16[] data, double sample_rate) {
+ if (simple == null || sample_rate != this.sample_rate)
+ prepare_for_sample_rate (sample_rate);
- public PaPlayer (uint32 sample_rate = 44100) {
- Object (sample_rate: sample_rate);
+ simple.write (data, sizeof (int16) * data.length);
}
- construct {
+ private void prepare_for_sample_rate (double sample_rate) {
+ this.sample_rate = sample_rate;
+
var sample_spec = SampleSpec() {
format = SampleFormat.S16NE,
- rate = sample_rate,
+ rate = (uint32) sample_rate,
channels = 2
};
simple = new Simple (null, null, Stream.Direction.PLAYBACK,
null, "", sample_spec, null, null,
null);
}
-
- private uint32 _sample_rate;
- public uint32 sample_rate {
- get { return _sample_rate; }
- set {
- if (_sample_rate == value) return;
-
- _sample_rate = value;
-
- var sample_spec = SampleSpec() {
- format = SampleFormat.S16NE,
- rate = value,
- channels = 2
- };
- simple = new Simple (null, null, Stream.Direction.PLAYBACK,
- null, "", sample_spec, null, null,
- null);
- }
- default = 44100;
- }
-
- private void play_sample (int16 left, int16 right) {
- int16[] data = { left, right };
- simple.write (data, sizeof (int16) * data.length);
- }
-
- private size_t play_batch (int16[] data, size_t frames) {
- simple.write (data, sizeof (int16) * data.length);
-
- return 0;
- }
-
- private void update_sample_rate () {
- if (core == null) return;
-
- var info = _core.av_info;
- if (info != null) sample_rate = (uint32) info.sample_rate;
- }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]