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;
|
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_audio_obj_volume_get(eo_obj, &volume);
|
2013-04-17 11:11:25 -07:00
|
|
|
|
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);
|
|
|
|
|
2016-03-11 04:24:08 -08:00
|
|
|
out = eo_add(ECORE_AUDIO_OBJ_OUT_PULSE_CLASS, NULL);
|
2013-04-17 11:11:25 -07:00
|
|
|
|
2016-03-11 04:24:08 -08:00
|
|
|
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;
|
|
|
|
}
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_audio_obj_name_set(in, "wail");
|
|
|
|
ecore_audio_obj_in_samplerate_set(in, 44100);
|
|
|
|
ecore_audio_obj_in_channels_set(in, 1);
|
|
|
|
ecore_audio_obj_volume_set(in, 0.7);
|
|
|
|
ecore_audio_obj_vio_set(in, &vio, NULL, NULL);
|
2012-12-14 15:38:31 -08:00
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
ret = ecore_audio_obj_out_input_attach(out, 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;
|
|
|
|
}
|
|
|
|
|