This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository enlightenment.

View the commit online.

commit 91e797eab7bb81678a40e58f108b9f6846a98b1d
Author: Carsten Haitzler <[email protected]>
AuthorDate: Sat Jun 18 12:20:05 2022 +0100

    add simple sound play api to play samples
---
 meson.build          |   1 +
 src/bin/e_includes.h |   1 +
 src/bin/e_sound.c    | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/e_sound.h    |  10 +++++
 src/bin/meson.build  |   6 ++-
 5 files changed, 140 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 925e1f537..526ef41f2 100644
--- a/meson.build
+++ b/meson.build
@@ -293,6 +293,7 @@ dep_ecore_con        = dependency('ecore-con'       , required: true)
 dep_ecore_input      = dependency('ecore-input'     , required: true)
 dep_ecore_input_evas = dependency('ecore-input-evas', required: true)
 dep_ecore_evas       = dependency('ecore-evas'      , required: true)
+dep_ecore_audio      = dependency('ecore-audio'     , required: true)
 dep_evas             = dependency('evas'            , required: true)
 dep_edje             = dependency('edje'            , required: true)
 dep_efreet           = dependency('efreet'          , required: true)
diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h
index c2b0e69a9..746573938 100644
--- a/src/bin/e_includes.h
+++ b/src/bin/e_includes.h
@@ -155,6 +155,7 @@
 #include "e_comp_x_randr.h"
 #include "e_watchdog.h"
 #include "e_gesture.h"
+#include "e_sound.h"
 
 #ifdef HAVE_WAYLAND
 # include "e_comp_wl.h"
diff --git a/src/bin/e_sound.c b/src/bin/e_sound.c
new file mode 100644
index 000000000..4f869f51c
--- /dev/null
+++ b/src/bin/e_sound.c
@@ -0,0 +1,123 @@
+#include <e.h>
+
+#include <Ecore_Audio.h>
+
+static int _can_sound_out = -1;
+static Eo *_sound_out = NULL;
+static int _outs = 0;
+static Ecore_Timer *_outs_end_timer = NULL;
+
+static void
+_cb_out_fail(void *data EINA_UNUSED, const Efl_Event *event)
+{
+   efl_unref(event->object);
+   _sound_out = NULL;
+   _can_sound_out = 0;
+}
+
+static void
+_cb_out_ready(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+   _can_sound_out = 1;
+}
+
+static Eina_Bool
+_cb_outs_end_timer(void *data EINA_UNUSED)
+{
+   efl_unref(_sound_out);
+   _sound_out = NULL;
+   return EINA_FALSE;
+}
+
+static void
+_out_end(void)
+{
+   if (_outs > 0) _outs--;
+   if (_outs == 0)
+     {
+        if (_outs_end_timer) ecore_timer_del(_outs_end_timer);
+        _outs_end_timer = ecore_timer_add(2.0, _cb_outs_end_timer, NULL);
+     }
+}
+
+static void
+_cb_in_stopped(void *data EINA_UNUSED, const Efl_Event *event)
+{
+   efl_unref(event->object);
+   _out_end();
+}
+
+E_API int
+e_sound_init(void)
+{
+   ecore_audio_init();
+   return 1;
+}
+
+E_API int
+e_sound_shutdown(void)
+{
+   if (_outs_end_timer)
+     {
+        ecore_timer_del(_outs_end_timer);
+        _outs_end_timer = NULL;
+     }
+   if (_sound_out)
+     {
+        efl_unref(_sound_out);
+        _sound_out = NULL;
+     }
+   ecore_audio_shutdown();
+   return 1;
+}
+
+E_API void
+e_sound_file_play(const char *file, double vol)
+{
+   Eo *in;
+   char buf[PATH_MAX];
+
+   if (_can_sound_out == 0) return;
+   if (!_sound_out)
+     _sound_out = efl_add_ref
+       (ECORE_AUDIO_OUT_PULSE_CLASS, NULL,
+        efl_event_callback_add(efl_added,
+                               ECORE_AUDIO_OUT_PULSE_EVENT_CONTEXT_FAIL,
+                               _cb_out_fail, NULL),
+        efl_event_callback_add(efl_added,
+                               ECORE_AUDIO_OUT_PULSE_EVENT_CONTEXT_READY,
+                               _cb_out_ready, NULL)
+       );
+   if (!_sound_out) return;
+
+   if (_outs_end_timer)
+     {
+        ecore_timer_del(_outs_end_timer);
+        _outs_end_timer = NULL;
+     }
+   _outs++;
+   snprintf(buf, sizeof(buf), "sound-file[%s]", file);
+   in = efl_add_ref(ECORE_AUDIO_IN_SNDFILE_CLASS, NULL,
+                    efl_name_set(efl_added, buf),
+                    efl_event_callback_add(efl_added,
+                                           ECORE_AUDIO_IN_EVENT_IN_STOPPED,
+                                           _cb_in_stopped, NULL));
+   if (!in)
+     {
+        _out_end();
+        return;
+     }
+   if (!ecore_audio_obj_source_set(in, file))
+     {
+        efl_unref(in);
+        _out_end();
+        return;
+     }
+   ecore_audio_obj_volume_set(in, vol);
+   if (!ecore_audio_obj_out_input_attach(_sound_out, in))
+     {
+        efl_unref(in);
+        _out_end();
+        return;
+     }
+}
diff --git a/src/bin/e_sound.h b/src/bin/e_sound.h
new file mode 100644
index 000000000..34be147d6
--- /dev/null
+++ b/src/bin/e_sound.h
@@ -0,0 +1,10 @@
+#ifdef E_TYPEDEFS
+
+#else
+#ifndef E_SOUND_H
+#define E_SOUND_H
+E_API int e_sound_init(void);
+E_API int e_sound_shutdown(void);
+E_API void e_sound_file_play(const char *file, double vol);
+#endif
+#endif
diff --git a/src/bin/meson.build b/src/bin/meson.build
index c530c9333..8f773ed89 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -25,6 +25,7 @@ deps_e = [
   dep_ecore_con,
   dep_ecore_input,
   dep_ecore_input_evas,
+  dep_ecore_audio,
   dep_evas,
   dep_efreet,
   dep_efreet_mime,
@@ -59,6 +60,7 @@ requires_e = ' '.join([
   'ecore-con',
   'ecore-input',
   'ecore-input-evas',
+  'ecore-audio',
   'evas',
   'efreet',
   'efreet-mime',
@@ -224,6 +226,7 @@ src = [
   'e_zoomap.c',
   'e_zone.c',
   'e_gesture.c',
+  'e_sound.c',
   'efx/efx_bumpmapping.c',
   'efx/efx.c',
   'efx/efx_fade.c',
@@ -403,7 +406,8 @@ hdr = [
   'e_xsettings.h',
   'e_zoomap.h',
   'e_zone.h',
-  'e_gesture.h'
+  'e_gesture.h',
+  'e_sound.h'
 ]
 
 if config_h.has('HAVE_WAYLAND') == true

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to