Changeset 5181:ca57e34b2a35 in roaraudio for libroardsp/filter_highp.c


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

updated filters to support 8 and 32 bit as well as 16 bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroardsp/filter_highp.c

    r4708 r5181  
    3030int roardsp_highp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 
    3131 struct roardsp_highp * self = roar_mm_malloc(sizeof(struct roardsp_highp)); 
    32  float freq = 25; 
    3332 
    3433 if ( self == NULL ) 
     
    3938 filter->inst = (void*) self; 
    4039 
    41  roardsp_highp_ctl(filter, ROARDSP_FCTL_FREQ, &freq); 
    42  
    43  return 0; 
     40 return roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 
    4441} 
    4542 
     
    5047} 
    5148 
    52 int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples) { 
    53  struct roardsp_highp * self = (struct roardsp_highp *) filter->inst; 
    54  int16_t * samp = (int16_t *) data; 
    55  register int32_t s, h; 
    56  int i, c; 
    57  int channels = filter->channels; 
     49#define _calcX(bits,twobits) \ 
     50int roardsp_highp_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ 
     51 struct roardsp_highp * self = (struct roardsp_highp *) filter->inst; \ 
     52 int##bits##_t * samp = (int##bits##_t *) data; \ 
     53 register int##twobits##_t s, h; \ 
     54 int i, c; \ 
     55 int channels = filter->channels; \ 
     56\ 
     57 if ( channels > ROAR_MAX_CHANNELS ) \ 
     58  return -1; \ 
     59\ 
     60 samples /= channels; \ 
     61\ 
     62 ROAR_DBG("roardsp_highp_calc16(*): filtering %i frames of %i channels...", samples, channels); \ 
     63\ 
     64/* *      output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1] */ \ 
     65\ 
     66\ 
     67 for (i = 0; i < samples; i++) { \ 
     68  for (c = 0; c < channels; c++) { \ 
     69   h = samp[i*channels + c]; \ 
     70   s = (int##twobits##_t)samp[i*channels + c] * self->a + (int##twobits##_t)self->oldin[c] * self->b + (int##twobits##_t)self->oldout[c] * self->c; \ 
     71\ 
     72   s /= 65536; \ 
     73\ 
     74   self->oldin[      c] = h; \ 
     75   samp[i*channels + c] = s; \ 
     76   self->oldout[     c] = s; \ 
     77  } \ 
     78 } \ 
     79\ 
     80 return 0; \ 
     81} 
    5882 
    59  if ( channels > ROAR_MAX_CHANNELS ) 
    60   return -1; 
    61  
    62  samples /= channels; 
    63  
    64  ROAR_DBG("roardsp_highp_calc16(*): filtering %i frames of %i channels...", samples, channels); 
    65  
    66 // *      output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1] 
    67  
    68  
    69  for (i = 0; i < samples; i++) { 
    70   for (c = 0; c < channels; c++) { 
    71    h = samp[i*channels + c]; 
    72    s = samp[i*channels + c] * self->a + self->oldin[c] * self->b + self->oldout[c] * self->c; 
    73  
    74    s /= 65536; 
    75  
    76    self->oldin[      c] = h; 
    77    samp[i*channels + c] = s; 
    78    self->oldout[     c] = s; 
    79   } 
    80  } 
    81  
    82  return 0; 
    83 } 
     83_calcX(8,32) /* we need 32 bit not 16 bit here as we multiplay with 65536 internally */ 
     84_calcX(16,32) 
     85_calcX(32,64) 
    8486 
    8587int roardsp_highp_ctl   (struct roardsp_filter * filter, int cmd, void * data) { 
     
    114116int roardsp_highp_reset (struct roardsp_filter * filter, int what) { 
    115117 struct roardsp_highp * self; 
    116  float freq = 25; 
     118 float freq = 25.; 
    117119 
    118120 if ( filter == NULL ) 
Note: See TracChangeset for help on using the changeset viewer.