source: roaraudio/roarclients/roarphone.c @ 5533:42f48072307c

Last change on this file since 5533:42f48072307c was 5533:42f48072307c, checked in by phi, 12 years ago

Fixed usage of -R/-B/-C/-E as well as --aiprofile in roarclients (Closes: #176)

File size: 17.7 KB
RevLine 
[2292]1//roarphone.c:
[2124]2
3/*
[5381]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012
[2124]5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[2124]23 *
24 */
25
26#include <roaraudio.h>
[2185]27#include <libroardsp/libroardsp.h>
[2282]28#include <libroareio/libroareio.h>
[2124]29
[2215]30#if defined(ROAR_HAVE_LIBSPEEX) && !defined(ROAR_HAVE_LIBSPEEXDSP)
31#define _SPEEX_API_OLD
32#elif defined(ROAR_HAVE_LIBSPEEX) && defined(ROAR_HAVE_LIBSPEEXDSP)
33#define _SPEEX_API_NEW
34#endif
35
36#ifdef _SPEEX_API_OLD
[2141]37#include <speex/speex_echo.h>
38#endif
39
40#define TIMEDIV  100
[2124]41
[2125]42#define DRIVER  "oss"
43
[2140]44// anti echo:
45#define AE_NONE      0
46#define AE_SIMPLE    1
47#define AE_SPEEX     2
[2141]48#define AE_ROARD     3
[2140]49
[2322]50#define DTX_F        25
51
[2329]52#define CON_NONE     0x00
53#define CON_CON      0x01
54#define CON_STREAM   0x02
55
[2140]56struct {
57 int antiecho;
[2166]58 int samples;
[2167]59 int transcode;
[2321]60 int64_t dtx_threshold;
[2986]61 size_t jumbo_mtu;
[2993]62 int    ioflush_interval;
[2991]63 struct {
64  struct {
65   int downmix;
66   float lowp_freq;
[3006]67   int speex_prep;
[3007]68   int speex_prep_denoise;
69   int speex_prep_agc;
70   int speex_prep_vad;
[2991]71  } in;
72 } filter;
[2140]73} g_conf;
74
[2322]75int dtx_counter = 0;
76
[2329]77struct {
78 int state;
79 struct roar_connection con;
80 struct roar_stream     stream;
81 struct roar_vio_calls * svio;
82} g_cons;
83
[2185]84struct roar_bixcoder transcoder[1];
85
[2330]86struct {
[2977]87 struct roardsp_filterchain input;
88 struct roardsp_filterchain output;
89} g_filterchains;
90
91struct {
[2330]92 struct {
93  char key[ROAR_META_MAX_NAMELEN];
94  char value[LIBROAR_BUFFER_MSGDATA];
95 } tmp;
96 char * rn;
97 char * nick;
98 char * org;
99 char * email;
100 char * hp;
101 char * loc;
102 char * thumbnail;
103} g_meta;
104
[2124]105void usage (void) {
[2292]106 printf("roarphone [OPTIONS]...\n");
[2124]107
[2330]108 printf("\nServer Options:\n\n");
[2124]109
[2995]110 printf("  --server    SERVER   - Set server hostname\n"
[2994]111        "  --jumbo-mtu MTU      - Sets the MTU for Jumbo Packets\n"
112        "  --io-flush  INTERVAL - Flushs output every INTERVAL packets\n"
[2330]113       );
114
115 printf("\nAudio Options:\n\n");
[5533]116 printf("  --rate  -R RATE      - Set sample rate\n"
117        "  --bits  -B BITS      - Set bits per sample\n"
118        "  --chans -C CHANNELS  - Set number of channels\n"
119        "  --aiprofile PROFILE  - Set audio profile\n"
[2330]120       );
121
[2991]122 printf("\nAudio Filter Options:\n\n");
123 printf("  --afi-downmix        - Enable input downmixing\n"
124        "  --afi-lowpass FREQ   - Enable input lowpass at FREQ (in Hz)\n"
[3006]125        "  --afi-speex-prep     - Enable speex preprocessor\n"
[3007]126        "  --afi-speex-denoise  - Enable speex denoiser\n"
127        "  --afi-speex-agc      - Enable speex AGC\n"
128        "  --afi-speex-vad      - Enable speex VAD\n"
[2991]129       );
130
[2330]131 printf("\nCodec Options:\n\n");
[5533]132 printf("  --codec -E CODEC     - Set the codec\n"
[2330]133        "  --transcode          - Use local transcodeing\n"
134       );
135
136 printf("\nDriver Options:\n\n");
137 printf("  --driver   DRIVER    - Set the driver\n"
[2141]138        "  --device   DEVICE    - Set the device\n"
[2330]139       );
140
141 printf("\nGeneral Options:\n\n");
142 printf("  --antiecho AEMODE    - Set the anti echo mode\n"
[2321]143        "  --threshold DTXTHRES - Set the DTX threshold, disabled by default\n"
[2141]144        "  --help               - Show this help\n"
[2124]145       );
146
[2330]147 printf("\nMeta Data Options:\n\n");
148 printf("  --m-rn    REALNAME   - Sets the real name\n"
149        "  --m-nick  NICK       - Sets the nick name\n"
150        "  --m-email EMAIL      - Sets the email address\n"
151        "  --m-hp    HOMEPAGE   - Sets the homepage URL\n"
152        "  --m-thumbn THUMBNAIL - Sets a URL to a thumbnail\n"
153        "  --m-loc   LOCATION   - Sets the location (room number)\n"
154        "  --m-org ORGANIZATION - Sets the organization/company name\n"
155       );
[2124]156}
157
[2128]158int open_stream (struct roar_vio_calls * vio, char * server, struct roar_audio_info * info) {
[2329]159 int fh;
160
161 g_cons.svio = vio;
162
163 if ( !(g_cons.state & CON_CON) )
164  if ( roar_simple_connect(&(g_cons.con), server, "roarphone") == -1 )
165   return -1;
166
167 g_cons.state |= CON_CON;
168
[3013]169 if ( (fh = roar_vio_simple_new_stream_obj(vio, &(g_cons.con), &(g_cons.stream),
170                                           info->rate, info->channels, info->bits, info->codec,
[5289]171                                           ROAR_DIR_BIDIR, -1
[3013]172                                          )) == -1 )
[2329]173  return -1;
174
175 g_cons.state |= CON_STREAM;
176
177 return 0;
[2128]178}
179
[2330]180#define _SET_META(ivar,itype) if ( (ivar) != NULL ) {  \
181                              meta.value = (ivar);     \
182                              meta.type  = (itype);    \
183                              roar_stream_meta_set(&(g_cons.con), &(g_cons.stream), ROAR_META_MODE_SET, &meta); \
184                              }
185int set_meta (void) {
186 struct roar_meta   meta;
187
188 meta.value  = g_meta.tmp.value;
189 meta.key[0] = 0;
190 meta.type   = ROAR_META_TYPE_NONE;
191
192 roar_stream_meta_set(&(g_cons.con), &(g_cons.stream), ROAR_META_MODE_CLEAR, &meta);
193
194 _SET_META(g_meta.thumbnail, ROAR_META_TYPE_THUMBNAIL);
195 _SET_META(g_meta.loc,       ROAR_META_TYPE_LOCATION);
196 _SET_META(g_meta.hp,        ROAR_META_TYPE_HOMEPAGE);
197 _SET_META(g_meta.org,       ROAR_META_TYPE_ORGANIZATION);
198
199 if ( g_meta.nick != NULL ) {
200  if ( g_meta.rn  != NULL ) {
201   snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s (%s)", g_meta.rn, g_meta.nick);
202   g_meta.tmp.value[LIBROAR_BUFFER_MSGDATA-1] = 0;
203   _SET_META(g_meta.tmp.value, ROAR_META_TYPE_AUTHOR);
204  } else {
205   _SET_META(g_meta.nick, ROAR_META_TYPE_AUTHOR);
206  }
207 } else {
208  if ( g_meta.rn  != NULL ) {
209   _SET_META(g_meta.rn, ROAR_META_TYPE_AUTHOR);
210  }
211 }
212
213 // TODO: make this more nice...
214 if ( g_meta.email != NULL ) {
215  if ( g_meta.nick != NULL ) {
216   if ( g_meta.rn != NULL ) {
217    snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s (%s) <%s>", g_meta.rn, g_meta.nick, g_meta.email);
218   } else {
219    snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s <%s>", g_meta.nick, g_meta.email);
220   }
221  } else {
222   if ( g_meta.rn != NULL ) {
223    snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s <%s>", g_meta.rn, g_meta.email);
224   } else {
225    snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "<%s>", g_meta.email);
226   }
227  }
228  g_meta.tmp.value[LIBROAR_BUFFER_MSGDATA-1] = 0;
229  _SET_META(g_meta.tmp.value, ROAR_META_TYPE_CONTACT);
230 }
231
232 return 0;
233}
234
[2215]235#ifdef _SPEEX_API_OLD
[2141]236int anti_echo_speex16(int16_t * buf, int16_t * aebuf, size_t len, struct roar_audio_info * info) {
237 static SpeexEchoState * state = NULL;
238 size_t samples = info->rate / TIMEDIV;
239 static int16_t * obuf = NULL;
240
241 if ( info->channels != 1 )
242  return -1;
243
244 if (len != samples)
245  return -1;
246
[2142]247 ROAR_DBG("anti_echo_speex16(*) = ?");
248
[2141]249 if ( state == NULL ) {
250  if ( (state = speex_echo_state_init(samples, 100*samples)) == NULL )
251   return -1;
252
253  // todo: set sample rate.
254 }
255
[2142]256 ROAR_DBG("anti_echo_speex16(*) = ?");
257
[2141]258 if ( obuf == NULL ) {
[5294]259  if ( (obuf = roar_mm_malloc(2*samples)) == NULL )
[2141]260   return -1;
261 }
262
[2142]263 ROAR_DBG("anti_echo_speex16(*) = ?");
264
[2141]265/*
266 speex_echo_cancellation(state, buf, aebuf, obuf);
267*/
268
269 speex_echo_cancel(state, buf, aebuf, obuf, NULL);
270
271 memcpy(buf, obuf, 2*samples);
272
[2142]273 ROAR_DBG("anti_echo_speex16(*) = 0");
274
[2141]275 return 0;
276}
277#endif
278
279int anti_echo16(int16_t * buf, int16_t * aebuf, size_t len, struct roar_audio_info * info) {
[2140]280 size_t i;
281
[3787]282 (void)info;
283
[2140]284 switch (g_conf.antiecho) {
285  case AE_NONE:
286    return 0;
287   break;
288  case AE_SIMPLE:
289    for (i = 0; i < len; i++)
290     buf[i] -= aebuf[i];
[2293]291    return 0;
[2140]292   break;
[2215]293#ifdef _SPEEX_API_OLD
[2141]294  case AE_SPEEX:
295    return anti_echo_speex16(buf, aebuf, len, info);
296   break;
297#endif
[2293]298  case AE_ROARD:
299    return 0;
300   break;
[2140]301  default:
302    return -1;
303   break;
304 }
305
306 return -1;
307}
308
[2321]309int zero_if_noise16 (int16_t * data, size_t samples) {
310 int64_t rms = roar_rms2_1_16(data, samples);
311
[2322]312 if ( rms < g_conf.dtx_threshold ) {
313  if ( dtx_counter ) {
314   dtx_counter--;
315  } else {
316   memset(data, 0, samples*2);
317  }
318 } else {
319  dtx_counter = DTX_F;
320 }
[2321]321
322 return 0;
323}
324
[2128]325int run_stream (struct roar_vio_calls * s0, struct roar_vio_calls * s1, struct roar_audio_info * info) {
[2129]326 size_t len;
[2140]327 void * outbuf, * micbuf;
328 ssize_t outlen, miclen;
[2993]329 unsigned long int pkg_count = 0;
[2129]330
[2312]331 ROAR_DBG("run_stream(*): g_conf.samples = %i, info->bits = %i", g_conf.samples, info->bits);
[2166]332 len = g_conf.samples * info->bits / 8;
[2312]333 ROAR_DBG("run_stream(*): len=%lu", (unsigned long) len);
[2129]334
[5294]335 if ( (outbuf = roar_mm_malloc(2*len)) == NULL )
[2129]336  return -1;
337
[2140]338 micbuf = outbuf + len;
339
[2129]340 while (1) {
[2140]341  if ( (miclen = roar_vio_read(s0, micbuf, len)) <= 0 )
[2129]342   break;
[2321]343
[2977]344  if ( roardsp_fchain_num(&(g_filterchains.input)) ) {
345   if ( roardsp_fchain_calc(&(g_filterchains.input), micbuf, len) == -1 )
346    break;
347  }
348
[2321]349  if ( g_conf.dtx_threshold > 0 )
350   if ( info->bits == 16 )
351    zero_if_noise16(micbuf, miclen/2);
352
[2185]353  if ( g_conf.transcode ) {
354   if ( roar_bixcoder_write_packet(transcoder, micbuf, miclen) == -1 )
355    break;
356  } else {
357   if ( roar_vio_write(s1, micbuf, miclen) != miclen )
358    break;
359  }
360
[2993]361  if ( g_conf.ioflush_interval != -1 ) {
362   if ( !(pkg_count % g_conf.ioflush_interval) )
363    roar_vio_sync(s1);
364  }
365
[2185]366  if ( g_conf.transcode ) {
[2312]367   ROAR_DBG("run_stream(*): outbuf=%p, len=%lu", outbuf, (unsigned long) len);
[2185]368   if ( roar_bixcoder_read_packet(transcoder, outbuf, len) == -1 )
369    break;
370
371   outlen = len;
372  } else {
373   if ( (outlen = roar_vio_read(s1, outbuf, len)) <= 0 )
374    break;
375  }
[2140]376
[2162]377  if ( g_conf.antiecho != AE_NONE && info->bits == 16 )
[2141]378   anti_echo16(outbuf, micbuf, ROAR_MIN(miclen, outlen)/2, info);
[2140]379
[2977]380  if ( roardsp_fchain_num(&(g_filterchains.output)) ) {
381   if ( roardsp_fchain_calc(&(g_filterchains.output), outbuf, outlen) == -1 )
382    break;
383  }
384
[2140]385  if ( roar_vio_write(s0, outbuf, outlen) != outlen )
[2129]386   break;
[2993]387
388  pkg_count++;
[2129]389 }
390
[5294]391 roar_mm_free(outbuf);
[2129]392
393 return 0;
[2128]394}
395
[2124]396int main (int argc, char * argv[]) {
[2125]397 struct roar_audio_info info = {.rate     = ROAR_RATE_DEFAULT,
398                                .bits     = ROAR_BITS_DEFAULT,
399                                .channels = ROAR_CHANNELS_DEFAULT,
400                                .codec    = ROAR_CODEC_DEFAULT
401                               };
[2167]402 struct roar_audio_info dinfo;
[2986]403 struct roar_vio_calls dvio, svio, svio_jumbo, svio_real;
404 struct roar_vio_calls * svio_p;
[2991]405 struct roardsp_filter * filter;
[2126]406 char * driver   = DRIVER;
407 char * device   = NULL;
[2124]408 char * server   = NULL;
409 char * k;
410 int    i;
[3007]411 union {
412  int32_t i32;
413  size_t  size;
414 } tmp;
[2124]415
[2140]416 memset(&g_conf, 0, sizeof(g_conf));
417
[2993]418 g_conf.antiecho         = AE_ROARD;
419 g_conf.dtx_threshold    = -1;
420 g_conf.ioflush_interval = -1;
[2140]421
[2329]422 memset(&g_cons, 0, sizeof(g_cons));
423 g_cons.state = CON_NONE;
424
[2330]425 memset(&g_meta, 0, sizeof(g_meta));
426
[2977]427 roardsp_fchain_init(&(g_filterchains.input));
428 roardsp_fchain_init(&(g_filterchains.output));
429
[2124]430 for (i = 1; i < argc; i++) {
431  k = argv[i];
432
433  if ( strcmp(k, "--server") == 0 ) {
434   server = argv[++i];
[2986]435  } else if ( strcmp(k, "--jumbo-mtu") == 0 ) {
436   g_conf.jumbo_mtu = atoi(argv[++i]);
[2993]437  } else if ( strcmp(k, "--io-flush") == 0 ) {
438   g_conf.ioflush_interval = atoi(argv[++i]);
[5533]439  } else if ( strcmp(k, "--rate") == 0 || strcmp(k, "-R") == 0 ) {
[4883]440   info.rate = roar_str2rate(argv[++i]);
[5533]441  } else if ( strcmp(k, "--bits") == 0 || strcmp(k, "-B") == 0 ) {
[4883]442   info.bits = roar_str2bits(argv[++i]);
[5533]443  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 || strcmp(k, "-C") == 0 ) {
[4883]444   info.channels = roar_str2channels(argv[++i]);
[5533]445  } else if ( !strcmp(k, "--aiprofile") ) {
446   if ( roar_profile2info(&info, argv[++i]) == -1 ) {
447    fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error));
448    return 1;
449   }
[2991]450
451  } else if ( strcmp(k, "--afi-downmix") == 0 ) {
452   g_conf.filter.in.downmix = 1;
453  } else if ( strcmp(k, "--afi-lowpass") == 0 ) {
454   g_conf.filter.in.lowp_freq = atof(argv[++i]);
[3006]455  } else if ( strcmp(k, "--afi-speex-prep") == 0 ) {
456   g_conf.filter.in.speex_prep = 1;
[3007]457  } else if ( strcmp(k, "--afi-speex-denoise") == 0 ) {
458   g_conf.filter.in.speex_prep = 1;
459   g_conf.filter.in.speex_prep_denoise = 1;
460  } else if ( strcmp(k, "--afi-speex-agc") == 0 ) {
461   g_conf.filter.in.speex_prep = 1;
462   g_conf.filter.in.speex_prep_agc = 1;
463  } else if ( strcmp(k, "--afi-speex-vad") == 0 ) {
464   g_conf.filter.in.speex_prep = 1;
465   g_conf.filter.in.speex_prep_vad = 1;
[2991]466
[5533]467  } else if ( strcmp(k, "--codec") == 0 || strcmp(k, "-E") == 0 ) {
[2125]468   info.codec = roar_str2codec(argv[++i]);
[2991]469
[2127]470  } else if ( strcmp(k, "--driver") == 0 ) {
471   driver = argv[++i];
472  } else if ( strcmp(k, "--device") == 0 ) {
473   device = argv[++i];
[2141]474  } else if ( strcmp(k, "--antiecho") == 0 ) {
475   k = argv[++i];
476   if ( !strcmp(k, "none") ) {
477    g_conf.antiecho = AE_NONE;
478   } else if ( !strcmp(k, "simple") ) {
479    g_conf.antiecho = AE_SIMPLE;
480   } else if ( !strcmp(k, "speex") ) {
481    g_conf.antiecho = AE_SPEEX;
482   } else if ( !strcmp(k, "roard") ) {
483    g_conf.antiecho = AE_ROARD;
484   } else {
485    fprintf(stderr, "Error: unknown mode: %s\n", k);
486    return 1;
487   }
[2321]488  } else if ( strcmp(k, "--threshold") == 0 ) {
489   g_conf.dtx_threshold = atol(argv[++i]);
490
491   // use threshold^2 or threshold < 0 for not using DTX
492   if ( g_conf.dtx_threshold > 0 )
493    g_conf.dtx_threshold *= g_conf.dtx_threshold;
[2167]494  } else if ( strcmp(k, "--transcode") == 0 ) {
495   g_conf.transcode = 1;
[2330]496
497  // META DATA:
498  } else if ( strcmp(k, "--m-rn") == 0 ) {
499   g_meta.rn = argv[++i];
500  } else if ( strcmp(k, "--m-nick") == 0 ) {
501   g_meta.nick = argv[++i];
502  } else if ( strcmp(k, "--m-email") == 0 ) {
503   g_meta.email = argv[++i];
504  } else if ( strcmp(k, "--m-hp") == 0 ) {
505   g_meta.hp = argv[++i];
506  } else if ( strcmp(k, "--m-thumbn") == 0 ) {
507   g_meta.thumbnail = argv[++i];
508  } else if ( strcmp(k, "--m-loc") == 0 ) {
509   g_meta.loc = argv[++i];
510  } else if ( strcmp(k, "--m-org") == 0 ) {
511   g_meta.org = argv[++i];
512
513
[2124]514  } else if ( strcmp(k, "--help") == 0 ) {
515   usage();
516   return 0;
517  } else {
518   fprintf(stderr, "Error: unknown argument: %s\n", k);
519   usage();
520   return 1;
521  }
522 }
523
[2568]524 // ignore errors, maybe it will work even if this fails
525 // (btw. it will never fail without crashing the rest of the app ;)
526 roar_libroar_set_server(server);
527
[2293]528 if ( g_conf.antiecho == AE_SPEEX ) {
529  ROAR_WARN("Speex Antiecho is obsolete and may be removed in future versions. Use --antiecho roard");
530 }
531
[2166]532 g_conf.samples = info.channels * info.rate / TIMEDIV;
533
[2167]534 memcpy(&dinfo, &info, sizeof(dinfo));
535
536 if ( g_conf.transcode ) {
537  dinfo.bits  = 16;
538  dinfo.codec = ROAR_CODEC_DEFAULT;
539
540  switch (info.codec) {
541   case ROAR_CODEC_ALAW:
542   case ROAR_CODEC_MULAW:
543     info.bits = 8;
544    break;
545   case ROAR_CODEC_ROAR_CELT:
546     info.bits = 16;
547    break;
548   case ROAR_CODEC_ROAR_SPEEX:
549     info.bits = 16;
550    break;
551  }
552 }
553
[5380]554 if ( roar_cdriver_open(&dvio, driver, device, &dinfo, ROAR_DIR_RECPLAY) == -1 ) {
[2570]555  ROAR_ERR("Can not open sound card.");
[2126]556  return 1;
557 }
558
[2312]559 ROAR_DBG("main(*): CALL open_stream(&svio, server, &info)");
[2570]560 if ( open_stream(&svio_real, server, &info) == -1 ) {
561  ROAR_ERR("Can not open connection to server.");
[2128]562  roar_vio_close(&dvio);
563  return 2;
564 }
[2312]565 ROAR_DBG("main(*): RET");
[2128]566
[2570]567 if ( roar_vio_open_re(&svio, &svio_real) == -1 ) {
568  ROAR_ERR("Can not open connection to server (RE VIO).");
569  roar_vio_close(&dvio);
570  return 2;
571 }
572
[2986]573 if ( g_conf.jumbo_mtu ) {
574  if ( roar_vio_open_jumbo(&svio_jumbo, &svio, g_conf.jumbo_mtu) == -1 ) {
575   roar_vio_close(&dvio);
576   roar_vio_close(&svio);
577   return 2;
578  }
579  svio_p = &svio_jumbo;
580 } else {
581  svio_p = &svio;
582 }
583
[2330]584 set_meta();
585
[3008]586 if ( g_conf.transcode ) {
587  dinfo.codec = info.codec;
588
589  if ( roar_bixcoder_init(transcoder, &dinfo, svio_p) == -1 ) {
590   roar_vio_close(&svio);
591   roar_vio_close(&dvio);
592   return 10;
593  }
594
595  // ignore errors as it may also work if this fails
596  roar_bixcoder_write_header(transcoder);
597  roar_bixcoder_read_header(transcoder);
598
599  g_conf.samples = 8 * roar_bixcoder_packet_size(transcoder, -1) / dinfo.bits;
600 }
601
[2991]602#define _err(x) roar_vio_close(&dvio); roar_vio_close(&svio); return (x)
603
604 if ( g_conf.filter.in.downmix ) {
605  if ( roardsp_filter_new(&filter, &(g_cons.stream), ROARDSP_FILTER_DOWNMIX) == -1 ) {
606   _err(2);
607  }
608
609  if ( roardsp_fchain_add(&(g_filterchains.input), filter) == -1 ) {
610   _err(2);
611  }
612 }
613
614 if ( g_conf.filter.in.lowp_freq > 1 ) {
615  if ( roardsp_filter_new(&filter, &(g_cons.stream), ROARDSP_FILTER_LOWP) == -1 ) {
616   _err(2);
617  }
618
619  if ( roardsp_filter_ctl(filter, ROARDSP_FCTL_FREQ, &(g_conf.filter.in.lowp_freq)) == -1 ) {
620   _err(2);
621  }
622
623  if ( roardsp_fchain_add(&(g_filterchains.input), filter) == -1 ) {
624   _err(2);
625  }
626 }
627
[3006]628 if ( g_conf.filter.in.speex_prep ) {
629  if ( roardsp_filter_new(&filter, &(g_cons.stream), ROARDSP_FILTER_SPEEX_PREP) == -1 ) {
630   _err(2);
631  }
632
[3007]633  tmp.size = g_conf.samples;
634  if ( roardsp_filter_ctl(filter, ROARDSP_FCTL_PACKET_SIZE, &tmp) == -1 ) {
635   _err(2);
636  }
637
638  tmp.i32 = 0;
639
640  if ( g_conf.filter.in.speex_prep_denoise )
641   tmp.i32 |= ROARDSP_SPEEX_PREP_DENOISE_ON;
642
643  if ( g_conf.filter.in.speex_prep_agc )
644   tmp.i32 |= ROARDSP_SPEEX_PREP_AGC_ON;
645
646  if ( g_conf.filter.in.speex_prep_vad )
647   tmp.i32 |= ROARDSP_SPEEX_PREP_VAD_ON;
648
649  if ( roardsp_filter_ctl(filter, ROARDSP_FCTL_MODE, &tmp) == -1 ) {
650   _err(2);
651  }
652
[3006]653  if ( roardsp_fchain_add(&(g_filterchains.input), filter) == -1 ) {
654   _err(2);
655  }
656 }
657
[2991]658#undef _err
659
[2312]660 ROAR_DBG("main(*): CALL run_stream(&dvio, &svio, &info);");
[2986]661 run_stream(&dvio, svio_p, &info);
[2312]662 ROAR_DBG("main(*): RET");
[2128]663
[2185]664 roar_bixcoder_close(transcoder);
665
[2986]666 roar_vio_close(svio_p);
[2126]667 roar_vio_close(&dvio);
668
[2977]669 roardsp_fchain_uninit(&(g_filterchains.input));
670 roardsp_fchain_uninit(&(g_filterchains.output));
671
[2329]672 roar_disconnect(&(g_cons.con));
673
[2124]674 return 0;
675}
676
677//ll
Note: See TracBrowser for help on using the repository browser.