Changeset 2141:ae202c734bd4 in roaraudio for roarclients/roarphone.c
- Timestamp:
- 07/24/09 04:19:27 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarphone.c
r2140 r2141 26 26 #include "driver.h" 27 27 28 #define BUFSIZE 1024 28 #ifdef ROAR_HAVE_LIBSPEEX 29 #include <speex/speex_echo.h> 30 #endif 31 32 #define TIMEDIV 100 29 33 30 34 #define DRIVER "oss" … … 34 38 #define AE_SIMPLE 1 35 39 #define AE_SPEEX 2 40 #define AE_ROARD 3 36 41 37 42 struct { … … 44 49 printf("\nOptions:\n\n"); 45 50 46 printf(" --server SERVER - Set server hostname\n" 47 " --rate RATE - Set sample rate\n" 48 " --bits BITS - Set bits per sample\n" 49 " --chans CHANNELS - Set number of channels\n" 50 " --codec CODEC - Set the codec\n" 51 " --driver DRIVER - Set the driver\n" 52 " --device DEVICE - Set the device\n" 53 " --help - Show this help\n" 51 printf(" --server SERVER - Set server hostname\n" 52 " --rate RATE - Set sample rate\n" 53 " --bits BITS - Set bits per sample\n" 54 " --chans CHANNELS - Set number of channels\n" 55 " --codec CODEC - Set the codec\n" 56 " --driver DRIVER - Set the driver\n" 57 " --device DEVICE - Set the device\n" 58 " --antiecho AEMODE - Set the anti echo mode\n" 59 " --help - Show this help\n" 54 60 ); 55 61 … … 64 70 } 65 71 66 int anti_echo16(int16_t * buf, int16_t * aebuf, size_t len) { 72 #ifdef ROAR_HAVE_LIBSPEEX 73 int anti_echo_speex16(int16_t * buf, int16_t * aebuf, size_t len, struct roar_audio_info * info) { 74 static SpeexEchoState * state = NULL; 75 size_t samples = info->rate / TIMEDIV; 76 static int16_t * obuf = NULL; 77 78 if ( info->channels != 1 ) 79 return -1; 80 81 if (len != samples) 82 return -1; 83 84 if ( state == NULL ) { 85 if ( (state = speex_echo_state_init(samples, 100*samples)) == NULL ) 86 return -1; 87 88 // todo: set sample rate. 89 } 90 91 if ( obuf == NULL ) { 92 if ( (obuf = malloc(2*samples)) == NULL ) 93 return -1; 94 } 95 96 /* 97 speex_echo_cancellation(state, buf, aebuf, obuf); 98 */ 99 100 speex_echo_cancel(state, buf, aebuf, obuf, NULL); 101 102 memcpy(buf, obuf, 2*samples); 103 104 return 0; 105 } 106 #endif 107 108 int anti_echo16(int16_t * buf, int16_t * aebuf, size_t len, struct roar_audio_info * info) { 67 109 size_t i; 68 110 … … 75 117 buf[i] -= aebuf[i]; 76 118 break; 119 #ifdef ROAR_HAVE_LIBSPEEX 120 case AE_SPEEX: 121 return anti_echo_speex16(buf, aebuf, len, info); 122 break; 123 #endif 77 124 default: 78 125 return -1; … … 88 135 ssize_t outlen, miclen; 89 136 90 len = (info->rate / 100) * info->channels * info->bits / 8;137 len = (info->rate / TIMEDIV) * info->channels * info->bits / 8; 91 138 92 139 if ( (outbuf = malloc(2*len)) == NULL ) … … 104 151 105 152 if ( g_conf.antiecho != AE_NONE ) 106 anti_echo16(outbuf, micbuf, ROAR_MIN(miclen, outlen)/2 );153 anti_echo16(outbuf, micbuf, ROAR_MIN(miclen, outlen)/2, info); 107 154 108 155 if ( roar_vio_write(s0, outbuf, outlen) != outlen ) … … 130 177 memset(&g_conf, 0, sizeof(g_conf)); 131 178 132 g_conf.antiecho = AE_ SIMPLE;179 g_conf.antiecho = AE_NONE; 133 180 134 181 for (i = 1; i < argc; i++) { … … 149 196 } else if ( strcmp(k, "--device") == 0 ) { 150 197 device = argv[++i]; 198 } else if ( strcmp(k, "--antiecho") == 0 ) { 199 k = argv[++i]; 200 if ( !strcmp(k, "none") ) { 201 g_conf.antiecho = AE_NONE; 202 } else if ( !strcmp(k, "simple") ) { 203 g_conf.antiecho = AE_SIMPLE; 204 } else if ( !strcmp(k, "speex") ) { 205 g_conf.antiecho = AE_SPEEX; 206 } else if ( !strcmp(k, "roard") ) { 207 g_conf.antiecho = AE_ROARD; 208 } else { 209 fprintf(stderr, "Error: unknown mode: %s\n", k); 210 return 1; 211 } 151 212 } else if ( strcmp(k, "--help") == 0 ) { 152 213 usage();
Note: See TracChangeset
for help on using the changeset viewer.