2013-02-08 09:35:17 -08:00
|
|
|
// Compile with:
|
|
|
|
// gcc -o ecore_audio_custom ecore_audio_custom.c `pkg-config --libs --cflags ecore ecore-audio`
|
|
|
|
|
2012-12-14 15:38:31 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Audio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2013-04-17 11:11:25 -07:00
|
|
|
Eo *in = NULL;
|
|
|
|
Eo *out = NULL;
|
2012-12-14 15:38:31 -08:00
|
|
|
unsigned char volume = 255;
|
|
|
|
|
|
|
|
|
2013-04-17 11:11:25 -07:00
|
|
|
int read_cb(void *data EINA_UNUSED, Eo *eo_obj, void *buf, int len)
|
2012-12-14 15:38:31 -08:00
|
|
|
{
|
|
|
|
static long int phase1 = 0, phase2 = 0;
|
|
|
|
static int modulation = 0;
|
|
|
|
|
2013-04-17 11:11:25 -07:00
|
|
|
double volume;
|
|
|
|
float *val = buf;
|
2012-12-14 15:38:31 -08:00
|
|
|
int i;
|
|
|
|
|
2013-04-17 11:11:25 -07:00
|
|
|
eo_do(eo_obj, ecore_audio_obj_volume_get(&volume));
|
|
|
|
|
2012-12-14 15:38:31 -08:00
|
|
|
for(i=0; i<len/4; i++, phase1++)
|
|
|
|
{
|
|
|
|
if (phase1 >= 44100/(440+modulation))
|
|
|
|
{
|
|
|
|
phase1 = 0;
|
|
|
|
modulation = sin(2 * M_PI * phase2 / 1000) * 100;
|
|
|
|
phase2++;
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:11:25 -07:00
|
|
|
val[i] = sin(2 * M_PI * (440+modulation) * (phase1) / 44100.0) * volume;
|
2012-12-14 15:38:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:11:25 -07:00
|
|
|
Ecore_Audio_Vio vio = {
|
|
|
|
.read = read_cb,
|
|
|
|
};
|
2012-12-14 15:38:31 -08:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, const char *argv[])
|
|
|
|
{
|
2013-04-23 09:10:16 -07:00
|
|
|
Eina_Bool ret;
|
|
|
|
|
2012-12-14 15:38:31 -08:00
|
|
|
ecore_init();
|
|
|
|
ecore_audio_init();
|
|
|
|
|
2013-04-18 11:34:33 -07:00
|
|
|
ecore_app_args_set(argc, argv);
|
|
|
|
|
2013-04-17 11:11:25 -07:00
|
|
|
out = eo_add(ECORE_AUDIO_OBJ_OUT_PULSE_CLASS, NULL);
|
|
|
|
|
|
|
|
in = eo_add(ECORE_AUDIO_OBJ_IN_CLASS, NULL);
|
2012-12-14 15:38:31 -08:00
|
|
|
if (!in)
|
|
|
|
{
|
|
|
|
printf("error when creating ecore audio source.\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2013-04-17 11:11:25 -07:00
|
|
|
eo_do(in, ecore_audio_obj_name_set("wail"));
|
|
|
|
eo_do(in, ecore_audio_obj_in_samplerate_set(44100));
|
|
|
|
eo_do(in, ecore_audio_obj_in_channels_set(1));
|
|
|
|
eo_do(in, ecore_audio_obj_volume_set(0.7));
|
|
|
|
eo_do(in, ecore_audio_obj_vio_set(&vio, NULL, NULL));
|
2012-12-14 15:38:31 -08:00
|
|
|
|
2014-04-10 02:07:42 -07:00
|
|
|
eo_do(out, ret = ecore_audio_obj_out_input_attach(in));
|
2013-04-23 09:10:16 -07:00
|
|
|
if (!ret) {
|
|
|
|
printf("Could not attach input");
|
|
|
|
goto end;
|
|
|
|
}
|
2012-12-14 15:38:31 -08:00
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
|
|
|
end:
|
|
|
|
ecore_audio_shutdown();
|
|
|
|
ecore_shutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|