Changeset 5180:e8efeb11e78b in roaraudio


Ignore:
Timestamp:
10/22/11 14:17:16 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

updated roarfilt

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • include/roaraudio.h

    r5109 r5180  
    169169#include <libroar/libroar.h> 
    170170 
     171// Some settings for roard: 
     172#ifndef ROAR_ROARD_BITS 
     173#define ROAR_ROARD_BITS 32 
     174#endif 
     175 
    171176// Some glocal network defaults: 
    172177#ifndef ROAR_NET_INET4_LOCALHOST 
  • libroar/stream.c

    r5148 r5180  
    12681268                .channels = ROAR_CHANNELS_DEFAULT, 
    12691269                .codec    = ROAR_CODEC_DEFAULT}}, 
     1270 {"default-server", 
     1271               {.rate     = ROAR_RATE_DEFAULT, 
     1272                .bits     = ROAR_ROARD_BITS, 
     1273                .channels = ROAR_CHANNELS_DEFAULT, 
     1274                .codec    = ROAR_CODEC_DEFAULT}}, 
    12701275 {"wav",       {.rate     = ROAR_RATE_DEFAULT, 
    12711276                .bits     = ROAR_BITS_DEFAULT, 
  • roarclients/roarfilt.c

    r5179 r5180  
    5757        "  --div VAL          - Set div\n" 
    5858#ifdef ROAR_HAVE_LIBM 
    59         "  --lowpass freq     - lowpass filter\n" 
     59        "  --lowpass freq     - lowpass filter (obsolete)\n" 
    6060#endif 
    6161        "  --filter  name     - add filter name\n" 
     
    7171} 
    7272 
    73 void vol2 (void * data, int mul, int div, int len) { 
    74  int16_t * samples = (int16_t *) data; 
    75  int i; 
    76  
    77  len /= 2; 
    78  
    79  for (i = 0; i < len; i++) 
    80   samples[i] = ((int) samples[i] * mul) / div; 
    81 } 
    82  
    83 void vol1 (void * data, int mul, int div, int len) { 
    84  int8_t * samples = (int8_t *) data; 
    85  int i; 
    86  
    87  for (i = 0; i < len; i++) 
    88   samples[i] = ((int) samples[i] * mul) / div; 
    89 } 
     73#define _volX(bits,twobits,sf) \ 
     74void vol##bits (void * data, int32_t mul, int32_t div, size_t len) { \ 
     75 int##bits##_t * samples = (int##bits##_t *) data; \ 
     76 size_t i; \ 
     77\ 
     78 len /= sf; \ 
     79\ 
     80 for (i = 0; i < len; i++) \ 
     81  samples[i] = ((int##twobits##_t) samples[i] * mul) / div; \ 
     82} 
     83 
     84_volX( 8,16,1) 
     85_volX(16,32,2) 
     86_volX(32,64,4) 
    9087 
    9188#ifdef ROAR_HAVE_LIBM 
     
    139136 
    140137int main (int argc, char * argv[]) { 
    141  int    rate     = 44100; 
    142  int    bits     = 16; 
    143  int    channels = 2; 
    144  int    codec    = ROAR_CODEC_DEFAULT; 
    145  char * server   = NULL; 
    146  char * k; 
    147  int    i; 
    148  int    mul = 1, div = 1; 
    149  int    filter_id; 
     138 struct roar_audio_info info; 
     139 char  * server   = NULL; 
     140 char  * k; 
     141 int     i; 
     142 int32_t mul = 1, div = 1; 
     143 int     filter_id; 
    150144 int32_t tmp; 
    151  float  logscale = 0; 
    152  float  lp       = 0; 
    153  char buf[BUFFERSIZE]; 
     145 float   logscale = 0; 
     146 float   lp       = 0; 
     147 char    buf[BUFFERSIZE]; 
    154148 struct roardsp_filterchain fc; 
    155149 struct roardsp_filter      filter_real[8]; 
     
    158152 struct roar_vio_calls      svio; 
    159153 
     154 _LIBROAR_IGNORE_RET(roar_profile2info(&info, "default-server")); 
     155 info.codec = ROAR_CODEC_DEFAULT; 
     156 
    160157#ifdef ROAR_HAVE_LIBM 
    161158 memset(&g_lowpass, 0, sizeof(g_lowpass)); 
     
    170167   server = argv[++i]; 
    171168  } else if ( strcmp(k, "--rate") == 0 || strcmp(k, "-R") == 0 || strcmp(k, "-r") == 0 ) { 
    172    rate = roar_str2rate(argv[++i]); 
     169   info.rate = roar_str2rate(argv[++i]); 
    173170  } else if ( strcmp(k, "--bits") == 0 || strcmp(k, "-B") == 0 ) { 
    174    bits = roar_str2bits(argv[++i]); 
     171   info.bits = roar_str2bits(argv[++i]); 
    175172  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 || strcmp(k, "-C") == 0 ) { 
    176    channels = roar_str2channels(argv[++i]); 
     173   info.channels = roar_str2channels(argv[++i]); 
    177174  } else if ( strcmp(k, "-b") == 0 ) { 
    178    bits = 8; 
     175   info.bits = 8; 
    179176  } else if ( strcmp(k, "-m") == 0 ) { 
    180    channels = 1; 
     177   info.channels = 1; 
    181178  } else if ( strcmp(k, "--half") == 0 || strcmp(k, "-half") == 0 ) { 
    182179   div *= 2; 
     
    190187   div  = atoi(argv[++i]); 
    191188  } else if ( strcmp(k, "--log") == 0 ) { 
     189   ROAR_WARN("The logscaler is obsolete and will be removed soon."); 
    192190   logscale = atof(argv[++i]); 
    193191#ifdef ROAR_HAVE_LIBM 
    194192  } else if ( strcmp(k, "--lowpass") == 0 ) { 
    195    lp = exp(-2 * M_PI * atof(argv[++i]) / rate) * 65536; 
     193   ROAR_WARN("The builtin lowpass is obsolete and will be removed soon. Use --filter lowpass."); 
     194   lp = exp(-2 * M_PI * atof(argv[++i]) / info.rate) * 65536; 
    196195   g_lowpass.b = lp; 
    197196   g_lowpass.a = 65536 - lp; 
     
    199198//   printf("lowpass: A=%i, B=%i\n", g_lowpass.a, g_lowpass.b); 
    200199  } else if ( strcmp(k, "--filter") == 0 ) { 
    201    stream.info.channels = channels; 
    202    stream.info.bits     = bits; 
    203    stream.info.rate     = rate; 
     200   stream.info = info; 
    204201   filter_id = roardsp_filter_str2id(argv[++i]); 
    205202   if ( filter_id == -1 ) { 
     
    245242 } 
    246243 
    247  if ( roar_vio_simple_stream(&svio, rate, channels, bits, codec, server, ROAR_DIR_FILTER, "roarfilt") == -1 ) { 
     244 if ( roar_vio_simple_stream(&svio, 
     245                             info.rate, info.channels, info.bits, info.codec, 
     246                             server, ROAR_DIR_FILTER, "roarfilt") == -1 ) { 
    248247  fprintf(stderr, "Error: can not start playback\n"); 
    249248  return 1; 
     
    259258 } 
    260259 
    261  switch (bits) { 
     260 switch (info.bits) { 
    262261  case 8: 
    263262    while((i = roar_vio_read(&svio, buf, sizeof(buf)))) { 
    264      vol1((void*)buf, mul, div, i); 
    265      roardsp_fchain_calc(&fc, (void*)buf, (8*i)/bits); 
     263     vol8((void*)buf, mul, div, i); 
     264     roardsp_fchain_calc(&fc, (void*)buf, (8*i)/info.bits); 
    266265     if (roar_vio_write(&svio, buf, i) != i) 
    267266      break; 
     
    271270    while((i = roar_vio_read(&svio, buf, sizeof(buf)))) { 
    272271     if ( mul != div ) 
    273       vol2((void*)buf, mul, div, i); 
     272      vol16((void*)buf, mul, div, i); 
    274273#ifdef ROAR_HAVE_LIBM 
    275274     if ( logscale ) 
    276275      logs2((void*)buf, logscale, i); 
    277276     if ( g_lowpass.a ) 
    278       lowpass2((void*)buf, i, channels); 
    279 #endif 
    280      roardsp_fchain_calc(&fc, (void*)buf, (8*i)/bits); 
     277      lowpass2((void*)buf, i, info.channels); 
     278#endif 
     279     roardsp_fchain_calc(&fc, (void*)buf, (8*i)/info.bits); 
    281280     if (roar_vio_write(&svio, buf, i) != i) 
    282281      break; 
     
    285284  case 32: 
    286285    while((i = roar_vio_read(&svio, buf, sizeof(buf)))) { 
    287      roardsp_fchain_calc(&fc, (void*)buf, (8*i)/bits); 
     286     vol32((void*)buf, mul, div, i); 
     287     roardsp_fchain_calc(&fc, (void*)buf, (8*i)/info.bits); 
    288288     if (roar_vio_write(&svio, buf, i) != i) 
    289289      break; 
     
    291291   break; 
    292292  default: 
    293     fprintf(stderr, "Error: %i bits per sample is not supported!\n", bits); 
     293    fprintf(stderr, "Error: %i bits per sample is not supported!\n", (int)info.bits); 
    294294    return 1; 
    295295 } 
  • roard/include/roard.h

    r5140 r5180  
    189189int g_terminate; 
    190190 
    191 #ifndef ROAR_ROARD_BITS 
    192 #define ROAR_ROARD_BITS 32 
    193 #endif 
    194  
    195191struct roar_audio_info * g_sa, * g_max_sa; 
    196192 
  • roard/roard.c

    r5161 r5180  
    14361436 g_verbose       = ROAR_DBG_INFO_NONE; 
    14371437 
    1438  sa.bits     = ROAR_ROARD_BITS; 
    1439  sa.channels = ROAR_CHANNELS_DEFAULT; 
    1440  sa.rate     = ROAR_RATE_DEFAULT; 
    1441  sa.codec    = ROAR_CODEC_DEFAULT; 
     1438 _LIBROAR_IGNORE_RET(roar_profile2info(&sa, "default-server")); 
    14421439 
    14431440 g_sa        = &sa; 
Note: See TracChangeset for help on using the changeset viewer.