summaryrefslogtreecommitdiff
path: root/src/examples/ecore
diff options
context:
space:
mode:
authorDaniel Willmann <d.willmann@samsung.com>2012-12-14 23:38:31 +0000
committerDaniel Willmann <daniel@totalueberwachung.de>2012-12-14 23:38:31 +0000
commit55f6091e3d0b971d9c2ccad8c810aca075f25279 (patch)
tree70e4e9620d8abf7fdcaa2a0b870758d52671cbfd /src/examples/ecore
parent21436714202ccb866350a23e04631d66491d7163 (diff)
ecore_audio: Example for user generated sounds
Uses the custom function support, which can probably be improved Signed-off-by: Daniel Willmann <d.willmann@samsung.com> SVN revision: 81002
Diffstat (limited to 'src/examples/ecore')
-rw-r--r--src/examples/ecore/Makefile.am4
-rw-r--r--src/examples/ecore/ecore_audio_custom.c75
2 files changed, 79 insertions, 0 deletions
diff --git a/src/examples/ecore/Makefile.am b/src/examples/ecore/Makefile.am
index 170e3b7fb4..a91d874dd2 100644
--- a/src/examples/ecore/Makefile.am
+++ b/src/examples/ecore/Makefile.am
@@ -53,8 +53,12 @@ ecore_timer_example
53 53
54if HAVE_ECORE_AUDIO 54if HAVE_ECORE_AUDIO
55EXTRA_PROGRAMS += \ 55EXTRA_PROGRAMS += \
56ecore_audio_custom \
56ecore_audio_playback 57ecore_audio_playback
57 58
59ecore_audio_custom_SOURCES = ecore_audio_custom.c
60ecore_audio_custom_LDADD = $(top_builddir)/src/lib/ecore_audio/libecore_audio.la $(top_builddir)/src/lib/ecore/libecore.la $(top_builddir)/src/lib/eina/libeina.la @ECORE_LIBS@
61
58ecore_audio_playback_SOURCES = ecore_audio_playback.c 62ecore_audio_playback_SOURCES = ecore_audio_playback.c
59ecore_audio_playback_LDADD = $(top_builddir)/src/lib/ecore_audio/libecore_audio.la $(top_builddir)/src/lib/ecore/libecore.la $(top_builddir)/src/lib/eina/libeina.la @ECORE_LIBS@ 63ecore_audio_playback_LDADD = $(top_builddir)/src/lib/ecore_audio/libecore_audio.la $(top_builddir)/src/lib/ecore/libecore.la $(top_builddir)/src/lib/eina/libeina.la @ECORE_LIBS@
60 64
diff --git a/src/examples/ecore/ecore_audio_custom.c b/src/examples/ecore/ecore_audio_custom.c
new file mode 100644
index 0000000000..d94a4b4095
--- /dev/null
+++ b/src/examples/ecore/ecore_audio_custom.c
@@ -0,0 +1,75 @@
1#include <stdio.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <termios.h>
5#include <unistd.h>
6#include <fcntl.h>
7#include <Ecore.h>
8#include <Ecore_Audio.h>
9#include <math.h>
10
11Ecore_Audio_Object *in = NULL;
12Ecore_Audio_Object *out = NULL;
13unsigned char volume = 255;
14
15
16int read_cb(void *user_data, void *data, int len)
17{
18 static long int phase1 = 0, phase2 = 0;
19 static int modulation = 0;
20
21 float *val = data;
22 int i;
23
24 for(i=0; i<len/4; i++, phase1++)
25 {
26 if (phase1 >= 44100/(440+modulation))
27 {
28 phase1 = 0;
29 modulation = sin(2 * M_PI * phase2 / 1000) * 100;
30 phase2++;
31 }
32
33 val[i++] = sin(2 * M_PI * (440+modulation) * (phase1) / 44100.0);
34 val[i] = sin(2 * M_PI * (440+modulation) * (phase1) / 44100.0);
35 }
36
37 return len;
38}
39
40Eina_Bool
41output_add(void *data)
42{
43 out = ecore_audio_output_add(ECORE_AUDIO_TYPE_PULSE);
44 ecore_audio_output_input_add(out, in);
45// ecore_event_handler_add(ECORE_AUDIO_EVENT_SOURCE_DONE, _play_finished, NULL);
46
47 return EINA_FALSE;
48}
49
50int
51main(int argc, const char *argv[])
52{
53 ecore_init();
54 ecore_audio_init();
55
56 in = ecore_audio_input_add(ECORE_AUDIO_TYPE_CUSTOM);
57 if (!in)
58 {
59 printf("error when creating ecore audio source.\n");
60 goto end;
61 }
62 ecore_audio_input_name_set(in, "custom");
63 ecore_audio_input_callback_setup(in, read_cb, NULL);
64
65 ecore_timer_add(1, output_add, NULL);
66
67 ecore_main_loop_begin();
68
69end:
70 ecore_audio_shutdown();
71 ecore_shutdown();
72
73 return 0;
74}
75