1 | #include <pjlib.h>
|
---|
2 | #include <pjmedia.h>
|
---|
3 |
|
---|
4 | #define CLOCK_RATE 16000
|
---|
5 | #define NSAMPLES 320
|
---|
6 |
|
---|
7 | //#define TEST_WSOLA
|
---|
8 | #define TEST_EC
|
---|
9 |
|
---|
10 | int main()
|
---|
11 | {
|
---|
12 | pj_caching_pool cp;
|
---|
13 | pj_pool_t *pool;
|
---|
14 | pjmedia_port *src_port;
|
---|
15 | pjmedia_port *dst_port;
|
---|
16 | #ifdef TEST_WSOLA
|
---|
17 | pjmedia_wsola *wsola;
|
---|
18 | #elif defined(TEST_EC)
|
---|
19 | pjmedia_echo_state *ec;
|
---|
20 | #else
|
---|
21 | pjmedia_delay_buf *db;
|
---|
22 | #endif
|
---|
23 | pjmedia_frame frame;
|
---|
24 | short framebuf[NSAMPLES];
|
---|
25 | pjmedia_tone_desc tone;
|
---|
26 | unsigned i;
|
---|
27 | pj_bool_t prevlost = PJ_FALSE;
|
---|
28 | pj_status_t status;
|
---|
29 |
|
---|
30 | status = pj_init();
|
---|
31 | pj_assert(status == PJ_SUCCESS);
|
---|
32 |
|
---|
33 | pj_caching_pool_init(&cp, NULL, 0);
|
---|
34 | pool = pj_pool_create(&cp.factory, "", 1000, 1000, NULL);
|
---|
35 |
|
---|
36 | status = pjmedia_tonegen_create(pool, CLOCK_RATE, 1, NSAMPLES, 16, 0, &src_port);
|
---|
37 | pj_assert(status == PJ_SUCCESS);
|
---|
38 |
|
---|
39 | tone.freq1 = 440;
|
---|
40 | tone.freq2 = 480;
|
---|
41 | tone.on_msec = 10000;
|
---|
42 | tone.off_msec = 0;
|
---|
43 | tone.volume = 0;
|
---|
44 | tone.flags = 0;
|
---|
45 |
|
---|
46 | status = pjmedia_tonegen_play(src_port, 1, &tone, PJMEDIA_TONEGEN_LOOP);
|
---|
47 | pj_assert(status == PJ_SUCCESS);
|
---|
48 |
|
---|
49 | #ifdef TEST_WSOLA
|
---|
50 | status = pjmedia_wsola_create(pool, CLOCK_RATE, NSAMPLES, 1, 0, &wsola);
|
---|
51 | #elif defined(TEST_EC)
|
---|
52 | status = pjmedia_echo_create(pool, CLOCK_RATE, NSAMPLES, 200, 100, 0, &ec);
|
---|
53 | pj_assert(status == PJ_SUCCESS);
|
---|
54 | #else
|
---|
55 | status = pjmedia_delay_buf_create(pool, "", CLOCK_RATE, NSAMPLES, 1, 400, 0, &db);
|
---|
56 | #endif
|
---|
57 | pj_assert(status == PJ_SUCCESS);
|
---|
58 |
|
---|
59 | status = pjmedia_wav_writer_port_create(pool, "expanded.wav", CLOCK_RATE, 1, NSAMPLES, 16, 0, 0, &dst_port);
|
---|
60 | pj_assert(status == PJ_SUCCESS);
|
---|
61 |
|
---|
62 | frame.buf = framebuf;
|
---|
63 | frame.size = NSAMPLES * 2;
|
---|
64 | frame.type = PJMEDIA_FRAME_TYPE_AUDIO;
|
---|
65 |
|
---|
66 | for (i=0; i<5000; ++i) {
|
---|
67 | #ifdef TEST_WSOLA
|
---|
68 | if ((i%50) != 0) {
|
---|
69 | status = status = pjmedia_port_get_frame(src_port, &frame);
|
---|
70 | pj_assert(status == PJ_SUCCESS);
|
---|
71 |
|
---|
72 | status = pjmedia_wsola_save(wsola, framebuf, PJ_FALSE);
|
---|
73 | pj_assert(status == PJ_SUCCESS);
|
---|
74 | prevlost = PJ_FALSE;
|
---|
75 | } else {
|
---|
76 | status = pjmedia_wsola_generate(wsola, framebuf);
|
---|
77 | pj_assert(status == PJ_SUCCESS);
|
---|
78 | prevlost = PJ_TRUE;
|
---|
79 | }
|
---|
80 | #elif defined(TEST_EC)
|
---|
81 | if (i==0 || (i%50) != 0) {
|
---|
82 | status = status = pjmedia_port_get_frame(src_port, &frame);
|
---|
83 | pj_assert(status == PJ_SUCCESS);
|
---|
84 |
|
---|
85 | status = pjmedia_echo_playback(ec, framebuf);
|
---|
86 | pj_assert(status == PJ_SUCCESS);
|
---|
87 |
|
---|
88 | status = pjmedia_port_put_frame(dst_port, &frame);
|
---|
89 | pj_assert(status == PJ_SUCCESS);
|
---|
90 |
|
---|
91 | status = pjmedia_echo_capture(ec, NULL, 0);
|
---|
92 | pj_assert(status == PJ_SUCCESS);
|
---|
93 |
|
---|
94 | } else {
|
---|
95 | status = pjmedia_echo_capture(ec, NULL, 0);
|
---|
96 | pj_assert(status == PJ_SUCCESS);
|
---|
97 | }
|
---|
98 |
|
---|
99 | #else
|
---|
100 | if ((i%50) != 0) {
|
---|
101 | status = status = pjmedia_port_get_frame(src_port, &frame);
|
---|
102 | pj_assert(status == PJ_SUCCESS);
|
---|
103 |
|
---|
104 | status = pjmedia_delay_buf_put(db, framebuf);
|
---|
105 | pj_assert(status == PJ_SUCCESS);
|
---|
106 | }
|
---|
107 |
|
---|
108 | status = pjmedia_delay_buf_get(db, framebuf);
|
---|
109 | pj_assert(status == PJ_SUCCESS);
|
---|
110 | #endif
|
---|
111 | }
|
---|
112 | pjmedia_port_destroy(dst_port);
|
---|
113 | pjmedia_port_destroy(src_port);
|
---|
114 | #ifdef TEST_WSOLA
|
---|
115 | pjmedia_wsola_destroy(wsola);
|
---|
116 | #elif defined(TEST_EC)
|
---|
117 | pjmedia_echo_destroy(ec);
|
---|
118 | #else
|
---|
119 | pjmedia_delay_buf_destroy(db);
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | pj_pool_release(pool);
|
---|
123 | pj_caching_pool_destroy(&cp);
|
---|
124 | pj_shutdown();
|
---|
125 |
|
---|
126 | return 0;
|
---|
127 | }
|
---|