summaryrefslogtreecommitdiff
path: root/src/lib/ecore_audio
diff options
context:
space:
mode:
authorYossi Kantor <yossi.kantor@samsung.com>2014-03-26 18:30:35 +0200
committerDaniel Zaoui <daniel.zaoui@samsung.com>2014-04-02 15:56:14 +0300
commit6295d77a3c7d20c94a5d460692be30139784935b (patch)
tree7ada93b78b0510c75dd23bd1ed30322729eaa4a2 /src/lib/ecore_audio
parent70b39368e61e6740e741f8ff34bb0c1bddbaaacd (diff)
Eolian: Integration of Ecore Audio In Sndfile
Diffstat (limited to 'src/lib/ecore_audio')
-rw-r--r--src/lib/ecore_audio/ecore_audio_in_sndfile.eo15
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c139
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_in_sndfile.h3
3 files changed, 50 insertions, 107 deletions
diff --git a/src/lib/ecore_audio/ecore_audio_in_sndfile.eo b/src/lib/ecore_audio/ecore_audio_in_sndfile.eo
new file mode 100644
index 0000000000..296a3e3339
--- /dev/null
+++ b/src/lib/ecore_audio/ecore_audio_in_sndfile.eo
@@ -0,0 +1,15 @@
1class Ecore_Audio_In_Sndfile (Ecore_Audio_In)
2{
3 eo_prefix: ecore_audio_obj_in_sndfile;
4 implements {
5 Eo_Base::constructor;
6 Eo_Base::destructor;
7 Ecore_Audio::source::set;
8 Ecore_Audio::source::get;
9 Ecore_Audio::format::set;
10 Ecore_Audio::format::get;
11 Ecore_Audio::vio_set;
12 Ecore_Audio_In::seek;
13 Ecore_Audio_In::read_internal;
14 }
15} \ No newline at end of file
diff --git a/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c b/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c
index 4f8e711fed..d18908da79 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c
+++ b/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c
@@ -14,64 +14,42 @@
14#include "ecore_audio_private.h" 14#include "ecore_audio_private.h"
15#include <sndfile.h> 15#include <sndfile.h>
16 16
17EAPI Eo_Op ECORE_AUDIO_OBJ_IN_SNDFILE_BASE_ID = EO_NOOP;
18
19#define MY_CLASS ECORE_AUDIO_OBJ_IN_SNDFILE_CLASS 17#define MY_CLASS ECORE_AUDIO_OBJ_IN_SNDFILE_CLASS
20#define MY_CLASS_NAME "Ecore_Audio_In_Sndfile" 18#define MY_CLASS_NAME "Ecore_Audio_In_Sndfile"
21 19
22extern SF_VIRTUAL_IO vio_wrapper; 20extern SF_VIRTUAL_IO vio_wrapper;
23 21
24struct _Ecore_Audio_Sndfile 22struct _Ecore_Audio_In_Sndfile_Data
25{ 23{
26 SNDFILE *handle; 24 SNDFILE *handle;
27 SF_INFO sfinfo; 25 SF_INFO sfinfo;
28}; 26};
29 27
30typedef struct _Ecore_Audio_Sndfile Ecore_Audio_Sndfile; 28typedef struct _Ecore_Audio_In_Sndfile_Data Ecore_Audio_In_Sndfile_Data;
31 29
32static void _sndfile_read(Eo *eo_obj EINA_UNUSED, void *_pd, va_list *list) 30EOLIAN static ssize_t
31_ecore_audio_in_sndfile_ecore_audio_in_read_internal(Eo *eo_obj EINA_UNUSED, Ecore_Audio_In_Sndfile_Data *obj, void *data, size_t len)
33{ 32{
34 Ecore_Audio_Sndfile *obj = _pd; 33 return sf_read_float(obj->handle, data, len/4)*4;
35 int read;
36 void *data = va_arg(*list, void *);
37 size_t len = va_arg(*list, size_t);
38 ssize_t *ret = va_arg(*list, ssize_t *);
39
40 read = sf_read_float(obj->handle, data, len/4)*4;
41
42 if (ret)
43 *ret = read;
44} 34}
45 35
46static void _seek(Eo *eo_obj EINA_UNUSED, void *_pd, va_list *list) 36EOLIAN static double
37_ecore_audio_in_sndfile_ecore_audio_in_seek(Eo *eo_obj EINA_UNUSED, Ecore_Audio_In_Sndfile_Data *obj, double offs, int mode)
47{ 38{
48 Ecore_Audio_Sndfile *obj = _pd;
49 sf_count_t count, pos; 39 sf_count_t count, pos;
50 40
51 double offs = va_arg(*list, double);
52 int mode = va_arg(*list, int);
53 double *ret = va_arg(*list, double *);
54
55 count = offs * obj->sfinfo.samplerate; 41 count = offs * obj->sfinfo.samplerate;
56 pos = sf_seek(obj->handle, count, mode); 42 pos = sf_seek(obj->handle, count, mode);
57 43
58 if (ret) 44 return (double)pos / obj->sfinfo.samplerate;
59 *ret = (double)pos / obj->sfinfo.samplerate;
60} 45}
61 46
62static void _source_set(Eo *eo_obj, void *_pd, va_list *list) 47EOLIAN static Eina_Bool
48_ecore_audio_in_sndfile_ecore_audio_source_set(Eo *eo_obj, Ecore_Audio_In_Sndfile_Data *obj, const char *source)
63{ 49{
64 Ecore_Audio_Sndfile *obj = _pd;
65
66 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS); 50 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
67 Ecore_Audio_Input *in_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS); 51 Ecore_Audio_Input *in_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS);
68 52
69 const char *source = va_arg(*list, const char *);
70 Eina_Bool *ret = va_arg(*list, Eina_Bool *);
71
72 if (ret)
73 *ret = EINA_FALSE;
74
75 if (obj->handle) { 53 if (obj->handle) {
76 sf_close(obj->handle); 54 sf_close(obj->handle);
77 obj->handle = NULL; 55 obj->handle = NULL;
@@ -80,19 +58,16 @@ static void _source_set(Eo *eo_obj, void *_pd, va_list *list)
80 eina_stringshare_replace(&ea_obj->source, source); 58 eina_stringshare_replace(&ea_obj->source, source);
81 59
82 if (!ea_obj->source) 60 if (!ea_obj->source)
83 return; 61 return EINA_FALSE;
84 62
85 obj->handle = sf_open(ea_obj->source, SFM_READ, &obj->sfinfo); 63 obj->handle = sf_open(ea_obj->source, SFM_READ, &obj->sfinfo);
86 64
87 if (!obj->handle) { 65 if (!obj->handle) {
88 eina_stringshare_del(ea_obj->source); 66 eina_stringshare_del(ea_obj->source);
89 ea_obj->source = NULL; 67 ea_obj->source = NULL;
90 return; 68 return EINA_FALSE;
91 } 69 }
92 70
93 if (ret)
94 *ret = EINA_TRUE;
95
96 in_obj->seekable = EINA_TRUE; 71 in_obj->seekable = EINA_TRUE;
97 in_obj->length = (double)obj->sfinfo.frames / obj->sfinfo.samplerate; 72 in_obj->length = (double)obj->sfinfo.frames / obj->sfinfo.samplerate;
98 73
@@ -107,29 +82,25 @@ static void _source_set(Eo *eo_obj, void *_pd, va_list *list)
107 ea_obj->format = ECORE_AUDIO_FORMAT_FLAC; 82 ea_obj->format = ECORE_AUDIO_FORMAT_FLAC;
108 else 83 else
109 ea_obj->format = ECORE_AUDIO_FORMAT_AUTO; 84 ea_obj->format = ECORE_AUDIO_FORMAT_AUTO;
85
86 return EINA_TRUE;
110} 87}
111 88
112static void _source_get(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list) 89EOLIAN static const char*
90_ecore_audio_in_sndfile_ecore_audio_source_get(Eo *eo_obj, Ecore_Audio_In_Sndfile_Data *_pd EINA_UNUSED)
113{ 91{
114 Ecore_Audio_Object *obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS); 92 Ecore_Audio_Object *obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
115 93 return obj->source;
116 const char **ret = va_arg(*list, const char **);
117
118 if (ret)
119 *ret = obj->source;
120} 94}
121 95
122static void _format_set(Eo *eo_obj, void *_pd, va_list *list) 96EOLIAN static Eina_Bool
97_ecore_audio_in_sndfile_ecore_audio_format_set(Eo *eo_obj, Ecore_Audio_In_Sndfile_Data *obj, Ecore_Audio_Format format)
123{ 98{
124 Ecore_Audio_Sndfile *obj = _pd;
125 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS); 99 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
126 100
127 Ecore_Audio_Format format= va_arg(*list, Ecore_Audio_Format);
128 Eina_Bool *ret = va_arg(*list, Eina_Bool *);
129
130 if (ea_obj->source) { 101 if (ea_obj->source) {
131 ERR("Input is already open - cannot change format"); 102 ERR("Input is already open - cannot change format");
132 return; 103 return EINA_FALSE;
133 } 104 }
134 105
135 switch (format) { 106 switch (format) {
@@ -147,24 +118,18 @@ static void _format_set(Eo *eo_obj, void *_pd, va_list *list)
147 break; 118 break;
148 default: 119 default:
149 ERR("Format not supported!"); 120 ERR("Format not supported!");
150 if (ret) 121 return EINA_FALSE;
151 *ret = EINA_FALSE;
152 return;
153 } 122 }
154 ea_obj->format = format; 123 ea_obj->format = format;
155 124
156 if (ret) 125 return EINA_TRUE;
157 *ret = EINA_TRUE;
158} 126}
159 127
160static void _format_get(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list) 128EOLIAN static Ecore_Audio_Format
129_ecore_audio_in_sndfile_ecore_audio_format_get(Eo *eo_obj, Ecore_Audio_In_Sndfile_Data *_pd EINA_UNUSED)
161{ 130{
162 Ecore_Audio_Object *obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS); 131 Ecore_Audio_Object *obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
163 132 return obj->format;;
164 Ecore_Audio_Format *ret = va_arg(*list, Ecore_Audio_Format *);
165
166 if (ret)
167 *ret = obj->format;
168} 133}
169 134
170static void _free_vio(Ecore_Audio_Object *ea_obj) 135static void _free_vio(Ecore_Audio_Object *ea_obj)
@@ -176,16 +141,12 @@ static void _free_vio(Ecore_Audio_Object *ea_obj)
176 ea_obj->vio = NULL; 141 ea_obj->vio = NULL;
177} 142}
178 143
179static void _vio_set(Eo *eo_obj, void *_pd, va_list *list) 144EOLIAN static void
145_ecore_audio_in_sndfile_ecore_audio_vio_set(Eo *eo_obj, Ecore_Audio_In_Sndfile_Data *obj, Ecore_Audio_Vio *vio, void *data, eo_base_data_free_func free_func)
180{ 146{
181 Ecore_Audio_Sndfile *obj = _pd;
182 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS); 147 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
183 Ecore_Audio_Input *in_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS); 148 Ecore_Audio_Input *in_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS);
184 149
185 Ecore_Audio_Vio *vio = va_arg(*list, Ecore_Audio_Vio *);
186 void *data = va_arg(*list, Ecore_Audio_Vio *);
187 eo_base_data_free_func free_func = va_arg(*list, eo_base_data_free_func);
188
189 if (obj->handle) { 150 if (obj->handle) {
190 sf_close(obj->handle); 151 sf_close(obj->handle);
191 obj->handle = NULL; 152 obj->handle = NULL;
@@ -233,15 +194,16 @@ static void _vio_set(Eo *eo_obj, void *_pd, va_list *list)
233 ea_obj->format = ECORE_AUDIO_FORMAT_AUTO; 194 ea_obj->format = ECORE_AUDIO_FORMAT_AUTO;
234} 195}
235 196
236static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED) 197EOLIAN static void
198_ecore_audio_in_sndfile_eo_base_constructor(Eo *eo_obj, Ecore_Audio_In_Sndfile_Data *_pd EINA_UNUSED)
237{ 199{
238 eo_do_super(eo_obj, MY_CLASS, eo_constructor()); 200 eo_do_super(eo_obj, MY_CLASS, eo_constructor());
239 201
240} 202}
241 203
242static void _destructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED) 204EOLIAN static void
205_ecore_audio_in_sndfile_eo_base_destructor(Eo *eo_obj, Ecore_Audio_In_Sndfile_Data *obj)
243{ 206{
244 Ecore_Audio_Sndfile *obj = _pd;
245 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS); 207 Ecore_Audio_Object *ea_obj = eo_data_scope_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
246 208
247 if (obj->handle) 209 if (obj->handle)
@@ -253,41 +215,4 @@ static void _destructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
253 eo_do_super(eo_obj, MY_CLASS, eo_destructor()); 215 eo_do_super(eo_obj, MY_CLASS, eo_destructor());
254} 216}
255 217
256static void _class_constructor(Eo_Class *klass) 218#include "ecore_audio_in_sndfile.eo.c"
257{
258 const Eo_Op_Func_Description func_desc[] = {
259 /* Virtual functions of parent class implemented in this class */
260 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
261 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
262
263 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_SOURCE_SET), _source_set),
264 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_SOURCE_GET), _source_get),
265 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_SET), _format_set),
266 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET), _format_get),
267
268 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SEEK), _seek),
269 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_READ_INTERNAL), _sndfile_read),
270 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_VIO_SET), _vio_set),
271
272 EO_OP_FUNC_SENTINEL
273 };
274
275 eo_class_funcs_set(klass, func_desc);
276}
277
278static const Eo_Op_Description op_desc[] = {
279 EO_OP_DESCRIPTION_SENTINEL
280};
281
282static const Eo_Class_Description class_desc = {
283 EO_VERSION,
284 MY_CLASS_NAME,
285 EO_CLASS_TYPE_REGULAR,
286 EO_CLASS_DESCRIPTION_OPS(&ECORE_AUDIO_OBJ_IN_SNDFILE_BASE_ID, op_desc, ECORE_AUDIO_OBJ_IN_SNDFILE_SUB_ID_LAST),
287 NULL,
288 sizeof(Ecore_Audio_Sndfile),
289 _class_constructor,
290 NULL
291};
292
293EO_DEFINE_CLASS(ecore_audio_obj_in_sndfile_class_get, &class_desc, ECORE_AUDIO_OBJ_IN_CLASS, NULL);
diff --git a/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.h b/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.h
index 9ed5e7d209..f759d5c9b7 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.h
+++ b/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.h
@@ -33,7 +33,9 @@ extern "C"
33 * @ingroup Ecore_Audio_Group 33 * @ingroup Ecore_Audio_Group
34 * @{ 34 * @{
35 */ 35 */
36#include "ecore_audio_in_sndfile.eo.h"
36 37
38#if 0
37#define ECORE_AUDIO_OBJ_IN_SNDFILE_CLASS ecore_audio_obj_in_sndfile_class_get() /**< Ecore_Audio sndfile input */ 39#define ECORE_AUDIO_OBJ_IN_SNDFILE_CLASS ecore_audio_obj_in_sndfile_class_get() /**< Ecore_Audio sndfile input */
38 40
39/** 41/**
@@ -52,6 +54,7 @@ enum Ecore_Audio_Obj_In_Sndfile_Sub_Ids
52 54
53#define ECORE_AUDIO_OBJ_IN_SNDFILE_ID(sub_id) (ECORE_AUDIO_OBJ_IN_SNDFILE_BASE_ID + EO_TYPECHECK(enum Ecore_Audio_Obj_In_Sndfile_Sub_Ids, sub_id) 55#define ECORE_AUDIO_OBJ_IN_SNDFILE_ID(sub_id) (ECORE_AUDIO_OBJ_IN_SNDFILE_BASE_ID + EO_TYPECHECK(enum Ecore_Audio_Obj_In_Sndfile_Sub_Ids, sub_id)
54 56
57#endif
55/** 58/**
56 * @} 59 * @}
57 */ 60 */