summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_ecore_audio.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-26 18:33:36 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-26 18:33:36 +0900
commitb6f4af28b24481ab33dccfd1522538fdb6b42a58 (patch)
tree6e83240bfa2818fd56be9591517e51523bcb7cc1 /src/tests/ecore/ecore_test_ecore_audio.c
parent01a4b8bacb49094dc3b3f0ecd69129081e6ae98c (diff)
ecore audio: tests - remove #if0'd out code
Diffstat (limited to 'src/tests/ecore/ecore_test_ecore_audio.c')
-rw-r--r--src/tests/ecore/ecore_test_ecore_audio.c227
1 files changed, 0 insertions, 227 deletions
diff --git a/src/tests/ecore/ecore_test_ecore_audio.c b/src/tests/ecore/ecore_test_ecore_audio.c
index a3d45aa..0a55e3f 100644
--- a/src/tests/ecore/ecore_test_ecore_audio.c
+++ b/src/tests/ecore/ecore_test_ecore_audio.c
@@ -13,233 +13,6 @@
13#include <Ecore.h> 13#include <Ecore.h>
14#include <Ecore_Audio.h> 14#include <Ecore_Audio.h>
15 15
16#if 0
17
18
19Eina_Bool
20output_add_default(void *data)
21{
22 out = ecore_audio_output_add(ECORE_AUDIO_TYPE_PULSE);
23 fail_if(!out);
24
25 printf("Adding input\n");
26 ecore_audio_output_input_add(out, in);
27
28 return EINA_FALSE;
29}
30
31Eina_Bool
32input_resume(void *data)
33{
34 double pos;
35
36 fail_if(ecore_audio_input_paused_get(in) != EINA_TRUE);
37 fail_if(ecore_audio_input_seek(in, 0, SEEK_CUR) != 0);
38 ecore_audio_input_paused_set(in, EINA_FALSE);
39
40 ecore_audio_input_looped_set(in, EINA_TRUE);
41
42 return EINA_FALSE;
43}
44
45Eina_Bool
46input_pause_seek(void *data)
47{
48 double pos;
49
50 fail_if(ecore_audio_input_paused_get(in) != EINA_FALSE);
51 ecore_audio_input_paused_set(in, EINA_TRUE);
52 pos = ecore_audio_input_seek(in, 0, SEEK_CUR);
53
54 fail_if(ecore_audio_input_seek(in, 0, SEEK_SET) != 0);
55 pos = ecore_audio_input_seek(in, 0, SEEK_CUR);
56 fail_if(pos > 0.01);
57
58 ecore_timer_add(0.2, input_resume, NULL);
59 return EINA_FALSE;
60}
61
62Eina_Bool looped(void *data, int type, void *event)
63{
64 Ecore_Audio_Object *in = (Ecore_Audio_Object *)event;
65 fail_if(!in);
66
67 fail_if(!ecore_audio_input_looped_get(in));
68 ecore_audio_input_looped_set(in, EINA_FALSE);
69 ecore_audio_input_seek(in, -0.5, SEEK_END);
70}
71
72Eina_Bool play_done(void *data, int type, void *event)
73{
74 Ecore_Audio_Object *in = (Ecore_Audio_Object *)event;
75 Eina_List *ins;
76 fail_if(!in);
77
78 ins = ecore_audio_output_inputs_get(out);
79 fail_if(eina_list_count(ins) != 1);
80
81 fail_if(eina_list_data_get(ins) != in);
82 ecore_audio_output_input_del(ecore_audio_input_output_get(in), in);
83 ecore_audio_input_del(in);
84 ecore_audio_output_del(out);
85 ecore_main_loop_quit();
86}
87
88START_TEST(ecore_test_ecore_audio_default)
89{
90 in = ecore_audio_input_add(ECORE_AUDIO_TYPE_SNDFILE);
91 ecore_audio_input_name_set(in, "modem.wav");
92 ecore_audio_input_sndfile_filename_set(in, SOUNDS_DIR"modem.wav");
93
94 ecore_timer_add(1, output_add_default, NULL);
95 ecore_timer_add(1.2, input_pause_seek, NULL);
96 ecore_event_handler_add(ECORE_AUDIO_INPUT_LOOPED, looped, NULL);
97 ecore_event_handler_add(ECORE_AUDIO_INPUT_ENDED, play_done, NULL);
98
99 ecore_main_loop_begin();
100
101}
102END_TEST
103
104struct buffer {
105 int offset;
106 int length;
107 unsigned char data[1024];
108};
109
110int _get_length(Ecore_Audio_Object *in)
111{
112 struct buffer *buf = ecore_audio_input_data_get(in);
113 return buf->length;
114}
115
116int _seek(Ecore_Audio_Object *in, int offs, int whence)
117{
118 struct buffer *buf = ecore_audio_input_data_get(in);
119
120 switch (whence) {
121 case SEEK_SET:
122 buf->offset = offs;
123 break;
124 case SEEK_CUR:
125 buf->offset += offs;
126 break;
127 case SEEK_END:
128 buf->offset = buf->length + offs;
129 break;
130 }
131 return buf->offset;
132}
133
134int _tell(Ecore_Audio_Object *in)
135{
136 struct buffer *buf = ecore_audio_input_data_get(in);
137 return buf->offset;
138}
139
140int _read(Ecore_Audio_Object *in, void *buffer, int length)
141{
142 struct buffer *buf = ecore_audio_input_data_get(in);
143
144 if ((buf->offset + length) > buf->length)
145 length = buf->length - buf->offset;
146
147 memcpy(buffer, buf->data + buf->offset, length);
148 buf->offset += length;
149
150 return length;
151}
152
153int _write(Ecore_Audio_Object *out, const void *buffer, int length)
154{
155 struct buffer *buf = ecore_audio_output_data_get(out);
156
157 if ((buf->offset + length) > buf->length)
158 length = buf->length - buf->offset;
159
160 memcpy(buf->data + buf->offset, buffer, length);
161
162 buf->offset += length;
163
164 return length;
165}
166
167Ecore_Audio_Vio vio = {
168 .get_length = _get_length,
169 .seek = _seek,
170 .tell = _tell,
171 .read = _read,
172 .write = _write,
173};
174
175Eina_Bool sndfile_done(void *data, int type, void *event)
176{
177 Ecore_Audio_Object *in = (Ecore_Audio_Object *)event;
178
179 ecore_audio_input_seek(in, 0, SEEK_SET);
180 ecore_audio_input_del(in);
181 ecore_audio_output_del(out);
182 ecore_main_loop_quit();
183}
184
185START_TEST(ecore_test_ecore_audio_sndfile_vio)
186{
187 struct buffer indata = {
188 .length = 1000,
189 .offset = 0,
190 };
191 for (int i=0; i < 1000; i++) {
192 indata.data[i] = i%256;
193 }
194
195 struct buffer outdata = {
196 .length = 1000,
197 .offset = 0,
198 };
199 for (int i=0; i < 1000; i++) {
200 outdata.data[i] = 0;
201 }
202
203 in = ecore_audio_input_add(ECORE_AUDIO_TYPE_SNDFILE);
204 fail_if(!in);
205
206 ecore_audio_input_name_set(in, "tmp");
207 ecore_audio_input_channels_set(in, 1);
208 ecore_audio_input_samplerate_set(in, 44100);
209 ecore_audio_input_data_set(in, &indata);
210 ecore_audio_input_sndfile_format_set(in, SF_FORMAT_RAW | SF_FORMAT_PCM_U8);
211
212 ecore_audio_input_sndfile_vio_set(in, &vio);
213
214 out = ecore_audio_output_add(ECORE_AUDIO_TYPE_SNDFILE);
215 fail_if(!out);
216 ecore_audio_output_name_set(out, "tmp");
217 ecore_audio_output_sndfile_format_set(out, SF_FORMAT_RAW | SF_FORMAT_PCM_U8);
218 ecore_audio_output_data_set(out, &outdata);
219
220 ecore_audio_output_sndfile_vio_set(out, &vio);
221
222 ecore_audio_output_input_add(out, in);
223 ecore_event_handler_add(ECORE_AUDIO_INPUT_ENDED, sndfile_done, NULL);
224
225 ecore_main_loop_begin();
226
227 // Off-by-one...must be libsndfile float conversion error?!
228 for (int i = 0; i<1000; i++) {
229 fail_if(indata.data[i] - outdata.data[i] > 1);
230 fail_if(indata.data[i] - outdata.data[i] < -1);
231 }
232}
233END_TEST
234
235START_TEST(ecore_test_ecore_audio_custom)
236{
237 in = ecore_audio_input_add(ECORE_AUDIO_TYPE_CUSTOM);
238 ecore_audio_input_del(in);
239}
240END_TEST
241#endif
242
243static Eina_Bool _finished_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) 16static Eina_Bool _finished_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
244{ 17{
245 ecore_main_loop_quit(); 18 ecore_main_loop_quit();