forked from enlightenment/efl
ecore audio: tests - remove #if0'd out code
This commit is contained in:
parent
01a4b8bacb
commit
b6f4af28b2
|
@ -13,233 +13,6 @@
|
|||
#include <Ecore.h>
|
||||
#include <Ecore_Audio.h>
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
Eina_Bool
|
||||
output_add_default(void *data)
|
||||
{
|
||||
out = ecore_audio_output_add(ECORE_AUDIO_TYPE_PULSE);
|
||||
fail_if(!out);
|
||||
|
||||
printf("Adding input\n");
|
||||
ecore_audio_output_input_add(out, in);
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
input_resume(void *data)
|
||||
{
|
||||
double pos;
|
||||
|
||||
fail_if(ecore_audio_input_paused_get(in) != EINA_TRUE);
|
||||
fail_if(ecore_audio_input_seek(in, 0, SEEK_CUR) != 0);
|
||||
ecore_audio_input_paused_set(in, EINA_FALSE);
|
||||
|
||||
ecore_audio_input_looped_set(in, EINA_TRUE);
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
input_pause_seek(void *data)
|
||||
{
|
||||
double pos;
|
||||
|
||||
fail_if(ecore_audio_input_paused_get(in) != EINA_FALSE);
|
||||
ecore_audio_input_paused_set(in, EINA_TRUE);
|
||||
pos = ecore_audio_input_seek(in, 0, SEEK_CUR);
|
||||
|
||||
fail_if(ecore_audio_input_seek(in, 0, SEEK_SET) != 0);
|
||||
pos = ecore_audio_input_seek(in, 0, SEEK_CUR);
|
||||
fail_if(pos > 0.01);
|
||||
|
||||
ecore_timer_add(0.2, input_resume, NULL);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
Eina_Bool looped(void *data, int type, void *event)
|
||||
{
|
||||
Ecore_Audio_Object *in = (Ecore_Audio_Object *)event;
|
||||
fail_if(!in);
|
||||
|
||||
fail_if(!ecore_audio_input_looped_get(in));
|
||||
ecore_audio_input_looped_set(in, EINA_FALSE);
|
||||
ecore_audio_input_seek(in, -0.5, SEEK_END);
|
||||
}
|
||||
|
||||
Eina_Bool play_done(void *data, int type, void *event)
|
||||
{
|
||||
Ecore_Audio_Object *in = (Ecore_Audio_Object *)event;
|
||||
Eina_List *ins;
|
||||
fail_if(!in);
|
||||
|
||||
ins = ecore_audio_output_inputs_get(out);
|
||||
fail_if(eina_list_count(ins) != 1);
|
||||
|
||||
fail_if(eina_list_data_get(ins) != in);
|
||||
ecore_audio_output_input_del(ecore_audio_input_output_get(in), in);
|
||||
ecore_audio_input_del(in);
|
||||
ecore_audio_output_del(out);
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_ecore_audio_default)
|
||||
{
|
||||
in = ecore_audio_input_add(ECORE_AUDIO_TYPE_SNDFILE);
|
||||
ecore_audio_input_name_set(in, "modem.wav");
|
||||
ecore_audio_input_sndfile_filename_set(in, SOUNDS_DIR"modem.wav");
|
||||
|
||||
ecore_timer_add(1, output_add_default, NULL);
|
||||
ecore_timer_add(1.2, input_pause_seek, NULL);
|
||||
ecore_event_handler_add(ECORE_AUDIO_INPUT_LOOPED, looped, NULL);
|
||||
ecore_event_handler_add(ECORE_AUDIO_INPUT_ENDED, play_done, NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
struct buffer {
|
||||
int offset;
|
||||
int length;
|
||||
unsigned char data[1024];
|
||||
};
|
||||
|
||||
int _get_length(Ecore_Audio_Object *in)
|
||||
{
|
||||
struct buffer *buf = ecore_audio_input_data_get(in);
|
||||
return buf->length;
|
||||
}
|
||||
|
||||
int _seek(Ecore_Audio_Object *in, int offs, int whence)
|
||||
{
|
||||
struct buffer *buf = ecore_audio_input_data_get(in);
|
||||
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
buf->offset = offs;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
buf->offset += offs;
|
||||
break;
|
||||
case SEEK_END:
|
||||
buf->offset = buf->length + offs;
|
||||
break;
|
||||
}
|
||||
return buf->offset;
|
||||
}
|
||||
|
||||
int _tell(Ecore_Audio_Object *in)
|
||||
{
|
||||
struct buffer *buf = ecore_audio_input_data_get(in);
|
||||
return buf->offset;
|
||||
}
|
||||
|
||||
int _read(Ecore_Audio_Object *in, void *buffer, int length)
|
||||
{
|
||||
struct buffer *buf = ecore_audio_input_data_get(in);
|
||||
|
||||
if ((buf->offset + length) > buf->length)
|
||||
length = buf->length - buf->offset;
|
||||
|
||||
memcpy(buffer, buf->data + buf->offset, length);
|
||||
buf->offset += length;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
int _write(Ecore_Audio_Object *out, const void *buffer, int length)
|
||||
{
|
||||
struct buffer *buf = ecore_audio_output_data_get(out);
|
||||
|
||||
if ((buf->offset + length) > buf->length)
|
||||
length = buf->length - buf->offset;
|
||||
|
||||
memcpy(buf->data + buf->offset, buffer, length);
|
||||
|
||||
buf->offset += length;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
Ecore_Audio_Vio vio = {
|
||||
.get_length = _get_length,
|
||||
.seek = _seek,
|
||||
.tell = _tell,
|
||||
.read = _read,
|
||||
.write = _write,
|
||||
};
|
||||
|
||||
Eina_Bool sndfile_done(void *data, int type, void *event)
|
||||
{
|
||||
Ecore_Audio_Object *in = (Ecore_Audio_Object *)event;
|
||||
|
||||
ecore_audio_input_seek(in, 0, SEEK_SET);
|
||||
ecore_audio_input_del(in);
|
||||
ecore_audio_output_del(out);
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_ecore_audio_sndfile_vio)
|
||||
{
|
||||
struct buffer indata = {
|
||||
.length = 1000,
|
||||
.offset = 0,
|
||||
};
|
||||
for (int i=0; i < 1000; i++) {
|
||||
indata.data[i] = i%256;
|
||||
}
|
||||
|
||||
struct buffer outdata = {
|
||||
.length = 1000,
|
||||
.offset = 0,
|
||||
};
|
||||
for (int i=0; i < 1000; i++) {
|
||||
outdata.data[i] = 0;
|
||||
}
|
||||
|
||||
in = ecore_audio_input_add(ECORE_AUDIO_TYPE_SNDFILE);
|
||||
fail_if(!in);
|
||||
|
||||
ecore_audio_input_name_set(in, "tmp");
|
||||
ecore_audio_input_channels_set(in, 1);
|
||||
ecore_audio_input_samplerate_set(in, 44100);
|
||||
ecore_audio_input_data_set(in, &indata);
|
||||
ecore_audio_input_sndfile_format_set(in, SF_FORMAT_RAW | SF_FORMAT_PCM_U8);
|
||||
|
||||
ecore_audio_input_sndfile_vio_set(in, &vio);
|
||||
|
||||
out = ecore_audio_output_add(ECORE_AUDIO_TYPE_SNDFILE);
|
||||
fail_if(!out);
|
||||
ecore_audio_output_name_set(out, "tmp");
|
||||
ecore_audio_output_sndfile_format_set(out, SF_FORMAT_RAW | SF_FORMAT_PCM_U8);
|
||||
ecore_audio_output_data_set(out, &outdata);
|
||||
|
||||
ecore_audio_output_sndfile_vio_set(out, &vio);
|
||||
|
||||
ecore_audio_output_input_add(out, in);
|
||||
ecore_event_handler_add(ECORE_AUDIO_INPUT_ENDED, sndfile_done, NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
// Off-by-one...must be libsndfile float conversion error?!
|
||||
for (int i = 0; i<1000; i++) {
|
||||
fail_if(indata.data[i] - outdata.data[i] > 1);
|
||||
fail_if(indata.data[i] - outdata.data[i] < -1);
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_audio_custom)
|
||||
{
|
||||
in = ecore_audio_input_add(ECORE_AUDIO_TYPE_CUSTOM);
|
||||
ecore_audio_input_del(in);
|
||||
}
|
||||
END_TEST
|
||||
#endif
|
||||
|
||||
static Eina_Bool _finished_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
|
|
Loading…
Reference in New Issue