summaryrefslogtreecommitdiff
path: root/src/lib/ecore_audio
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-26 21:35:17 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-26 21:35:17 +0900
commit0df9bd2cdb987f795e69265b4c3cbabc8fda1466 (patch)
tree43e4d0bf751c58010ddab577018ca9db3a54f25f /src/lib/ecore_audio
parentb6f4af28b24481ab33dccfd1522538fdb6b42a58 (diff)
ecore-audio: remove src files that are never compiled
Diffstat (limited to 'src/lib/ecore_audio')
-rw-r--r--src/lib/ecore_audio/ecore_audio_sndfile.c489
-rw-r--r--src/lib/ecore_audio/ecore_audio_tone.c158
2 files changed, 0 insertions, 647 deletions
diff --git a/src/lib/ecore_audio/ecore_audio_sndfile.c b/src/lib/ecore_audio/ecore_audio_sndfile.c
deleted file mode 100644
index ee3a930bc1..0000000000
--- a/src/lib/ecore_audio/ecore_audio_sndfile.c
+++ /dev/null
@@ -1,489 +0,0 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#ifdef HAVE_SNDFILE
6#include "Ecore.h"
7#include "ecore_private.h"
8#include "Ecore_Audio.h"
9#include "ecore_audio_private.h"
10
11#include <sndfile.h>
12
13static Ecore_Audio_Module *module = NULL;
14
15/* Virtual IO wrapper functions */
16
17static sf_count_t _sndfile_wrap_get_filelen(void *data)
18{
19 Ecore_Audio_Object *obj = data;
20 struct _Ecore_Audio_Sndfile *sndfile = obj->module_data;
21
22 if (!sndfile->vio)
23 goto error;
24
25 if (sndfile->vio->get_length)
26 return sndfile->vio->get_length(obj);
27
28error:
29 return -1;
30}
31
32static sf_count_t _sndfile_wrap_seek(sf_count_t offset, int whence, void *data)
33{
34 Ecore_Audio_Object *obj = data;
35 struct _Ecore_Audio_Sndfile *sndfile = obj->module_data;
36
37 if (!sndfile->vio)
38 goto error;
39
40 if (sndfile->vio->seek)
41 return sndfile->vio->seek(obj, offset, whence);
42
43error:
44 return -1;
45}
46
47static sf_count_t _sndfile_wrap_read(void *buffer, sf_count_t count, void *data)
48{
49 Ecore_Audio_Object *obj = data;
50 struct _Ecore_Audio_Sndfile *sndfile = obj->module_data;
51
52 if (!sndfile->vio)
53 goto error;
54
55 if (sndfile->vio->read)
56 return sndfile->vio->read(obj, buffer, count);
57
58error:
59 return 0;
60}
61
62static sf_count_t _sndfile_wrap_write(const void *buffer, sf_count_t count, void *data)
63{
64 Ecore_Audio_Object *obj = data;
65 struct _Ecore_Audio_Sndfile *sndfile = obj->module_data;
66
67 if (!sndfile->vio)
68 goto error;
69
70 if (sndfile->vio->write)
71 return sndfile->vio->write(obj, buffer, count);
72
73error:
74 return 0;
75}
76
77static sf_count_t _sndfile_wrap_tell(void *data)
78{
79 Ecore_Audio_Object *obj = data;
80 struct _Ecore_Audio_Sndfile *sndfile = obj->module_data;
81
82 if (!sndfile->vio)
83 goto error;
84
85 if (sndfile->vio->tell)
86 return sndfile->vio->tell(obj);
87
88error:
89 return -1;
90}
91
92/* End virtual IO wrapper functions */
93
94static Ecore_Audio_Object *
95_sndfile_input_new(Ecore_Audio_Object *input)
96{
97 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
98 struct _Ecore_Audio_Sndfile *sndfile;
99
100 sndfile = calloc(1, sizeof(struct _Ecore_Audio_Sndfile));
101 if (!sndfile)
102 {
103 ERR("Could not allocate memory for private structure.");
104 free(in);
105 return NULL;
106 }
107
108 in->module_data = sndfile;
109
110 sndfile->sfinfo.format = 0;
111 sndfile->volume = 1.0;
112
113 return (Ecore_Audio_Object *)in;
114}
115
116static void
117_sndfile_input_del(Ecore_Audio_Object *input)
118{
119 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
120 struct _Ecore_Audio_Sndfile *sndfile = in->module_data;
121
122 eina_stringshare_del(sndfile->filename);
123
124 sf_close(sndfile->handle);
125 free(sndfile);
126}
127
128static int
129_sndfile_input_read(Ecore_Audio_Object *input, void *data, int len)
130{
131 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
132 struct _Ecore_Audio_Sndfile *sndfile = in->module_data;
133 int read;
134
135 /* FIXME: Nicer way to return bytes read instead of items */
136 read = sf_read_float(sndfile->handle, data, len / 4) * 4;
137
138 return read;
139}
140
141static double
142_sndfile_input_seek(Ecore_Audio_Object *input, double offs, int mode)
143{
144 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
145 struct _Ecore_Audio_Sndfile *sndfile = in->module_data;
146 sf_count_t count, pos;
147
148 count = offs * sndfile->sfinfo.samplerate;
149 pos = sf_seek(sndfile->handle, count, mode);
150 return (double)pos / sndfile->sfinfo.samplerate;
151}
152
153static struct input_api inops = {
154 .input_new = _sndfile_input_new,
155 .input_del = _sndfile_input_del,
156 .input_read = _sndfile_input_read,
157 .input_seek = _sndfile_input_seek,
158};
159
160EAPI void ecore_audio_input_sndfile_format_set(Ecore_Audio_Object *input, int format)
161{
162 Ecore_Audio_Output *in = (Ecore_Audio_Output *)input;
163 struct _Ecore_Audio_Sndfile *sndfile = in->module_data;
164
165 sndfile->sfinfo.format = format;
166}
167
168void ecore_audio_input_sndfile_filename_set(Ecore_Audio_Object *input, const char *filename)
169{
170 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
171 struct _Ecore_Audio_Sndfile *sndfile = in->module_data;
172
173 if (sndfile->handle)
174 sf_close(sndfile->handle);
175
176 if (sndfile->filename)
177 eina_stringshare_del(sndfile->filename);
178
179 if (sndfile->vio)
180 {
181 free(sndfile->vio);
182 sndfile->vio = NULL;
183 }
184
185 sndfile->filename = eina_stringshare_add(filename);
186
187 sndfile->handle = sf_open(sndfile->filename, SFM_READ, &sndfile->sfinfo);
188
189 in->length = (double)sndfile->sfinfo.frames / sndfile->sfinfo.samplerate;
190
191 // XXX: Propagate samplerate/channel update to output
192 in->samplerate = sndfile->sfinfo.samplerate;
193 in->channels = sndfile->sfinfo.channels;
194}
195
196void ecore_audio_input_sndfile_vio_set(Ecore_Audio_Object *input, Ecore_Audio_Vio *vio)
197{
198 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
199 struct _Ecore_Audio_Sndfile *sndfile = in->module_data;
200 struct _Ecore_Audio_Sndfile_Private *priv = in->module->priv;
201
202 if (sndfile->handle)
203 sf_close(sndfile->handle);
204
205 if (sndfile->filename)
206 {
207 eina_stringshare_del(sndfile->filename);
208 sndfile->filename = NULL;
209 }
210
211 if (sndfile->vio)
212 free(sndfile->vio);
213
214 sndfile->vio = calloc(1, sizeof(Ecore_Audio_Vio));
215 sndfile->vio->get_length = vio->get_length;
216 sndfile->vio->seek = vio->seek;
217 sndfile->vio->read = vio->read;
218 sndfile->vio->tell = vio->tell;
219
220 if (sndfile->sfinfo.format != 0) {
221 sndfile->sfinfo.samplerate = in->samplerate;
222 sndfile->sfinfo.channels = in->channels;
223 }
224
225 sndfile->handle = sf_open_virtual(&priv->vio_wrapper, SFM_READ, &sndfile->sfinfo, in);
226
227 in->length = (double)sndfile->sfinfo.frames / sndfile->sfinfo.samplerate;
228
229 // XXX: Propagate samplerate/channel update to output
230 in->samplerate = sndfile->sfinfo.samplerate;
231 in->channels = sndfile->sfinfo.channels;
232}
233
234static Ecore_Audio_Object *
235_sndfile_output_new(Ecore_Audio_Object *output)
236{
237 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
238 struct _Ecore_Audio_Sndfile *sndfile;
239
240 sndfile = calloc(1, sizeof(struct _Ecore_Audio_Sndfile));
241 if (!sndfile)
242 {
243 ERR("Could not allocate memory for private structure.");
244 free(out);
245 return NULL;
246 }
247
248 out->module_data = sndfile;
249
250 sndfile->sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS;
251
252 return (Ecore_Audio_Object *)out;
253}
254
255static void
256_sndfile_output_del(Ecore_Audio_Object *output)
257{
258 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
259 struct _Ecore_Audio_Sndfile *sndfile = out->module_data;
260
261 eina_stringshare_del(sndfile->filename);
262 free(sndfile->vio);
263
264 sf_close(sndfile->handle);
265 free(sndfile);
266}
267
268static void
269_sndfile_output_volume_set(Ecore_Audio_Object *output, double volume)
270{
271 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
272 struct _Ecore_Audio_Sndfile *sndfile = out->module_data;
273
274 if ((volume < 0) || (volume > 1.0))
275 return;
276
277 sndfile->volume = volume;
278}
279
280static double
281_sndfile_output_volume_get(Ecore_Audio_Object *output)
282{
283 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
284 struct _Ecore_Audio_Sndfile *sndfile = out->module_data;
285
286 return sndfile->volume;
287}
288
289static Eina_Bool
290_sndfile_output_write_cb(void *data)
291{
292 Ecore_Audio_Output *out = (Ecore_Audio_Output *)data;
293 struct _Ecore_Audio_Sndfile *sndfile = out->module_data;
294 Ecore_Audio_Input *in;
295 int written, bread;
296 void *buf;
297
298 buf = malloc(1024);
299
300 in = eina_list_data_get(out->inputs);
301
302 bread = ecore_audio_input_read((Ecore_Audio_Object *)in, buf, 1024);
303 DBG("read: %i", bread);
304 if (bread == 0)
305 {
306 DBG("read done");
307 out->paused = EINA_TRUE;
308 return EINA_FALSE;
309 }
310
311 // XXX: Check for errors
312 written = sf_write_float(sndfile->handle, buf, bread/4)*4;
313 DBG("written: %i", written);
314
315 return EINA_TRUE;
316}
317
318static void
319_sndfile_output_paused_set(Ecore_Audio_Object *output, Eina_Bool paused)
320{
321 struct _Ecore_Audio_Sndfile *sndfile = output->module_data;
322 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
323
324 if (paused && sndfile->timer)
325 ecore_timer_del(sndfile->timer);
326 else if (out->inputs)
327 sndfile->timer = ecore_timer_add(0.01, _sndfile_output_write_cb, output);
328}
329
330static Eina_Bool
331_sndfile_output_add_input(Ecore_Audio_Object *output, Ecore_Audio_Object *input)
332{
333 struct _Ecore_Audio_Sndfile *sndfile = output->module_data;
334 struct _Ecore_Audio_Sndfile_Private *priv = output->module->priv;
335
336 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
337 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
338
339 sndfile->sfinfo.samplerate = in->samplerate;
340 sndfile->sfinfo.channels = in->channels;
341
342 if (sndfile->vio)
343 sndfile->handle = sf_open_virtual(&priv->vio_wrapper, SFM_WRITE, &sndfile->sfinfo, out);
344 else if (sndfile->filename)
345 sndfile->handle = sf_open(sndfile->filename, SFM_WRITE, &sndfile->sfinfo);
346
347 if (output->paused)
348 return EINA_TRUE;
349
350 if (!out->inputs)
351 sndfile->timer = ecore_timer_add(0.01, _sndfile_output_write_cb, output);
352
353 return EINA_TRUE;
354}
355
356static Eina_Bool
357_sndfile_output_del_input(Ecore_Audio_Object *out EINA_UNUSED, Ecore_Audio_Object *in EINA_UNUSED)
358{
359 //XXX: Check if it's the last one and pause the timer
360 return EINA_TRUE;
361}
362
363static void
364_sndfile_output_update_input_format(Ecore_Audio_Object *out EINA_UNUSED, Ecore_Audio_Object *in EINA_UNUSED)
365{
366}
367
368static struct output_api outops = {
369 .output_new = _sndfile_output_new,
370 .output_del = _sndfile_output_del,
371 .output_volume_set = _sndfile_output_volume_set,
372 .output_volume_get = _sndfile_output_volume_get,
373 .output_paused_set = _sndfile_output_paused_set,
374 .output_add_input = _sndfile_output_add_input,
375 .output_del_input = _sndfile_output_del_input,
376 .output_update_input_format = _sndfile_output_update_input_format,
377};
378
379EAPI void ecore_audio_output_sndfile_filename_set(Ecore_Audio_Object *output, const char *filename)
380{
381 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
382 struct _Ecore_Audio_Sndfile *sndfile = out->module_data;
383
384 if (sndfile->handle)
385 sf_close(sndfile->handle);
386
387 if (sndfile->filename)
388 eina_stringshare_del(sndfile->filename);
389
390 if (sndfile->vio)
391 {
392 free(sndfile->vio);
393 sndfile->vio = NULL;
394 }
395
396 sndfile->filename = eina_stringshare_add(filename);
397}
398
399EAPI void ecore_audio_output_sndfile_format_set(Ecore_Audio_Object *output, int format)
400{
401 Ecore_Audio_Output *out = (Ecore_Audio_Output *)output;
402 struct _Ecore_Audio_Sndfile *sndfile = out->module_data;
403
404 sndfile->sfinfo.format = format;
405}
406
407EAPI void ecore_audio_output_sndfile_vio_set(Ecore_Audio_Object *output, Ecore_Audio_Vio *vio)
408{
409 struct _Ecore_Audio_Sndfile *sndfile = output->module_data;
410
411 if (sndfile->handle)
412 sf_close(sndfile->handle);
413
414 if (sndfile->filename)
415 {
416 eina_stringshare_del(sndfile->filename);
417 sndfile->filename = NULL;
418 }
419
420 if (sndfile->vio)
421 free(sndfile->vio);
422
423 sndfile->vio = calloc(1, sizeof(Ecore_Audio_Vio));
424 sndfile->vio->get_length = vio->get_length;
425 sndfile->vio->seek = vio->seek;
426 sndfile->vio->write = vio->write;
427 sndfile->vio->tell = vio->tell;
428}
429
430/**
431 * @brief Initialize the Ecore_Audio sndfile module
432 *
433 * @return the initialized module on success, NULL on error
434 */
435Ecore_Audio_Module *
436ecore_audio_sndfile_init(void)
437{
438 struct _Ecore_Audio_Sndfile_Private *priv;
439
440 module = calloc(1, sizeof(Ecore_Audio_Module));
441 if (!module)
442 {
443 ERR("Could not allocate memory for module.");
444 return NULL;
445 }
446
447 priv = calloc(1, sizeof(struct _Ecore_Audio_Sndfile_Private));
448 if (!priv)
449 {
450 ERR("Could not allocate memory for private module region.");
451 free(module);
452 return NULL;
453 }
454
455 priv->vio_wrapper.get_filelen = _sndfile_wrap_get_filelen;
456 priv->vio_wrapper.seek = _sndfile_wrap_seek;
457 priv->vio_wrapper.read = _sndfile_wrap_read;
458 priv->vio_wrapper.write = _sndfile_wrap_write;
459 priv->vio_wrapper.tell = _sndfile_wrap_tell;
460
461 ECORE_MAGIC_SET(module, ECORE_MAGIC_AUDIO_MODULE);
462 module->type = ECORE_AUDIO_TYPE_SNDFILE;
463 module->name = "sndfile";
464 module->priv = priv;
465 module->inputs = NULL;
466 module->outputs = NULL;
467 module->in_ops = &inops;
468 module->out_ops = &outops;
469
470 DBG("Initialized");
471 return module;
472}
473
474/**
475 * @brief Shut down the Ecore_Audio sndfile module
476 */
477void
478ecore_audio_sndfile_shutdown(void)
479{
480 struct _Ecore_Audio_Sndfile_Private *priv = (struct _Ecore_Audio_Sndfile_Private *)module->priv;
481
482 free(priv);
483 free(module);
484 module = NULL;
485
486 DBG("Shutting down");
487}
488
489#endif /* HAVE_SNDFILE */
diff --git a/src/lib/ecore_audio/ecore_audio_tone.c b/src/lib/ecore_audio/ecore_audio_tone.c
deleted file mode 100644
index 08713c1db9..0000000000
--- a/src/lib/ecore_audio/ecore_audio_tone.c
+++ /dev/null
@@ -1,158 +0,0 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include "Ecore.h"
6#include "ecore_private.h"
7#include "Ecore_Audio.h"
8#include "ecore_audio_private.h"
9
10#include <math.h>
11
12static Ecore_Audio_Module *module = NULL;
13
14static Ecore_Audio_Object *
15_tone_input_new(Ecore_Audio_Object *input)
16{
17 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
18 struct _Ecore_Audio_Tone *tone;
19
20 tone = calloc(1, sizeof(struct _Ecore_Audio_Tone));
21 if (!tone)
22 {
23 ERR("Could not allocate memory for private structure.");
24 free(in);
25 return NULL;
26 }
27
28 in->samplerate = 44100;
29 in->channels = 1;
30
31 in->module_data = tone;
32
33 in->length = 1;
34 tone->freq = 1000;
35 tone->phase = 0;
36
37 return (Ecore_Audio_Object *)in;
38}
39
40static void
41_tone_input_del(Ecore_Audio_Object *input)
42{
43 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
44 free(in->module_data);
45}
46
47static int
48_tone_input_read(Ecore_Audio_Object *input, void *data, int len)
49{
50 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
51 struct _Ecore_Audio_Tone *tone = in->module_data;
52 float *val = data;
53 int i, remain;
54
55 remain = in->length * in->samplerate * 4 - tone->phase * 4;
56 if (remain > len)
57 remain = len;
58
59 for (i = 0; i < remain / 4; i++)
60 {
61 val[i] = sin(2 * M_PI * tone->freq * (tone->phase + i) / in->samplerate);
62 }
63 tone->phase += i;
64
65 return remain;
66}
67
68static double
69_tone_input_seek(Ecore_Audio_Object *input, double offs, int mode)
70{
71 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
72 struct _Ecore_Audio_Tone *tone = in->module_data;
73 int tmp;
74
75 switch (mode) {
76 case SEEK_SET:
77 tmp = offs * in->samplerate;
78 break;
79 case SEEK_CUR:
80 tmp = tone->phase + offs * in->samplerate;
81 break;
82 case SEEK_END:
83 tmp = (in->length + offs) * in->samplerate;
84 break;
85 default:
86 return -1;
87 }
88
89 if ((tmp < 0) || (tmp > in->length * in->samplerate))
90 return -1;
91
92 tone->phase = tmp;
93 return (double)tone->phase / in->samplerate;
94}
95
96static struct input_api inops = {
97 .input_new = _tone_input_new,
98 .input_del = _tone_input_del,
99 .input_read = _tone_input_read,
100 .input_seek = _tone_input_seek,
101};
102
103EAPI void ecore_audio_input_tone_frequency_set(Ecore_Audio_Object *input, int freq)
104{
105 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
106 struct _Ecore_Audio_Tone *tone = in->module_data;
107
108 tone->freq = freq;
109}
110
111EAPI void ecore_audio_input_tone_duration_set(Ecore_Audio_Object *input, double duration)
112{
113 Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
114
115 in->length = duration;
116}
117
118
119/**
120 * @brief Initialize the Ecore_Audio sndfile module
121 *
122 * @return the initialized module on success, NULL on error
123 */
124Ecore_Audio_Module *
125ecore_audio_tone_init(void)
126{
127 module = calloc(1, sizeof(Ecore_Audio_Module));
128 if (!module)
129 {
130 ERR("Could not allocate memory for module.");
131 return NULL;
132 }
133
134 ECORE_MAGIC_SET(module, ECORE_MAGIC_AUDIO_MODULE);
135 module->type = ECORE_AUDIO_TYPE_TONE;
136 module->name = "tone";
137 module->priv = NULL;
138 module->inputs = NULL;
139 module->outputs = NULL;
140 module->in_ops = &inops;
141 module->out_ops = NULL;
142
143 DBG("Initialized");
144 return module;
145}
146
147/**
148 * @brief Shut down the Ecore_Audio sndfile module
149 */
150void
151ecore_audio_tone_shutdown(void)
152{
153 free(module);
154 module = NULL;
155
156 DBG("Shutting down");
157}
158