summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Willmann <d.willmann@samsung.com>2013-04-12 19:11:15 +0100
committerDaniel Willmann <d.willmann@samsung.com>2013-04-18 19:14:32 +0100
commite865d5b0a4b8eb41def9c5f6412e650b7660a7d9 (patch)
treefced5dd7ad118f7eeb4ea6da49a4da7ec7f81625
parent542b8743bbae5bba73a7431df570dd034016956f (diff)
downloadefl-e865d5b0a4b8eb41def9c5f6412e650b7660a7d9.tar.gz
ecore_audio: Add tone input class
Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
-rw-r--r--src/Makefile_Ecore_Audio.am2
-rw-r--r--src/lib/ecore_audio/Ecore_Audio.h2
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_in_tone.c199
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_in_tone.h57
-rw-r--r--src/lib/ecore_audio/ecore_audio_private.h8
5 files changed, 260 insertions, 8 deletions
diff --git a/src/Makefile_Ecore_Audio.am b/src/Makefile_Ecore_Audio.am
index ad6a4d623a..7e062702f2 100644
--- a/src/Makefile_Ecore_Audio.am
+++ b/src/Makefile_Ecore_Audio.am
@@ -12,6 +12,7 @@ lib/ecore_audio/ecore_audio_obj_in.h \
lib/ecore_audio/ecore_audio_obj_out.h \
lib/ecore_audio/ecore_audio_obj_in_sndfile.h \
lib/ecore_audio/ecore_audio_obj_out_sndfile.h \
+lib/ecore_audio/ecore_audio_obj_in_tone.h \
lib/ecore_audio/ecore_audio_protected.h
@@ -22,6 +23,7 @@ lib/ecore_audio/ecore_audio_obj_in.c \
lib/ecore_audio/ecore_audio_obj_out.c \
lib/ecore_audio/ecore_audio_obj_in_sndfile.c \
lib/ecore_audio/ecore_audio_obj_out_sndfile.c \
+lib/ecore_audio/ecore_audio_obj_in_tone.c \
lib/ecore_audio/ecore_audio_private.h
lib_ecore_audio_libecore_audio_la_CPPFLAGS = @ECORE_AUDIO_CFLAGS@
diff --git a/src/lib/ecore_audio/Ecore_Audio.h b/src/lib/ecore_audio/Ecore_Audio.h
index ddf34a0497..8a542176e1 100644
--- a/src/lib/ecore_audio/Ecore_Audio.h
+++ b/src/lib/ecore_audio/Ecore_Audio.h
@@ -574,4 +574,6 @@ EAPI void ecore_audio_input_callback_setup(Ecore_Audio_Object *in
#include <ecore_audio_obj_in_sndfile.h>
#include <ecore_audio_obj_out_sndfile.h>
+#include <ecore_audio_obj_in_tone.h>
+
#endif
diff --git a/src/lib/ecore_audio/ecore_audio_obj_in_tone.c b/src/lib/ecore_audio/ecore_audio_obj_in_tone.c
new file mode 100644
index 0000000000..53286cb762
--- /dev/null
+++ b/src/lib/ecore_audio/ecore_audio_obj_in_tone.c
@@ -0,0 +1,199 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef HAVE_FEATURES_H
+#include <features.h>
+#endif
+
+#include <Eo.h>
+#include "ecore_audio_private.h"
+#include <math.h>
+
+EAPI Eo_Op ECORE_AUDIO_OBJ_IN_TONE_BASE_ID = EO_NOOP;
+
+#define MY_CLASS ECORE_AUDIO_OBJ_IN_TONE_CLASS
+#define MY_CLASS_NAME "ecore_audio_obj_in_tone"
+
+struct _Ecore_Audio_Tone
+{
+ int freq;
+ int phase;
+};
+
+typedef struct _Ecore_Audio_Tone Ecore_Audio_Tone;
+
+static void _read(Eo *eo_obj, void *_pd, va_list *list)
+{
+ int i, remain;
+ Ecore_Audio_Tone *obj = _pd;
+ Ecore_Audio_Input *in_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS);
+
+
+ void *data = va_arg(*list, void *);
+ int len = va_arg(*list, int);
+ int *ret = va_arg(*list, int *);
+
+ float *val = data;
+
+ remain = in_obj->length * in_obj->samplerate * 4 - obj->phase * 4;
+ if (remain > len)
+ remain = len;
+
+ for (i=0; i<remain/4; i++) {
+ val[i] = sin(2* M_PI * obj->freq * (obj->phase + i) / in_obj->samplerate);
+ }
+
+ obj->phase += i;
+
+ if (ret)
+ *ret = remain;
+}
+
+static void _seek(Eo *eo_obj, void *_pd, va_list *list)
+{
+ int tmp;
+ Ecore_Audio_Tone *obj = _pd;
+ Ecore_Audio_Input *in_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS);
+
+ double offs = va_arg(*list, double);
+ int mode = va_arg(*list, int);
+ double *ret = va_arg(*list, double *);
+
+ switch (mode) {
+ case SEEK_SET:
+ tmp = offs * in_obj->samplerate;
+ break;
+ case SEEK_CUR:
+ tmp = obj->phase + offs * in_obj->samplerate;
+ break;
+ case SEEK_END:
+ tmp = (in_obj->length + offs) * in_obj->samplerate;
+ break;
+ default:
+ goto err;
+ }
+ if ((tmp < 0) || (tmp > in_obj->length * in_obj->samplerate))
+ goto err;
+
+ obj->phase = tmp;
+
+ if (ret)
+ *ret = (double)obj->phase / in_obj->samplerate;
+
+err:
+ if (ret)
+ *ret = -1.0;
+}
+
+static void _source_set(Eo *eo_obj, void *_pd, va_list *list)
+{
+ Ecore_Audio_Tone *obj = _pd;
+
+ Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
+ Ecore_Audio_Input *in_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS);
+
+ const char *source = va_arg(*list, const char *);
+
+ eina_stringshare_replace(&ea_obj->source, source);
+
+ if (!ea_obj->source)
+ return;
+
+ ea_obj->format = ECORE_AUDIO_FORMAT_AUTO;
+}
+
+static void _source_get(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
+{
+ Ecore_Audio_Object *obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
+
+ const char **ret = va_arg(*list, const char **);
+
+ if (ret)
+ *ret = obj->source;
+}
+
+static void _format_set(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
+{
+ Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
+
+ Ecore_Audio_Format format= va_arg(*list, Ecore_Audio_Format);
+
+ if (ea_obj->source) {
+ ERR("Input is already open - cannot change format");
+ return;
+ }
+
+ switch (format) {
+ default:
+ ERR("Format not supported!");
+ return;
+ }
+ ea_obj->format = format;
+}
+
+static void _format_get(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
+{
+ Ecore_Audio_Object *obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
+
+ Ecore_Audio_Format *ret = va_arg(*list, Ecore_Audio_Format *);
+
+ if (ret)
+ *ret = obj->format;
+}
+
+static void _constructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
+{
+ Ecore_Audio_Tone *obj = _pd;
+ Ecore_Audio_Input *in_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS);
+
+ eo_do_super(eo_obj, MY_CLASS, eo_constructor());
+
+ in_obj->channels = 1;
+ in_obj->samplerate = 44100;
+ in_obj->length = 1;
+
+ obj->freq = 1000;
+}
+
+static void _class_constructor(Eo_Class *klass)
+{
+ const Eo_Op_Func_Description func_desc[] = {
+ /* Virtual functions of parent class implemented in this class */
+ EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
+ //EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
+
+ EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_SOURCE_SET), _source_set),
+ EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_SOURCE_GET), _source_get),
+ EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_SET), _format_set),
+ EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET), _format_get),
+
+ EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SEEK), _seek),
+ EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_READ_INTERNAL), _read),
+
+ EO_OP_FUNC_SENTINEL
+ };
+
+ eo_class_funcs_set(klass, func_desc);
+}
+
+static const Eo_Op_Description op_desc[] = {
+ EO_OP_DESCRIPTION_SENTINEL
+};
+
+static const Eo_Class_Description class_desc = {
+ EO_VERSION,
+ MY_CLASS_NAME,
+ EO_CLASS_TYPE_REGULAR,
+ EO_CLASS_DESCRIPTION_OPS(&ECORE_AUDIO_OBJ_IN_TONE_BASE_ID, op_desc, ECORE_AUDIO_OBJ_IN_TONE_SUB_ID_LAST),
+ NULL,
+ sizeof(Ecore_Audio_Tone),
+ _class_constructor,
+ NULL
+};
+
+EO_DEFINE_CLASS(ecore_audio_obj_in_tone_class_get, &class_desc, ECORE_AUDIO_OBJ_IN_CLASS, NULL);
diff --git a/src/lib/ecore_audio/ecore_audio_obj_in_tone.h b/src/lib/ecore_audio/ecore_audio_obj_in_tone.h
new file mode 100644
index 0000000000..a02669118b
--- /dev/null
+++ b/src/lib/ecore_audio/ecore_audio_obj_in_tone.h
@@ -0,0 +1,57 @@
+#ifndef ECORE_AUDIO_IN_TONE_H
+#define ECORE_AUDIO_IN_TONE_H
+
+#include <Eina.h>
+#include <Eo.h>
+
+#ifdef EAPI
+#undef EAPI
+#endif
+
+#ifdef __GNUC__
+#if __GNUC__ >= 4
+#define EAPI __attribute__ ((visibility("default")))
+#else
+#define EAPI
+#endif
+#else
+#define EAPI
+#endif
+
+/**
+ * @file ecore_audio_obj_in_tone.h
+ * @brief Audio Module
+ */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @addtogroup Ecore_Audio_Group
+ * @{
+ */
+
+#define ECORE_AUDIO_OBJ_IN_TONE_CLASS ecore_audio_obj_in_tone_class_get()
+
+const Eo_Class *ecore_audio_obj_in_tone_class_get() EINA_CONST;
+
+extern EAPI Eo_Op ECORE_AUDIO_OBJ_IN_TONE_BASE_ID;
+
+enum Ecore_Audio_Obj_In_Tone_Sub_Ids
+{
+ ECORE_AUDIO_OBJ_IN_TONE_SUB_ID_LAST
+};
+
+#define ECORE_AUDIO_OBJ_IN_TONE_ID(sub_id) (ECORE_AUDIO_OBJ_IN_TONE_BASE_ID + EO_TYPECHECK(enum Ecore_Audio_Obj_In_Tone_Sub_Ids, sub_id)
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/lib/ecore_audio/ecore_audio_private.h b/src/lib/ecore_audio/ecore_audio_private.h
index 7d74215a19..ef08b74a9b 100644
--- a/src/lib/ecore_audio/ecore_audio_private.h
+++ b/src/lib/ecore_audio/ecore_audio_private.h
@@ -184,14 +184,6 @@ Ecore_Audio_Module *ecore_audio_sndfile_init(void);
void ecore_audio_sndfile_shutdown(void);
#endif /* HAVE_SNDFILE */
-/* ecore_audio_tone */
-struct _Ecore_Audio_Tone
-{
- int freq;
- double duration;
- int phase;
-};
-
Ecore_Audio_Module *ecore_audio_tone_init(void);
void ecore_audio_tone_shutdown(void);