Changeset 2141:ae202c734bd4 in roaraudio


Ignore:
Timestamp:
07/24/09 04:19:27 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added old style speex AEC support

Location:
roarclients
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roarclients/Makefile

    r2131 r2141  
    5151        $L 
    5252roarphone: roarphone.o $(DRVOBJS) 
    53         ${CC} ${LDFLAGS} -o roarphone roarphone.o $(DRVOBJS) $(DSPLIBS) 
     53        ${CC} ${LDFLAGS} -o roarphone roarphone.o $(DRVOBJS) $(DSPLIBS) $(lib_speex) 
    5454roarfilt: roarfilt.o 
    5555        ${CC} ${LDFLAGS} -o roarfilt roarfilt.o $(DSPLIBS) 
  • roarclients/roarphone.c

    r2140 r2141  
    2626#include "driver.h" 
    2727 
    28 #define BUFSIZE 1024 
     28#ifdef ROAR_HAVE_LIBSPEEX 
     29#include <speex/speex_echo.h> 
     30#endif 
     31 
     32#define TIMEDIV  100 
    2933 
    3034#define DRIVER  "oss" 
     
    3438#define AE_SIMPLE    1 
    3539#define AE_SPEEX     2 
     40#define AE_ROARD     3 
    3641 
    3742struct { 
     
    4449 printf("\nOptions:\n\n"); 
    4550 
    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" 
    5460       ); 
    5561 
     
    6470} 
    6571 
    66 int anti_echo16(int16_t * buf, int16_t * aebuf, size_t len) { 
     72#ifdef ROAR_HAVE_LIBSPEEX 
     73int 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 
     108int anti_echo16(int16_t * buf, int16_t * aebuf, size_t len, struct roar_audio_info * info) { 
    67109 size_t i; 
    68110 
     
    75117     buf[i] -= aebuf[i]; 
    76118   break; 
     119#ifdef ROAR_HAVE_LIBSPEEX 
     120  case AE_SPEEX: 
     121    return anti_echo_speex16(buf, aebuf, len, info); 
     122   break; 
     123#endif 
    77124  default: 
    78125    return -1; 
     
    88135 ssize_t outlen, miclen; 
    89136 
    90  len = (info->rate / 100) * info->channels * info->bits / 8; 
     137 len = (info->rate / TIMEDIV) * info->channels * info->bits / 8; 
    91138 
    92139 if ( (outbuf = malloc(2*len)) == NULL ) 
     
    104151 
    105152  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); 
    107154 
    108155  if ( roar_vio_write(s0, outbuf, outlen) != outlen ) 
     
    130177 memset(&g_conf, 0, sizeof(g_conf)); 
    131178 
    132  g_conf.antiecho = AE_SIMPLE; 
     179 g_conf.antiecho = AE_NONE; 
    133180 
    134181 for (i = 1; i < argc; i++) { 
     
    149196  } else if ( strcmp(k, "--device") == 0 ) { 
    150197   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   } 
    151212  } else if ( strcmp(k, "--help") == 0 ) { 
    152213   usage(); 
Note: See TracChangeset for help on using the changeset viewer.